mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
!wip
This commit is contained in:
parent
ff6e3868bb
commit
47aababfa7
9 changed files with 171 additions and 42 deletions
|
@ -1,6 +1,6 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Ombi.Api.MusicBrainz.Models.Lookup;
|
using Ombi.Api.MusicBrainz.Models.Browse;
|
||||||
using Ombi.Api.MusicBrainz.Models.Search;
|
using Ombi.Api.MusicBrainz.Models.Search;
|
||||||
|
|
||||||
namespace Ombi.Api.MusicBrainz
|
namespace Ombi.Api.MusicBrainz
|
||||||
|
@ -8,6 +8,6 @@ namespace Ombi.Api.MusicBrainz
|
||||||
public interface IMusicBrainzApi
|
public interface IMusicBrainzApi
|
||||||
{
|
{
|
||||||
Task<IEnumerable<Artist>> SearchArtist(string artistQuery);
|
Task<IEnumerable<Artist>> SearchArtist(string artistQuery);
|
||||||
Task<IEnumerable<ReleaseGroups>> GetReleaseGroups(string artistId);
|
Task<IEnumerable<Release>> GetReleaseForArtist(string artistId);
|
||||||
}
|
}
|
||||||
}
|
}
|
106
src/Ombi.Api.MusicBrainz/Models/Browse/ReleaseResult.cs
Normal file
106
src/Ombi.Api.MusicBrainz/Models/Browse/ReleaseResult.cs
Normal file
|
@ -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<Track> 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<string> Iso31661Codes { get; set; }
|
||||||
|
[JsonProperty(PropertyName = "iso-3166-2-codes")]
|
||||||
|
public List<string> 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<Medium> media { get; set; }
|
||||||
|
public string id { get; set; }
|
||||||
|
[JsonProperty(PropertyName = "release-events")]
|
||||||
|
public List<ReleaseEvent> 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<Release> releases { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -3,9 +3,9 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Ombi.Api;
|
|
||||||
using Ombi.Api.MusicBrainz.Models;
|
using Ombi.Api.MusicBrainz.Models;
|
||||||
using Ombi.Api.MusicBrainz.Models.Lookup;
|
using Ombi.Api.MusicBrainz.Models.Browse;
|
||||||
using Ombi.Api.MusicBrainz.Models.Search;
|
using Ombi.Api.MusicBrainz.Models.Search;
|
||||||
|
|
||||||
namespace Ombi.Api.MusicBrainz
|
namespace Ombi.Api.MusicBrainz
|
||||||
|
@ -30,16 +30,16 @@ namespace Ombi.Api.MusicBrainz
|
||||||
return albums.Data.Where(x => !x.type.Equals("Person", StringComparison.CurrentCultureIgnoreCase));
|
return albums.Data.Where(x => !x.type.Equals("Person", StringComparison.CurrentCultureIgnoreCase));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<ReleaseGroups>> GetReleaseGroups(string artistId)
|
public async Task<IEnumerable<Release>> 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("artist", artistId);
|
||||||
|
request.AddQueryString("inc", "recordings");
|
||||||
AddHeaders(request);
|
AddHeaders(request);
|
||||||
|
|
||||||
// The count properties for release groups is called releasegroupcount... Will sort this out if I need paging
|
var releases = await _api.Request<ReleaseResult>(request);
|
||||||
var releases = await _api.Request<MusicBrainzResult<ReleaseGroups>>(request);
|
return releases.releases;
|
||||||
return releases.Data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddHeaders(Request req)
|
private void AddHeaders(Request req)
|
||||||
|
|
|
@ -2,11 +2,12 @@
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Ombi.Api.TheMovieDb.Models;
|
using Ombi.Api.TheMovieDb.Models;
|
||||||
|
using Ombi.Core.Models.Search.V2;
|
||||||
|
|
||||||
namespace Ombi.Core.Engine.V2
|
namespace Ombi.Core.Engine.V2
|
||||||
{
|
{
|
||||||
public interface IMultiSearchEngine
|
public interface IMultiSearchEngine
|
||||||
{
|
{
|
||||||
Task<List<MultiSearch>> MultiSearch(string searchTerm, CancellationToken cancellationToken, string lang = "en");
|
Task<List<MultiSearchResult>> MultiSearch(string searchTerm, CancellationToken cancellationToken, string lang = "en");
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,15 +1,19 @@
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Ombi.Api.MusicBrainz;
|
||||||
using Ombi.Api.TheMovieDb;
|
using Ombi.Api.TheMovieDb;
|
||||||
using Ombi.Api.TheMovieDb.Models;
|
using Ombi.Api.TheMovieDb.Models;
|
||||||
using Ombi.Core.Authentication;
|
using Ombi.Core.Authentication;
|
||||||
using Ombi.Core.Models.Requests;
|
using Ombi.Core.Models.Requests;
|
||||||
|
using Ombi.Core.Models.Search.V2;
|
||||||
using Ombi.Core.Rule.Interfaces;
|
using Ombi.Core.Rule.Interfaces;
|
||||||
using Ombi.Core.Settings;
|
using Ombi.Core.Settings;
|
||||||
using Ombi.Helpers;
|
using Ombi.Helpers;
|
||||||
using Ombi.Settings.Settings.Models;
|
using Ombi.Settings.Settings.Models;
|
||||||
|
using Ombi.Settings.Settings.Models.External;
|
||||||
using Ombi.Store.Entities;
|
using Ombi.Store.Entities;
|
||||||
using Ombi.Store.Repository;
|
using Ombi.Store.Repository;
|
||||||
|
|
||||||
|
@ -19,18 +23,54 @@ namespace Ombi.Core.Engine.V2
|
||||||
{
|
{
|
||||||
public MultiSearchEngine(IPrincipal identity, IRequestServiceMain requestService, IRuleEvaluator rules,
|
public MultiSearchEngine(IPrincipal identity, IRequestServiceMain requestService, IRuleEvaluator rules,
|
||||||
OmbiUserManager um, ICacheService cache, ISettingsService<OmbiSettings> ombiSettings, IRepository<RequestSubscription> sub,
|
OmbiUserManager um, ICacheService cache, ISettingsService<OmbiSettings> ombiSettings, IRepository<RequestSubscription> sub,
|
||||||
IMovieDbApi movieDbApi)
|
IMovieDbApi movieDbApi, ISettingsService<LidarrSettings> lidarrSettings, IMusicBrainzApi musicApi)
|
||||||
: base(identity, requestService, rules, um, cache, ombiSettings, sub)
|
: base(identity, requestService, rules, um, cache, ombiSettings, sub)
|
||||||
{
|
{
|
||||||
_movieDbApi = movieDbApi;
|
_movieDbApi = movieDbApi;
|
||||||
|
_lidarrSettings = lidarrSettings;
|
||||||
|
_musicApi = musicApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly IMovieDbApi _movieDbApi;
|
private readonly IMovieDbApi _movieDbApi;
|
||||||
|
private readonly ISettingsService<LidarrSettings> _lidarrSettings;
|
||||||
|
private readonly IMusicBrainzApi _musicApi;
|
||||||
|
|
||||||
|
|
||||||
public async Task<List<MultiSearch>> MultiSearch(string searchTerm, CancellationToken cancellationToken, string lang = "en")
|
public async Task<List<MultiSearchResult>> MultiSearch(string searchTerm, CancellationToken cancellationToken, string lang = "en")
|
||||||
{
|
{
|
||||||
return (await _movieDbApi.MultiSearch(searchTerm, lang, cancellationToken)).results;
|
var model = new List<MultiSearchResult>();
|
||||||
|
|
||||||
|
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 =
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
8
src/Ombi.Core/Models/Search/V2/MultiSearchResult.cs
Normal file
8
src/Ombi.Core/Models/Search/V2/MultiSearchResult.cs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
namespace Ombi.Core.Models.Search.V2
|
||||||
|
{
|
||||||
|
public class MultiSearchResult
|
||||||
|
{
|
||||||
|
public string MediaType { get; set; }
|
||||||
|
public string Title { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,6 +23,7 @@
|
||||||
<ProjectReference Include="..\Ombi.Api.DogNzb\Ombi.Api.DogNzb.csproj" />
|
<ProjectReference Include="..\Ombi.Api.DogNzb\Ombi.Api.DogNzb.csproj" />
|
||||||
<ProjectReference Include="..\Ombi.Api.Emby\Ombi.Api.Emby.csproj" />
|
<ProjectReference Include="..\Ombi.Api.Emby\Ombi.Api.Emby.csproj" />
|
||||||
<ProjectReference Include="..\Ombi.Api.Lidarr\Ombi.Api.Lidarr.csproj" />
|
<ProjectReference Include="..\Ombi.Api.Lidarr\Ombi.Api.Lidarr.csproj" />
|
||||||
|
<ProjectReference Include="..\Ombi.Api.MusicBrainz\Ombi.Api.MusicBrainz.csproj" />
|
||||||
<ProjectReference Include="..\Ombi.Api.Plex\Ombi.Api.Plex.csproj" />
|
<ProjectReference Include="..\Ombi.Api.Plex\Ombi.Api.Plex.csproj" />
|
||||||
<ProjectReference Include="..\Ombi.Api.Radarr\Ombi.Api.Radarr.csproj" />
|
<ProjectReference Include="..\Ombi.Api.Radarr\Ombi.Api.Radarr.csproj" />
|
||||||
<ProjectReference Include="..\Ombi.Api.SickRage\Ombi.Api.SickRage.csproj" />
|
<ProjectReference Include="..\Ombi.Api.SickRage\Ombi.Api.SickRage.csproj" />
|
||||||
|
|
|
@ -49,7 +49,7 @@ namespace Ombi.Controllers.V2
|
||||||
/// all Star Wars movies and Star Wars Rebels the TV Sho</param>
|
/// all Star Wars movies and Star Wars Rebels the TV Sho</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("multi/{searchTerm}")]
|
[HttpGet("multi/{searchTerm}")]
|
||||||
public async Task<List<MultiSearch>> MultiSearch(string searchTerm)
|
public async Task<List<MultiSearchResult>> MultiSearch(string searchTerm)
|
||||||
{
|
{
|
||||||
return await _multiSearchEngine.MultiSearch(searchTerm, Request.HttpContext.RequestAborted);
|
return await _multiSearchEngine.MultiSearch(searchTerm, Request.HttpContext.RequestAborted);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue