From d7f3214b3251a210d784e86fcdcfdca9765e69b8 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 13 Jul 2014 17:03:57 -0400 Subject: [PATCH] move last fm providers to a plugin --- .../Channels/ChannelMediaInfo.cs | 2 + .../Configuration/UserConfiguration.cs | 1 + .../MediaBrowser.Providers.csproj | 4 - .../MediaInfo/FFProbeHelpers.cs | 5 + .../Music/AudioDbAlbumProvider.cs | 3 + .../Music/FanArtAlbumProvider.cs | 2 +- .../Music/FanArtArtistProvider.cs | 4 +- .../Music/LastFmImageProvider.cs | 164 --------- .../Music/LastfmAlbumProvider.cs | 322 ------------------ .../Music/LastfmArtistProvider.cs | 160 --------- MediaBrowser.Providers/Music/LastfmHelper.cs | 76 ----- .../Collections/ManualCollectionsFolder.cs | 2 +- .../Library/UserViewManager.cs | 4 +- 13 files changed, 17 insertions(+), 732 deletions(-) delete mode 100644 MediaBrowser.Providers/Music/LastFmImageProvider.cs delete mode 100644 MediaBrowser.Providers/Music/LastfmAlbumProvider.cs delete mode 100644 MediaBrowser.Providers/Music/LastfmArtistProvider.cs delete mode 100644 MediaBrowser.Providers/Music/LastfmHelper.cs diff --git a/MediaBrowser.Controller/Channels/ChannelMediaInfo.cs b/MediaBrowser.Controller/Channels/ChannelMediaInfo.cs index 64b4804148..f16fd11205 100644 --- a/MediaBrowser.Controller/Channels/ChannelMediaInfo.cs +++ b/MediaBrowser.Controller/Channels/ChannelMediaInfo.cs @@ -29,6 +29,8 @@ namespace MediaBrowser.Controller.Channels public MediaProtocol Protocol { get; set; } + public long? RunTimeTicks { get; set; } + public ChannelMediaInfo() { RequiredHttpHeaders = new Dictionary(StringComparer.OrdinalIgnoreCase); diff --git a/MediaBrowser.Model/Configuration/UserConfiguration.cs b/MediaBrowser.Model/Configuration/UserConfiguration.cs index 0834452fbc..1afc9a191c 100644 --- a/MediaBrowser.Model/Configuration/UserConfiguration.cs +++ b/MediaBrowser.Model/Configuration/UserConfiguration.cs @@ -93,6 +93,7 @@ namespace MediaBrowser.Model.Configuration BlockUnratedItems = new UnratedItem[] { }; ExcludeFoldersFromGrouping = new string[] { }; + DisplayCollectionsView = true; } } } diff --git a/MediaBrowser.Providers/MediaBrowser.Providers.csproj b/MediaBrowser.Providers/MediaBrowser.Providers.csproj index fe22d4c99b..9a26101a1f 100644 --- a/MediaBrowser.Providers/MediaBrowser.Providers.csproj +++ b/MediaBrowser.Providers/MediaBrowser.Providers.csproj @@ -126,7 +126,6 @@ - @@ -138,11 +137,8 @@ - - - diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeHelpers.cs b/MediaBrowser.Providers/MediaInfo/FFProbeHelpers.cs index 49c7ebec8f..2044979e4e 100644 --- a/MediaBrowser.Providers/MediaInfo/FFProbeHelpers.cs +++ b/MediaBrowser.Providers/MediaInfo/FFProbeHelpers.cs @@ -12,6 +12,11 @@ namespace MediaBrowser.Providers.MediaInfo /// The result. public static void NormalizeFFProbeResult(InternalMediaInfoResult result) { + if (result == null) + { + throw new ArgumentNullException("result"); + } + if (result.format != null && result.format.tags != null) { result.format.tags = ConvertDictionaryToCaseInSensitive(result.format.tags); diff --git a/MediaBrowser.Providers/Music/AudioDbAlbumProvider.cs b/MediaBrowser.Providers/Music/AudioDbAlbumProvider.cs index a9b3d8e115..ab9ac2331b 100644 --- a/MediaBrowser.Providers/Music/AudioDbAlbumProvider.cs +++ b/MediaBrowser.Providers/Music/AudioDbAlbumProvider.cs @@ -1,4 +1,5 @@ using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Configuration; @@ -86,6 +87,8 @@ namespace MediaBrowser.Providers.Music item.SetProviderId(MetadataProviders.MusicBrainzAlbumArtist, result.strMusicBrainzArtistID); item.SetProviderId(MetadataProviders.MusicBrainzReleaseGroup, result.strMusicBrainzID); + + item.Overview = (result.strDescriptionEN ?? string.Empty).StripHtml(); } public string Name diff --git a/MediaBrowser.Providers/Music/FanArtAlbumProvider.cs b/MediaBrowser.Providers/Music/FanArtAlbumProvider.cs index ccab30bc6c..94d682f44b 100644 --- a/MediaBrowser.Providers/Music/FanArtAlbumProvider.cs +++ b/MediaBrowser.Providers/Music/FanArtAlbumProvider.cs @@ -67,7 +67,7 @@ namespace MediaBrowser.Providers.Music if (!string.IsNullOrEmpty(artistMusicBrainzId)) { - await FanartArtistProvider.Current.EnsureMovieXml(artistMusicBrainzId, cancellationToken).ConfigureAwait(false); + await FanartArtistProvider.Current.EnsureArtistXml(artistMusicBrainzId, cancellationToken).ConfigureAwait(false); var artistXmlPath = FanartArtistProvider.GetArtistXmlPath(_config.CommonApplicationPaths, artistMusicBrainzId); diff --git a/MediaBrowser.Providers/Music/FanArtArtistProvider.cs b/MediaBrowser.Providers/Music/FanArtArtistProvider.cs index b9916dfbaa..a8df95fd1b 100644 --- a/MediaBrowser.Providers/Music/FanArtArtistProvider.cs +++ b/MediaBrowser.Providers/Music/FanArtArtistProvider.cs @@ -79,7 +79,7 @@ namespace MediaBrowser.Providers.Music if (!String.IsNullOrEmpty(artistMusicBrainzId)) { - await EnsureMovieXml(artistMusicBrainzId, cancellationToken).ConfigureAwait(false); + await EnsureArtistXml(artistMusicBrainzId, cancellationToken).ConfigureAwait(false); var artistXmlPath = GetArtistXmlPath(_config.CommonApplicationPaths, artistMusicBrainzId); @@ -390,7 +390,7 @@ namespace MediaBrowser.Providers.Music } private readonly Task _cachedTask = Task.FromResult(true); - internal Task EnsureMovieXml(string musicBrainzId, CancellationToken cancellationToken) + internal Task EnsureArtistXml(string musicBrainzId, CancellationToken cancellationToken) { var xmlPath = GetArtistXmlPath(_config.ApplicationPaths, musicBrainzId); diff --git a/MediaBrowser.Providers/Music/LastFmImageProvider.cs b/MediaBrowser.Providers/Music/LastFmImageProvider.cs deleted file mode 100644 index b55a973516..0000000000 --- a/MediaBrowser.Providers/Music/LastFmImageProvider.cs +++ /dev/null @@ -1,164 +0,0 @@ -using MediaBrowser.Common.Net; -using MediaBrowser.Controller.Configuration; -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Entities.Audio; -using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Providers; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Providers.Music -{ - public class LastfmImageProvider : IRemoteImageProvider, IHasOrder - { - private readonly IHttpClient _httpClient; - private readonly IServerConfigurationManager _config; - - public LastfmImageProvider(IHttpClient httpClient, IServerConfigurationManager config) - { - _httpClient = httpClient; - _config = config; - } - - public string Name - { - get { return ProviderName; } - } - - public static string ProviderName - { - get { return "last.fm"; } - } - - public bool Supports(IHasImages item) - { - return item is MusicAlbum || item is MusicArtist; - } - - public IEnumerable GetSupportedImages(IHasImages item) - { - return new List - { - ImageType.Primary - }; - } - - public Task> GetImages(IHasImages item, CancellationToken cancellationToken) - { - var list = new List(); - - RemoteImageInfo info = null; - - var musicBrainzId = item is MusicAlbum ? - item.GetProviderId(MetadataProviders.MusicBrainzAlbum) : - item.GetProviderId(MetadataProviders.MusicBrainzArtist); - - if (!string.IsNullOrEmpty(musicBrainzId)) - { - var cachePath = Path.Combine(_config.ApplicationPaths.CachePath, "lastfm", musicBrainzId, "image.txt"); - - try - { - var parts = File.ReadAllText(cachePath).Split('|'); - - info = GetInfo(parts.FirstOrDefault(), parts.LastOrDefault()); - } - catch (DirectoryNotFoundException) - { - } - catch (FileNotFoundException) - { - } - } - - if (info == null) - { - var musicBrainzReleaseGroupId = item.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup); - - if (!string.IsNullOrEmpty(musicBrainzReleaseGroupId)) - { - var cachePath = Path.Combine(_config.ApplicationPaths.CachePath, "lastfm", musicBrainzReleaseGroupId, "image.txt"); - - try - { - var parts = File.ReadAllText(cachePath).Split('|'); - - info = GetInfo(parts.FirstOrDefault(), parts.LastOrDefault()); - } - catch (DirectoryNotFoundException) - { - } - catch (FileNotFoundException) - { - } - } - } - - if (info != null) - { - list.Add(info); - } - - // The only info we have is size - return Task.FromResult>(list.OrderByDescending(i => i.Width ?? 0)); - } - - private RemoteImageInfo GetInfo(string url, string size) - { - if (string.IsNullOrEmpty(url)) - { - return null; - } - - var info = new RemoteImageInfo - { - ProviderName = Name, - Url = url, - Type = ImageType.Primary - }; - - if (string.Equals(size, "mega", StringComparison.OrdinalIgnoreCase)) - { - - } - else if (string.Equals(size, "extralarge", StringComparison.OrdinalIgnoreCase)) - { - - } - else if (string.Equals(size, "large", StringComparison.OrdinalIgnoreCase)) - { - - } - else if (string.Equals(size, "medium", StringComparison.OrdinalIgnoreCase)) - { - - } - - return info; - } - - public int Order - { - get - { - // After all others - return 3; - } - } - - public Task GetImageResponse(string url, CancellationToken cancellationToken) - { - return _httpClient.GetResponse(new HttpRequestOptions - { - CancellationToken = cancellationToken, - Url = url, - ResourcePool = LastfmArtistProvider.LastfmResourcePool - }); - } - } -} diff --git a/MediaBrowser.Providers/Music/LastfmAlbumProvider.cs b/MediaBrowser.Providers/Music/LastfmAlbumProvider.cs deleted file mode 100644 index 8465397484..0000000000 --- a/MediaBrowser.Providers/Music/LastfmAlbumProvider.cs +++ /dev/null @@ -1,322 +0,0 @@ -using MediaBrowser.Common.Net; -using MediaBrowser.Controller.Configuration; -using MediaBrowser.Controller.Entities.Audio; -using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Logging; -using MediaBrowser.Model.Providers; -using MediaBrowser.Model.Serialization; -using MoreLinq; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Providers.Music -{ - public class LastfmAlbumProvider : IRemoteMetadataProvider, IHasOrder - { - private readonly IJsonSerializer _json; - private readonly IHttpClient _httpClient; - - private readonly IServerConfigurationManager _config; - private readonly ILogger _logger; - - public LastfmAlbumProvider(IHttpClient httpClient, IJsonSerializer json, IServerConfigurationManager config, ILogger logger) - { - _httpClient = httpClient; - _json = json; - _config = config; - _logger = logger; - } - - public async Task> GetSearchResults(AlbumInfo searchInfo, CancellationToken cancellationToken) - { - return new List(); - } - - public async Task> GetMetadata(AlbumInfo id, CancellationToken cancellationToken) - { - var result = new MetadataResult(); - - var lastFmData = await GetAlbumResult(id, cancellationToken).ConfigureAwait(false); - - if (lastFmData != null && lastFmData.album != null) - { - result.HasMetadata = true; - result.Item = new MusicAlbum(); - ProcessAlbumData(result.Item, lastFmData.album); - } - - return result; - } - - private async Task GetAlbumResult(AlbumInfo item, CancellationToken cancellationToken) - { - // Try album release Id - var id = item.GetReleaseId(); - if (!string.IsNullOrEmpty(id)) - { - var result = await GetAlbumResult(id, cancellationToken).ConfigureAwait(false); - - if (result != null && result.album != null) - { - return result; - } - } - - // Try album release group Id - id = item.GetReleaseGroupId(); - if (!string.IsNullOrEmpty(id)) - { - var result = await GetAlbumResult(id, cancellationToken).ConfigureAwait(false); - - if (result != null && result.album != null) - { - return result; - } - } - - var albumArtist = item.GetAlbumArtist(); - // Get each song, distinct by the combination of AlbumArtist and Album - var songs = item.SongInfos.DistinctBy(i => (i.AlbumArtists.FirstOrDefault() ?? string.Empty) + (i.Album ?? string.Empty), StringComparer.OrdinalIgnoreCase).ToList(); - - foreach (var song in songs.Where(song => !string.IsNullOrEmpty(song.Album) && !string.IsNullOrEmpty(song.AlbumArtists.FirstOrDefault()))) - { - var result = await GetAlbumResult(song.AlbumArtists.FirstOrDefault(), song.Album, cancellationToken).ConfigureAwait(false); - - if (result != null && result.album != null) - { - return result; - } - } - - if (string.IsNullOrEmpty(albumArtist)) - { - return null; - } - - return await GetAlbumResult(albumArtist, item.Name, cancellationToken); - } - - private async Task GetAlbumResult(string artist, string album, CancellationToken cancellationToken) - { - // Get albu info using artist and album name - var url = LastfmArtistProvider.RootUrl + string.Format("method=album.getInfo&artist={0}&album={1}&api_key={2}&format=json", UrlEncode(artist), UrlEncode(album), LastfmArtistProvider.ApiKey); - - using (var json = await _httpClient.Get(new HttpRequestOptions - { - Url = url, - ResourcePool = LastfmArtistProvider.LastfmResourcePool, - CancellationToken = cancellationToken, - EnableHttpCompression = false - - }).ConfigureAwait(false)) - { - using (var reader = new StreamReader(json)) - { - var jsonText = await reader.ReadToEndAsync().ConfigureAwait(false); - - // Fix their bad json - jsonText = jsonText.Replace("\"#text\"", "\"url\""); - - return _json.DeserializeFromString(jsonText); - } - } - } - - private async Task GetAlbumResult(string musicbraizId, CancellationToken cancellationToken) - { - // Get albu info using artist and album name - var url = LastfmArtistProvider.RootUrl + string.Format("method=album.getInfo&mbid={0}&api_key={1}&format=json", musicbraizId, LastfmArtistProvider.ApiKey); - - using (var json = await _httpClient.Get(new HttpRequestOptions - { - Url = url, - ResourcePool = LastfmArtistProvider.LastfmResourcePool, - CancellationToken = cancellationToken, - EnableHttpCompression = false - - }).ConfigureAwait(false)) - { - return _json.DeserializeFromStream(json); - } - } - - private void ProcessAlbumData(MusicAlbum item, LastfmAlbum data) - { - var overview = data.wiki != null ? data.wiki.content : null; - - if (!item.LockedFields.Contains(MetadataFields.Overview)) - { - item.Overview = overview; - } - - // Only grab the date here if the album doesn't already have one, since id3 tags are preferred - DateTime release; - - if (DateTime.TryParse(data.releasedate, out release)) - { - // Lastfm sends back null as sometimes 1901, other times 0 - if (release.Year > 1901) - { - if (!item.PremiereDate.HasValue) - { - item.PremiereDate = release; - } - - if (!item.ProductionYear.HasValue) - { - item.ProductionYear = release.Year; - } - } - } - - string imageSize; - var url = LastfmHelper.GetImageUrl(data, out imageSize); - - var musicBrainzId = item.GetProviderId(MetadataProviders.MusicBrainzAlbum) ?? - item.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup); - - if (!string.IsNullOrEmpty(musicBrainzId) && !string.IsNullOrEmpty(url)) - { - LastfmHelper.SaveImageInfo(_config.ApplicationPaths, _logger, musicBrainzId, url, imageSize); - } - } - - /// - /// Encodes an URL. - /// - /// The name. - /// System.String. - private string UrlEncode(string name) - { - return WebUtility.UrlEncode(name); - } - - public string Name - { - get { return "last.fm"; } - } - - public int Order - { - get - { - // After fanart & audiodb - return 2; - } - } - - public Task GetImageResponse(string url, CancellationToken cancellationToken) - { - throw new NotImplementedException(); - } - } - - #region Result Objects - - public class LastfmStats - { - public string listeners { get; set; } - public string playcount { get; set; } - } - - public class LastfmTag - { - public string name { get; set; } - public string url { get; set; } - } - - - public class LastfmTags - { - public List tag { get; set; } - } - - public class LastfmFormationInfo - { - public string yearfrom { get; set; } - public string yearto { get; set; } - } - - public class LastFmBio - { - public string published { get; set; } - public string summary { get; set; } - public string content { get; set; } - public string placeformed { get; set; } - public string yearformed { get; set; } - public List formationlist { get; set; } - } - - public class LastFmImage - { - public string url { get; set; } - public string size { get; set; } - } - - public class LastfmArtist : IHasLastFmImages - { - public string name { get; set; } - public string mbid { get; set; } - public string url { get; set; } - public string streamable { get; set; } - public string ontour { get; set; } - public LastfmStats stats { get; set; } - public List similar { get; set; } - public LastfmTags tags { get; set; } - public LastFmBio bio { get; set; } - public List image { get; set; } - } - - - public class LastfmAlbum : IHasLastFmImages - { - public string name { get; set; } - public string artist { get; set; } - public string id { get; set; } - public string mbid { get; set; } - public string releasedate { get; set; } - public int listeners { get; set; } - public int playcount { get; set; } - public LastfmTags toptags { get; set; } - public LastFmBio wiki { get; set; } - public List image { get; set; } - } - - public interface IHasLastFmImages - { - List image { get; set; } - } - - public class LastfmGetAlbumResult - { - public LastfmAlbum album { get; set; } - } - - public class LastfmGetArtistResult - { - public LastfmArtist artist { get; set; } - } - - public class Artistmatches - { - public List artist { get; set; } - } - - public class LastfmArtistSearchResult - { - public Artistmatches artistmatches { get; set; } - } - - public class LastfmArtistSearchResults - { - public LastfmArtistSearchResult results { get; set; } - } - - #endregion -} diff --git a/MediaBrowser.Providers/Music/LastfmArtistProvider.cs b/MediaBrowser.Providers/Music/LastfmArtistProvider.cs deleted file mode 100644 index a2aa9d719e..0000000000 --- a/MediaBrowser.Providers/Music/LastfmArtistProvider.cs +++ /dev/null @@ -1,160 +0,0 @@ -using MediaBrowser.Common.Extensions; -using MediaBrowser.Common.Net; -using MediaBrowser.Controller.Configuration; -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Entities.Audio; -using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Logging; -using MediaBrowser.Model.Providers; -using MediaBrowser.Model.Serialization; -using System; -using System.Collections.Generic; -using System.IO; -using System.Net; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Providers.Music -{ - public class LastfmArtistProvider : IRemoteMetadataProvider, IHasOrder - { - private readonly IJsonSerializer _json; - private readonly IHttpClient _httpClient; - - internal static readonly SemaphoreSlim LastfmResourcePool = new SemaphoreSlim(4, 4); - - internal const string RootUrl = @"http://ws.audioscrobbler.com/2.0/?"; - internal static string ApiKey = "7b76553c3eb1d341d642755aecc40a33"; - - private readonly IServerConfigurationManager _config; - private readonly ILogger _logger; - - public LastfmArtistProvider(IHttpClient httpClient, IJsonSerializer json, IServerConfigurationManager config, ILogger logger) - { - _httpClient = httpClient; - _json = json; - _config = config; - _logger = logger; - } - - public async Task> GetSearchResults(ArtistInfo searchInfo, CancellationToken cancellationToken) - { - return new List(); - } - - public async Task> GetMetadata(ArtistInfo id, CancellationToken cancellationToken) - { - var result = new MetadataResult(); - - var musicBrainzId = id.GetMusicBrainzArtistId(); - - if (!String.IsNullOrWhiteSpace(musicBrainzId)) - { - cancellationToken.ThrowIfCancellationRequested(); - - result.Item = new MusicArtist(); - result.HasMetadata = true; - - await FetchLastfmData(result.Item, musicBrainzId, cancellationToken).ConfigureAwait(false); - } - - return result; - } - - protected async Task FetchLastfmData(MusicArtist item, string musicBrainzId, CancellationToken cancellationToken) - { - // Get artist info with provided id - var url = RootUrl + String.Format("method=artist.getInfo&mbid={0}&api_key={1}&format=json", UrlEncode(musicBrainzId), ApiKey); - - LastfmGetArtistResult result; - - using (var json = await _httpClient.Get(new HttpRequestOptions - { - Url = url, - ResourcePool = LastfmResourcePool, - CancellationToken = cancellationToken, - EnableHttpCompression = false - - }).ConfigureAwait(false)) - { - using (var reader = new StreamReader(json)) - { - var jsonText = await reader.ReadToEndAsync().ConfigureAwait(false); - - // Fix their bad json - jsonText = jsonText.Replace("\"#text\"", "\"url\""); - - result = _json.DeserializeFromString(jsonText); - } - } - - if (result != null && result.artist != null) - { - ProcessArtistData(item, result.artist, musicBrainzId); - } - } - - private void ProcessArtistData(MusicArtist artist, LastfmArtist data, string musicBrainzId) - { - var yearFormed = 0; - - if (data.bio != null) - { - Int32.TryParse(data.bio.yearformed, out yearFormed); - if (!artist.LockedFields.Contains(MetadataFields.Overview)) - { - artist.Overview = (data.bio.content ?? string.Empty).StripHtml(); - } - if (!string.IsNullOrEmpty(data.bio.placeformed) && !artist.LockedFields.Contains(MetadataFields.ProductionLocations)) - { - artist.AddProductionLocation(data.bio.placeformed); - } - } - - if (yearFormed > 0) - { - artist.PremiereDate = new DateTime(yearFormed, 1, 1, 0, 0, 0, DateTimeKind.Utc); - - artist.ProductionYear = yearFormed; - } - - string imageSize; - var url = LastfmHelper.GetImageUrl(data, out imageSize); - - if (!string.IsNullOrEmpty(musicBrainzId) && !string.IsNullOrEmpty(url)) - { - LastfmHelper.SaveImageInfo(_config.ApplicationPaths, _logger, musicBrainzId, url, imageSize); - } - } - - /// - /// Encodes an URL. - /// - /// The name. - /// System.String. - private string UrlEncode(string name) - { - return WebUtility.UrlEncode(name); - } - - public string Name - { - get { return "last.fm"; } - } - - public int Order - { - get - { - // After fanart & audiodb - return 2; - } - } - - public Task GetImageResponse(string url, CancellationToken cancellationToken) - { - throw new NotImplementedException(); - } - } -} diff --git a/MediaBrowser.Providers/Music/LastfmHelper.cs b/MediaBrowser.Providers/Music/LastfmHelper.cs deleted file mode 100644 index 7c83cec6b4..0000000000 --- a/MediaBrowser.Providers/Music/LastfmHelper.cs +++ /dev/null @@ -1,76 +0,0 @@ -using MediaBrowser.Common.Configuration; -using MediaBrowser.Model.Logging; -using System; -using System.IO; -using System.Linq; - -namespace MediaBrowser.Providers.Music -{ - public static class LastfmHelper - { - public static string GetImageUrl(IHasLastFmImages data, out string size) - { - size = null; - - if (data.image == null) - { - return null; - } - - var validImages = data.image - .Where(i => !string.IsNullOrWhiteSpace(i.url)) - .ToList(); - - var img = validImages - .FirstOrDefault(i => string.Equals(i.size, "mega", StringComparison.OrdinalIgnoreCase)) ?? - data.image.FirstOrDefault(i => string.Equals(i.size, "extralarge", StringComparison.OrdinalIgnoreCase)) ?? - data.image.FirstOrDefault(i => string.Equals(i.size, "large", StringComparison.OrdinalIgnoreCase)) ?? - data.image.FirstOrDefault(i => string.Equals(i.size, "medium", StringComparison.OrdinalIgnoreCase)) ?? - data.image.FirstOrDefault(); - - if (img != null) - { - size = img.size; - return img.url; - } - - return null; - } - - public static void SaveImageInfo(IApplicationPaths appPaths, ILogger logger, string musicBrainzId, string url, string size) - { - if (appPaths == null) - { - throw new ArgumentNullException("appPaths"); - } - if (string.IsNullOrEmpty(musicBrainzId)) - { - throw new ArgumentNullException("musicBrainzId"); - } - if (string.IsNullOrEmpty(url)) - { - throw new ArgumentNullException("url"); - } - - var cachePath = Path.Combine(appPaths.CachePath, "lastfm", musicBrainzId, "image.txt"); - - try - { - if (string.IsNullOrEmpty(url)) - { - File.Delete(cachePath); - } - else - { - Directory.CreateDirectory(Path.GetDirectoryName(cachePath)); - File.WriteAllText(cachePath, url + "|" + size); - } - } - catch (IOException ex) - { - // Don't fail if this is unable to write - logger.ErrorException("Error saving to {0}", ex, cachePath); - } - } - } -} diff --git a/MediaBrowser.Server.Implementations/Collections/ManualCollectionsFolder.cs b/MediaBrowser.Server.Implementations/Collections/ManualCollectionsFolder.cs index 07c86ed314..aaa02c7209 100644 --- a/MediaBrowser.Server.Implementations/Collections/ManualCollectionsFolder.cs +++ b/MediaBrowser.Server.Implementations/Collections/ManualCollectionsFolder.cs @@ -26,7 +26,7 @@ namespace MediaBrowser.Server.Implementations.Collections public override bool IsHiddenFromUser(User user) { - return true; + return !user.Configuration.DisplayCollectionsView; } public override string CollectionType diff --git a/MediaBrowser.Server.Implementations/Library/UserViewManager.cs b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs index dd2978b17b..73afa22e38 100644 --- a/MediaBrowser.Server.Implementations/Library/UserViewManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs @@ -10,12 +10,12 @@ using MediaBrowser.Controller.Localization; using MediaBrowser.Model.Channels; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Library; +using MediaBrowser.Model.Querying; using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; -using MediaBrowser.Model.Querying; namespace MediaBrowser.Server.Implementations.Library { @@ -82,7 +82,7 @@ namespace MediaBrowser.Server.Implementations.Library list.Add(await GetUserView(CollectionType.Games, user, string.Empty, cancellationToken).ConfigureAwait(false)); } - if (user.Configuration.DisplayCollectionsView || + if (user.Configuration.DisplayCollectionsView && recursiveChildren.OfType().Any()) { list.Add(await GetUserView(CollectionType.BoxSets, user, CollectionType.BoxSets, cancellationToken).ConfigureAwait(false));