mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-30 03:28:28 -07:00
!wip on Music API
This commit is contained in:
parent
ca010a0282
commit
c2764fe780
10 changed files with 147 additions and 1 deletions
|
@ -23,5 +23,6 @@ namespace Ombi.Api.Lidarr
|
|||
Task<List<LanguageProfiles>> GetLanguageProfile(string apiKey, string baseUrl);
|
||||
Task<LidarrStatus> Status(string apiKey, string baseUrl);
|
||||
Task<CommandResult> AlbumSearch(int[] albumIds, string apiKey, string baseUrl);
|
||||
Task<AlbumResponse> AlbumInformation(string albumId, string apiKey, string baseUrl);
|
||||
}
|
||||
}
|
|
@ -105,6 +105,32 @@ namespace Ombi.Api.Lidarr
|
|||
return Api.Request<List<AlbumResponse>>(request);
|
||||
}
|
||||
|
||||
public async Task<AlbumResponse> AlbumInformation(string albumId, string apiKey, string baseUrl)
|
||||
{
|
||||
var request = new Request($"{ApiVersion}/album", baseUrl, HttpMethod.Get);
|
||||
request.AddQueryString("foreignAlbumId", albumId);
|
||||
AddHeaders(request, apiKey);
|
||||
var albums = await Api.Request<List<AlbumResponse>>(request);
|
||||
return albums.Where(x => x.foreignAlbumId.Equals(albumId, StringComparison.InvariantCultureIgnoreCase))
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// THIS ONLY SUPPORTS ALBUMS THAT THE ARTIST IS IN LIDARR
|
||||
/// </summary>
|
||||
/// <param name="albumId"></param>
|
||||
/// <param name="apiKey"></param>
|
||||
/// <param name="baseUrl"></param>
|
||||
/// <returns></returns>
|
||||
public Task<List<LidarrTrack>> GetTracksForAlbum(int albumId, string apiKey, string baseUrl)
|
||||
{
|
||||
var request = new Request($"{ApiVersion}/album", baseUrl, HttpMethod.Get);
|
||||
request.AddQueryString("albumId", albumId.ToString());
|
||||
AddHeaders(request, apiKey);
|
||||
return Api.Request<List<LidarrTrack>>(request);
|
||||
}
|
||||
|
||||
public Task<ArtistResult> AddArtist(ArtistAdd artist, string apiKey, string baseUrl)
|
||||
{
|
||||
var request = new Request($"{ApiVersion}/artist", baseUrl, HttpMethod.Post);
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ombi.Api.Lidarr.Models
|
||||
{
|
||||
public class AlbumLookup
|
||||
{
|
||||
public string title { get; set; }
|
||||
public string status { get; set; }
|
||||
public string artistType { get; set; }
|
||||
public string disambiguation { get; set; }
|
||||
public List<LidarrLinks> links { get; set; }
|
||||
public int artistId { get; set; }
|
||||
public string foreignAlbumId { get; set; }
|
||||
public bool monitored { get; set; }
|
||||
|
|
12
src/Ombi.Api.Lidarr/Models/LidarrLinks.cs
Normal file
12
src/Ombi.Api.Lidarr/Models/LidarrLinks.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Ombi.Api.Lidarr.Models
|
||||
{
|
||||
public class LidarrLinks
|
||||
{
|
||||
public string url { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
}
|
8
src/Ombi.Api.Lidarr/Models/LidarrRatings.cs
Normal file
8
src/Ombi.Api.Lidarr/Models/LidarrRatings.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace Ombi.Api.Lidarr.Models
|
||||
{
|
||||
public class LidarrRatings
|
||||
{
|
||||
public int votes { get; set; }
|
||||
public decimal value { get; set; }
|
||||
}
|
||||
}
|
22
src/Ombi.Api.Lidarr/Models/LidarrTrack.cs
Normal file
22
src/Ombi.Api.Lidarr/Models/LidarrTrack.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Ombi.Api.Lidarr.Models
|
||||
{
|
||||
public class LidarrTrack
|
||||
{
|
||||
public int artistId { get; set; }
|
||||
public int trackFileId { get; set; }
|
||||
public int albumId { get; set; }
|
||||
public bool _explicit { get; set; }
|
||||
public int absoluteTrackNumber { get; set; }
|
||||
public string trackNumber { get; set; }
|
||||
public string title { get; set; }
|
||||
public int duration { get; set; }
|
||||
public int mediumNumber { get; set; }
|
||||
public bool hasFile { get; set; }
|
||||
public bool monitored { get; set; }
|
||||
public int id { get; set; }
|
||||
}
|
||||
}
|
|
@ -12,5 +12,6 @@ namespace Ombi.Core.Engine
|
|||
Task<IEnumerable<SearchAlbumViewModel>> GetArtistAlbums(string foreignArtistId);
|
||||
Task<IEnumerable<SearchAlbumViewModel>> SearchAlbum(string search);
|
||||
Task<IEnumerable<SearchArtistViewModel>> SearchArtist(string search);
|
||||
Task<SearchAlbumViewModel> GetAlbumInformation(string foreignAlbumId);
|
||||
}
|
||||
}
|
|
@ -60,6 +60,18 @@ namespace Ombi.Core.Engine
|
|||
return vm;
|
||||
}
|
||||
|
||||
public async Task<SearchAlbumViewModel> GetAlbumInformation(string foreignAlbumId)
|
||||
{
|
||||
var settings = await GetSettings();
|
||||
var result = await _lidarrApi.AlbumInformation(foreignAlbumId, settings.ApiKey, settings.FullUri);
|
||||
|
||||
|
||||
var vm = await MapIntoAlbumVm(result, settings);
|
||||
|
||||
|
||||
return vm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searches the specified artist
|
||||
/// </summary>
|
||||
|
@ -143,6 +155,48 @@ namespace Ombi.Core.Engine
|
|||
return vm;
|
||||
}
|
||||
|
||||
|
||||
// TODO
|
||||
private async Task<SearchAlbumViewModel> MapIntoAlbumVm(AlbumResponse a, LidarrSettings settings)
|
||||
{
|
||||
var vm = new SearchAlbumViewModel
|
||||
{
|
||||
ForeignAlbumId = a.foreignAlbumId,
|
||||
Monitored = a.monitored,
|
||||
Rating = a.ratings?.value ?? 0m,
|
||||
ReleaseDate = a.releaseDate,
|
||||
Title = a.title,
|
||||
Disk = a.images?.FirstOrDefault(x => x.coverType.Equals("disc"))?.url?.Replace("http", "https"),
|
||||
Genres = a.genres
|
||||
};
|
||||
if (a.artistId > 0)
|
||||
{
|
||||
//TODO THEY HAVE FIXED THIS IN DEV
|
||||
// The JSON is different for some stupid reason
|
||||
// Need to lookup the artist now and all the images -.-"
|
||||
var artist = await _lidarrApi.GetArtist(a.artistId, settings.ApiKey, settings.FullUri);
|
||||
vm.ArtistName = artist.artistName;
|
||||
vm.ForeignArtistId = artist.foreignArtistId;
|
||||
}
|
||||
else
|
||||
{
|
||||
//vm.ForeignArtistId = a.artistId?.foreignArtistId;
|
||||
//vm.ArtistName = a.artist?.artistName;
|
||||
}
|
||||
|
||||
vm.Cover = a.images?.FirstOrDefault(x => x.coverType.Equals("cover"))?.url?.Replace("http", "https");
|
||||
if (vm.Cover.IsNullOrEmpty())
|
||||
{
|
||||
//vm.Cover = a.remoteCover;
|
||||
}
|
||||
|
||||
await Rules.StartSpecificRules(vm, SpecificRules.LidarrAlbum);
|
||||
|
||||
await RunSearchRules(vm);
|
||||
|
||||
return vm;
|
||||
}
|
||||
|
||||
private async Task<SearchAlbumViewModel> MapIntoAlbumVm(AlbumLookup a, LidarrSettings settings)
|
||||
{
|
||||
var vm = new SearchAlbumViewModel
|
||||
|
@ -152,7 +206,7 @@ namespace Ombi.Core.Engine
|
|||
Rating = a.ratings?.value ?? 0m,
|
||||
ReleaseDate = a.releaseDate,
|
||||
Title = a.title,
|
||||
Disk = a.images?.FirstOrDefault(x => x.coverType.Equals("disc"))?.url?.Replace("http","https"),
|
||||
Disk = a.images?.FirstOrDefault(x => x.coverType.Equals("disc"))?.url?.Replace("http", "https"),
|
||||
Genres = a.genres
|
||||
};
|
||||
if (a.artistId > 0)
|
||||
|
|
|
@ -20,5 +20,9 @@ namespace Ombi.Core.Models.Search
|
|||
public override RequestType Type => RequestType.Album;
|
||||
public bool PartiallyAvailable => PercentOfTracks != 100 && PercentOfTracks > 0;
|
||||
public bool FullyAvailable => PercentOfTracks == 100;
|
||||
|
||||
|
||||
// Below is from the INFO call NEED A SEPERATE VM FOR THIS IN V4 TODO
|
||||
// TODO ADD TRACK COUNT
|
||||
}
|
||||
}
|
|
@ -369,6 +369,19 @@ namespace Ombi.Controllers
|
|||
return await MusicEngine.SearchAlbum(searchTerm);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the album information specified by the foreignAlbumId passed in
|
||||
/// </summary>
|
||||
/// <remarks>We use Lidarr as the Provider</remarks>
|
||||
/// <returns></returns>
|
||||
[HttpGet("music/album/info/{foreignAlbumId}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesDefaultResponseType]
|
||||
public async Task<SearchAlbumViewModel> GetAlbumInformation(string foreignAlbumId)
|
||||
{
|
||||
return await MusicEngine.GetAlbumInformation(foreignAlbumId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all albums for the artist using the ForeignArtistId
|
||||
/// </summary>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue