From 432c7763ee7fafe35d7b4d6435690158394a782f Mon Sep 17 00:00:00 2001 From: TidusJar Date: Wed, 22 Aug 2018 14:16:45 +0100 Subject: [PATCH] Started on the Music Search Engine !wip --- src/Ombi.Api.Lidarr/ILidarrApi.cs | 2 +- src/Ombi.Api.Lidarr/LidarrApi.cs | 4 +- src/Ombi.Core/Engine/MusicSearchEngline.cs | 98 +++++++++++++++++++ src/Ombi.Core/Ombi.Core.csproj | 1 + .../app/search/music/musicsearch.component.ts | 29 +----- 5 files changed, 104 insertions(+), 30 deletions(-) create mode 100644 src/Ombi.Core/Engine/MusicSearchEngline.cs diff --git a/src/Ombi.Api.Lidarr/ILidarrApi.cs b/src/Ombi.Api.Lidarr/ILidarrApi.cs index 6732693db..8e7f7dfcf 100644 --- a/src/Ombi.Api.Lidarr/ILidarrApi.cs +++ b/src/Ombi.Api.Lidarr/ILidarrApi.cs @@ -7,7 +7,7 @@ namespace Ombi.Api.Lidarr public interface ILidarrApi { Task> AlbumLookup(string searchTerm, string apiKey, string baseUrl); - Task> ArtistLookup(string searchTerm, string apiKey, string baseUrl); + Task> ArtistLookup(string searchTerm, string apiKey, string baseUrl); Task> GetProfiles(string apiKey, string baseUrl); Task> GetRootFolders(string apiKey, string baseUrl); } diff --git a/src/Ombi.Api.Lidarr/LidarrApi.cs b/src/Ombi.Api.Lidarr/LidarrApi.cs index 2becb57aa..db2e380d3 100644 --- a/src/Ombi.Api.Lidarr/LidarrApi.cs +++ b/src/Ombi.Api.Lidarr/LidarrApi.cs @@ -36,13 +36,13 @@ namespace Ombi.Api.Lidarr return await Api.Request>(request); } - public async Task> ArtistLookup(string searchTerm, string apiKey, string baseUrl) + public async Task> ArtistLookup(string searchTerm, string apiKey, string baseUrl) { var request = new Request($"{ApiVersion}/Artist/lookup", baseUrl, HttpMethod.Get); request.AddQueryString("term", searchTerm); AddHeaders(request, apiKey); - return await Api.Request>(request); + return await Api.Request>(request); } public async Task> AlbumLookup(string searchTerm, string apiKey, string baseUrl) diff --git a/src/Ombi.Core/Engine/MusicSearchEngline.cs b/src/Ombi.Core/Engine/MusicSearchEngline.cs new file mode 100644 index 000000000..ddb50ec12 --- /dev/null +++ b/src/Ombi.Core/Engine/MusicSearchEngline.cs @@ -0,0 +1,98 @@ +using System; +using AutoMapper; +using Microsoft.Extensions.Logging; +using Ombi.Api.TheMovieDb; +using Ombi.Api.TheMovieDb.Models; +using Ombi.Core.Models.Requests; +using Ombi.Core.Models.Search; +using System.Collections.Generic; +using System.Linq; +using System.Security.Principal; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Ombi.Core.Rule.Interfaces; +using Microsoft.Extensions.Caching.Memory; +using Ombi.Api.Lidarr; +using Ombi.Api.Lidarr.Models; +using Ombi.Core.Authentication; +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; + +namespace Ombi.Core.Engine +{ + public class MusicSearchEngine : BaseMediaEngine + { + public MusicSearchEngine(IPrincipal identity, IRequestServiceMain service, ILidarrApi lidarrApi, IMapper mapper, + ILogger logger, IRuleEvaluator r, OmbiUserManager um, ICacheService mem, ISettingsService s, IRepository sub, + ISettingsService lidarrSettings) + : base(identity, service, r, um, mem, s, sub) + { + _lidarrApi = lidarrApi; + _lidarrSettings = lidarrSettings; + Mapper = mapper; + Logger = logger; + } + + private readonly ILidarrApi _lidarrApi; + private IMapper Mapper { get; } + private ILogger Logger { get; } + private readonly ISettingsService _lidarrSettings; + + /// + /// Searches the specified album. + /// + /// The search. + /// + public async Task> SearchAlbum(string search) + { + var settings = await GetSettings(); + var result = await _lidarrApi.AlbumLookup(search, settings.ApiKey, settings.FullUri); + + return result; + } + + /// + /// Searches the specified artist + /// + /// The search. + /// + public async Task> SearchArtist(string search) + { + var settings = await GetSettings(); + var result = await _lidarrApi.ArtistLookup(search, settings.ApiKey, settings.FullUri); + + return result; + } + + /// + /// Returns all albums by the specified artist + /// + /// + /// + public async Task GetArtistAlbums(int artistId) + { + throw new NotImplementedException(); + } + + /// + /// Returns the artist that produced the album + /// + /// + /// + public async Task GetAlbumArtist(int albumId) + { + throw new NotImplementedException(); + } + + + private LidarrSettings _settings; + private async Task GetSettings() + { + return _settings ?? (_settings = await _lidarrSettings.GetSettingsAsync()); + } + } +} \ No newline at end of file diff --git a/src/Ombi.Core/Ombi.Core.csproj b/src/Ombi.Core/Ombi.Core.csproj index 104db24fc..f75d08e6b 100644 --- a/src/Ombi.Core/Ombi.Core.csproj +++ b/src/Ombi.Core/Ombi.Core.csproj @@ -22,6 +22,7 @@ + diff --git a/src/Ombi/ClientApp/app/search/music/musicsearch.component.ts b/src/Ombi/ClientApp/app/search/music/musicsearch.component.ts index 38f02eb8b..2d1becf3a 100644 --- a/src/Ombi/ClientApp/app/search/music/musicsearch.component.ts +++ b/src/Ombi/ClientApp/app/search/music/musicsearch.component.ts @@ -1,6 +1,5 @@ import { PlatformLocation } from "@angular/common"; import { Component, Input, OnInit } from "@angular/core"; -import { DomSanitizer } from "@angular/platform-browser"; import { TranslateService } from "@ngx-translate/core"; import { Subject } from "rxjs"; import { debounceTime, distinctUntilChanged } from "rxjs/operators"; @@ -33,7 +32,7 @@ export class MusicSearchComponent implements OnInit { constructor( private searchService: SearchService, private requestService: RequestService, private notificationService: NotificationService, private authService: AuthService, - private readonly translate: TranslateService, private sanitizer: DomSanitizer, + private readonly translate: TranslateService, private readonly platformLocation: PlatformLocation) { this.searchChanged.pipe( @@ -49,9 +48,6 @@ export class MusicSearchComponent implements OnInit { .subscribe(x => { this.movieResults = x; this.searchApplied = true; - // Now let's load some extra info including IMDB Id - // This way the search is fast at displaying results. - this.getExtraInfo(); }); }); this.defaultPoster = "../../../images/default_movie_poster.png"; @@ -120,7 +116,6 @@ export class MusicSearchComponent implements OnInit { this.searchService.popularMovies() .subscribe(x => { this.movieResults = x; - this.getExtraInfo(); }); } public nowPlayingMovies() { @@ -128,7 +123,6 @@ export class MusicSearchComponent implements OnInit { this.searchService.nowPlayingMovies() .subscribe(x => { this.movieResults = x; - this.getExtraInfo(); }); } public topRatedMovies() { @@ -136,7 +130,6 @@ export class MusicSearchComponent implements OnInit { this.searchService.topRatedMovies() .subscribe(x => { this.movieResults = x; - this.getExtraInfo(); }); } public upcomingMovies() { @@ -144,7 +137,6 @@ export class MusicSearchComponent implements OnInit { this.searchService.upcomingMovies() .subscribe(x => { this.movieResults = x; - this.getExtraInfo(); }); } @@ -181,24 +173,7 @@ export class MusicSearchComponent implements OnInit { }); } - private getExtraInfo() { - - this.movieResults.forEach((val, index) => { - if (val.posterPath === null) { - val.posterPath = this.defaultPoster; - } else { - val.posterPath = "https://image.tmdb.org/t/p/w300/" + val.posterPath; - } - val.background = this.sanitizer.bypassSecurityTrustStyle - ("url(" + "https://image.tmdb.org/t/p/w1280" + val.backdropPath + ")"); - this.searchService.getMovieInformation(val.id) - .subscribe(m => { - this.updateItem(val, m); - }); - }); - } - - private updateItem(key: ISearchMovieResult, updated: ISearchMovieResult) { + private updateItem(key: ISearchMovieResult, updated: ISearchMovieResult) { const index = this.movieResults.indexOf(key, 0); if (index > -1) { const copy = { ...this.movieResults[index] };