make library scan a bit more hands off

pull/702/head
Luke Pulverenti 10 years ago
parent 7a136349ee
commit 628c6cbc28

@ -4,9 +4,9 @@ using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.LiveTv;
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Users;
using System.Collections.Generic;
using System.Linq;
using MediaBrowser.Model.Users;
namespace MediaBrowser.Controller.LiveTv
{
@ -21,19 +21,6 @@ namespace MediaBrowser.Controller.LiveTv
return GetClientTypeName() + "-" + Name;
}
/// <summary>
/// Returns the folder containing the item.
/// If the item is a folder, it returns the folder itself
/// </summary>
/// <value>The containing folder path.</value>
public override string ContainingFolderPath
{
get
{
return Path;
}
}
protected override bool GetBlockUnratedValue(UserPolicy config)
{
return config.BlockUnratedItems.Contains(UnratedItem.LiveTvChannel);
@ -51,11 +38,6 @@ namespace MediaBrowser.Controller.LiveTv
}
}
public override bool IsSaveLocalMetadataEnabled()
{
return true;
}
/// <summary>
/// Gets or sets the number.
/// </summary>

@ -61,7 +61,6 @@
<Compile Include="Providers\AlbumXmlProvider.cs" />
<Compile Include="Providers\ArtistXmlProvider.cs" />
<Compile Include="Providers\BoxSetXmlProvider.cs" />
<Compile Include="Providers\ChannelXmlProvider.cs" />
<Compile Include="Providers\EpisodeXmlProvider.cs" />
<Compile Include="Providers\FolderXmlProvider.cs" />
<Compile Include="Providers\GameSystemXmlProvider.cs" />
@ -74,7 +73,6 @@
<Compile Include="Providers\SeriesXmlProvider.cs" />
<Compile Include="Providers\VideoXmlProvider.cs" />
<Compile Include="Savers\BoxSetXmlSaver.cs" />
<Compile Include="Savers\ChannelXmlSaver.cs" />
<Compile Include="Savers\EpisodeXmlSaver.cs" />
<Compile Include="Savers\FolderXmlSaver.cs" />
<Compile Include="Savers\GameSystemXmlSaver.cs" />

@ -1,30 +0,0 @@
using System.IO;
using System.Threading;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Logging;
namespace MediaBrowser.LocalMetadata.Providers
{
public class ChannelXmlProvider : BaseXmlProvider<LiveTvChannel>
{
private readonly ILogger _logger;
public ChannelXmlProvider(IFileSystem fileSystem, ILogger logger)
: base(fileSystem)
{
_logger = logger;
}
protected override void Fetch(LocalMetadataResult<LiveTvChannel> result, string path, CancellationToken cancellationToken)
{
new BaseItemXmlParser<LiveTvChannel>(_logger).Fetch(result.Item, path, cancellationToken);
}
protected override FileSystemInfo GetXmlFile(ItemInfo info, IDirectoryService directoryService)
{
return directoryService.GetFile(Path.Combine(info.Path, "channel.xml"));
}
}
}

@ -1,81 +0,0 @@
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
namespace MediaBrowser.LocalMetadata.Savers
{
/// <summary>
/// Class PersonXmlSaver
/// </summary>
public class ChannelXmlSaver : IMetadataFileSaver
{
private readonly IServerConfigurationManager _config;
public ChannelXmlSaver(IServerConfigurationManager config)
{
_config = config;
}
/// <summary>
/// Determines whether [is enabled for] [the specified item].
/// </summary>
/// <param name="item">The item.</param>
/// <param name="updateType">Type of the update.</param>
/// <returns><c>true</c> if [is enabled for] [the specified item]; otherwise, <c>false</c>.</returns>
public bool IsEnabledFor(IHasMetadata item, ItemUpdateType updateType)
{
if (!item.SupportsLocalMetadata)
{
return false;
}
return item is LiveTvChannel && updateType >= ItemUpdateType.MetadataDownload;
}
public string Name
{
get
{
return XmlProviderUtils.Name;
}
}
/// <summary>
/// Saves the specified item.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
public void Save(IHasMetadata item, CancellationToken cancellationToken)
{
var builder = new StringBuilder();
builder.Append("<Item>");
XmlSaverHelpers.AddCommonNodes((LiveTvChannel)item, builder);
builder.Append("</Item>");
var xmlFilePath = GetSavePath(item);
XmlSaverHelpers.Save(builder, xmlFilePath, new List<string>
{
}, _config);
}
/// <summary>
/// Gets the save path.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>System.String.</returns>
public string GetSavePath(IHasMetadata item)
{
return Path.Combine(item.Path, "channel.xml");
}
}
}

@ -62,6 +62,8 @@ namespace MediaBrowser.Model.Users
EnableLiveTvAccess = true;
EnableSharedDeviceControl = true;
EnabledChannels = new string[] { };
BlockedMediaFolders = new string[] { };
BlockedTags = new string[] { };
BlockUnratedItems = new UnratedItem[] { };

@ -12,6 +12,7 @@ using MediaBrowser.Providers.Manager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MediaBrowser.Providers.BoxSets
{
@ -51,10 +52,12 @@ namespace MediaBrowser.Providers.BoxSets
}
}
protected override ItemUpdateType BeforeSave(BoxSet item)
protected override async Task<ItemUpdateType> BeforeSave(BoxSet item, bool isFullRefresh, ItemUpdateType currentUpdateType)
{
var updateType = base.BeforeSave(item);
var updateType = await base.BeforeSave(item, isFullRefresh, currentUpdateType).ConfigureAwait(false);
if (isFullRefresh || currentUpdateType > ItemUpdateType.None)
{
if (!item.LockedFields.Contains(MetadataFields.OfficialRating))
{
var currentOfficialRating = item.OfficialRating;
@ -78,6 +81,7 @@ namespace MediaBrowser.Providers.BoxSets
updateType = updateType | ItemUpdateType.MetadataEdit;
}
}
}
return updateType;
}

@ -163,14 +163,13 @@ namespace MediaBrowser.Providers.Manager
}
}
updateType = updateType | BeforeSave(itemOfType);
var providersHadChanges = updateType > ItemUpdateType.None;
updateType = updateType | (await BeforeSave(itemOfType, item.DateLastSaved == default(DateTime) || refreshOptions.ReplaceAllMetadata, updateType).ConfigureAwait(false));
// Save if changes were made, or it's never been saved before
if (refreshOptions.ForceSave || providersHadChanges || item.DateLastSaved == default(DateTime) || refreshOptions.ReplaceAllMetadata)
if (refreshOptions.ForceSave || updateType > ItemUpdateType.None || item.DateLastSaved == default(DateTime) || refreshOptions.ReplaceAllMetadata)
{
if (refreshOptions.ForceSave || providersHadChanges || refreshOptions.ReplaceAllMetadata)
// If any of these properties are set then make sure the updateType is not None, just to force everything to save
if (refreshOptions.ForceSave || refreshOptions.ReplaceAllMetadata)
{
updateType = updateType | ItemUpdateType.MetadataDownload;
}
@ -179,7 +178,7 @@ namespace MediaBrowser.Providers.Manager
await SaveItem(itemOfType, updateType, cancellationToken);
}
if (providersHadChanges || refreshResult.IsDirty)
if (updateType > ItemUpdateType.None || refreshResult.IsDirty)
{
await SaveProviderResult(itemOfType, refreshResult, refreshOptions.DirectoryService).ConfigureAwait(false);
}
@ -194,14 +193,17 @@ namespace MediaBrowser.Providers.Manager
}
}
private readonly Task<ItemUpdateType> _cachedResult = Task.FromResult(ItemUpdateType.None);
/// <summary>
/// Befores the save.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="isFullRefresh">if set to <c>true</c> [is full refresh].</param>
/// <param name="currentUpdateType">Type of the current update.</param>
/// <returns>ItemUpdateType.</returns>
protected virtual ItemUpdateType BeforeSave(TItemType item)
protected virtual Task<ItemUpdateType> BeforeSave(TItemType item, bool isFullRefresh, ItemUpdateType currentUpdateType)
{
return ItemUpdateType.None;
return _cachedResult;
}
/// <summary>
@ -549,11 +551,6 @@ namespace MediaBrowser.Providers.Manager
}
}
if (refreshResult.Successes > 0)
{
AfterRemoteRefresh(temp);
}
return refreshResult;
}
@ -570,11 +567,6 @@ namespace MediaBrowser.Providers.Manager
}
}
protected virtual void AfterRemoteRefresh(TItemType item)
{
}
private async Task<TIdType> CreateInitialLookupInfo(TItemType item, CancellationToken cancellationToken)
{
var info = item.GetLookupInfo();

@ -9,6 +9,7 @@ using MediaBrowser.Providers.Manager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MediaBrowser.Providers.Music
{
@ -36,14 +37,16 @@ namespace MediaBrowser.Providers.Music
}
}
protected override ItemUpdateType BeforeSave(MusicAlbum item)
protected override async Task<ItemUpdateType> BeforeSave(MusicAlbum item, bool isFullRefresh, ItemUpdateType currentUpdateType)
{
var updateType = base.BeforeSave(item);
var songs = item.RecursiveChildren.OfType<Audio>().ToList();
var updateType = await base.BeforeSave(item, isFullRefresh, currentUpdateType).ConfigureAwait(false);
if (isFullRefresh || currentUpdateType > ItemUpdateType.None)
{
if (!item.IsLocked)
{
var songs = item.RecursiveChildren.OfType<Audio>().ToList();
if (!item.LockedFields.Contains(MetadataFields.Genres))
{
var currentList = item.Genres.ToList();
@ -90,6 +93,7 @@ namespace MediaBrowser.Providers.Music
updateType = updateType | SetArtistsFromSongs(item, songs);
updateType = updateType | SetDateFromSongs(item, songs);
}
}
return updateType;
}

@ -9,13 +9,17 @@ using MediaBrowser.Providers.Manager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MediaBrowser.Providers.Music
{
public class ArtistMetadataService : MetadataService<MusicArtist, ArtistInfo>
{
public ArtistMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IProviderRepository providerRepo, IFileSystem fileSystem, IUserDataManager userDataManager) : base(serverConfigurationManager, logger, providerManager, providerRepo, fileSystem, userDataManager)
private readonly ILibraryManager _libraryManager;
public ArtistMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IProviderRepository providerRepo, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, providerRepo, fileSystem, userDataManager)
{
_libraryManager = libraryManager;
}
/// <summary>
@ -31,19 +35,23 @@ namespace MediaBrowser.Providers.Music
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
}
protected override ItemUpdateType BeforeSave(MusicArtist item)
protected override async Task<ItemUpdateType> BeforeSave(MusicArtist item, bool isFullRefresh, ItemUpdateType currentUpdateType)
{
var updateType = base.BeforeSave(item);
var updateType = await base.BeforeSave(item, isFullRefresh, currentUpdateType).ConfigureAwait(false);
if (!item.IsAccessedByName && !item.IsLocked)
if (isFullRefresh || currentUpdateType > ItemUpdateType.None)
{
if (!item.LockedFields.Contains(MetadataFields.Genres))
if (!item.IsLocked)
{
var songs = item.RecursiveChildren.OfType<Audio>().ToList();
var taggedItems = item.IsAccessedByName ?
item.GetTaggedItems(_libraryManager.RootFolder.RecursiveChildren.Where(i => i is IHasArtist && !i.IsFolder)).ToList() :
item.RecursiveChildren.Where(i => i is IHasArtist && !i.IsFolder).ToList();
if (!item.LockedFields.Contains(MetadataFields.Genres))
{
var currentList = item.Genres.ToList();
item.Genres = songs.SelectMany(i => i.Genres)
item.Genres = taggedItems.SelectMany(i => i.Genres)
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
@ -53,6 +61,7 @@ namespace MediaBrowser.Providers.Music
}
}
}
}
return updateType;
}

@ -1,10 +1,11 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Localization;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using System;
using System.Globalization;
using System.Linq;
using System.Threading;
@ -17,18 +18,22 @@ namespace MediaBrowser.Providers.TV
private readonly IServerConfigurationManager _config;
private readonly ILogger _logger;
private readonly ILocalizationManager _localization;
private readonly ILibraryManager _libraryManager;
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
public DummySeasonProvider(IServerConfigurationManager config, ILogger logger, ILocalizationManager localization)
public DummySeasonProvider(IServerConfigurationManager config, ILogger logger, ILocalizationManager localization, ILibraryManager libraryManager)
{
_config = config;
_logger = logger;
_localization = localization;
_libraryManager = libraryManager;
}
public async Task Run(Series series, CancellationToken cancellationToken)
{
await RemoveObsoleteSeasons(series).ConfigureAwait(false);
var hasNewSeasons = await AddDummySeasonFolders(series, cancellationToken).ConfigureAwait(false);
if (hasNewSeasons)
@ -117,5 +122,61 @@ namespace MediaBrowser.Providers.TV
return season;
}
private async Task<bool> RemoveObsoleteSeasons(Series series)
{
var existingSeasons = series.Children.OfType<Season>().ToList();
var physicalSeasons = existingSeasons
.Where(i => i.LocationType != LocationType.Virtual)
.ToList();
var virtualSeasons = existingSeasons
.Where(i => i.LocationType == LocationType.Virtual)
.ToList();
var episodes = series.RecursiveChildren.OfType<Episode>().ToList();
var seasonsToRemove = virtualSeasons
.Where(i =>
{
if (i.IndexNumber.HasValue)
{
var seasonNumber = i.IndexNumber.Value;
// If there's a physical season with the same number, delete it
if (physicalSeasons.Any(p => p.IndexNumber.HasValue && (p.IndexNumber.Value == seasonNumber)))
{
return true;
}
// If there are no episodes with this season number, delete it
if (episodes.All(e => !e.ParentIndexNumber.HasValue || e.ParentIndexNumber.Value != seasonNumber))
{
return true;
}
return false;
}
// Season does not have a number
// Remove if there are no episodes directly in series without a season number
return episodes.All(s => s.ParentIndexNumber.HasValue || !s.IsInSeasonFolder);
})
.ToList();
var hasChanges = false;
foreach (var seasonToRemove in seasonsToRemove)
{
_logger.Info("Removing virtual season {0} {1}", seasonToRemove.Series.Name, seasonToRemove.IndexNumber);
await _libraryManager.DeleteItem(seasonToRemove).ConfigureAwait(false);
hasChanges = true;
}
return hasChanges;
}
}
}

@ -361,7 +361,7 @@ namespace MediaBrowser.Providers.TV
// Season does not have a number
// Remove if there are no episodes directly in series without a season number
return i.Season.Series.RecursiveChildren.OfType<Episode>().All(s => s.ParentIndexNumber.HasValue || s.IsInSeasonFolder);
return i.Season.Series.RecursiveChildren.OfType<Episode>().All(s => s.ParentIndexNumber.HasValue || !s.IsInSeasonFolder);
})
.ToList();
@ -394,7 +394,7 @@ namespace MediaBrowser.Providers.TV
if (season == null)
{
var provider = new DummySeasonProvider(_config, _logger, _localization);
var provider = new DummySeasonProvider(_config, _logger, _localization, _libraryManager);
season = await provider.AddSeason(series, seasonNumber, cancellationToken).ConfigureAwait(false);
}

@ -6,7 +6,9 @@ using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Providers.Manager;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace MediaBrowser.Providers.TV
{
@ -29,14 +31,20 @@ namespace MediaBrowser.Providers.TV
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
}
protected override void AfterRemoteRefresh(Season item)
protected override async Task<ItemUpdateType> BeforeSave(Season item, bool isFullRefresh, ItemUpdateType currentUpdateType)
{
base.AfterRemoteRefresh(item);
var updateType = await base.BeforeSave(item, isFullRefresh, currentUpdateType).ConfigureAwait(false);
if (item.IndexNumber.HasValue && item.IndexNumber.Value == 0)
{
if (!string.Equals(item.Name, ServerConfigurationManager.Configuration.SeasonZeroDisplayName, StringComparison.OrdinalIgnoreCase))
{
item.Name = ServerConfigurationManager.Configuration.SeasonZeroDisplayName;
updateType = updateType | ItemUpdateType.MetadataEdit;
}
}
return updateType;
}
}
}

@ -2,18 +2,26 @@
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Localization;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Providers.Manager;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Providers.TV
{
public class SeriesMetadataService : MetadataService<Series, SeriesInfo>
{
public SeriesMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IProviderRepository providerRepo, IFileSystem fileSystem, IUserDataManager userDataManager) : base(serverConfigurationManager, logger, providerManager, providerRepo, fileSystem, userDataManager)
private readonly ILocalizationManager _localization;
private readonly ILibraryManager _libraryManager;
public SeriesMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IProviderRepository providerRepo, IFileSystem fileSystem, IUserDataManager userDataManager, ILocalizationManager localization, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, providerRepo, fileSystem, userDataManager)
{
_localization = localization;
_libraryManager = libraryManager;
}
/// <summary>
@ -53,5 +61,16 @@ namespace MediaBrowser.Providers.TV
target.DisplaySpecialsWithSeasons = source.DisplaySpecialsWithSeasons;
}
}
protected override async Task<ItemUpdateType> BeforeSave(Series item, bool isFullRefresh, ItemUpdateType currentUpdateType)
{
var updateType = await base.BeforeSave(item, isFullRefresh, currentUpdateType).ConfigureAwait(false);
//var provider = new DummySeasonProvider(ServerConfigurationManager, Logger, _localization, _libraryManager);
//await provider.Run(item, CancellationToken.None).ConfigureAwait(false);
return updateType;
}
}
}

@ -48,7 +48,7 @@ namespace MediaBrowser.Providers.TV
.OfType<Series>()
.ToList();
var provider = new DummySeasonProvider(_config, _logger, _localization);
var provider = new DummySeasonProvider(_config, _logger, _localization, _libraryManager);
foreach (var series in seriesList)
{

@ -985,76 +985,6 @@ namespace MediaBrowser.Server.Implementations.Library
return new PeopleValidator(this, _logger, ConfigurationManager).ValidatePeople(cancellationToken, progress);
}
/// <summary>
/// Validates the artists.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress.</param>
/// <returns>Task.</returns>
public Task ValidateArtists(CancellationToken cancellationToken, IProgress<double> progress)
{
// Ensure the location is unavailable.
Directory.CreateDirectory(ArtistsPath);
return new ArtistsValidator(this, _userManager, _logger).Run(progress, cancellationToken);
}
/// <summary>
/// Validates the music genres.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress.</param>
/// <returns>Task.</returns>
public Task ValidateMusicGenres(CancellationToken cancellationToken, IProgress<double> progress)
{
// Ensure the location is unavailable.
Directory.CreateDirectory(ConfigurationManager.ApplicationPaths.MusicGenrePath);
return new MusicGenresValidator(this, _logger).Run(progress, cancellationToken);
}
/// <summary>
/// Validates the game genres.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress.</param>
/// <returns>Task.</returns>
public Task ValidateGameGenres(CancellationToken cancellationToken, IProgress<double> progress)
{
// Ensure the location is unavailable.
Directory.CreateDirectory(ConfigurationManager.ApplicationPaths.GameGenrePath);
return new GameGenresValidator(this, _userManager, _logger).Run(progress, cancellationToken);
}
/// <summary>
/// Validates the studios.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress.</param>
/// <returns>Task.</returns>
public Task ValidateStudios(CancellationToken cancellationToken, IProgress<double> progress)
{
// Ensure the location is unavailable.
Directory.CreateDirectory(ConfigurationManager.ApplicationPaths.StudioPath);
return new StudiosValidator(this, _userManager, _logger).Run(progress, cancellationToken);
}
/// <summary>
/// Validates the genres.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress.</param>
/// <returns>Task.</returns>
public Task ValidateGenres(CancellationToken cancellationToken, IProgress<double> progress)
{
// Ensure the location is unavailable.
Directory.CreateDirectory(ConfigurationManager.ApplicationPaths.GenrePath);
return new GenresValidator(this, _userManager, _logger).Run(progress, cancellationToken);
}
/// <summary>
/// Reloads the root media folder
/// </summary>

@ -6,11 +6,10 @@ using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Naming.Audio;
using MediaBrowser.Naming.Common;
using MediaBrowser.Server.Implementations.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using MediaBrowser.Server.Implementations.Logging;
namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
{

@ -1,4 +1,5 @@
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
@ -14,14 +15,16 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
/// The _library manager
/// </summary>
private readonly ILibraryManager _libraryManager;
private readonly ILogger _logger;
/// <summary>
/// Initializes a new instance of the <see cref="ArtistsPostScanTask" /> class.
/// </summary>
/// <param name="libraryManager">The library manager.</param>
public ArtistsPostScanTask(ILibraryManager libraryManager)
public ArtistsPostScanTask(ILibraryManager libraryManager, ILogger logger)
{
_libraryManager = libraryManager;
_logger = logger;
}
/// <summary>
@ -32,7 +35,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
/// <returns>Task.</returns>
public Task Run(IProgress<double> progress, CancellationToken cancellationToken)
{
return ((LibraryManager)_libraryManager).ValidateArtists(cancellationToken, progress);
return new ArtistsValidator(_libraryManager, _logger).Run(progress, cancellationToken);
}
}
}

@ -1,7 +1,5 @@
using MediaBrowser.Common.Progress;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
@ -22,11 +20,6 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
/// </summary>
private readonly ILibraryManager _libraryManager;
/// <summary>
/// The _user manager
/// </summary>
private readonly IUserManager _userManager;
/// <summary>
/// The _logger
/// </summary>
@ -36,12 +29,10 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
/// Initializes a new instance of the <see cref="ArtistsPostScanTask" /> class.
/// </summary>
/// <param name="libraryManager">The library manager.</param>
/// <param name="userManager">The user manager.</param>
/// <param name="logger">The logger.</param>
public ArtistsValidator(ILibraryManager libraryManager, IUserManager userManager, ILogger logger)
public ArtistsValidator(ILibraryManager libraryManager, ILogger logger)
{
_libraryManager = libraryManager;
_userManager = userManager;
_logger = logger;
}
@ -55,56 +46,8 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
{
var allItems = _libraryManager.RootFolder.GetRecursiveChildren();
var allSongs = allItems.OfType<Audio>().ToList();
var innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(pct => progress.Report(pct * .8));
var allArtists = await GetAllArtists(allSongs, cancellationToken, innerProgress).ConfigureAwait(false);
progress.Report(80);
var numComplete = 0;
var numArtists = allArtists.Count;
var allSongs = allItems.Where(i => !i.IsFolder).OfType<IHasArtist>().ToList();
foreach (var artist in allArtists)
{
cancellationToken.ThrowIfCancellationRequested();
// Only do this for artists accessed by name. Folder-based artists get it from the normal refresh
if (artist.IsAccessedByName && !artist.LockedFields.Contains(MetadataFields.Genres))
{
// Avoid implicitly captured closure
var artist1 = artist;
artist.Genres = allSongs.Where(i => i.HasArtist(artist1.Name))
.SelectMany(i => i.Genres)
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
}
numComplete++;
double percent = numComplete;
percent /= numArtists;
percent *= 20;
progress.Report(80 + percent);
}
progress.Report(100);
}
/// <summary>
/// Gets all artists.
/// </summary>
/// <param name="allSongs">All songs.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress.</param>
/// <returns>Task{Artist[]}.</returns>
private async Task<List<MusicArtist>> GetAllArtists(IEnumerable<Audio> allSongs, CancellationToken cancellationToken, IProgress<double> progress)
{
var allArtists = allSongs.SelectMany(i => i.AllArtists)
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
@ -138,8 +81,6 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
progress.Report(100 * percent);
}
return returnArtists;
}
}
}

@ -1,4 +1,5 @@
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
@ -14,14 +15,17 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
/// The _library manager
/// </summary>
private readonly ILibraryManager _libraryManager;
private readonly ILogger _logger;
/// <summary>
/// Initializes a new instance of the <see cref="GameGenresPostScanTask" /> class.
/// </summary>
/// <param name="libraryManager">The library manager.</param>
public GameGenresPostScanTask(ILibraryManager libraryManager)
/// <param name="logger">The logger.</param>
public GameGenresPostScanTask(ILibraryManager libraryManager, ILogger logger)
{
_libraryManager = libraryManager;
_logger = logger;
}
/// <summary>
@ -32,7 +36,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
/// <returns>Task.</returns>
public Task Run(IProgress<double> progress, CancellationToken cancellationToken)
{
return ((LibraryManager)_libraryManager).ValidateGameGenres(cancellationToken, progress);
return new GameGenresValidator(_libraryManager, _logger).Run(progress, cancellationToken);
}
}
}

@ -15,20 +15,14 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
/// </summary>
private readonly ILibraryManager _libraryManager;
/// <summary>
/// The _user manager
/// </summary>
private readonly IUserManager _userManager;
/// <summary>
/// The _logger
/// </summary>
private readonly ILogger _logger;
public GameGenresValidator(ILibraryManager libraryManager, IUserManager userManager, ILogger logger)
public GameGenresValidator(ILibraryManager libraryManager, ILogger logger)
{
_libraryManager = libraryManager;
_userManager = userManager;
_logger = logger;
}
@ -45,14 +39,11 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
progress.Report(2);
var numComplete = 0;
var count = items.Count;
foreach (var name in items)
{
cancellationToken.ThrowIfCancellationRequested();
try
{
var itemByName = _libraryManager.GetGameGenre(name);
@ -72,9 +63,9 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
numComplete++;
double percent = numComplete;
percent /= count;
percent *= 90;
percent *= 100;
progress.Report(percent + 10);
progress.Report(percent);
}
progress.Report(100);

@ -2,6 +2,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Logging;
namespace MediaBrowser.Server.Implementations.Library.Validators
{
@ -11,14 +12,17 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
/// The _library manager
/// </summary>
private readonly ILibraryManager _libraryManager;
private readonly ILogger _logger;
/// <summary>
/// Initializes a new instance of the <see cref="ArtistsPostScanTask" /> class.
/// </summary>
/// <param name="libraryManager">The library manager.</param>
public GenresPostScanTask(ILibraryManager libraryManager)
/// <param name="logger">The logger.</param>
public GenresPostScanTask(ILibraryManager libraryManager, ILogger logger)
{
_libraryManager = libraryManager;
_logger = logger;
}
/// <summary>
@ -29,7 +33,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
/// <returns>Task.</returns>
public Task Run(IProgress<double> progress, CancellationToken cancellationToken)
{
return ((LibraryManager)_libraryManager).ValidateGenres(cancellationToken, progress);
return new GenresValidator(_libraryManager, _logger).Run(progress, cancellationToken);
}
}
}

@ -16,20 +16,14 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
/// </summary>
private readonly ILibraryManager _libraryManager;
/// <summary>
/// The _user manager
/// </summary>
private readonly IUserManager _userManager;
/// <summary>
/// The _logger
/// </summary>
private readonly ILogger _logger;
public GenresValidator(ILibraryManager libraryManager, IUserManager userManager, ILogger logger)
public GenresValidator(ILibraryManager libraryManager, ILogger logger)
{
_libraryManager = libraryManager;
_userManager = userManager;
_logger = logger;
}
@ -46,14 +40,11 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
progress.Report(2);
var numComplete = 0;
var count = items.Count;
foreach (var name in items)
{
cancellationToken.ThrowIfCancellationRequested();
try
{
var itemByName = _libraryManager.GetGenre(name);
@ -73,9 +64,9 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
numComplete++;
double percent = numComplete;
percent /= count;
percent *= 90;
percent *= 100;
progress.Report(percent + 10);
progress.Report(percent);
}
progress.Report(100);

@ -1,4 +1,5 @@
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
@ -14,14 +15,17 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
/// The _library manager
/// </summary>
private readonly ILibraryManager _libraryManager;
private readonly ILogger _logger;
/// <summary>
/// Initializes a new instance of the <see cref="ArtistsPostScanTask" /> class.
/// </summary>
/// <param name="libraryManager">The library manager.</param>
public MusicGenresPostScanTask(ILibraryManager libraryManager)
/// <param name="logger">The logger.</param>
public MusicGenresPostScanTask(ILibraryManager libraryManager, ILogger logger)
{
_libraryManager = libraryManager;
_logger = logger;
}
/// <summary>
@ -32,7 +36,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
/// <returns>Task.</returns>
public Task Run(IProgress<double> progress, CancellationToken cancellationToken)
{
return ((LibraryManager)_libraryManager).ValidateMusicGenres(cancellationToken, progress);
return new MusicGenresValidator(_libraryManager, _logger).Run(progress, cancellationToken);
}
}
}

@ -39,14 +39,11 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
progress.Report(2);
var numComplete = 0;
var count = items.Count;
foreach (var name in items)
{
cancellationToken.ThrowIfCancellationRequested();
try
{
var itemByName = _libraryManager.GetMusicGenre(name);
@ -66,9 +63,9 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
numComplete++;
double percent = numComplete;
percent /= count;
percent *= 90;
percent *= 100;
progress.Report(percent + 10);
progress.Report(percent);
}
progress.Report(100);

@ -1,4 +1,5 @@
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
@ -15,13 +16,16 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
/// </summary>
private readonly ILibraryManager _libraryManager;
private readonly ILogger _logger;
/// <summary>
/// Initializes a new instance of the <see cref="ArtistsPostScanTask" /> class.
/// </summary>
/// <param name="libraryManager">The library manager.</param>
public StudiosPostScanTask(ILibraryManager libraryManager)
public StudiosPostScanTask(ILibraryManager libraryManager, ILogger logger)
{
_libraryManager = libraryManager;
_logger = logger;
}
/// <summary>
@ -32,7 +36,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
/// <returns>Task.</returns>
public Task Run(IProgress<double> progress, CancellationToken cancellationToken)
{
return ((LibraryManager)_libraryManager).ValidateStudios(cancellationToken, progress);
return new StudiosValidator(_libraryManager, _logger).Run(progress, cancellationToken);
}
}
}

@ -14,20 +14,14 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
/// </summary>
private readonly ILibraryManager _libraryManager;
/// <summary>
/// The _user manager
/// </summary>
private readonly IUserManager _userManager;
/// <summary>
/// The _logger
/// </summary>
private readonly ILogger _logger;
public StudiosValidator(ILibraryManager libraryManager, IUserManager userManager, ILogger logger)
public StudiosValidator(ILibraryManager libraryManager, ILogger logger)
{
_libraryManager = libraryManager;
_userManager = userManager;
_logger = logger;
}
@ -44,14 +38,11 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
progress.Report(2);
var numComplete = 0;
var count = items.Count;
foreach (var name in items)
{
cancellationToken.ThrowIfCancellationRequested();
try
{
var itemByName = _libraryManager.GetStudio(name);
@ -71,9 +62,9 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
numComplete++;
double percent = numComplete;
percent /= count;
percent *= 90;
percent *= 100;
progress.Report(percent + 10);
progress.Report(percent);
}
progress.Report(100);

@ -26,17 +26,15 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
.Distinct()
.ToList();
progress.Report(10);
var count = allYears.Count;
var numComplete = 0;
foreach (var yearNumber in allYears)
{
var year = _libraryManager.GetYear(yearNumber);
try
{
var year = _libraryManager.GetYear(yearNumber);
await year.RefreshMetadata(cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException)
@ -46,15 +44,15 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
}
catch (Exception ex)
{
_logger.ErrorException("Error refreshing year {0}", ex, year);
_logger.ErrorException("Error refreshing year {0}", ex, yearNumber);
}
numComplete++;
double percent = numComplete;
percent /= count;
percent *= 90;
percent *= 100;
progress.Report(percent + 10);
progress.Report(percent);
}
}
}

@ -436,40 +436,19 @@ namespace MediaBrowser.Server.Implementations.LiveTv
private async Task<LiveTvChannel> GetChannel(ChannelInfo channelInfo, string serviceName, CancellationToken cancellationToken)
{
var path = Path.Combine(_config.ApplicationPaths.ItemsByNamePath, "tvchannels", _fileSystem.GetValidFilename(channelInfo.Name));
var fileInfo = new DirectoryInfo(path);
var isNew = false;
if (!fileInfo.Exists)
{
_logger.Debug("Creating directory {0}", path);
Directory.CreateDirectory(path);
fileInfo = new DirectoryInfo(path);
if (!fileInfo.Exists)
{
throw new IOException("Path not created: " + path);
}
isNew = true;
}
var id = _tvDtoService.GetInternalChannelId(serviceName, channelInfo.Id);
var item = _itemRepo.RetrieveItem(id) as LiveTvChannel;
if (item == null || !string.Equals(item.Path, path, StringComparison.OrdinalIgnoreCase))
if (item == null)
{
item = new LiveTvChannel
{
Name = channelInfo.Name,
Id = id,
DateCreated = _fileSystem.GetCreationTimeUtc(fileInfo),
DateModified = _fileSystem.GetLastWriteTimeUtc(fileInfo),
Path = path
DateCreated = DateTime.UtcNow,
};
isNew = true;

Loading…
Cancel
Save