From 76e49a1eb73077ce710591d46a0c7aa5d6d04812 Mon Sep 17 00:00:00 2001 From: dkanada Date: Tue, 3 Mar 2020 02:07:31 +0900 Subject: migrate audiodb to plugin --- .../Music/AudioDbAlbumImageProvider.cs | 107 --------- .../Music/AudioDbAlbumProvider.cs | 251 -------------------- .../Music/AudioDbArtistImageProvider.cs | 148 ------------ .../Music/AudioDbArtistProvider.cs | 248 -------------------- MediaBrowser.Providers/Music/AudioDbExternalIds.cs | 68 ------ .../Plugins/AudioDb/AlbumImageProvider.cs | 107 +++++++++ .../Plugins/AudioDb/AlbumProvider.cs | 252 +++++++++++++++++++++ .../Plugins/AudioDb/ArtistImageProvider.cs | 148 ++++++++++++ .../Plugins/AudioDb/ArtistProvider.cs | 249 ++++++++++++++++++++ .../AudioDb/Configuration/PluginConfiguration.cs | 9 + .../Plugins/AudioDb/Configuration/config.html | 51 +++++ .../Plugins/AudioDb/ExternalIds.cs | 66 ++++++ MediaBrowser.Providers/Plugins/AudioDb/Plugin.cs | 35 +++ 13 files changed, 917 insertions(+), 822 deletions(-) delete mode 100644 MediaBrowser.Providers/Music/AudioDbAlbumImageProvider.cs delete mode 100644 MediaBrowser.Providers/Music/AudioDbAlbumProvider.cs delete mode 100644 MediaBrowser.Providers/Music/AudioDbArtistImageProvider.cs delete mode 100644 MediaBrowser.Providers/Music/AudioDbArtistProvider.cs delete mode 100644 MediaBrowser.Providers/Music/AudioDbExternalIds.cs create mode 100644 MediaBrowser.Providers/Plugins/AudioDb/AlbumImageProvider.cs create mode 100644 MediaBrowser.Providers/Plugins/AudioDb/AlbumProvider.cs create mode 100644 MediaBrowser.Providers/Plugins/AudioDb/ArtistImageProvider.cs create mode 100644 MediaBrowser.Providers/Plugins/AudioDb/ArtistProvider.cs create mode 100644 MediaBrowser.Providers/Plugins/AudioDb/Configuration/PluginConfiguration.cs create mode 100644 MediaBrowser.Providers/Plugins/AudioDb/Configuration/config.html create mode 100644 MediaBrowser.Providers/Plugins/AudioDb/ExternalIds.cs create mode 100644 MediaBrowser.Providers/Plugins/AudioDb/Plugin.cs diff --git a/MediaBrowser.Providers/Music/AudioDbAlbumImageProvider.cs b/MediaBrowser.Providers/Music/AudioDbAlbumImageProvider.cs deleted file mode 100644 index 85a87630d..000000000 --- a/MediaBrowser.Providers/Music/AudioDbAlbumImageProvider.cs +++ /dev/null @@ -1,107 +0,0 @@ -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -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 MediaBrowser.Model.Serialization; - -namespace MediaBrowser.Providers.Music -{ - public class AudioDbAlbumImageProvider : IRemoteImageProvider, IHasOrder - { - private readonly IServerConfigurationManager _config; - private readonly IHttpClient _httpClient; - private readonly IJsonSerializer _json; - - public AudioDbAlbumImageProvider(IServerConfigurationManager config, IHttpClient httpClient, IJsonSerializer json) - { - _config = config; - _httpClient = httpClient; - _json = json; - } - - /// - public string Name => "TheAudioDB"; - - /// - // After embedded and fanart - public int Order => 2; - - /// - public IEnumerable GetSupportedImages(BaseItem item) - { - return new List - { - ImageType.Primary, - ImageType.Disc - }; - } - - /// - public async Task> GetImages(BaseItem item, CancellationToken cancellationToken) - { - var id = item.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup); - - if (!string.IsNullOrWhiteSpace(id)) - { - await AudioDbAlbumProvider.Current.EnsureInfo(id, cancellationToken).ConfigureAwait(false); - - var path = AudioDbAlbumProvider.GetAlbumInfoPath(_config.ApplicationPaths, id); - - var obj = _json.DeserializeFromFile(path); - - if (obj != null && obj.album != null && obj.album.Count > 0) - { - return GetImages(obj.album[0]); - } - } - - return new List(); - } - - private IEnumerable GetImages(AudioDbAlbumProvider.Album item) - { - var list = new List(); - - if (!string.IsNullOrWhiteSpace(item.strAlbumThumb)) - { - list.Add(new RemoteImageInfo - { - ProviderName = Name, - Url = item.strAlbumThumb, - Type = ImageType.Primary - }); - } - - if (!string.IsNullOrWhiteSpace(item.strAlbumCDart)) - { - list.Add(new RemoteImageInfo - { - ProviderName = Name, - Url = item.strAlbumCDart, - Type = ImageType.Disc - }); - } - - return list; - } - - /// - public Task GetImageResponse(string url, CancellationToken cancellationToken) - { - return _httpClient.GetResponse(new HttpRequestOptions - { - CancellationToken = cancellationToken, - Url = url - }); - } - - /// - public bool Supports(BaseItem item) => item is MusicAlbum; - } -} diff --git a/MediaBrowser.Providers/Music/AudioDbAlbumProvider.cs b/MediaBrowser.Providers/Music/AudioDbAlbumProvider.cs deleted file mode 100644 index 939c74c01..000000000 --- a/MediaBrowser.Providers/Music/AudioDbAlbumProvider.cs +++ /dev/null @@ -1,251 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; -using MediaBrowser.Common.Configuration; -using MediaBrowser.Common.Extensions; -using MediaBrowser.Common.Net; -using MediaBrowser.Controller.Configuration; -using MediaBrowser.Controller.Entities.Audio; -using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Entities; -using MediaBrowser.Model.IO; -using MediaBrowser.Model.Providers; -using MediaBrowser.Model.Serialization; - -namespace MediaBrowser.Providers.Music -{ - public class AudioDbAlbumProvider : IRemoteMetadataProvider, IHasOrder - { - private readonly IServerConfigurationManager _config; - private readonly IFileSystem _fileSystem; - private readonly IHttpClient _httpClient; - private readonly IJsonSerializer _json; - - public static AudioDbAlbumProvider Current; - - public AudioDbAlbumProvider(IServerConfigurationManager config, IFileSystem fileSystem, IHttpClient httpClient, IJsonSerializer json) - { - _config = config; - _fileSystem = fileSystem; - _httpClient = httpClient; - _json = json; - - Current = this; - } - - /// - public string Name => "TheAudioDB"; - - /// - // After music brainz - public int Order => 1; - - /// - public Task> GetSearchResults(AlbumInfo searchInfo, CancellationToken cancellationToken) - => Task.FromResult(Enumerable.Empty()); - - /// - public async Task> GetMetadata(AlbumInfo info, CancellationToken cancellationToken) - { - var result = new MetadataResult(); - - var id = info.GetReleaseGroupId(); - - if (!string.IsNullOrWhiteSpace(id)) - { - await EnsureInfo(id, cancellationToken).ConfigureAwait(false); - - var path = GetAlbumInfoPath(_config.ApplicationPaths, id); - - var obj = _json.DeserializeFromFile(path); - - if (obj != null && obj.album != null && obj.album.Count > 0) - { - result.Item = new MusicAlbum(); - result.HasMetadata = true; - ProcessResult(result.Item, obj.album[0], info.MetadataLanguage); - } - } - - return result; - } - - private void ProcessResult(MusicAlbum item, Album result, string preferredLanguage) - { - if (!string.IsNullOrWhiteSpace(result.strArtist)) - { - item.AlbumArtists = new string[] { result.strArtist }; - } - - if (!string.IsNullOrEmpty(result.intYearReleased)) - { - item.ProductionYear = int.Parse(result.intYearReleased, CultureInfo.InvariantCulture); - } - - if (!string.IsNullOrEmpty(result.strGenre)) - { - item.Genres = new[] { result.strGenre }; - } - - item.SetProviderId(MetadataProviders.AudioDbArtist, result.idArtist); - item.SetProviderId(MetadataProviders.AudioDbAlbum, result.idAlbum); - - item.SetProviderId(MetadataProviders.MusicBrainzAlbumArtist, result.strMusicBrainzArtistID); - item.SetProviderId(MetadataProviders.MusicBrainzReleaseGroup, result.strMusicBrainzID); - - string overview = null; - - if (string.Equals(preferredLanguage, "de", StringComparison.OrdinalIgnoreCase)) - { - overview = result.strDescriptionDE; - } - else if (string.Equals(preferredLanguage, "fr", StringComparison.OrdinalIgnoreCase)) - { - overview = result.strDescriptionFR; - } - else if (string.Equals(preferredLanguage, "nl", StringComparison.OrdinalIgnoreCase)) - { - overview = result.strDescriptionNL; - } - else if (string.Equals(preferredLanguage, "ru", StringComparison.OrdinalIgnoreCase)) - { - overview = result.strDescriptionRU; - } - else if (string.Equals(preferredLanguage, "it", StringComparison.OrdinalIgnoreCase)) - { - overview = result.strDescriptionIT; - } - else if ((preferredLanguage ?? string.Empty).StartsWith("pt", StringComparison.OrdinalIgnoreCase)) - { - overview = result.strDescriptionPT; - } - - if (string.IsNullOrWhiteSpace(overview)) - { - overview = result.strDescriptionEN; - } - - item.Overview = (overview ?? string.Empty).StripHtml(); - } - - internal Task EnsureInfo(string musicBrainzReleaseGroupId, CancellationToken cancellationToken) - { - var xmlPath = GetAlbumInfoPath(_config.ApplicationPaths, musicBrainzReleaseGroupId); - - var fileInfo = _fileSystem.GetFileSystemInfo(xmlPath); - - if (fileInfo.Exists) - { - if ((DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 2) - { - return Task.CompletedTask; - } - } - - return DownloadInfo(musicBrainzReleaseGroupId, cancellationToken); - } - - internal async Task DownloadInfo(string musicBrainzReleaseGroupId, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - - var url = AudioDbArtistProvider.BaseUrl + "/album-mb.php?i=" + musicBrainzReleaseGroupId; - - var path = GetAlbumInfoPath(_config.ApplicationPaths, musicBrainzReleaseGroupId); - - Directory.CreateDirectory(Path.GetDirectoryName(path)); - - using (var httpResponse = await _httpClient.SendAsync( - new HttpRequestOptions - { - Url = url, - CancellationToken = cancellationToken - }, - HttpMethod.Get).ConfigureAwait(false)) - using (var response = httpResponse.Content) - using (var xmlFileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, true)) - { - await response.CopyToAsync(xmlFileStream).ConfigureAwait(false); - } - } - - private static string GetAlbumDataPath(IApplicationPaths appPaths, string musicBrainzReleaseGroupId) - { - var dataPath = Path.Combine(GetAlbumDataPath(appPaths), musicBrainzReleaseGroupId); - - return dataPath; - } - - private static string GetAlbumDataPath(IApplicationPaths appPaths) - { - var dataPath = Path.Combine(appPaths.CachePath, "audiodb-album"); - - return dataPath; - } - - internal static string GetAlbumInfoPath(IApplicationPaths appPaths, string musicBrainzReleaseGroupId) - { - var dataPath = GetAlbumDataPath(appPaths, musicBrainzReleaseGroupId); - - return Path.Combine(dataPath, "album.json"); - } - - public class Album - { - public string idAlbum { get; set; } - public string idArtist { get; set; } - public string strAlbum { get; set; } - public string strArtist { get; set; } - public string intYearReleased { get; set; } - public string strGenre { get; set; } - public string strSubGenre { get; set; } - public string strReleaseFormat { get; set; } - public string intSales { get; set; } - public string strAlbumThumb { get; set; } - public string strAlbumCDart { get; set; } - public string strDescriptionEN { get; set; } - public string strDescriptionDE { get; set; } - public string strDescriptionFR { get; set; } - public string strDescriptionCN { get; set; } - public string strDescriptionIT { get; set; } - public string strDescriptionJP { get; set; } - public string strDescriptionRU { get; set; } - public string strDescriptionES { get; set; } - public string strDescriptionPT { get; set; } - public string strDescriptionSE { get; set; } - public string strDescriptionNL { get; set; } - public string strDescriptionHU { get; set; } - public string strDescriptionNO { get; set; } - public string strDescriptionIL { get; set; } - public string strDescriptionPL { get; set; } - public object intLoved { get; set; } - public object intScore { get; set; } - public string strReview { get; set; } - public object strMood { get; set; } - public object strTheme { get; set; } - public object strSpeed { get; set; } - public object strLocation { get; set; } - public string strMusicBrainzID { get; set; } - public string strMusicBrainzArtistID { get; set; } - public object strItunesID { get; set; } - public object strAmazonID { get; set; } - public string strLocked { get; set; } - } - - public class RootObject - { - public List album { get; set; } - } - - /// - public Task GetImageResponse(string url, CancellationToken cancellationToken) - { - throw new NotImplementedException(); - } - } -} diff --git a/MediaBrowser.Providers/Music/AudioDbArtistImageProvider.cs b/MediaBrowser.Providers/Music/AudioDbArtistImageProvider.cs deleted file mode 100644 index b9315744f..000000000 --- a/MediaBrowser.Providers/Music/AudioDbArtistImageProvider.cs +++ /dev/null @@ -1,148 +0,0 @@ -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -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 MediaBrowser.Model.Serialization; - -namespace MediaBrowser.Providers.Music -{ - public class AudioDbArtistImageProvider : IRemoteImageProvider, IHasOrder - { - private readonly IServerConfigurationManager _config; - private readonly IHttpClient _httpClient; - private readonly IJsonSerializer _json; - - public AudioDbArtistImageProvider(IServerConfigurationManager config, IJsonSerializer json, IHttpClient httpClient) - { - _config = config; - _json = json; - _httpClient = httpClient; - } - - /// - public string Name => "TheAudioDB"; - - /// - // After fanart - public int Order => 1; - - /// - public IEnumerable GetSupportedImages(BaseItem item) - { - return new List - { - ImageType.Primary, - ImageType.Logo, - ImageType.Banner, - ImageType.Backdrop - }; - } - - /// - public async Task> GetImages(BaseItem item, CancellationToken cancellationToken) - { - var id = item.GetProviderId(MetadataProviders.MusicBrainzArtist); - - if (!string.IsNullOrWhiteSpace(id)) - { - await AudioDbArtistProvider.Current.EnsureArtistInfo(id, cancellationToken).ConfigureAwait(false); - - var path = AudioDbArtistProvider.GetArtistInfoPath(_config.ApplicationPaths, id); - - var obj = _json.DeserializeFromFile(path); - - if (obj != null && obj.artists != null && obj.artists.Count > 0) - { - return GetImages(obj.artists[0]); - } - } - - return new List(); - } - - private IEnumerable GetImages(AudioDbArtistProvider.Artist item) - { - var list = new List(); - - if (!string.IsNullOrWhiteSpace(item.strArtistThumb)) - { - list.Add(new RemoteImageInfo - { - ProviderName = Name, - Url = item.strArtistThumb, - Type = ImageType.Primary - }); - } - - if (!string.IsNullOrWhiteSpace(item.strArtistLogo)) - { - list.Add(new RemoteImageInfo - { - ProviderName = Name, - Url = item.strArtistLogo, - Type = ImageType.Logo - }); - } - - if (!string.IsNullOrWhiteSpace(item.strArtistBanner)) - { - list.Add(new RemoteImageInfo - { - ProviderName = Name, - Url = item.strArtistBanner, - Type = ImageType.Banner - }); - } - - if (!string.IsNullOrWhiteSpace(item.strArtistFanart)) - { - list.Add(new RemoteImageInfo - { - ProviderName = Name, - Url = item.strArtistFanart, - Type = ImageType.Backdrop - }); - } - - if (!string.IsNullOrWhiteSpace(item.strArtistFanart2)) - { - list.Add(new RemoteImageInfo - { - ProviderName = Name, - Url = item.strArtistFanart2, - Type = ImageType.Backdrop - }); - } - - if (!string.IsNullOrWhiteSpace(item.strArtistFanart3)) - { - list.Add(new RemoteImageInfo - { - ProviderName = Name, - Url = item.strArtistFanart3, - Type = ImageType.Backdrop - }); - } - - return list; - } - - public Task GetImageResponse(string url, CancellationToken cancellationToken) - { - return _httpClient.GetResponse(new HttpRequestOptions - { - CancellationToken = cancellationToken, - Url = url - }); - } - - /// - public bool Supports(BaseItem item) => item is MusicArtist; - } -} diff --git a/MediaBrowser.Providers/Music/AudioDbArtistProvider.cs b/MediaBrowser.Providers/Music/AudioDbArtistProvider.cs deleted file mode 100644 index e073a295b..000000000 --- a/MediaBrowser.Providers/Music/AudioDbArtistProvider.cs +++ /dev/null @@ -1,248 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; -using MediaBrowser.Common.Configuration; -using MediaBrowser.Common.Extensions; -using MediaBrowser.Common.Net; -using MediaBrowser.Controller.Configuration; -using MediaBrowser.Controller.Entities.Audio; -using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Entities; -using MediaBrowser.Model.IO; -using MediaBrowser.Model.Providers; -using MediaBrowser.Model.Serialization; - -namespace MediaBrowser.Providers.Music -{ - public class AudioDbArtistProvider : IRemoteMetadataProvider, IHasOrder - { - private readonly IServerConfigurationManager _config; - private readonly IFileSystem _fileSystem; - private readonly IHttpClient _httpClient; - private readonly IJsonSerializer _json; - - public static AudioDbArtistProvider Current; - - private const string ApiKey = "195003"; - public const string BaseUrl = "https://www.theaudiodb.com/api/v1/json/" + ApiKey; - - public AudioDbArtistProvider(IServerConfigurationManager config, IFileSystem fileSystem, IHttpClient httpClient, IJsonSerializer json) - { - _config = config; - _fileSystem = fileSystem; - _httpClient = httpClient; - _json = json; - Current = this; - } - - /// - public string Name => "TheAudioDB"; - - /// - // After musicbrainz - public int Order => 1; - - /// - public Task> GetSearchResults(ArtistInfo searchInfo, CancellationToken cancellationToken) - => Task.FromResult(Enumerable.Empty()); - - /// - public async Task> GetMetadata(ArtistInfo info, CancellationToken cancellationToken) - { - var result = new MetadataResult(); - - var id = info.GetMusicBrainzArtistId(); - - if (!string.IsNullOrWhiteSpace(id)) - { - await EnsureArtistInfo(id, cancellationToken).ConfigureAwait(false); - - var path = GetArtistInfoPath(_config.ApplicationPaths, id); - - var obj = _json.DeserializeFromFile(path); - - if (obj != null && obj.artists != null && obj.artists.Count > 0) - { - result.Item = new MusicArtist(); - result.HasMetadata = true; - ProcessResult(result.Item, obj.artists[0], info.MetadataLanguage); - } - } - - return result; - } - - private void ProcessResult(MusicArtist item, Artist result, string preferredLanguage) - { - //item.HomePageUrl = result.strWebsite; - - if (!string.IsNullOrEmpty(result.strGenre)) - { - item.Genres = new[] { result.strGenre }; - } - - item.SetProviderId(MetadataProviders.AudioDbArtist, result.idArtist); - item.SetProviderId(MetadataProviders.MusicBrainzArtist, result.strMusicBrainzID); - - string overview = null; - - if (string.Equals(preferredLanguage, "de", StringComparison.OrdinalIgnoreCase)) - { - overview = result.strBiographyDE; - } - else if (string.Equals(preferredLanguage, "fr", StringComparison.OrdinalIgnoreCase)) - { - overview = result.strBiographyFR; - } - else if (string.Equals(preferredLanguage, "nl", StringComparison.OrdinalIgnoreCase)) - { - overview = result.strBiographyNL; - } - else if (string.Equals(preferredLanguage, "ru", StringComparison.OrdinalIgnoreCase)) - { - overview = result.strBiographyRU; - } - else if (string.Equals(preferredLanguage, "it", StringComparison.OrdinalIgnoreCase)) - { - overview = result.strBiographyIT; - } - else if ((preferredLanguage ?? string.Empty).StartsWith("pt", StringComparison.OrdinalIgnoreCase)) - { - overview = result.strBiographyPT; - } - - if (string.IsNullOrWhiteSpace(overview)) - { - overview = result.strBiographyEN; - } - - item.Overview = (overview ?? string.Empty).StripHtml(); - } - - internal Task EnsureArtistInfo(string musicBrainzId, CancellationToken cancellationToken) - { - var xmlPath = GetArtistInfoPath(_config.ApplicationPaths, musicBrainzId); - - var fileInfo = _fileSystem.GetFileSystemInfo(xmlPath); - - if (fileInfo.Exists - && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 2) - { - return Task.CompletedTask; - } - - return DownloadArtistInfo(musicBrainzId, cancellationToken); - } - - internal async Task DownloadArtistInfo(string musicBrainzId, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - - var url = BaseUrl + "/artist-mb.php?i=" + musicBrainzId; - - var path = GetArtistInfoPath(_config.ApplicationPaths, musicBrainzId); - - using (var httpResponse = await _httpClient.SendAsync( - new HttpRequestOptions - { - Url = url, - CancellationToken = cancellationToken, - BufferContent = true - }, - HttpMethod.Get).ConfigureAwait(false)) - using (var response = httpResponse.Content) - { - Directory.CreateDirectory(Path.GetDirectoryName(path)); - - using (var xmlFileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, true)) - { - await response.CopyToAsync(xmlFileStream).ConfigureAwait(false); - } - } - } - - /// - /// Gets the artist data path. - /// - /// The application paths. - /// The music brainz artist identifier. - /// System.String. - private static string GetArtistDataPath(IApplicationPaths appPaths, string musicBrainzArtistId) - => Path.Combine(GetArtistDataPath(appPaths), musicBrainzArtistId); - - /// - /// Gets the artist data path. - /// - /// The application paths. - /// System.String. - private static string GetArtistDataPath(IApplicationPaths appPaths) - => Path.Combine(appPaths.CachePath, "audiodb-artist"); - - internal static string GetArtistInfoPath(IApplicationPaths appPaths, string musicBrainzArtistId) - { - var dataPath = GetArtistDataPath(appPaths, musicBrainzArtistId); - - return Path.Combine(dataPath, "artist.json"); - } - - public class Artist - { - public string idArtist { get; set; } - public string strArtist { get; set; } - public string strArtistAlternate { get; set; } - public object idLabel { get; set; } - public string intFormedYear { get; set; } - public string intBornYear { get; set; } - public object intDiedYear { get; set; } - public object strDisbanded { get; set; } - public string strGenre { get; set; } - public string strSubGenre { get; set; } - public string strWebsite { get; set; } - public string strFacebook { get; set; } - public string strTwitter { get; set; } - public string strBiographyEN { get; set; } - public string strBiographyDE { get; set; } - public string strBiographyFR { get; set; } - public string strBiographyCN { get; set; } - public string strBiographyIT { get; set; } - public string strBiographyJP { get; set; } - public string strBiographyRU { get; set; } - public string strBiographyES { get; set; } - public string strBiographyPT { get; set; } - public string strBiographySE { get; set; } - public string strBiographyNL { get; set; } - public string strBiographyHU { get; set; } - public string strBiographyNO { get; set; } - public string strBiographyIL { get; set; } - public string strBiographyPL { get; set; } - public string strGender { get; set; } - public string intMembers { get; set; } - public string strCountry { get; set; } - public string strCountryCode { get; set; } - public string strArtistThumb { get; set; } - public string strArtistLogo { get; set; } - public string strArtistFanart { get; set; } - public string strArtistFanart2 { get; set; } - public string strArtistFanart3 { get; set; } - public string strArtistBanner { get; set; } - public string strMusicBrainzID { get; set; } - public object strLastFMChart { get; set; } - public string strLocked { get; set; } - } - - public class RootObject - { - public List artists { get; set; } - } - - /// - public Task GetImageResponse(string url, CancellationToken cancellationToken) - { - throw new NotImplementedException(); - } - } -} diff --git a/MediaBrowser.Providers/Music/AudioDbExternalIds.cs b/MediaBrowser.Providers/Music/AudioDbExternalIds.cs deleted file mode 100644 index c866d12de..000000000 --- a/MediaBrowser.Providers/Music/AudioDbExternalIds.cs +++ /dev/null @@ -1,68 +0,0 @@ -using MediaBrowser.Controller.Entities.Audio; -using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Entities; - -namespace MediaBrowser.Providers.Music -{ - public class AudioDbAlbumExternalId : IExternalId - { - /// - public string Name => "TheAudioDb"; - - /// - public string Key => MetadataProviders.AudioDbAlbum.ToString(); - - /// - public string UrlFormatString => "https://www.theaudiodb.com/album/{0}"; - - /// - public bool Supports(IHasProviderIds item) - => item is MusicAlbum; - } - - public class AudioDbOtherAlbumExternalId : IExternalId - { - /// - public string Name => "TheAudioDb Album"; - - /// - public string Key => MetadataProviders.AudioDbAlbum.ToString(); - - /// - public string UrlFormatString => "https://www.theaudiodb.com/album/{0}"; - - /// - public bool Supports(IHasProviderIds item) => item is Audio; - } - - public class AudioDbArtistExternalId : IExternalId - { - /// - public string Name => "TheAudioDb"; - - /// - public string Key => MetadataProviders.AudioDbArtist.ToString(); - - /// - public string UrlFormatString => "https://www.theaudiodb.com/artist/{0}"; - - /// - public bool Supports(IHasProviderIds item) => item is MusicArtist; - } - - public class AudioDbOtherArtistExternalId : IExternalId - { - /// - public string Name => "TheAudioDb Artist"; - - /// - public string Key => MetadataProviders.AudioDbArtist.ToString(); - - /// - public string UrlFormatString => "https://www.theaudiodb.com/artist/{0}"; - - /// - public bool Supports(IHasProviderIds item) - => item is Audio || item is MusicAlbum; - } -} diff --git a/MediaBrowser.Providers/Plugins/AudioDb/AlbumImageProvider.cs b/MediaBrowser.Providers/Plugins/AudioDb/AlbumImageProvider.cs new file mode 100644 index 000000000..85719fa51 --- /dev/null +++ b/MediaBrowser.Providers/Plugins/AudioDb/AlbumImageProvider.cs @@ -0,0 +1,107 @@ +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +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 MediaBrowser.Model.Serialization; + +namespace MediaBrowser.Providers.Plugins.AudioDb +{ + public class AudioDbAlbumImageProvider : IRemoteImageProvider, IHasOrder + { + private readonly IServerConfigurationManager _config; + private readonly IHttpClient _httpClient; + private readonly IJsonSerializer _json; + + public AudioDbAlbumImageProvider(IServerConfigurationManager config, IHttpClient httpClient, IJsonSerializer json) + { + _config = config; + _httpClient = httpClient; + _json = json; + } + + /// + public string Name => "TheAudioDB"; + + /// + // After embedded and fanart + public int Order => 2; + + /// + public IEnumerable GetSupportedImages(BaseItem item) + { + return new List + { + ImageType.Primary, + ImageType.Disc + }; + } + + /// + public async Task> GetImages(BaseItem item, CancellationToken cancellationToken) + { + var id = item.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup); + + if (!string.IsNullOrWhiteSpace(id)) + { + await AudioDbAlbumProvider.Current.EnsureInfo(id, cancellationToken).ConfigureAwait(false); + + var path = AudioDbAlbumProvider.GetAlbumInfoPath(_config.ApplicationPaths, id); + + var obj = _json.DeserializeFromFile(path); + + if (obj != null && obj.album != null && obj.album.Count > 0) + { + return GetImages(obj.album[0]); + } + } + + return new List(); + } + + private IEnumerable GetImages(AudioDbAlbumProvider.Album item) + { + var list = new List(); + + if (!string.IsNullOrWhiteSpace(item.strAlbumThumb)) + { + list.Add(new RemoteImageInfo + { + ProviderName = Name, + Url = item.strAlbumThumb, + Type = ImageType.Primary + }); + } + + if (!string.IsNullOrWhiteSpace(item.strAlbumCDart)) + { + list.Add(new RemoteImageInfo + { + ProviderName = Name, + Url = item.strAlbumCDart, + Type = ImageType.Disc + }); + } + + return list; + } + + /// + public Task GetImageResponse(string url, CancellationToken cancellationToken) + { + return _httpClient.GetResponse(new HttpRequestOptions + { + CancellationToken = cancellationToken, + Url = url + }); + } + + /// + public bool Supports(BaseItem item) => item is MusicAlbum; + } +} diff --git a/MediaBrowser.Providers/Plugins/AudioDb/AlbumProvider.cs b/MediaBrowser.Providers/Plugins/AudioDb/AlbumProvider.cs new file mode 100644 index 000000000..7f9f8c628 --- /dev/null +++ b/MediaBrowser.Providers/Plugins/AudioDb/AlbumProvider.cs @@ -0,0 +1,252 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities.Audio; +using MediaBrowser.Controller.Providers; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.IO; +using MediaBrowser.Model.Providers; +using MediaBrowser.Model.Serialization; +using MediaBrowser.Providers.Music; + +namespace MediaBrowser.Providers.Plugins.AudioDb +{ + public class AudioDbAlbumProvider : IRemoteMetadataProvider, IHasOrder + { + private readonly IServerConfigurationManager _config; + private readonly IFileSystem _fileSystem; + private readonly IHttpClient _httpClient; + private readonly IJsonSerializer _json; + + public static AudioDbAlbumProvider Current; + + public AudioDbAlbumProvider(IServerConfigurationManager config, IFileSystem fileSystem, IHttpClient httpClient, IJsonSerializer json) + { + _config = config; + _fileSystem = fileSystem; + _httpClient = httpClient; + _json = json; + + Current = this; + } + + /// + public string Name => "TheAudioDB"; + + /// + // After music brainz + public int Order => 1; + + /// + public Task> GetSearchResults(AlbumInfo searchInfo, CancellationToken cancellationToken) + => Task.FromResult(Enumerable.Empty()); + + /// + public async Task> GetMetadata(AlbumInfo info, CancellationToken cancellationToken) + { + var result = new MetadataResult(); + + var id = info.GetReleaseGroupId(); + + if (!string.IsNullOrWhiteSpace(id)) + { + await EnsureInfo(id, cancellationToken).ConfigureAwait(false); + + var path = GetAlbumInfoPath(_config.ApplicationPaths, id); + + var obj = _json.DeserializeFromFile(path); + + if (obj != null && obj.album != null && obj.album.Count > 0) + { + result.Item = new MusicAlbum(); + result.HasMetadata = true; + ProcessResult(result.Item, obj.album[0], info.MetadataLanguage); + } + } + + return result; + } + + private void ProcessResult(MusicAlbum item, Album result, string preferredLanguage) + { + if (!string.IsNullOrWhiteSpace(result.strArtist)) + { + item.AlbumArtists = new string[] { result.strArtist }; + } + + if (!string.IsNullOrEmpty(result.intYearReleased)) + { + item.ProductionYear = int.Parse(result.intYearReleased, CultureInfo.InvariantCulture); + } + + if (!string.IsNullOrEmpty(result.strGenre)) + { + item.Genres = new[] { result.strGenre }; + } + + item.SetProviderId(MetadataProviders.AudioDbArtist, result.idArtist); + item.SetProviderId(MetadataProviders.AudioDbAlbum, result.idAlbum); + + item.SetProviderId(MetadataProviders.MusicBrainzAlbumArtist, result.strMusicBrainzArtistID); + item.SetProviderId(MetadataProviders.MusicBrainzReleaseGroup, result.strMusicBrainzID); + + string overview = null; + + if (string.Equals(preferredLanguage, "de", StringComparison.OrdinalIgnoreCase)) + { + overview = result.strDescriptionDE; + } + else if (string.Equals(preferredLanguage, "fr", StringComparison.OrdinalIgnoreCase)) + { + overview = result.strDescriptionFR; + } + else if (string.Equals(preferredLanguage, "nl", StringComparison.OrdinalIgnoreCase)) + { + overview = result.strDescriptionNL; + } + else if (string.Equals(preferredLanguage, "ru", StringComparison.OrdinalIgnoreCase)) + { + overview = result.strDescriptionRU; + } + else if (string.Equals(preferredLanguage, "it", StringComparison.OrdinalIgnoreCase)) + { + overview = result.strDescriptionIT; + } + else if ((preferredLanguage ?? string.Empty).StartsWith("pt", StringComparison.OrdinalIgnoreCase)) + { + overview = result.strDescriptionPT; + } + + if (string.IsNullOrWhiteSpace(overview)) + { + overview = result.strDescriptionEN; + } + + item.Overview = (overview ?? string.Empty).StripHtml(); + } + + internal Task EnsureInfo(string musicBrainzReleaseGroupId, CancellationToken cancellationToken) + { + var xmlPath = GetAlbumInfoPath(_config.ApplicationPaths, musicBrainzReleaseGroupId); + + var fileInfo = _fileSystem.GetFileSystemInfo(xmlPath); + + if (fileInfo.Exists) + { + if ((DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 2) + { + return Task.CompletedTask; + } + } + + return DownloadInfo(musicBrainzReleaseGroupId, cancellationToken); + } + + internal async Task DownloadInfo(string musicBrainzReleaseGroupId, CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + + var url = AudioDbArtistProvider.BaseUrl + "/album-mb.php?i=" + musicBrainzReleaseGroupId; + + var path = GetAlbumInfoPath(_config.ApplicationPaths, musicBrainzReleaseGroupId); + + Directory.CreateDirectory(Path.GetDirectoryName(path)); + + using (var httpResponse = await _httpClient.SendAsync( + new HttpRequestOptions + { + Url = url, + CancellationToken = cancellationToken + }, + HttpMethod.Get).ConfigureAwait(false)) + using (var response = httpResponse.Content) + using (var xmlFileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, true)) + { + await response.CopyToAsync(xmlFileStream).ConfigureAwait(false); + } + } + + private static string GetAlbumDataPath(IApplicationPaths appPaths, string musicBrainzReleaseGroupId) + { + var dataPath = Path.Combine(GetAlbumDataPath(appPaths), musicBrainzReleaseGroupId); + + return dataPath; + } + + private static string GetAlbumDataPath(IApplicationPaths appPaths) + { + var dataPath = Path.Combine(appPaths.CachePath, "audiodb-album"); + + return dataPath; + } + + internal static string GetAlbumInfoPath(IApplicationPaths appPaths, string musicBrainzReleaseGroupId) + { + var dataPath = GetAlbumDataPath(appPaths, musicBrainzReleaseGroupId); + + return Path.Combine(dataPath, "album.json"); + } + + public class Album + { + public string idAlbum { get; set; } + public string idArtist { get; set; } + public string strAlbum { get; set; } + public string strArtist { get; set; } + public string intYearReleased { get; set; } + public string strGenre { get; set; } + public string strSubGenre { get; set; } + public string strReleaseFormat { get; set; } + public string intSales { get; set; } + public string strAlbumThumb { get; set; } + public string strAlbumCDart { get; set; } + public string strDescriptionEN { get; set; } + public string strDescriptionDE { get; set; } + public string strDescriptionFR { get; set; } + public string strDescriptionCN { get; set; } + public string strDescriptionIT { get; set; } + public string strDescriptionJP { get; set; } + public string strDescriptionRU { get; set; } + public string strDescriptionES { get; set; } + public string strDescriptionPT { get; set; } + public string strDescriptionSE { get; set; } + public string strDescriptionNL { get; set; } + public string strDescriptionHU { get; set; } + public string strDescriptionNO { get; set; } + public string strDescriptionIL { get; set; } + public string strDescriptionPL { get; set; } + public object intLoved { get; set; } + public object intScore { get; set; } + public string strReview { get; set; } + public object strMood { get; set; } + public object strTheme { get; set; } + public object strSpeed { get; set; } + public object strLocation { get; set; } + public string strMusicBrainzID { get; set; } + public string strMusicBrainzArtistID { get; set; } + public object strItunesID { get; set; } + public object strAmazonID { get; set; } + public string strLocked { get; set; } + } + + public class RootObject + { + public List album { get; set; } + } + + /// + public Task GetImageResponse(string url, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + } +} diff --git a/MediaBrowser.Providers/Plugins/AudioDb/ArtistImageProvider.cs b/MediaBrowser.Providers/Plugins/AudioDb/ArtistImageProvider.cs new file mode 100644 index 000000000..51b0eacfc --- /dev/null +++ b/MediaBrowser.Providers/Plugins/AudioDb/ArtistImageProvider.cs @@ -0,0 +1,148 @@ +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +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 MediaBrowser.Model.Serialization; + +namespace MediaBrowser.Providers.Plugins.AudioDb +{ + public class AudioDbArtistImageProvider : IRemoteImageProvider, IHasOrder + { + private readonly IServerConfigurationManager _config; + private readonly IHttpClient _httpClient; + private readonly IJsonSerializer _json; + + public AudioDbArtistImageProvider(IServerConfigurationManager config, IJsonSerializer json, IHttpClient httpClient) + { + _config = config; + _json = json; + _httpClient = httpClient; + } + + /// + public string Name => "TheAudioDB"; + + /// + // After fanart + public int Order => 1; + + /// + public IEnumerable GetSupportedImages(BaseItem item) + { + return new List + { + ImageType.Primary, + ImageType.Logo, + ImageType.Banner, + ImageType.Backdrop + }; + } + + /// + public async Task> GetImages(BaseItem item, CancellationToken cancellationToken) + { + var id = item.GetProviderId(MetadataProviders.MusicBrainzArtist); + + if (!string.IsNullOrWhiteSpace(id)) + { + await AudioDbArtistProvider.Current.EnsureArtistInfo(id, cancellationToken).ConfigureAwait(false); + + var path = AudioDbArtistProvider.GetArtistInfoPath(_config.ApplicationPaths, id); + + var obj = _json.DeserializeFromFile(path); + + if (obj != null && obj.artists != null && obj.artists.Count > 0) + { + return GetImages(obj.artists[0]); + } + } + + return new List(); + } + + private IEnumerable GetImages(AudioDbArtistProvider.Artist item) + { + var list = new List(); + + if (!string.IsNullOrWhiteSpace(item.strArtistThumb)) + { + list.Add(new RemoteImageInfo + { + ProviderName = Name, + Url = item.strArtistThumb, + Type = ImageType.Primary + }); + } + + if (!string.IsNullOrWhiteSpace(item.strArtistLogo)) + { + list.Add(new RemoteImageInfo + { + ProviderName = Name, + Url = item.strArtistLogo, + Type = ImageType.Logo + }); + } + + if (!string.IsNullOrWhiteSpace(item.strArtistBanner)) + { + list.Add(new RemoteImageInfo + { + ProviderName = Name, + Url = item.strArtistBanner, + Type = ImageType.Banner + }); + } + + if (!string.IsNullOrWhiteSpace(item.strArtistFanart)) + { + list.Add(new RemoteImageInfo + { + ProviderName = Name, + Url = item.strArtistFanart, + Type = ImageType.Backdrop + }); + } + + if (!string.IsNullOrWhiteSpace(item.strArtistFanart2)) + { + list.Add(new RemoteImageInfo + { + ProviderName = Name, + Url = item.strArtistFanart2, + Type = ImageType.Backdrop + }); + } + + if (!string.IsNullOrWhiteSpace(item.strArtistFanart3)) + { + list.Add(new RemoteImageInfo + { + ProviderName = Name, + Url = item.strArtistFanart3, + Type = ImageType.Backdrop + }); + } + + return list; + } + + public Task GetImageResponse(string url, CancellationToken cancellationToken) + { + return _httpClient.GetResponse(new HttpRequestOptions + { + CancellationToken = cancellationToken, + Url = url + }); + } + + /// + public bool Supports(BaseItem item) => item is MusicArtist; + } +} diff --git a/MediaBrowser.Providers/Plugins/AudioDb/ArtistProvider.cs b/MediaBrowser.Providers/Plugins/AudioDb/ArtistProvider.cs new file mode 100644 index 000000000..a51c107df --- /dev/null +++ b/MediaBrowser.Providers/Plugins/AudioDb/ArtistProvider.cs @@ -0,0 +1,249 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities.Audio; +using MediaBrowser.Controller.Providers; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.IO; +using MediaBrowser.Model.Providers; +using MediaBrowser.Model.Serialization; +using MediaBrowser.Providers.Music; + +namespace MediaBrowser.Providers.Plugins.AudioDb +{ + public class AudioDbArtistProvider : IRemoteMetadataProvider, IHasOrder + { + private readonly IServerConfigurationManager _config; + private readonly IFileSystem _fileSystem; + private readonly IHttpClient _httpClient; + private readonly IJsonSerializer _json; + + public static AudioDbArtistProvider Current; + + private const string ApiKey = "195003"; + public const string BaseUrl = "https://www.theaudiodb.com/api/v1/json/" + ApiKey; + + public AudioDbArtistProvider(IServerConfigurationManager config, IFileSystem fileSystem, IHttpClient httpClient, IJsonSerializer json) + { + _config = config; + _fileSystem = fileSystem; + _httpClient = httpClient; + _json = json; + Current = this; + } + + /// + public string Name => "TheAudioDB"; + + /// + // After musicbrainz + public int Order => 1; + + /// + public Task> GetSearchResults(ArtistInfo searchInfo, CancellationToken cancellationToken) + => Task.FromResult(Enumerable.Empty()); + + /// + public async Task> GetMetadata(ArtistInfo info, CancellationToken cancellationToken) + { + var result = new MetadataResult(); + + var id = info.GetMusicBrainzArtistId(); + + if (!string.IsNullOrWhiteSpace(id)) + { + await EnsureArtistInfo(id, cancellationToken).ConfigureAwait(false); + + var path = GetArtistInfoPath(_config.ApplicationPaths, id); + + var obj = _json.DeserializeFromFile(path); + + if (obj != null && obj.artists != null && obj.artists.Count > 0) + { + result.Item = new MusicArtist(); + result.HasMetadata = true; + ProcessResult(result.Item, obj.artists[0], info.MetadataLanguage); + } + } + + return result; + } + + private void ProcessResult(MusicArtist item, Artist result, string preferredLanguage) + { + //item.HomePageUrl = result.strWebsite; + + if (!string.IsNullOrEmpty(result.strGenre)) + { + item.Genres = new[] { result.strGenre }; + } + + item.SetProviderId(MetadataProviders.AudioDbArtist, result.idArtist); + item.SetProviderId(MetadataProviders.MusicBrainzArtist, result.strMusicBrainzID); + + string overview = null; + + if (string.Equals(preferredLanguage, "de", StringComparison.OrdinalIgnoreCase)) + { + overview = result.strBiographyDE; + } + else if (string.Equals(preferredLanguage, "fr", StringComparison.OrdinalIgnoreCase)) + { + overview = result.strBiographyFR; + } + else if (string.Equals(preferredLanguage, "nl", StringComparison.OrdinalIgnoreCase)) + { + overview = result.strBiographyNL; + } + else if (string.Equals(preferredLanguage, "ru", StringComparison.OrdinalIgnoreCase)) + { + overview = result.strBiographyRU; + } + else if (string.Equals(preferredLanguage, "it", StringComparison.OrdinalIgnoreCase)) + { + overview = result.strBiographyIT; + } + else if ((preferredLanguage ?? string.Empty).StartsWith("pt", StringComparison.OrdinalIgnoreCase)) + { + overview = result.strBiographyPT; + } + + if (string.IsNullOrWhiteSpace(overview)) + { + overview = result.strBiographyEN; + } + + item.Overview = (overview ?? string.Empty).StripHtml(); + } + + internal Task EnsureArtistInfo(string musicBrainzId, CancellationToken cancellationToken) + { + var xmlPath = GetArtistInfoPath(_config.ApplicationPaths, musicBrainzId); + + var fileInfo = _fileSystem.GetFileSystemInfo(xmlPath); + + if (fileInfo.Exists + && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 2) + { + return Task.CompletedTask; + } + + return DownloadArtistInfo(musicBrainzId, cancellationToken); + } + + internal async Task DownloadArtistInfo(string musicBrainzId, CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + + var url = BaseUrl + "/artist-mb.php?i=" + musicBrainzId; + + var path = GetArtistInfoPath(_config.ApplicationPaths, musicBrainzId); + + using (var httpResponse = await _httpClient.SendAsync( + new HttpRequestOptions + { + Url = url, + CancellationToken = cancellationToken, + BufferContent = true + }, + HttpMethod.Get).ConfigureAwait(false)) + using (var response = httpResponse.Content) + { + Directory.CreateDirectory(Path.GetDirectoryName(path)); + + using (var xmlFileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, true)) + { + await response.CopyToAsync(xmlFileStream).ConfigureAwait(false); + } + } + } + + /// + /// Gets the artist data path. + /// + /// The application paths. + /// The music brainz artist identifier. + /// System.String. + private static string GetArtistDataPath(IApplicationPaths appPaths, string musicBrainzArtistId) + => Path.Combine(GetArtistDataPath(appPaths), musicBrainzArtistId); + + /// + /// Gets the artist data path. + /// + /// The application paths. + /// System.String. + private static string GetArtistDataPath(IApplicationPaths appPaths) + => Path.Combine(appPaths.CachePath, "audiodb-artist"); + + internal static string GetArtistInfoPath(IApplicationPaths appPaths, string musicBrainzArtistId) + { + var dataPath = GetArtistDataPath(appPaths, musicBrainzArtistId); + + return Path.Combine(dataPath, "artist.json"); + } + + public class Artist + { + public string idArtist { get; set; } + public string strArtist { get; set; } + public string strArtistAlternate { get; set; } + public object idLabel { get; set; } + public string intFormedYear { get; set; } + public string intBornYear { get; set; } + public object intDiedYear { get; set; } + public object strDisbanded { get; set; } + public string strGenre { get; set; } + public string strSubGenre { get; set; } + public string strWebsite { get; set; } + public string strFacebook { get; set; } + public string strTwitter { get; set; } + public string strBiographyEN { get; set; } + public string strBiographyDE { get; set; } + public string strBiographyFR { get; set; } + public string strBiographyCN { get; set; } + public string strBiographyIT { get; set; } + public string strBiographyJP { get; set; } + public string strBiographyRU { get; set; } + public string strBiographyES { get; set; } + public string strBiographyPT { get; set; } + public string strBiographySE { get; set; } + public string strBiographyNL { get; set; } + public string strBiographyHU { get; set; } + public string strBiographyNO { get; set; } + public string strBiographyIL { get; set; } + public string strBiographyPL { get; set; } + public string strGender { get; set; } + public string intMembers { get; set; } + public string strCountry { get; set; } + public string strCountryCode { get; set; } + public string strArtistThumb { get; set; } + public string strArtistLogo { get; set; } + public string strArtistFanart { get; set; } + public string strArtistFanart2 { get; set; } + public string strArtistFanart3 { get; set; } + public string strArtistBanner { get; set; } + public string strMusicBrainzID { get; set; } + public object strLastFMChart { get; set; } + public string strLocked { get; set; } + } + + public class RootObject + { + public List artists { get; set; } + } + + /// + public Task GetImageResponse(string url, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + } +} diff --git a/MediaBrowser.Providers/Plugins/AudioDb/Configuration/PluginConfiguration.cs b/MediaBrowser.Providers/Plugins/AudioDb/Configuration/PluginConfiguration.cs new file mode 100644 index 000000000..90790d26f --- /dev/null +++ b/MediaBrowser.Providers/Plugins/AudioDb/Configuration/PluginConfiguration.cs @@ -0,0 +1,9 @@ +using MediaBrowser.Model.Plugins; + +namespace MediaBrowser.Providers.Plugins.AudioDb +{ + public class PluginConfiguration : BasePluginConfiguration + { + public bool Enable { get; set; } + } +} diff --git a/MediaBrowser.Providers/Plugins/AudioDb/Configuration/config.html b/MediaBrowser.Providers/Plugins/AudioDb/Configuration/config.html new file mode 100644 index 000000000..56c32e13e --- /dev/null +++ b/MediaBrowser.Providers/Plugins/AudioDb/Configuration/config.html @@ -0,0 +1,51 @@ + + + + AudioDB + + +
+
+
+
+ +
+
+ +
+
+
+
+ +
+ + diff --git a/MediaBrowser.Providers/Plugins/AudioDb/ExternalIds.cs b/MediaBrowser.Providers/Plugins/AudioDb/ExternalIds.cs new file mode 100644 index 000000000..2d8cb431c --- /dev/null +++ b/MediaBrowser.Providers/Plugins/AudioDb/ExternalIds.cs @@ -0,0 +1,66 @@ +using MediaBrowser.Controller.Entities.Audio; +using MediaBrowser.Controller.Providers; +using MediaBrowser.Model.Entities; + +namespace MediaBrowser.Providers.Plugins.AudioDb +{ + public class AudioDbAlbumExternalId : IExternalId + { + /// + public string Name => "TheAudioDb"; + + /// + public string Key => MetadataProviders.AudioDbAlbum.ToString(); + + /// + public string UrlFormatString => "https://www.theaudiodb.com/album/{0}"; + + /// + public bool Supports(IHasProviderIds item) => item is MusicAlbum; + } + + public class AudioDbOtherAlbumExternalId : IExternalId + { + /// + public string Name => "TheAudioDb Album"; + + /// + public string Key => MetadataProviders.AudioDbAlbum.ToString(); + + /// + public string UrlFormatString => "https://www.theaudiodb.com/album/{0}"; + + /// + public bool Supports(IHasProviderIds item) => item is Audio; + } + + public class AudioDbArtistExternalId : IExternalId + { + /// + public string Name => "TheAudioDb"; + + /// + public string Key => MetadataProviders.AudioDbArtist.ToString(); + + /// + public string UrlFormatString => "https://www.theaudiodb.com/artist/{0}"; + + /// + public bool Supports(IHasProviderIds item) => item is MusicArtist; + } + + public class AudioDbOtherArtistExternalId : IExternalId + { + /// + public string Name => "TheAudioDb Artist"; + + /// + public string Key => MetadataProviders.AudioDbArtist.ToString(); + + /// + public string UrlFormatString => "https://www.theaudiodb.com/artist/{0}"; + + /// + public bool Supports(IHasProviderIds item) => item is Audio || item is MusicAlbum; + } +} diff --git a/MediaBrowser.Providers/Plugins/AudioDb/Plugin.cs b/MediaBrowser.Providers/Plugins/AudioDb/Plugin.cs new file mode 100644 index 000000000..8532c4df3 --- /dev/null +++ b/MediaBrowser.Providers/Plugins/AudioDb/Plugin.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Plugins; +using MediaBrowser.Model.Plugins; +using MediaBrowser.Model.Serialization; + +namespace MediaBrowser.Providers.Plugins.AudioDb +{ + public class Plugin : BasePlugin, IHasWebPages + { + public static Plugin Instance { get; private set; } + + public override Guid Id => new Guid("a629c0da-fac5-4c7e-931a-7174223f14c8"); + + public override string Name => "AudioDB"; + + public override string Description => "Get artist and album metadata or images from AudioDB."; + + public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer) + : base(applicationPaths, xmlSerializer) + { + Instance = this; + } + + public IEnumerable GetPages() + { + yield return new PluginPageInfo + { + Name = Name, + EmbeddedResourcePath = GetType().Namespace + ".Configuration.config.html" + }; + } + } +} -- cgit v1.2.3 From 26c778eb166ead97f32a736e22d99513f9784654 Mon Sep 17 00:00:00 2001 From: dkanada Date: Sun, 8 Mar 2020 12:10:25 +0900 Subject: implement option to disable audiodb for now --- MediaBrowser.Providers/Plugins/AudioDb/AlbumImageProvider.cs | 3 ++- MediaBrowser.Providers/Plugins/AudioDb/AlbumProvider.cs | 11 +++++++++++ MediaBrowser.Providers/Plugins/AudioDb/ArtistImageProvider.cs | 3 ++- MediaBrowser.Providers/Plugins/AudioDb/ArtistProvider.cs | 6 ++++++ .../Plugins/AudioDb/Configuration/PluginConfiguration.cs | 2 ++ .../Plugins/AudioDb/Configuration/config.html | 4 ++++ 6 files changed, 27 insertions(+), 2 deletions(-) diff --git a/MediaBrowser.Providers/Plugins/AudioDb/AlbumImageProvider.cs b/MediaBrowser.Providers/Plugins/AudioDb/AlbumImageProvider.cs index 85719fa51..dee2d59f0 100644 --- a/MediaBrowser.Providers/Plugins/AudioDb/AlbumImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/AudioDb/AlbumImageProvider.cs @@ -102,6 +102,7 @@ namespace MediaBrowser.Providers.Plugins.AudioDb } /// - public bool Supports(BaseItem item) => item is MusicAlbum; + public bool Supports(BaseItem item) + => Plugin.Instance.Configuration.Enable && item is MusicAlbum; } } diff --git a/MediaBrowser.Providers/Plugins/AudioDb/AlbumProvider.cs b/MediaBrowser.Providers/Plugins/AudioDb/AlbumProvider.cs index 7f9f8c628..1a0e87871 100644 --- a/MediaBrowser.Providers/Plugins/AudioDb/AlbumProvider.cs +++ b/MediaBrowser.Providers/Plugins/AudioDb/AlbumProvider.cs @@ -55,6 +55,12 @@ namespace MediaBrowser.Providers.Plugins.AudioDb { var result = new MetadataResult(); + // TODO maybe remove when artist metadata can be disabled + if (!Plugin.Instance.Configuration.Enable) + { + return result; + } + var id = info.GetReleaseGroupId(); if (!string.IsNullOrWhiteSpace(id)) @@ -78,6 +84,11 @@ namespace MediaBrowser.Providers.Plugins.AudioDb private void ProcessResult(MusicAlbum item, Album result, string preferredLanguage) { + if (Plugin.Instance.Configuration.ReplaceAlbumName && !string.IsNullOrWhiteSpace(result.strAlbum)) + { + item.Album = result.strAlbum; + } + if (!string.IsNullOrWhiteSpace(result.strArtist)) { item.AlbumArtists = new string[] { result.strArtist }; diff --git a/MediaBrowser.Providers/Plugins/AudioDb/ArtistImageProvider.cs b/MediaBrowser.Providers/Plugins/AudioDb/ArtistImageProvider.cs index 51b0eacfc..18afd5dd5 100644 --- a/MediaBrowser.Providers/Plugins/AudioDb/ArtistImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/AudioDb/ArtistImageProvider.cs @@ -143,6 +143,7 @@ namespace MediaBrowser.Providers.Plugins.AudioDb } /// - public bool Supports(BaseItem item) => item is MusicArtist; + public bool Supports(BaseItem item) + => Plugin.Instance.Configuration.Enable && item is MusicArtist; } } diff --git a/MediaBrowser.Providers/Plugins/AudioDb/ArtistProvider.cs b/MediaBrowser.Providers/Plugins/AudioDb/ArtistProvider.cs index a51c107df..df0f3df8f 100644 --- a/MediaBrowser.Providers/Plugins/AudioDb/ArtistProvider.cs +++ b/MediaBrowser.Providers/Plugins/AudioDb/ArtistProvider.cs @@ -56,6 +56,12 @@ namespace MediaBrowser.Providers.Plugins.AudioDb { var result = new MetadataResult(); + // TODO maybe remove when artist metadata can be disabled + if (!Plugin.Instance.Configuration.Enable) + { + return result; + } + var id = info.GetMusicBrainzArtistId(); if (!string.IsNullOrWhiteSpace(id)) diff --git a/MediaBrowser.Providers/Plugins/AudioDb/Configuration/PluginConfiguration.cs b/MediaBrowser.Providers/Plugins/AudioDb/Configuration/PluginConfiguration.cs index 90790d26f..ad3c7eb4b 100644 --- a/MediaBrowser.Providers/Plugins/AudioDb/Configuration/PluginConfiguration.cs +++ b/MediaBrowser.Providers/Plugins/AudioDb/Configuration/PluginConfiguration.cs @@ -5,5 +5,7 @@ namespace MediaBrowser.Providers.Plugins.AudioDb public class PluginConfiguration : BasePluginConfiguration { public bool Enable { get; set; } + + public bool ReplaceAlbumName { get; set; } } } diff --git a/MediaBrowser.Providers/Plugins/AudioDb/Configuration/config.html b/MediaBrowser.Providers/Plugins/AudioDb/Configuration/config.html index 56c32e13e..c50dba71f 100644 --- a/MediaBrowser.Providers/Plugins/AudioDb/Configuration/config.html +++ b/MediaBrowser.Providers/Plugins/AudioDb/Configuration/config.html @@ -12,6 +12,10 @@ Enable this provider for metadata searches on artists and albums. +
-- cgit v1.2.3 From acf1698d2b9277afea001555c2bb8e8d90f275ae Mon Sep 17 00:00:00 2001 From: dkanada Date: Sun, 8 Mar 2020 12:17:49 +0900 Subject: include audiodb config page in release --- MediaBrowser.Providers/MediaBrowser.Providers.csproj | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MediaBrowser.Providers/MediaBrowser.Providers.csproj b/MediaBrowser.Providers/MediaBrowser.Providers.csproj index 48c16b643..dfe3eb2ef 100644 --- a/MediaBrowser.Providers/MediaBrowser.Providers.csproj +++ b/MediaBrowser.Providers/MediaBrowser.Providers.csproj @@ -24,6 +24,11 @@ true + + + + + -- cgit v1.2.3 From f8b391538d9283879e962e0dbffed12dc6024a7d Mon Sep 17 00:00:00 2001 From: dkanada Date: Sun, 8 Mar 2020 12:19:38 +0900 Subject: update audiodb config page --- MediaBrowser.Providers/Plugins/AudioDb/Configuration/config.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MediaBrowser.Providers/Plugins/AudioDb/Configuration/config.html b/MediaBrowser.Providers/Plugins/AudioDb/Configuration/config.html index c50dba71f..34494644d 100644 --- a/MediaBrowser.Providers/Plugins/AudioDb/Configuration/config.html +++ b/MediaBrowser.Providers/Plugins/AudioDb/Configuration/config.html @@ -13,7 +13,7 @@ Enable this provider for metadata searches on artists and albums.
@@ -32,6 +32,7 @@ Dashboard.showLoadingMsg(); ApiClient.getPluginConfiguration(PluginConfig.pluginId).then(function (config) { $('#enable').checked(config.Enable); + $('#replaceAlbumName').checked(config.ReplaceAlbumName); Dashboard.hideLoadingMsg(); }); @@ -43,6 +44,7 @@ var form = this; ApiClient.getPluginConfiguration(PluginConfig.pluginId).then(function (config) { config.Enable = $('#enable', form).checked(); + config.ReplaceAlbumName = $('#replaceAlbumName', form).checked(); ApiClient.updatePluginConfiguration(PluginConfig.pluginId, config).then(Dashboard.processPluginConfigurationUpdateResult); }); -- cgit v1.2.3