mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 03:26:07 +02:00
Incremental LastfmArtistProvider
This commit is contained in:
parent
014a66a8bd
commit
de878025e6
4 changed files with 174 additions and 2 deletions
|
@ -110,6 +110,8 @@
|
||||||
<Compile Include="IServerApplicationPaths.cs" />
|
<Compile Include="IServerApplicationPaths.cs" />
|
||||||
<Compile Include="Library\ChildrenChangedEventArgs.cs" />
|
<Compile Include="Library\ChildrenChangedEventArgs.cs" />
|
||||||
<Compile Include="Library\DtoBuilder.cs" />
|
<Compile Include="Library\DtoBuilder.cs" />
|
||||||
|
<Compile Include="Providers\Music\LastfmArtistProvider.cs" />
|
||||||
|
<Compile Include="Providers\Music\LastfmBaseArtistProvider.cs" />
|
||||||
<Compile Include="Resolvers\BaseItemResolver.cs" />
|
<Compile Include="Resolvers\BaseItemResolver.cs" />
|
||||||
<Compile Include="Resolvers\BaseVideoResolver.cs" />
|
<Compile Include="Resolvers\BaseVideoResolver.cs" />
|
||||||
<Compile Include="Resolvers\IItemResolver.cs" />
|
<Compile Include="Resolvers\IItemResolver.cs" />
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using MediaBrowser.Common.Net;
|
||||||
|
using MediaBrowser.Controller.Entities;
|
||||||
|
using MediaBrowser.Model.Logging;
|
||||||
|
using MediaBrowser.Model.Serialization;
|
||||||
|
|
||||||
|
namespace MediaBrowser.Controller.Providers.Music
|
||||||
|
{
|
||||||
|
public class LastfmArtistProvider : LastfmBaseArtistProvider
|
||||||
|
{
|
||||||
|
public LastfmArtistProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager)
|
||||||
|
: base(jsonSerializer, httpClient, logManager)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Task FetchLastfmData(BaseItem item, string id, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,124 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using MediaBrowser.Common.Net;
|
||||||
|
using MediaBrowser.Controller.Entities.Audio;
|
||||||
|
using MediaBrowser.Model.Logging;
|
||||||
|
using MediaBrowser.Model.Net;
|
||||||
|
using MediaBrowser.Model.Serialization;
|
||||||
|
|
||||||
|
namespace MediaBrowser.Controller.Providers.Music
|
||||||
|
{
|
||||||
|
public abstract class LastfmBaseArtistProvider : LastfmBaseProvider
|
||||||
|
{
|
||||||
|
protected LastfmBaseArtistProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager)
|
||||||
|
: base(jsonSerializer, httpClient, logManager)
|
||||||
|
{
|
||||||
|
LocalMetaFileName = "MBArtist.json";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Supports(Entities.BaseItem item)
|
||||||
|
{
|
||||||
|
return item is MusicArtist;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task<string> FindId(Entities.BaseItem item, System.Threading.CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
//Execute the Artist search against our name and assume first one is the one we want
|
||||||
|
var url = RootUrl + string.Format("method=artist.search&artist={0}&api_key={1}&format=json", UrlEncode(item.Name), ApiKey);
|
||||||
|
|
||||||
|
LastfmArtistSearchResults searchResult = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var json = await HttpClient.Get(url, Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false))
|
||||||
|
{
|
||||||
|
searchResult = JsonSerializer.DeserializeFromStream<LastfmArtistSearchResults>(json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (HttpException e)
|
||||||
|
{
|
||||||
|
if (e.StatusCode == HttpStatusCode.NotFound)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (searchResult != null && searchResult.results != null && searchResult.results.artistmatches != null && searchResult.results.artistmatches.artist.Any())
|
||||||
|
{
|
||||||
|
return searchResult.results.artistmatches.artist.First().mbid;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Result Objects
|
||||||
|
|
||||||
|
public class LastfmStats
|
||||||
|
{
|
||||||
|
public string listeners { get; set; }
|
||||||
|
public string playcount { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LastfmTag
|
||||||
|
{
|
||||||
|
public string name { get; set; }
|
||||||
|
public string url { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LastfmFormationInfo
|
||||||
|
{
|
||||||
|
public string yearfrom { get; set; }
|
||||||
|
public string yearto { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LastFmBio
|
||||||
|
{
|
||||||
|
public string published { get; set; }
|
||||||
|
public string summary { get; set; }
|
||||||
|
public string content { get; set; }
|
||||||
|
public string placeformed { get; set; }
|
||||||
|
public string yearformed { get; set; }
|
||||||
|
public List<LastfmFormationInfo> formationlist { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LastfmArtist
|
||||||
|
{
|
||||||
|
public string name { get; set; }
|
||||||
|
public string mbid { get; set; }
|
||||||
|
public string url { get; set; }
|
||||||
|
public string streamable { get; set; }
|
||||||
|
public string ontour { get; set; }
|
||||||
|
public LastfmStats stats { get; set; }
|
||||||
|
public List<LastfmArtist> similar { get; set; }
|
||||||
|
public List<LastfmTag> tags { get; set; }
|
||||||
|
public LastFmBio bio { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LastfmGetArtistResult
|
||||||
|
{
|
||||||
|
public LastfmArtist artist { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Artistmatches
|
||||||
|
{
|
||||||
|
public List<LastfmArtist> artist { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LastfmArtistSearchResult
|
||||||
|
{
|
||||||
|
public Artistmatches artistmatches { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LastfmArtistSearchResults
|
||||||
|
{
|
||||||
|
public LastfmArtistSearchResult results { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
|
@ -94,7 +94,7 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected const string RootUrl = @"http://ws.audioscrobbler.com/2.0/";
|
protected const string RootUrl = @"http://ws.audioscrobbler.com/2.0/?";
|
||||||
protected static string ApiKey = "7b76553c3eb1d341d642755aecc40a33";
|
protected static string ApiKey = "7b76553c3eb1d341d642755aecc40a33";
|
||||||
|
|
||||||
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
||||||
|
@ -186,7 +186,27 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||||
/// <param name="item">The item.</param>
|
/// <param name="item">The item.</param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
protected abstract Task FetchData(BaseItem item, CancellationToken cancellationToken);
|
protected async Task FetchData(BaseItem item, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var id = item.GetProviderId(MetadataProviders.Musicbrainz) ?? await FindId(item, cancellationToken).ConfigureAwait(false);
|
||||||
|
if (id != null)
|
||||||
|
{
|
||||||
|
Logger.Debug("LastfmProvider - getting info with id: " + id);
|
||||||
|
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
|
await FetchLastfmData(item, id, cancellationToken).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logger.Info("LastfmProvider could not find " + item.Name + ". Check name on Last.fm.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract Task<string> FindId(BaseItem item, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
protected abstract Task FetchLastfmData(BaseItem item, string id, CancellationToken cancellationToken);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Encodes an URL.
|
/// Encodes an URL.
|
||||||
|
|
Loading…
Reference in a new issue