pull/3338/head
tidusjar 5 years ago
parent cae9d64a03
commit 18dcddf67a

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Ombi.Api.Lidarr.Models;
@ -11,7 +12,7 @@ namespace Ombi.Api.Lidarr
Task<List<LidarrProfile>> GetProfiles(string apiKey, string baseUrl);
Task<List<LidarrRootFolder>> GetRootFolders(string apiKey, string baseUrl);
Task<ArtistResult> GetArtist(int artistId, string apiKey, string baseUrl);
Task<ArtistResult> GetArtistByForeignId(string foreignArtistId, string apiKey, string baseUrl);
Task<ArtistResult> GetArtistByForeignId(string foreignArtistId, string apiKey, string baseUrl, CancellationToken token = default);
Task<AlbumByArtistResponse> GetAlbumsByArtist(string foreignArtistId);
Task<AlbumLookup> GetAlbumByForeignId(string foreignArtistId, string apiKey, string baseUrl);
Task<List<ArtistResult>> GetArtists(string apiKey, string baseUrl);

@ -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)

@ -32,17 +32,21 @@ namespace Ombi.Api.Lidarr.Models
public class Addoptions
{
/// <summary>
/// Future = 1
/// Missing = 2
/// Existing = 3
/// First = 5
/// Latest = 4
/// None = 6
/// </summary>
public int selectedOption { get; set; }
public MonitorTypes monitor { get; set; }
public bool monitored { get; set; }
public bool searchForMissingAlbums { get; set; }
public bool searchForMissingAlbums { get; set; } // Only for Artists add
public string[] AlbumsToMonitor { get; set; } // Uses the MusicBrainzAlbumId!
}
public enum MonitorTypes
{
All,
Future,
Missing,
Existing,
Latest,
First,
None,
Unknown
}
}

@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
@ -69,12 +70,6 @@ namespace Ombi.Core.Engine
};
}
if(album?.artist == null)
{
// Lookup the artist
//album.artist = await _lidarrApi.ArtistLookup(album.artist, s.ApiKey, s.FullUri);
}
var userDetails = await GetUser();
var requestModel = new AlbumRequest
@ -132,7 +127,6 @@ namespace Ombi.Core.Engine
return await AddAlbumRequest(requestModel);
}
/// <summary>
/// Gets the requests.
/// </summary>

@ -100,8 +100,8 @@ namespace Ombi.Core.Senders
addOptions = new Addoptions
{
monitored = true,
monitor = MonitorTypes.None,
searchForMissingAlbums = false,
selectedOption = 6, // None
AlbumsToMonitor = new[] {model.ForeignAlbumId}
},
added = DateTime.Now,

Loading…
Cancel
Save