better cleanup of recording libraries

pull/702/head
Luke Pulverenti 9 years ago
parent efe9fa8a8d
commit f54a0da88e

@ -20,12 +20,15 @@ namespace MediaBrowser.Model.LiveTv
public int PrePaddingSeconds { get; set; }
public int PostPaddingSeconds { get; set; }
public string[] MediaLocationsCreated { get; set; }
public LiveTvOptions()
{
EnableMovieProviders = true;
EnableRecordingSubfolders = true;
TunerHosts = new List<TunerHostInfo>();
ListingProviders = new List<ListingsProviderInfo>();
MediaLocationsCreated = new string[] { };
}
}

@ -115,17 +115,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
{
var recordingFolders = GetRecordingFolders();
var defaultRecordingPath = DefaultRecordingPath;
if (!recordingFolders.Any(i => i.Locations.Contains(defaultRecordingPath, StringComparer.OrdinalIgnoreCase)))
{
RemovePathFromLibrary(defaultRecordingPath);
}
var virtualFolders = _libraryManager.GetVirtualFolders()
.ToList();
var allExistingPaths = virtualFolders.SelectMany(i => i.Locations).ToList();
var pathsAdded = new List<string>();
foreach (var recordingFolder in recordingFolders)
{
var pathsToCreate = recordingFolder.Locations
@ -145,11 +141,33 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
{
_logger.ErrorException("Error creating virtual folder", ex);
}
pathsAdded.AddRange(pathsToCreate);
}
var config = GetConfiguration();
var pathsToRemove = config.MediaLocationsCreated
.Except(recordingFolders.SelectMany(i => i.Locations))
.ToList();
if (pathsAdded.Count > 0 || pathsToRemove.Count > 0)
{
pathsAdded.InsertRange(0, config.MediaLocationsCreated);
config.MediaLocationsCreated = pathsAdded.Except(pathsToRemove).Distinct(StringComparer.OrdinalIgnoreCase).ToArray();
_config.SaveConfiguration("livetv", config);
}
foreach (var path in pathsToRemove)
{
RemovePathFromLibrary(path);
}
}
private void RemovePathFromLibrary(string path)
{
_logger.Debug("Removing path from library: {0}", path);
var requiresRefresh = false;
var virtualFolders = _libraryManager.GetVirtualFolders()
.ToList();

Loading…
Cancel
Save