mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-10 15:32:37 -07:00
A bit more work on #32 started working on requesting it. The DB is a bit of an issue...
This commit is contained in:
parent
c43f70a0e0
commit
45fb3ad376
10 changed files with 209 additions and 43 deletions
35
PlexRequests.Api.Interfaces/IHeadphonesApi.cs
Normal file
35
PlexRequests.Api.Interfaces/IHeadphonesApi.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: IHeadphonesApi.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
using System;
|
||||
|
||||
namespace PlexRequests.Api.Interfaces
|
||||
{
|
||||
public interface IHeadphonesApi
|
||||
{
|
||||
bool AddAlbum(string apiKey, Uri baseUrl, string albumId);
|
||||
}
|
||||
}
|
37
PlexRequests.Api.Interfaces/IMusicBrainzApi.cs
Normal file
37
PlexRequests.Api.Interfaces/IMusicBrainzApi.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: IMusicBrainzApi.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
using PlexRequests.Api.Models.Music;
|
||||
|
||||
namespace PlexRequests.Api.Interfaces
|
||||
{
|
||||
public interface IMusicBrainzApi
|
||||
{
|
||||
MusicBrainzSearchResults SearchAlbum(string searchTerm);
|
||||
MusicBrainzCoverArt GetCoverArt(string releaseId);
|
||||
MusicBrainzReleaseInfo GetAlbum(string releaseId);
|
||||
}
|
||||
}
|
|
@ -47,6 +47,8 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="IApiRequest.cs" />
|
||||
<Compile Include="ICouchPotatoApi.cs" />
|
||||
<Compile Include="IHeadphonesApi.cs" />
|
||||
<Compile Include="IMusicBrainzApi.cs" />
|
||||
<Compile Include="IPlexApi.cs" />
|
||||
<Compile Include="IPushbulletApi.cs" />
|
||||
<Compile Include="IPushoverApi.cs" />
|
||||
|
|
66
PlexRequests.Api.Models/Music/MusicBrainzReleaseInfo.cs
Normal file
66
PlexRequests.Api.Models/Music/MusicBrainzReleaseInfo.cs
Normal file
|
@ -0,0 +1,66 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: MusicBrainzReleaseInfo.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace PlexRequests.Api.Models.Music
|
||||
{
|
||||
public class CoverArtArchive
|
||||
{
|
||||
public int count { get; set; }
|
||||
public bool back { get; set; }
|
||||
public bool artwork { get; set; }
|
||||
public bool front { get; set; }
|
||||
public bool darkened { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class MusicBrainzReleaseInfo
|
||||
{
|
||||
public string date { get; set; }
|
||||
public string status { get; set; }
|
||||
public string asin { get; set; }
|
||||
public string title { get; set; }
|
||||
public string quality { get; set; }
|
||||
public string country { get; set; }
|
||||
public string packaging { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "text-representation")]
|
||||
public TextRepresentation TextRepresentation { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "cover-art-archive")]
|
||||
public CoverArtArchive CoverArtArchive { get; set; }
|
||||
public string barcode { get; set; }
|
||||
public string disambiguation { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "release-events")]
|
||||
public List<ReleaseEvent> ReleaseRvents { get; set; }
|
||||
public string id { get; set; }
|
||||
}
|
||||
|
||||
}
|
|
@ -51,6 +51,7 @@
|
|||
<Compile Include="Music\HeadphonesAlbumSearchResult.cs" />
|
||||
<Compile Include="Music\HeadphonesArtistSearchResult.cs" />
|
||||
<Compile Include="Music\MusicBrainzCoverArt.cs" />
|
||||
<Compile Include="Music\MusicBrainzReleaseInfo.cs" />
|
||||
<Compile Include="Music\MusicBrainzSearchResults.cs" />
|
||||
<Compile Include="Notifications\PushbulletPush.cs" />
|
||||
<Compile Include="Notifications\PushbulletResponse.cs" />
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: CouchPotatoApi.cs
|
||||
// File: HeadphonesApi.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
|
@ -26,51 +26,26 @@
|
|||
#endregion
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using NLog;
|
||||
|
||||
using PlexRequests.Api.Interfaces;
|
||||
using PlexRequests.Api.Models.Music;
|
||||
using PlexRequests.Api.Models.Sonarr;
|
||||
using PlexRequests.Helpers;
|
||||
|
||||
using RestSharp;
|
||||
|
||||
namespace PlexRequests.Api
|
||||
{
|
||||
public class HeadphonesApi
|
||||
public class HeadphonesApi : IHeadphonesApi
|
||||
{
|
||||
public HeadphonesApi()
|
||||
{
|
||||
Api = new ApiRequest();
|
||||
}
|
||||
private ApiRequest Api { get; }
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public List<HeadphonesAlbumSearchResult> SearchAlbum(string apiKey, Uri baseUrl, string searchTerm)
|
||||
{
|
||||
Log.Trace("Searching for album: {0}", searchTerm);
|
||||
var request = new RestRequest
|
||||
{
|
||||
Resource = "/api?cmd=findAlbum&name={searchTerm}",
|
||||
Method = Method.GET
|
||||
};
|
||||
|
||||
request.AddQueryParameter("apikey", apiKey);
|
||||
request.AddUrlSegment("searchTerm", searchTerm);
|
||||
|
||||
try
|
||||
{
|
||||
return Api.ExecuteJson<List<HeadphonesAlbumSearchResult>>(request, baseUrl);
|
||||
}
|
||||
catch (JsonSerializationException jse)
|
||||
{
|
||||
Log.Warn(jse);
|
||||
return new List<HeadphonesAlbumSearchResult>(); // If there is no matching result we do not get returned a JSON string, it just returns "false".
|
||||
}
|
||||
}
|
||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public bool AddAlbum(string apiKey, Uri baseUrl, string albumId)
|
||||
{
|
||||
|
|
|
@ -30,15 +30,16 @@ using Newtonsoft.Json;
|
|||
|
||||
using NLog;
|
||||
|
||||
using PlexRequests.Api.Interfaces;
|
||||
using PlexRequests.Api.Models.Music;
|
||||
|
||||
using RestSharp;
|
||||
|
||||
namespace PlexRequests.Api
|
||||
{
|
||||
public class MusicBrainsApi
|
||||
public class MusicBrainzApi : IMusicBrainzApi
|
||||
{
|
||||
public MusicBrainsApi()
|
||||
public MusicBrainzApi()
|
||||
{
|
||||
Api = new ApiRequest();
|
||||
}
|
||||
|
@ -67,6 +68,27 @@ namespace PlexRequests.Api
|
|||
}
|
||||
}
|
||||
|
||||
public MusicBrainzReleaseInfo GetAlbum(string releaseId)
|
||||
{
|
||||
Log.Trace("Getting album: {0}", releaseId);
|
||||
var request = new RestRequest
|
||||
{
|
||||
Resource = "release/{albumId}?fmt=json",
|
||||
Method = Method.GET
|
||||
};
|
||||
request.AddUrlSegment("albumId", releaseId);
|
||||
|
||||
try
|
||||
{
|
||||
return Api.Execute<MusicBrainzReleaseInfo>(request, BaseUri);
|
||||
}
|
||||
catch (JsonSerializationException jse)
|
||||
{
|
||||
Log.Warn(jse);
|
||||
return new MusicBrainzReleaseInfo(); // If there is no matching result we do not get returned a JSON string, it just returns "false".
|
||||
}
|
||||
}
|
||||
|
||||
public MusicBrainzCoverArt GetCoverArt(string releaseId)
|
||||
{
|
||||
Log.Trace("Getting cover art for release: {0}", releaseId);
|
||||
|
|
|
@ -38,6 +38,7 @@ namespace PlexRequests.Store
|
|||
public int[] SeasonList { get; set; }
|
||||
public int SeasonCount { get; set; }
|
||||
public string SeasonsRequested { get; set; }
|
||||
public string MusicBrainzId { get; set; }
|
||||
public List<string> RequestedUsers { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
|
|
|
@ -95,6 +95,8 @@ namespace PlexRequests.UI
|
|||
container.Register<ISickRageApi, SickrageApi>();
|
||||
container.Register<ISonarrApi, SonarrApi>();
|
||||
container.Register<IPlexApi, PlexApi>();
|
||||
container.Register<IMusicBrainzApi, MusicBrainzApi>();
|
||||
container.Register<IHeadphonesApi, HeadphonesApi>();
|
||||
|
||||
// NotificationService
|
||||
container.Register<INotificationService, NotificationService>().AsSingleton();
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace PlexRequests.UI.Modules
|
|||
ISettingsService<PlexRequestSettings> prSettings, IAvailabilityChecker checker,
|
||||
IRequestService request, ISonarrApi sonarrApi, ISettingsService<SonarrSettings> sonarrSettings,
|
||||
ISettingsService<SickRageSettings> sickRageService, ICouchPotatoApi cpApi, ISickRageApi srApi,
|
||||
INotificationService notify) : base("search")
|
||||
INotificationService notify, IMusicBrainzApi mbApi, IHeadphonesApi hpApi, ISettingsService<HeadphonesSettings> hpService) : base("search")
|
||||
{
|
||||
CpService = cpSettings;
|
||||
PrService = prSettings;
|
||||
|
@ -70,6 +70,10 @@ namespace PlexRequests.UI.Modules
|
|||
SickRageService = sickRageService;
|
||||
SickrageApi = srApi;
|
||||
NotificationService = notify;
|
||||
MusicBrainzApi = mbApi;
|
||||
HeadphonesApi = hpApi;
|
||||
HeadphonesService = hpService;
|
||||
|
||||
|
||||
Get["/"] = parameters => RequestLoad();
|
||||
|
||||
|
@ -96,9 +100,11 @@ namespace PlexRequests.UI.Modules
|
|||
private ISettingsService<PlexRequestSettings> PrService { get; }
|
||||
private ISettingsService<SonarrSettings> SonarrService { get; }
|
||||
private ISettingsService<SickRageSettings> SickRageService { get; }
|
||||
private ISettingsService<HeadphonesSettings> HeadphonesService { get; }
|
||||
private IAvailabilityChecker Checker { get; }
|
||||
private IMusicBrainzApi MusicBrainzApi { get; }
|
||||
private IHeadphonesApi HeadphonesApi { get; }
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private string AuthToken => Cache.GetOrSet(CacheKeys.TvDbToken, TvApi.Authenticate, 50);
|
||||
|
||||
private Negotiator RequestLoad()
|
||||
{
|
||||
|
@ -157,20 +163,12 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
private Response SearchMusic(string searchTerm)
|
||||
{
|
||||
var api = new MusicBrainsApi();
|
||||
var albums = api.SearchAlbum(searchTerm);
|
||||
var albums = MusicBrainzApi.SearchAlbum(searchTerm);
|
||||
var releases = albums.releases ?? new List<Release>();
|
||||
var model = new List<SearchMusicViewModel>();
|
||||
foreach (var a in releases)
|
||||
{
|
||||
var coverArt = api.GetCoverArt(a.id);
|
||||
var firstImage = coverArt?.images?.FirstOrDefault();
|
||||
var img = string.Empty;
|
||||
|
||||
if (firstImage != null)
|
||||
{
|
||||
img = firstImage.thumbnails?.small ?? firstImage.image;
|
||||
}
|
||||
var img = GetMusicBrainzCoverArt(a.id);
|
||||
model.Add(new SearchMusicViewModel
|
||||
{
|
||||
Title = a.title,
|
||||
|
@ -478,9 +476,36 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
private Response RequestAlbum(string releaseId)
|
||||
{
|
||||
var settings = HeadphonesService.GetSettings();
|
||||
|
||||
var albumInfo = MusicBrainzApi.GetAlbum(releaseId);
|
||||
var img = GetMusicBrainzCoverArt(albumInfo.id);
|
||||
var model = new RequestedModel
|
||||
{
|
||||
Title = albumInfo.title,
|
||||
MusicBrainzId = albumInfo.id,
|
||||
Overview = albumInfo.disambiguation,
|
||||
PosterPath = img,
|
||||
Type = RequestType.Album
|
||||
};
|
||||
|
||||
// TODO need to send to Headphones
|
||||
|
||||
return Response.AsJson("");
|
||||
}
|
||||
|
||||
private string GetMusicBrainzCoverArt(string id)
|
||||
{
|
||||
var coverArt = MusicBrainzApi.GetCoverArt(id);
|
||||
var firstImage = coverArt?.images?.FirstOrDefault();
|
||||
var img = string.Empty;
|
||||
|
||||
if (firstImage != null)
|
||||
{
|
||||
img = firstImage.thumbnails?.small ?? firstImage.image;
|
||||
}
|
||||
|
||||
return img;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue