|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Ombi.Api.Lidarr.Models;
|
|
|
|
@ -10,14 +11,12 @@ namespace Ombi.Api.Lidarr
|
|
|
|
|
{
|
|
|
|
|
public class LidarrApi : ILidarrApi
|
|
|
|
|
{
|
|
|
|
|
public LidarrApi(ILogger<LidarrApi> logger, IApi api)
|
|
|
|
|
public LidarrApi(IApi api)
|
|
|
|
|
{
|
|
|
|
|
Api = api;
|
|
|
|
|
Logger = logger;
|
|
|
|
|
_api = api;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IApi Api { get; }
|
|
|
|
|
private ILogger Logger { get; }
|
|
|
|
|
private IApi _api { get; }
|
|
|
|
|
|
|
|
|
|
private const string ApiVersion = "/api/v1";
|
|
|
|
|
|
|
|
|
@ -26,7 +25,7 @@ namespace Ombi.Api.Lidarr
|
|
|
|
|
var request = new Request($"{ApiVersion}/qualityprofile", baseUrl, HttpMethod.Get);
|
|
|
|
|
|
|
|
|
|
AddHeaders(request, apiKey);
|
|
|
|
|
return Api.Request<List<LidarrProfile>>(request);
|
|
|
|
|
return _api.Request<List<LidarrProfile>>(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<List<LidarrRootFolder>> GetRootFolders(string apiKey, string baseUrl)
|
|
|
|
@ -34,7 +33,7 @@ namespace Ombi.Api.Lidarr
|
|
|
|
|
var request = new Request($"{ApiVersion}/rootfolder", baseUrl, HttpMethod.Get);
|
|
|
|
|
|
|
|
|
|
AddHeaders(request, apiKey);
|
|
|
|
|
return Api.Request<List<LidarrRootFolder>>(request);
|
|
|
|
|
return _api.Request<List<LidarrRootFolder>>(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<List<ArtistLookup>> ArtistLookup(string searchTerm, string apiKey, string baseUrl)
|
|
|
|
@ -43,7 +42,7 @@ namespace Ombi.Api.Lidarr
|
|
|
|
|
request.AddQueryString("term", searchTerm);
|
|
|
|
|
|
|
|
|
|
AddHeaders(request, apiKey);
|
|
|
|
|
return await Api.Request<List<ArtistLookup>>(request);
|
|
|
|
|
return await _api.Request<List<ArtistLookup>>(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<List<AlbumLookup>> AlbumLookup(string searchTerm, string apiKey, string baseUrl)
|
|
|
|
@ -52,7 +51,7 @@ namespace Ombi.Api.Lidarr
|
|
|
|
|
request.AddQueryString("term", searchTerm);
|
|
|
|
|
|
|
|
|
|
AddHeaders(request, apiKey);
|
|
|
|
|
return Api.Request<List<AlbumLookup>>(request);
|
|
|
|
|
return _api.Request<List<AlbumLookup>>(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<ArtistResult> GetArtist(int artistId, string apiKey, string baseUrl)
|
|
|
|
@ -60,16 +59,16 @@ namespace Ombi.Api.Lidarr
|
|
|
|
|
var request = new Request($"{ApiVersion}/artist/{artistId}", baseUrl, HttpMethod.Get);
|
|
|
|
|
|
|
|
|
|
AddHeaders(request, apiKey);
|
|
|
|
|
return Api.Request<ArtistResult>(request);
|
|
|
|
|
return _api.Request<ArtistResult>(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<ArtistResult> GetArtistByForeignId(string foreignArtistId, string apiKey, string baseUrl)
|
|
|
|
|
public async Task<ArtistResult> GetArtistByForeignId(string foreignArtistId, string apiKey, string baseUrl, CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
var request = new Request($"{ApiVersion}/artist/lookup", baseUrl, HttpMethod.Get);
|
|
|
|
|
|
|
|
|
|
request.AddQueryString("term", $"lidarr:{foreignArtistId}");
|
|
|
|
|
AddHeaders(request, apiKey);
|
|
|
|
|
return (await Api.Request<List<ArtistResult>>(request)).FirstOrDefault();
|
|
|
|
|
return (await _api.Request<List<ArtistResult>>(request, token)).FirstOrDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<AlbumLookup> GetAlbumByForeignId(string foreignArtistId, string apiKey, string baseUrl)
|
|
|
|
@ -78,7 +77,7 @@ namespace Ombi.Api.Lidarr
|
|
|
|
|
|
|
|
|
|
request.AddQueryString("term", $"lidarr:{foreignArtistId}");
|
|
|
|
|
AddHeaders(request, apiKey);
|
|
|
|
|
var albums = await Api.Request<List<AlbumLookup>>(request);
|
|
|
|
|
var albums = await _api.Request<List<AlbumLookup>>(request);
|
|
|
|
|
return albums.FirstOrDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -86,7 +85,7 @@ namespace Ombi.Api.Lidarr
|
|
|
|
|
{
|
|
|
|
|
var request = new Request(string.Empty, $"https://api.lidarr.audio/api/v0.4/artist/{foreignArtistId}",
|
|
|
|
|
HttpMethod.Get) {IgnoreBaseUrlAppend = true};
|
|
|
|
|
return Api.Request<AlbumByArtistResponse>(request);
|
|
|
|
|
return _api.Request<AlbumByArtistResponse>(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<List<ArtistResult>> GetArtists(string apiKey, string baseUrl)
|
|
|
|
@ -94,7 +93,7 @@ namespace Ombi.Api.Lidarr
|
|
|
|
|
var request = new Request($"{ApiVersion}/artist", baseUrl, HttpMethod.Get);
|
|
|
|
|
|
|
|
|
|
AddHeaders(request, apiKey);
|
|
|
|
|
return Api.Request<List<ArtistResult>>(request);
|
|
|
|
|
return _api.Request<List<ArtistResult>>(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<List<AlbumResponse>> GetAllAlbums(string apiKey, string baseUrl)
|
|
|
|
@ -102,7 +101,7 @@ namespace Ombi.Api.Lidarr
|
|
|
|
|
var request = new Request($"{ApiVersion}/album", baseUrl, HttpMethod.Get);
|
|
|
|
|
|
|
|
|
|
AddHeaders(request, apiKey);
|
|
|
|
|
return Api.Request<List<AlbumResponse>>(request);
|
|
|
|
|
return _api.Request<List<AlbumResponse>>(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<AlbumByForeignId> AlbumInformation(string albumId, string apiKey, string baseUrl)
|
|
|
|
@ -110,7 +109,7 @@ namespace Ombi.Api.Lidarr
|
|
|
|
|
var request = new Request($"{ApiVersion}/album", baseUrl, HttpMethod.Get);
|
|
|
|
|
request.AddQueryString("foreignAlbumId", albumId);
|
|
|
|
|
AddHeaders(request, apiKey);
|
|
|
|
|
var albums = await Api.Request<List<AlbumByForeignId>>(request);
|
|
|
|
|
var albums = await _api.Request<List<AlbumByForeignId>>(request);
|
|
|
|
|
return albums.FirstOrDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -127,7 +126,7 @@ namespace Ombi.Api.Lidarr
|
|
|
|
|
var request = new Request($"{ApiVersion}/album", baseUrl, HttpMethod.Get);
|
|
|
|
|
request.AddQueryString("albumId", albumId.ToString());
|
|
|
|
|
AddHeaders(request, apiKey);
|
|
|
|
|
return Api.Request<List<LidarrTrack>>(request);
|
|
|
|
|
return _api.Request<List<LidarrTrack>>(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<ArtistResult> AddArtist(ArtistAdd artist, string apiKey, string baseUrl)
|
|
|
|
@ -135,7 +134,7 @@ namespace Ombi.Api.Lidarr
|
|
|
|
|
var request = new Request($"{ApiVersion}/artist", baseUrl, HttpMethod.Post);
|
|
|
|
|
request.AddJsonBody(artist);
|
|
|
|
|
AddHeaders(request, apiKey);
|
|
|
|
|
return Api.Request<ArtistResult>(request);
|
|
|
|
|
return _api.Request<ArtistResult>(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<AlbumResponse> MontiorAlbum(int albumId, string apiKey, string baseUrl)
|
|
|
|
@ -147,7 +146,7 @@ namespace Ombi.Api.Lidarr
|
|
|
|
|
monitored = true
|
|
|
|
|
});
|
|
|
|
|
AddHeaders(request, apiKey);
|
|
|
|
|
return (await Api.Request<List<AlbumResponse>>(request)).FirstOrDefault();
|
|
|
|
|
return (await _api.Request<List<AlbumResponse>>(request)).FirstOrDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<List<AlbumResponse>> GetAllAlbumsByArtistId(int artistId, string apiKey, string baseUrl)
|
|
|
|
@ -155,21 +154,21 @@ namespace Ombi.Api.Lidarr
|
|
|
|
|
var request = new Request($"{ApiVersion}/album", baseUrl, HttpMethod.Get);
|
|
|
|
|
request.AddQueryString("artistId", artistId.ToString());
|
|
|
|
|
AddHeaders(request, apiKey);
|
|
|
|
|
return Api.Request<List<AlbumResponse>>(request);
|
|
|
|
|
return _api.Request<List<AlbumResponse>>(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<List<MetadataProfile>> GetMetadataProfile(string apiKey, string baseUrl)
|
|
|
|
|
{
|
|
|
|
|
var request = new Request($"{ApiVersion}/metadataprofile", baseUrl, HttpMethod.Get);
|
|
|
|
|
AddHeaders(request, apiKey);
|
|
|
|
|
return Api.Request<List<MetadataProfile>>(request);
|
|
|
|
|
return _api.Request<List<MetadataProfile>>(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<LidarrStatus> Status(string apiKey, string baseUrl)
|
|
|
|
|
{
|
|
|
|
|
var request = new Request($"{ApiVersion}/system/status", baseUrl, HttpMethod.Get);
|
|
|
|
|
AddHeaders(request, apiKey);
|
|
|
|
|
return Api.Request<LidarrStatus>(request);
|
|
|
|
|
return _api.Request<LidarrStatus>(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<CommandResult> AlbumSearch(int[] albumIds, string apiKey, string baseUrl)
|
|
|
|
@ -177,7 +176,7 @@ namespace Ombi.Api.Lidarr
|
|
|
|
|
var request = new Request($"{ApiVersion}/command/", baseUrl, HttpMethod.Post);
|
|
|
|
|
request.AddJsonBody(new { name = "AlbumSearch", albumIds });
|
|
|
|
|
AddHeaders(request, apiKey);
|
|
|
|
|
return Api.Request<CommandResult>(request);
|
|
|
|
|
return _api.Request<CommandResult>(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddHeaders(Request request, string key)
|
|
|
|
|