2013-04-10 08:56:36 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-04-24 07:05:47 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2013-03-05 09:48:17 -07:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2013-03-12 15:49:45 -07:00
|
|
|
|
using System;
|
2013-05-17 08:22:08 -07:00
|
|
|
|
using System.Linq;
|
2013-03-04 13:03:36 -07:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Providers.Music
|
|
|
|
|
{
|
|
|
|
|
public static class LastfmHelper
|
|
|
|
|
{
|
2013-05-24 07:35:05 -07:00
|
|
|
|
public static string LocalArtistMetaFileName = "lastfmartist.json";
|
|
|
|
|
public static string LocalAlbumMetaFileName = "lastfmalbum.json";
|
2013-03-04 13:03:36 -07:00
|
|
|
|
|
|
|
|
|
public static void ProcessArtistData(BaseItem artist, LastfmArtist data)
|
|
|
|
|
{
|
2013-03-05 08:45:25 -07:00
|
|
|
|
var yearFormed = 0;
|
2013-04-10 08:56:36 -07:00
|
|
|
|
|
|
|
|
|
if (data.bio != null)
|
2013-03-05 08:45:25 -07:00
|
|
|
|
{
|
2013-04-10 08:56:36 -07:00
|
|
|
|
Int32.TryParse(data.bio.yearformed, out yearFormed);
|
2013-04-21 21:38:03 -07:00
|
|
|
|
|
|
|
|
|
artist.Overview = data.bio.content;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(data.bio.placeformed))
|
|
|
|
|
{
|
|
|
|
|
artist.AddProductionLocation(data.bio.placeformed);
|
|
|
|
|
}
|
2013-03-05 08:45:25 -07:00
|
|
|
|
}
|
2013-04-10 08:56:36 -07:00
|
|
|
|
|
2013-05-10 20:43:10 -07:00
|
|
|
|
artist.PremiereDate = yearFormed > 0 ? new DateTime(yearFormed, 1, 1, 0, 0, 0, DateTimeKind.Utc) : (DateTime?)null;
|
2013-03-12 07:27:37 -07:00
|
|
|
|
artist.ProductionYear = yearFormed;
|
2013-03-04 13:03:36 -07:00
|
|
|
|
if (data.tags != null)
|
|
|
|
|
{
|
2013-05-17 08:22:08 -07:00
|
|
|
|
AddTags(artist, data.tags);
|
2013-03-05 09:48:17 -07:00
|
|
|
|
}
|
2013-04-24 07:05:47 -07:00
|
|
|
|
|
|
|
|
|
var entity = artist as Artist;
|
|
|
|
|
|
|
|
|
|
if (entity != null)
|
|
|
|
|
{
|
|
|
|
|
entity.IsOnTour = string.Equals(data.ontour, "1");
|
|
|
|
|
}
|
2013-03-05 09:48:17 -07:00
|
|
|
|
}
|
2013-03-04 13:03:36 -07:00
|
|
|
|
|
2013-03-05 09:48:17 -07:00
|
|
|
|
public static void ProcessAlbumData(BaseItem item, LastfmAlbum data)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(data.mbid)) item.SetProviderId(MetadataProviders.Musicbrainz, data.mbid);
|
|
|
|
|
|
2013-03-11 21:09:31 -07:00
|
|
|
|
var overview = data.wiki != null ? data.wiki.content : null;
|
|
|
|
|
|
|
|
|
|
item.Overview = overview;
|
|
|
|
|
|
2013-04-10 08:56:36 -07:00
|
|
|
|
DateTime release;
|
2013-03-05 09:48:17 -07:00
|
|
|
|
DateTime.TryParse(data.releasedate, out release);
|
|
|
|
|
item.PremiereDate = release;
|
2013-03-12 07:27:37 -07:00
|
|
|
|
item.ProductionYear = release.Year;
|
2013-03-05 09:48:17 -07:00
|
|
|
|
if (data.toptags != null)
|
|
|
|
|
{
|
2013-05-17 08:22:08 -07:00
|
|
|
|
AddTags(item, data.toptags);
|
2013-03-04 13:03:36 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-17 08:22:08 -07:00
|
|
|
|
private static void AddTags(BaseItem item, LastfmTags tags)
|
2013-03-05 09:48:17 -07:00
|
|
|
|
{
|
2013-05-17 08:22:08 -07:00
|
|
|
|
var itemTags = (from tag in tags.tag where !string.IsNullOrEmpty(tag.name) select tag.name).ToList();
|
2013-04-27 22:44:45 -07:00
|
|
|
|
|
2013-05-17 08:22:08 -07:00
|
|
|
|
item.Tags = itemTags;
|
2013-03-05 09:48:17 -07:00
|
|
|
|
}
|
2013-03-04 13:03:36 -07:00
|
|
|
|
}
|
|
|
|
|
}
|