diff options
9 files changed, 76 insertions, 72 deletions
diff --git a/MediaBrowser.Api/Music/InstantMixService.cs b/MediaBrowser.Api/Music/InstantMixService.cs index 506b7bc3a..905ead86c 100644 --- a/MediaBrowser.Api/Music/InstantMixService.cs +++ b/MediaBrowser.Api/Music/InstantMixService.cs @@ -138,8 +138,9 @@ namespace MediaBrowser.Api.Music public object Get(GetInstantMixFromArtist request) { var user = _userManager.GetUserById(request.UserId); + var artist = _libraryManager.GetArtist(request.Name); - var items = _musicManager.GetInstantMixFromArtist(request.Name, user); + var items = _musicManager.GetInstantMixFromArtist(artist, user); return GetResult(items, user, request); } diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index 6906a25fb..9331ca759 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -502,5 +502,12 @@ namespace MediaBrowser.Controller.Library /// <param name="query">The query.</param> /// <returns>List<System.String>.</returns> List<string> GetPeopleNames(InternalPeopleQuery query); + + /// <summary> + /// Queries the items. + /// </summary> + /// <param name="query">The query.</param> + /// <returns>QueryResult<BaseItem>.</returns> + QueryResult<BaseItem> QueryItems(InternalItemsQuery query); } }
\ No newline at end of file diff --git a/MediaBrowser.Controller/Library/IMusicManager.cs b/MediaBrowser.Controller/Library/IMusicManager.cs index 0ce0687cc..9baf8b6f1 100644 --- a/MediaBrowser.Controller/Library/IMusicManager.cs +++ b/MediaBrowser.Controller/Library/IMusicManager.cs @@ -16,10 +16,10 @@ namespace MediaBrowser.Controller.Library /// <summary> /// Gets the instant mix from artist. /// </summary> - /// <param name="name">The name.</param> + /// <param name="artist">The artist.</param> /// <param name="user">The user.</param> /// <returns>IEnumerable{Audio}.</returns> - IEnumerable<Audio> GetInstantMixFromArtist(string name, User user); + IEnumerable<Audio> GetInstantMixFromArtist(MusicArtist artist, User user); /// <summary> /// Gets the instant mix from genre. /// </summary> diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 0cfd38479..a67e3d732 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -3,12 +3,14 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; using MediaBrowser.Common.Progress; using MediaBrowser.Common.ScheduledTasks; +using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Resolvers; @@ -244,10 +246,6 @@ namespace MediaBrowser.Server.Implementations.Library } /// <summary> - /// The _items by name path - /// </summary> - private string _itemsByNamePath; - /// <summary> /// The _season zero display name /// </summary> private string _seasonZeroDisplayName; @@ -260,7 +258,6 @@ namespace MediaBrowser.Server.Implementations.Library private void RecordConfigurationValues(ServerConfiguration configuration) { _seasonZeroDisplayName = configuration.SeasonZeroDisplayName; - _itemsByNamePath = ConfigurationManager.ApplicationPaths.ItemsByNamePath; _wizardCompleted = configuration.IsStartupWizardCompleted; } @@ -273,56 +270,24 @@ namespace MediaBrowser.Server.Implementations.Library { var config = ConfigurationManager.Configuration; - var ibnPathChanged = !string.Equals(_itemsByNamePath, ConfigurationManager.ApplicationPaths.ItemsByNamePath, StringComparison.Ordinal); - - if (ibnPathChanged) - { - RemoveItemsByNameFromCache(); - } - var newSeasonZeroName = ConfigurationManager.Configuration.SeasonZeroDisplayName; var seasonZeroNameChanged = !string.Equals(_seasonZeroDisplayName, newSeasonZeroName, StringComparison.Ordinal); var wizardChanged = config.IsStartupWizardCompleted != _wizardCompleted; RecordConfigurationValues(config); - Task.Run(async () => + if (seasonZeroNameChanged || wizardChanged) { - if (seasonZeroNameChanged) - { - await UpdateSeasonZeroNames(newSeasonZeroName, CancellationToken.None).ConfigureAwait(false); - } - - if (seasonZeroNameChanged || ibnPathChanged || wizardChanged) - { - _taskManager.CancelIfRunningAndQueue<RefreshMediaLibraryTask>(); - } - }); - } + _taskManager.CancelIfRunningAndQueue<RefreshMediaLibraryTask>(); + } - private void RemoveItemsByNameFromCache() - { - RemoveItemsFromCache(i => i is Person); - RemoveItemsFromCache(i => i is Year); - RemoveItemsFromCache(i => i is Genre); - RemoveItemsFromCache(i => i is MusicGenre); - RemoveItemsFromCache(i => i is GameGenre); - RemoveItemsFromCache(i => i is Studio); - RemoveItemsFromCache(i => + if (seasonZeroNameChanged) { - var artist = i as MusicArtist; - return artist != null && artist.IsAccessedByName; - }); - } - - private void RemoveItemsFromCache(Func<BaseItem, bool> remove) - { - var items = _libraryItemsCache.ToList().Where(i => remove(i.Value)).ToList(); + Task.Run(async () => + { + await UpdateSeasonZeroNames(newSeasonZeroName, CancellationToken.None).ConfigureAwait(false); - foreach (var item in items) - { - BaseItem value; - _libraryItemsCache.TryRemove(item.Key, out value); + }); } } @@ -374,6 +339,21 @@ namespace MediaBrowser.Server.Implementations.Library private void RegisterItem(Guid id, BaseItem item) { + if (item is LiveTvProgram) + { + return; + } + if (item is IChannelItem) + { + return; + } + if (item is IItemByName) + { + if (!(item is MusicArtist)) + { + return; + } + } LibraryItemsCache.AddOrUpdate(id, item, delegate { return item; }); } @@ -951,11 +931,14 @@ namespace MediaBrowser.Server.Implementations.Library DateModified = DateTime.UtcNow, Path = path }; - } - if (isArtist) - { - (item as MusicArtist).IsAccessedByName = true; + if (isArtist) + { + (item as MusicArtist).IsAccessedByName = true; + } + + var task = item.UpdateToRepository(ItemUpdateType.None, CancellationToken.None); + Task.WaitAll(task); } return item; @@ -1259,6 +1242,11 @@ namespace MediaBrowser.Server.Implementations.Library }; } + public QueryResult<BaseItem> QueryItems(InternalItemsQuery query) + { + return ItemRepository.GetItems(query); + } + public List<Guid> GetItemIds(InternalItemsQuery query) { return ItemRepository.GetItemIdsList(query); diff --git a/MediaBrowser.Server.Implementations/Library/MusicManager.cs b/MediaBrowser.Server.Implementations/Library/MusicManager.cs index 1a9e98268..b83256342 100644 --- a/MediaBrowser.Server.Implementations/Library/MusicManager.cs +++ b/MediaBrowser.Server.Implementations/Library/MusicManager.cs @@ -27,10 +27,8 @@ namespace MediaBrowser.Server.Implementations.Library return list.Concat(GetInstantMixFromGenres(item.Genres, user)); } - public IEnumerable<Audio> GetInstantMixFromArtist(string name, User user) + public IEnumerable<Audio> GetInstantMixFromArtist(MusicArtist artist, User user) { - var artist = _libraryManager.GetArtist(name); - var genres = user.RootFolder .GetRecursiveChildren(user, i => i is Audio) .Cast<Audio>() @@ -107,7 +105,7 @@ namespace MediaBrowser.Server.Implementations.Library var artist = item as MusicArtist; if (artist != null) { - return GetInstantMixFromArtist(artist.Name, user); + return GetInstantMixFromArtist(artist, user); } var song = item as Audio; diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 26007f145..cabe04f0f 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -1,5 +1,4 @@ -using System.IO; -using MediaBrowser.Common; +using MediaBrowser.Common; using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; @@ -26,6 +25,7 @@ using MoreLinq; using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -59,8 +59,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv private readonly SemaphoreSlim _refreshRecordingsLock = new SemaphoreSlim(1, 1); - private readonly ConcurrentDictionary<Guid, Guid> _refreshedPrograms = new ConcurrentDictionary<Guid, Guid>(); - private readonly List<ITunerHost> _tunerHosts = new List<ITunerHost>(); private readonly List<IListingsProvider> _listingProviders = new List<IListingsProvider>(); private readonly IFileSystem _fileSystem; @@ -253,7 +251,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv var now = DateTime.UtcNow; - var programs = _libraryManager.GetItems(new InternalItemsQuery + var programs = _libraryManager.QueryItems(new InternalItemsQuery { IncludeItemTypes = new[] { typeof(LiveTvProgram).Name }, MaxStartDate = now, @@ -799,7 +797,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv } } - IEnumerable<LiveTvProgram> programs = _libraryManager.GetItems(internalQuery).Items.Cast<LiveTvProgram>(); + IEnumerable<LiveTvProgram> programs = _libraryManager.QueryItems(internalQuery).Items.Cast<LiveTvProgram>(); programs = _libraryManager.Sort(programs, user, query.SortBy, query.SortOrder ?? SortOrder.Ascending) .Cast<LiveTvProgram>(); @@ -869,7 +867,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv } } - IEnumerable<LiveTvProgram> programs = _libraryManager.GetItems(internalQuery).Items.Cast<LiveTvProgram>(); + IEnumerable<LiveTvProgram> programs = _libraryManager.QueryItems(internalQuery).Items.Cast<LiveTvProgram>(); var programList = programs.ToList(); @@ -1081,8 +1079,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv await CleanDatabaseInternal(newChannelIdList, new[] { typeof(LiveTvChannel).Name }, progress, cancellationToken).ConfigureAwait(false); await CleanDatabaseInternal(newProgramIdList, new[] { typeof(LiveTvProgram).Name }, progress, cancellationToken).ConfigureAwait(false); - _refreshedPrograms.Clear(); - // Load these now which will prefetch metadata var dtoOptions = new DtoOptions(); dtoOptions.Fields.Remove(ItemFields.SyncInfo); diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs index fb6fa9084..649cecc85 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs @@ -176,7 +176,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts if (stream != null) { - return null; + return stream; } } } @@ -184,7 +184,20 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts throw new LiveTvConflictException(); } - protected abstract Task<bool> IsAvailable(TunerHostInfo tuner, string channelId, CancellationToken cancellationToken); + protected async Task<bool> IsAvailable(TunerHostInfo tuner, string channelId, CancellationToken cancellationToken) + { + try + { + return await IsAvailableInternal(tuner, channelId, cancellationToken).ConfigureAwait(false); + } + catch (Exception ex) + { + Logger.ErrorException("Error checking tuner availability", ex); + return false; + } + } + + protected abstract Task<bool> IsAvailableInternal(TunerHostInfo tuner, string channelId, CancellationToken cancellationToken); protected abstract bool IsValidChannelId(string channelId); diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs index 307a61588..5890e24eb 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs @@ -128,7 +128,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun var name = line.Substring(0, index - 1); var currentChannel = line.Substring(index + 7); if (currentChannel != "none") { status = LiveTvTunerStatus.LiveTv; } else { status = LiveTvTunerStatus.Available; } - tuners.Add(new LiveTvTunerInfo() + tuners.Add(new LiveTvTunerInfo { Name = name, SourceType = string.IsNullOrWhiteSpace(model) ? Name : model, @@ -385,10 +385,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun await GetChannels(info, false, CancellationToken.None).ConfigureAwait(false); } - protected override async Task<bool> IsAvailable(TunerHostInfo tuner, string channelId, CancellationToken cancellationToken) + protected override async Task<bool> IsAvailableInternal(TunerHostInfo tuner, string channelId, CancellationToken cancellationToken) { - // TODO - return true; + var info = await GetTunerInfos(tuner, cancellationToken).ConfigureAwait(false); + + return info.Any(i => i.Status == LiveTvTunerStatus.Available); } } } diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs index bd0feb573..e19b17ca4 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs @@ -210,7 +210,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts throw new NotImplementedException(); } - protected override Task<bool> IsAvailable(TunerHostInfo tuner, string channelId, CancellationToken cancellationToken) + protected override Task<bool> IsAvailableInternal(TunerHostInfo tuner, string channelId, CancellationToken cancellationToken) { return Task.FromResult(true); } |
