From 26d620cf01094033381681a95b952ee318ac68df Mon Sep 17 00:00:00 2001 From: TidusJar Date: Thu, 23 Aug 2018 08:58:13 +0100 Subject: [PATCH] Small work on the API !wip --- src/Ombi.Api.Lidarr/ILidarrApi.cs | 3 + src/Ombi.Api.Lidarr/LidarrApi.cs | 38 ++++++-- .../Models/AlbumByArtistResponse.cs | 27 ++++++ src/Ombi.Api.Lidarr/Models/ArtistResult.cs | 93 +++++++++++++++++++ ...cSearchEngline.cs => MusicSearchEngine.cs} | 13 ++- 5 files changed, 165 insertions(+), 9 deletions(-) create mode 100644 src/Ombi.Api.Lidarr/Models/AlbumByArtistResponse.cs create mode 100644 src/Ombi.Api.Lidarr/Models/ArtistResult.cs rename src/Ombi.Core/Engine/{MusicSearchEngline.cs => MusicSearchEngine.cs} (85%) diff --git a/src/Ombi.Api.Lidarr/ILidarrApi.cs b/src/Ombi.Api.Lidarr/ILidarrApi.cs index 8e7f7dfcf..5f677412f 100644 --- a/src/Ombi.Api.Lidarr/ILidarrApi.cs +++ b/src/Ombi.Api.Lidarr/ILidarrApi.cs @@ -10,5 +10,8 @@ namespace Ombi.Api.Lidarr Task> ArtistLookup(string searchTerm, string apiKey, string baseUrl); Task> GetProfiles(string apiKey, string baseUrl); Task> GetRootFolders(string apiKey, string baseUrl); + Task GetArtist(int artistId, string apiKey, string baseUrl); + Task GetArtistByForignId(string foreignArtistId, string apiKey, string baseUrl); + Task GetAlbumsByArtist(int artistId, string apiKey, string baseUrl); } } \ No newline at end of file diff --git a/src/Ombi.Api.Lidarr/LidarrApi.cs b/src/Ombi.Api.Lidarr/LidarrApi.cs index db2e380d3..87a723aa6 100644 --- a/src/Ombi.Api.Lidarr/LidarrApi.cs +++ b/src/Ombi.Api.Lidarr/LidarrApi.cs @@ -20,20 +20,20 @@ namespace Ombi.Api.Lidarr private const string ApiVersion = "/api/v1"; - public async Task> GetProfiles(string apiKey, string baseUrl) + public Task> GetProfiles(string apiKey, string baseUrl) { var request = new Request($"{ApiVersion}/profile", baseUrl, HttpMethod.Get); AddHeaders(request, apiKey); - return await Api.Request>(request); + return Api.Request>(request); } - public async Task> GetRootFolders(string apiKey, string baseUrl) + public Task> GetRootFolders(string apiKey, string baseUrl) { var request = new Request($"{ApiVersion}/rootfolder", baseUrl, HttpMethod.Get); AddHeaders(request, apiKey); - return await Api.Request>(request); + return Api.Request>(request); } public async Task> ArtistLookup(string searchTerm, string apiKey, string baseUrl) @@ -45,13 +45,39 @@ namespace Ombi.Api.Lidarr return await Api.Request>(request); } - public async Task> AlbumLookup(string searchTerm, string apiKey, string baseUrl) + public Task> AlbumLookup(string searchTerm, string apiKey, string baseUrl) { var request = new Request($"{ApiVersion}/Album/lookup", baseUrl, HttpMethod.Get); request.AddQueryString("term", searchTerm); AddHeaders(request, apiKey); - return await Api.Request>(request); + return Api.Request>(request); + } + + public Task GetArtist(int artistId, string apiKey, string baseUrl) + { + var request = new Request($"{ApiVersion}/artist/{artistId}", baseUrl, HttpMethod.Get); + + AddHeaders(request, apiKey); + return Api.Request(request); + } + + public Task GetArtistByForignId(string foreignArtistId, string apiKey, string baseUrl) + { + var request = new Request($"{ApiVersion}/artist/lookup", baseUrl, HttpMethod.Get); + + request.AddQueryString("term", $"lidarr:{foreignArtistId}"); + AddHeaders(request, apiKey); + return Api.Request(request); + } + + public Task GetAlbumsByArtist(int artistId, string apiKey, string baseUrl) + { + var request = new Request($"{ApiVersion}/album", baseUrl, HttpMethod.Get); + + request.AddQueryString("artistId", artistId.ToString()); + AddHeaders(request, apiKey); + return Api.Request(request); } private void AddHeaders(Request request, string key) diff --git a/src/Ombi.Api.Lidarr/Models/AlbumByArtistResponse.cs b/src/Ombi.Api.Lidarr/Models/AlbumByArtistResponse.cs new file mode 100644 index 000000000..0a54dbfeb --- /dev/null +++ b/src/Ombi.Api.Lidarr/Models/AlbumByArtistResponse.cs @@ -0,0 +1,27 @@ +using System; + +namespace Ombi.Api.Lidarr.Models +{ + public class AlbumByArtistResponse + { + public string title { get; set; } + public string disambiguation { get; set; } + public int artistId { get; set; } + public string foreignAlbumId { get; set; } + public bool monitored { get; set; } + public int profileId { get; set; } + public int duration { get; set; } + public string albumType { get; set; } + public object[] secondaryTypes { get; set; } + public int mediumCount { get; set; } + public Ratings ratings { get; set; } + public DateTime releaseDate { get; set; } + public Currentrelease currentRelease { get; set; } + public Release[] releases { get; set; } + public object[] genres { get; set; } + public Medium[] media { get; set; } + public Image[] images { get; set; } + public Statistics statistics { get; set; } + public int id { get; set; } + } +} \ No newline at end of file diff --git a/src/Ombi.Api.Lidarr/Models/ArtistResult.cs b/src/Ombi.Api.Lidarr/Models/ArtistResult.cs new file mode 100644 index 000000000..32b3aaab5 --- /dev/null +++ b/src/Ombi.Api.Lidarr/Models/ArtistResult.cs @@ -0,0 +1,93 @@ +using System; + +namespace Ombi.Api.Lidarr.Models +{ + + public class ArtistResult + { + public string status { get; set; } + public bool ended { get; set; } + public DateTime lastInfoSync { get; set; } + public string artistName { get; set; } + public string foreignArtistId { get; set; } + public int tadbId { get; set; } + public int discogsId { get; set; } + public string overview { get; set; } + public string artistType { get; set; } + public string disambiguation { get; set; } + public Link[] links { get; set; } + public Nextalbum nextAlbum { get; set; } + public Image[] images { get; set; } + public string path { get; set; } + public int qualityProfileId { get; set; } + public int languageProfileId { get; set; } + public int metadataProfileId { get; set; } + public bool albumFolder { get; set; } + public bool monitored { get; set; } + public object[] genres { get; set; } + public string cleanName { get; set; } + public string sortName { get; set; } + public object[] tags { get; set; } + public DateTime added { get; set; } + public Ratings ratings { get; set; } + public Statistics statistics { get; set; } + public int id { get; set; } + } + + public class Nextalbum + { + public string foreignAlbumId { get; set; } + public int artistId { get; set; } + public string title { get; set; } + public string disambiguation { get; set; } + public string cleanTitle { get; set; } + public DateTime releaseDate { get; set; } + public int profileId { get; set; } + public int duration { get; set; } + public bool monitored { get; set; } + public object[] images { get; set; } + public object[] genres { get; set; } + public Medium[] media { get; set; } + public DateTime lastInfoSync { get; set; } + public DateTime added { get; set; } + public string albumType { get; set; } + public object[] secondaryTypes { get; set; } + public Ratings ratings { get; set; } + public Release[] releases { get; set; } + public Currentrelease currentRelease { get; set; } + public int id { get; set; } + } + + public class Currentrelease + { + public string id { get; set; } + public string title { get; set; } + public DateTime releaseDate { get; set; } + public int trackCount { get; set; } + public int mediaCount { get; set; } + public string disambiguation { get; set; } + public string[] country { get; set; } + public string format { get; set; } + public string[] label { get; set; } + } + + public class Medium + { + public int number { get; set; } + public string name { get; set; } + public string format { get; set; } + } + + public class Release + { + public string id { get; set; } + public string title { get; set; } + public DateTime releaseDate { get; set; } + public int trackCount { get; set; } + public int mediaCount { get; set; } + public string disambiguation { get; set; } + public string[] country { get; set; } + public string format { get; set; } + public string[] label { get; set; } + } +} \ No newline at end of file diff --git a/src/Ombi.Core/Engine/MusicSearchEngline.cs b/src/Ombi.Core/Engine/MusicSearchEngine.cs similarity index 85% rename from src/Ombi.Core/Engine/MusicSearchEngline.cs rename to src/Ombi.Core/Engine/MusicSearchEngine.cs index ddb50ec12..38d137485 100644 --- a/src/Ombi.Core/Engine/MusicSearchEngline.cs +++ b/src/Ombi.Core/Engine/MusicSearchEngine.cs @@ -73,9 +73,10 @@ namespace Ombi.Core.Engine /// /// /// - public async Task GetArtistAlbums(int artistId) + public async Task GetArtistAlbums(string foreignArtistId) { - throw new NotImplementedException(); + var settings = await GetSettings(); + return await _lidarrApi.GetArtistByForignId(foreignArtistId, settings.ApiKey, settings.FullUri); } /// @@ -83,11 +84,17 @@ namespace Ombi.Core.Engine /// /// /// - public async Task GetAlbumArtist(int albumId) + public async Task GetAlbumArtist(string foreignArtistId) { throw new NotImplementedException(); } + public async Task GetArtist(int artistId) + { + var settings = await GetSettings(); + return await _lidarrApi.GetArtist(artistId, settings.ApiKey, settings.FullUri); + } + private LidarrSettings _settings; private async Task GetSettings()