mirror of https://github.com/Ombi-app/Ombi
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
170 lines
6.9 KiB
170 lines
6.9 KiB
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Security.Principal;
|
|
using System.Threading.Tasks;
|
|
using Hqub.MusicBrainz.API.Entities;
|
|
using Ombi.Api.MusicBrainz;
|
|
using Ombi.Core.Authentication;
|
|
using Ombi.Core.Engine.Interfaces;
|
|
using Ombi.Core.Models.Requests;
|
|
using Ombi.Core.Models.Search.V2.Music;
|
|
using Ombi.Core.Rule.Interfaces;
|
|
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;
|
|
using ReleaseGroup = Ombi.Core.Models.Search.V2.Music.ReleaseGroup;
|
|
|
|
namespace Ombi.Core.Engine.V2
|
|
{
|
|
public class MusicSearchEngineV2 : BaseMediaEngine, IMusicSearchEngineV2
|
|
{
|
|
private readonly IMusicBrainzApi _musicBrainzApi;
|
|
private readonly ISettingsService<LidarrSettings> _lidarrSettings;
|
|
|
|
public MusicSearchEngineV2(IPrincipal identity, IRequestServiceMain requestService, IRuleEvaluator rules,
|
|
OmbiUserManager um, ICacheService cache, ISettingsService<OmbiSettings> ombiSettings,
|
|
IRepository<RequestSubscription> sub, IMusicBrainzApi musicBrainzApi, ISettingsService<LidarrSettings> lidarrSettings)
|
|
: base(identity, requestService, rules, um, cache, ombiSettings, sub)
|
|
{
|
|
_musicBrainzApi = musicBrainzApi;
|
|
_lidarrSettings = lidarrSettings;
|
|
}
|
|
|
|
public async Task<ArtistInformation> GetArtistInformation(string artistId)
|
|
{
|
|
var artist = await _musicBrainzApi.GetArtistInformation(artistId);
|
|
|
|
var info = new ArtistInformation
|
|
{
|
|
Id = artistId,
|
|
Name = artist.Name,
|
|
Country = artist.Country,
|
|
Region = artist.Area?.Name,
|
|
Type = artist.Type,
|
|
StartYear = artist.LifeSpan?.Begin ?? "",
|
|
EndYear = artist.LifeSpan?.End ?? "",
|
|
Disambiguation = artist.Disambiguation,
|
|
ReleaseGroups = new List<ReleaseGroup>(),
|
|
Members = new List<BandMember>()
|
|
};
|
|
|
|
foreach (var g in artist.ReleaseGroups)
|
|
{
|
|
info.ReleaseGroups.Add(new ReleaseGroup
|
|
{
|
|
Type = g.PrimaryType,
|
|
Id = g.Id,
|
|
Title = g.Title,
|
|
ReleaseDate = g.FirstReleaseDate,
|
|
});
|
|
}
|
|
|
|
info.Links = GetLinksForArtist(artist);
|
|
info.Members = GetBandMembers(artist);
|
|
return info;
|
|
}
|
|
|
|
private List<BandMember> GetBandMembers(Artist artist)
|
|
{
|
|
var members = new List<BandMember>();
|
|
var membersOfBand = artist.Relations.Where(x => x.TypeId == RelationLinks.BandMember);
|
|
foreach (var member in membersOfBand)
|
|
{
|
|
members.Add(new BandMember
|
|
{
|
|
Name = member.Artist?.Name,
|
|
Attributes = member.Attributes,
|
|
IsCurrentMember = member.Ended == null,
|
|
End = member.End,
|
|
Start = member.Begin
|
|
});
|
|
}
|
|
|
|
return members;
|
|
}
|
|
|
|
private ArtistLinks GetLinksForArtist(Artist artist)
|
|
{
|
|
var links = new ArtistLinks();
|
|
foreach (var relation in artist.Relations)
|
|
{
|
|
switch (relation.TypeId)
|
|
{
|
|
case RelationLinks.AllMusic:
|
|
links.AllMusic = relation.Url?.Resource;
|
|
break;
|
|
case RelationLinks.BbcMusic:
|
|
links.BbcMusic = relation.Url?.Resource;
|
|
break;
|
|
case RelationLinks.Discogs:
|
|
links.Discogs = relation.Url?.Resource;
|
|
break;
|
|
case RelationLinks.Homepage:
|
|
links.HomePage = relation.Url?.Resource;
|
|
break;
|
|
case RelationLinks.Imdb:
|
|
links.Imdb = relation.Url?.Resource;
|
|
break;
|
|
case RelationLinks.LastFm:
|
|
links.LastFm = relation.Url?.Resource;
|
|
break;
|
|
case RelationLinks.MySpace:
|
|
links.MySpace = relation.Url?.Resource;
|
|
break;
|
|
case RelationLinks.OnlineCommunity:
|
|
links.OnlineCommunity = relation.Url?.Resource;
|
|
break;
|
|
case RelationLinks.SocialNetwork:
|
|
if ((relation.Url?.Resource ?? string.Empty).Contains("twitter", CompareOptions.IgnoreCase))
|
|
{
|
|
links.Twitter = relation.Url?.Resource;
|
|
}
|
|
if ((relation.Url?.Resource ?? string.Empty).Contains("facebook", CompareOptions.IgnoreCase))
|
|
{
|
|
links.Facebook = relation.Url?.Resource;
|
|
}
|
|
if ((relation.Url?.Resource ?? string.Empty).Contains("instagram", CompareOptions.IgnoreCase))
|
|
{
|
|
links.Instagram = relation.Url?.Resource;
|
|
}
|
|
if ((relation.Url?.Resource ?? string.Empty).Contains("vk", CompareOptions.IgnoreCase))
|
|
{
|
|
links.Vk = relation.Url?.Resource;
|
|
}
|
|
break;
|
|
case RelationLinks.Streams:
|
|
if ((relation.Url?.Resource ?? string.Empty).Contains("spotify", CompareOptions.IgnoreCase))
|
|
{
|
|
links.Spotify = relation.Url?.Resource;
|
|
}
|
|
if ((relation.Url?.Resource ?? string.Empty).Contains("deezer", CompareOptions.IgnoreCase))
|
|
{
|
|
links.Deezer = relation.Url?.Resource;
|
|
}
|
|
|
|
break;
|
|
case RelationLinks.YouTube:
|
|
links.YouTube = relation.Url?.Resource;
|
|
break;
|
|
case RelationLinks.Download:
|
|
if ((relation.Url?.Resource ?? string.Empty).Contains("google", CompareOptions.IgnoreCase))
|
|
{
|
|
links.Google = relation.Url?.Resource;
|
|
}
|
|
if ((relation.Url?.Resource ?? string.Empty).Contains("apple", CompareOptions.IgnoreCase))
|
|
{
|
|
links.Apple = relation.Url?.Resource;
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
return links;
|
|
}
|
|
}
|
|
} |