diff --git a/src/Ombi.Api.MusicBrainz/IMusicBrainzApi.cs b/src/Ombi.Api.MusicBrainz/IMusicBrainzApi.cs index ab8d7ad30..5a5a769ca 100644 --- a/src/Ombi.Api.MusicBrainz/IMusicBrainzApi.cs +++ b/src/Ombi.Api.MusicBrainz/IMusicBrainzApi.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using System.Threading.Tasks; -using Ombi.Api.MusicBrainz.Models.Lookup; +using Ombi.Api.MusicBrainz.Models.Browse; using Ombi.Api.MusicBrainz.Models.Search; namespace Ombi.Api.MusicBrainz @@ -8,6 +8,6 @@ namespace Ombi.Api.MusicBrainz public interface IMusicBrainzApi { Task> SearchArtist(string artistQuery); - Task> GetReleaseGroups(string artistId); + Task> GetReleaseForArtist(string artistId); } } \ No newline at end of file diff --git a/src/Ombi.Api.MusicBrainz/Models/Browse/ReleaseResult.cs b/src/Ombi.Api.MusicBrainz/Models/Browse/ReleaseResult.cs new file mode 100644 index 000000000..efc46ec90 --- /dev/null +++ b/src/Ombi.Api.MusicBrainz/Models/Browse/ReleaseResult.cs @@ -0,0 +1,106 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Ombi.Api.MusicBrainz.Models.Browse +{ + public class CoverArtArchive + { + public bool back { get; set; } + public bool artwork { get; set; } + public bool darkened { get; set; } + public int count { get; set; } + public bool front { get; set; } + } + + public class TextRepresentation + { + public string script { get; set; } + public string language { get; set; } + } + + public class Recording + { + public int length { get; set; } + public string disambiguation { get; set; } + public string title { get; set; } + public string id { get; set; } + public bool video { get; set; } + } + + public class Track + { + public string title { get; set; } + public Recording recording { get; set; } + public string number { get; set; } + public string id { get; set; } + public int? length { get; set; } + public int position { get; set; } + } + + public class Medium + { + [JsonProperty(PropertyName = "track-count")] + public int TrackCount { get; set; } + public string title { get; set; } + [JsonProperty(PropertyName = "track-offset")] + public int TrackOffset { get; set; } + public int position { get; set; } + [JsonProperty(PropertyName = "format-id")] + public string FormatId { get; set; } + public string format { get; set; } + public List tracks { get; set; } + } + + public class Area + { + public string id { get; set; } + [JsonProperty(PropertyName = "sort-name")] + public string SortName { get; set; } + public string disambiguation { get; set; } + public string name { get; set; } + [JsonProperty(PropertyName = "iso-3166-1-codes")] + public List Iso31661Codes { get; set; } + [JsonProperty(PropertyName = "iso-3166-2-codes")] + public List Iso31662Codes { get; set; } + } + + public class ReleaseEvent + { + public string date { get; set; } + public Area area { get; set; } + } + + public class Release + { + public string quality { get; set; } + public string asin { get; set; } + public string date { get; set; } + public string status { get; set; } + public string barcode { get; set; } + [JsonProperty(PropertyName = "cover-art-archive")] + public CoverArtArchive CoverArtArchive { get; set; } + public string packaging { get; set; } + [JsonProperty(PropertyName = "packaging-id")] + public string PackagingId { get; set; } + [JsonProperty(PropertyName = "status-id")] + public string StatusId { get; set; } + public string disambiguation { get; set; } + public string country { get; set; } + [JsonProperty(PropertyName = "text-representation")] + public TextRepresentation TextRepresentation { get; set; } + public string title { get; set; } + public List media { get; set; } + public string id { get; set; } + [JsonProperty(PropertyName = "release-events")] + public List ReleaseEvents { get; set; } + } + + public class ReleaseResult + { + [JsonProperty(PropertyName = "release-count")] + public int ReleaseCount { get; set; } + [JsonProperty(PropertyName = "release-offset")] + public int ReleaseOffset { get; set; } + public List releases { get; set; } + } +} \ No newline at end of file diff --git a/src/Ombi.Api.MusicBrainz/Models/Lookup/ReleaseGroups.cs b/src/Ombi.Api.MusicBrainz/Models/Lookup/ReleaseGroups.cs deleted file mode 100644 index 58730d144..000000000 --- a/src/Ombi.Api.MusicBrainz/Models/Lookup/ReleaseGroups.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Newtonsoft.Json; - -namespace Ombi.Api.MusicBrainz.Models.Lookup -{ - - [JsonPluralName("release-groups")] - public class ReleaseGroups - { - [JsonProperty(PropertyName = "id")] - public string Id { get; set; } - [JsonProperty(PropertyName = "primary-type-ids")] - public string PrimaryTypeId { get; set; } - [JsonProperty(PropertyName = "disambiguation")] - public string Disambiguation { get; set; } - [JsonProperty(PropertyName = "secondary-types")] - public string[] SecondaryTypes { get; set; } - [JsonProperty(PropertyName = "primary-type")] - public string PrimaryType { get; set; } // Album / Single / Live / EP - [JsonProperty(PropertyName = "first-release-date")] - public string FirstReleaseDate { get; set; } - [JsonProperty(PropertyName = "secondary-type-ids")] - public string[] SecondaryTypeIds { get; set; } - [JsonProperty(PropertyName = "title")] - public string Title { get; set; } // Release title - } - -} \ No newline at end of file diff --git a/src/Ombi.Api.MusicBrainz/MusicBrainzApi.cs b/src/Ombi.Api.MusicBrainz/MusicBrainzApi.cs index 196ad2a74..8a6573042 100644 --- a/src/Ombi.Api.MusicBrainz/MusicBrainzApi.cs +++ b/src/Ombi.Api.MusicBrainz/MusicBrainzApi.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Threading.Tasks; -using Ombi.Api; + using Ombi.Api.MusicBrainz.Models; -using Ombi.Api.MusicBrainz.Models.Lookup; +using Ombi.Api.MusicBrainz.Models.Browse; using Ombi.Api.MusicBrainz.Models.Search; namespace Ombi.Api.MusicBrainz @@ -30,16 +30,16 @@ namespace Ombi.Api.MusicBrainz return albums.Data.Where(x => !x.type.Equals("Person", StringComparison.CurrentCultureIgnoreCase)); } - public async Task> GetReleaseGroups(string artistId) + public async Task> GetReleaseForArtist(string artistId) { - var request = new Request("release-group", _baseUrl, HttpMethod.Get); + var request = new Request("release", _baseUrl, HttpMethod.Get); request.AddQueryString("artist", artistId); + request.AddQueryString("inc", "recordings"); AddHeaders(request); - // The count properties for release groups is called releasegroupcount... Will sort this out if I need paging - var releases = await _api.Request>(request); - return releases.Data; + var releases = await _api.Request(request); + return releases.releases; } private void AddHeaders(Request req) diff --git a/src/Ombi.Core/Engine/V2/IMultiSearchEngine.cs b/src/Ombi.Core/Engine/V2/IMultiSearchEngine.cs index 3fc5a9271..fdfcb06e6 100644 --- a/src/Ombi.Core/Engine/V2/IMultiSearchEngine.cs +++ b/src/Ombi.Core/Engine/V2/IMultiSearchEngine.cs @@ -2,11 +2,12 @@ using System.Threading; using System.Threading.Tasks; using Ombi.Api.TheMovieDb.Models; +using Ombi.Core.Models.Search.V2; namespace Ombi.Core.Engine.V2 { public interface IMultiSearchEngine { - Task> MultiSearch(string searchTerm, CancellationToken cancellationToken, string lang = "en"); + Task> MultiSearch(string searchTerm, CancellationToken cancellationToken, string lang = "en"); } } \ No newline at end of file diff --git a/src/Ombi.Core/Engine/V2/MultiSearchEngine.cs b/src/Ombi.Core/Engine/V2/MultiSearchEngine.cs index 0bfa33e3f..985e07cb2 100644 --- a/src/Ombi.Core/Engine/V2/MultiSearchEngine.cs +++ b/src/Ombi.Core/Engine/V2/MultiSearchEngine.cs @@ -1,15 +1,19 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Security.Principal; using System.Threading; using System.Threading.Tasks; +using Ombi.Api.MusicBrainz; using Ombi.Api.TheMovieDb; using Ombi.Api.TheMovieDb.Models; using Ombi.Core.Authentication; using Ombi.Core.Models.Requests; +using Ombi.Core.Models.Search.V2; using Ombi.Core.Rule.Interfaces; using Ombi.Core.Settings; using Ombi.Helpers; using Ombi.Settings.Settings.Models; +using Ombi.Settings.Settings.Models.External; using Ombi.Store.Entities; using Ombi.Store.Repository; @@ -19,18 +23,54 @@ namespace Ombi.Core.Engine.V2 { public MultiSearchEngine(IPrincipal identity, IRequestServiceMain requestService, IRuleEvaluator rules, OmbiUserManager um, ICacheService cache, ISettingsService ombiSettings, IRepository sub, - IMovieDbApi movieDbApi) + IMovieDbApi movieDbApi, ISettingsService lidarrSettings, IMusicBrainzApi musicApi) : base(identity, requestService, rules, um, cache, ombiSettings, sub) { _movieDbApi = movieDbApi; + _lidarrSettings = lidarrSettings; + _musicApi = musicApi; } private readonly IMovieDbApi _movieDbApi; + private readonly ISettingsService _lidarrSettings; + private readonly IMusicBrainzApi _musicApi; - public async Task> MultiSearch(string searchTerm, CancellationToken cancellationToken, string lang = "en") + public async Task> MultiSearch(string searchTerm, CancellationToken cancellationToken, string lang = "en") { - return (await _movieDbApi.MultiSearch(searchTerm, lang, cancellationToken)).results; + var model = new List(); + + var movieDbData = (await _movieDbApi.MultiSearch(searchTerm, lang, cancellationToken)).results; + + var lidarrSettings = await _lidarrSettings.GetSettingsAsync(); + if (lidarrSettings.Enabled) + { + var artistResult = await _musicApi.SearchArtist(searchTerm); + foreach (var artist in artistResult) + { + model.Add(new MultiSearchResult + { + MediaType = "Artist", + Title = artist.name + }); + } + } + + foreach (var multiSearch in movieDbData) + { + var result = new MultiSearchResult + { + MediaType = multiSearch.media_type, + }; + + if (multiSearch.media_type.Equals("movie", StringComparison.InvariantCultureIgnoreCase)) + { + if (multiSearch.release_date.HasValue() && DateTime.TryParse(multiSearch.release_date, out var releaseDate)) + { + result.Title = + } + } + } } } } diff --git a/src/Ombi.Core/Models/Search/V2/MultiSearchResult.cs b/src/Ombi.Core/Models/Search/V2/MultiSearchResult.cs new file mode 100644 index 000000000..171cec9cb --- /dev/null +++ b/src/Ombi.Core/Models/Search/V2/MultiSearchResult.cs @@ -0,0 +1,8 @@ +namespace Ombi.Core.Models.Search.V2 +{ + public class MultiSearchResult + { + public string MediaType { get; set; } + public string Title { get; set; } + } +} \ No newline at end of file diff --git a/src/Ombi.Core/Ombi.Core.csproj b/src/Ombi.Core/Ombi.Core.csproj index dcee27d01..9d1512277 100644 --- a/src/Ombi.Core/Ombi.Core.csproj +++ b/src/Ombi.Core/Ombi.Core.csproj @@ -23,6 +23,7 @@ + diff --git a/src/Ombi/Controllers/V2/SearchController.cs b/src/Ombi/Controllers/V2/SearchController.cs index 6cceb86aa..9bc532129 100644 --- a/src/Ombi/Controllers/V2/SearchController.cs +++ b/src/Ombi/Controllers/V2/SearchController.cs @@ -49,7 +49,7 @@ namespace Ombi.Controllers.V2 /// all Star Wars movies and Star Wars Rebels the TV Sho /// [HttpGet("multi/{searchTerm}")] - public async Task> MultiSearch(string searchTerm) + public async Task> MultiSearch(string searchTerm) { return await _multiSearchEngine.MultiSearch(searchTerm, Request.HttpContext.RequestAborted); }