mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-13 18:16:55 -07:00
Started on the Music Search Engine !wip
This commit is contained in:
parent
eb1c2a6959
commit
432c7763ee
5 changed files with 104 additions and 30 deletions
|
@ -7,7 +7,7 @@ namespace Ombi.Api.Lidarr
|
|||
public interface ILidarrApi
|
||||
{
|
||||
Task<List<AlbumLookup>> AlbumLookup(string searchTerm, string apiKey, string baseUrl);
|
||||
Task<List<AlbumLookup>> ArtistLookup(string searchTerm, string apiKey, string baseUrl);
|
||||
Task<List<ArtistLookup>> ArtistLookup(string searchTerm, string apiKey, string baseUrl);
|
||||
Task<List<LidarrProfile>> GetProfiles(string apiKey, string baseUrl);
|
||||
Task<List<LidarrRootFolder>> GetRootFolders(string apiKey, string baseUrl);
|
||||
}
|
||||
|
|
|
@ -36,13 +36,13 @@ namespace Ombi.Api.Lidarr
|
|||
return await Api.Request<List<LidarrRootFolder>>(request);
|
||||
}
|
||||
|
||||
public async Task<List<AlbumLookup>> ArtistLookup(string searchTerm, string apiKey, string baseUrl)
|
||||
public async Task<List<ArtistLookup>> 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<List<AlbumLookup>>(request);
|
||||
return await Api.Request<List<ArtistLookup>>(request);
|
||||
}
|
||||
|
||||
public async Task<List<AlbumLookup>> AlbumLookup(string searchTerm, string apiKey, string baseUrl)
|
||||
|
|
98
src/Ombi.Core/Engine/MusicSearchEngline.cs
Normal file
98
src/Ombi.Core/Engine/MusicSearchEngline.cs
Normal file
|
@ -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<MusicSearchEngine> logger, IRuleEvaluator r, OmbiUserManager um, ICacheService mem, ISettingsService<OmbiSettings> s, IRepository<RequestSubscription> sub,
|
||||
ISettingsService<LidarrSettings> 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> _lidarrSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Searches the specified album.
|
||||
/// </summary>
|
||||
/// <param name="search">The search.</param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<AlbumLookup>> SearchAlbum(string search)
|
||||
{
|
||||
var settings = await GetSettings();
|
||||
var result = await _lidarrApi.AlbumLookup(search, settings.ApiKey, settings.FullUri);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searches the specified artist
|
||||
/// </summary>
|
||||
/// <param name="search">The search.</param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<ArtistLookup>> SearchArtist(string search)
|
||||
{
|
||||
var settings = await GetSettings();
|
||||
var result = await _lidarrApi.ArtistLookup(search, settings.ApiKey, settings.FullUri);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all albums by the specified artist
|
||||
/// </summary>
|
||||
/// <param name="artistId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task GetArtistAlbums(int artistId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the artist that produced the album
|
||||
/// </summary>
|
||||
/// <param name="albumId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task GetAlbumArtist(int albumId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
private LidarrSettings _settings;
|
||||
private async Task<LidarrSettings> GetSettings()
|
||||
{
|
||||
return _settings ?? (_settings = await _lidarrSettings.GetSettingsAsync());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ombi.Api.DogNzb\Ombi.Api.DogNzb.csproj" />
|
||||
<ProjectReference Include="..\Ombi.Api.Lidarr\Ombi.Api.Lidarr.csproj" />
|
||||
<ProjectReference Include="..\Ombi.Api.Plex\Ombi.Api.Plex.csproj" />
|
||||
<ProjectReference Include="..\Ombi.Api.SickRage\Ombi.Api.SickRage.csproj" />
|
||||
<ProjectReference Include="..\Ombi.Api.Sonarr\Ombi.Api.Sonarr.csproj" />
|
||||
|
|
|
@ -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,23 +173,6 @@ 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) {
|
||||
const index = this.movieResults.indexOf(key, 0);
|
||||
if (index > -1) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue