2013-04-10 17:56:36 +02:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-04-24 16:05:47 +02:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2013-03-05 17:48:17 +01:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2013-03-12 23:49:45 +01:00
|
|
|
|
using System;
|
2013-05-17 17:22:08 +02:00
|
|
|
|
using System.Linq;
|
2013-03-04 21:03:36 +01:00
|
|
|
|
|
2013-06-09 18:47:28 +02:00
|
|
|
|
namespace MediaBrowser.Providers.Music
|
2013-03-04 21:03:36 +01:00
|
|
|
|
{
|
|
|
|
|
public static class LastfmHelper
|
|
|
|
|
{
|
|
|
|
|
public static void ProcessArtistData(BaseItem artist, LastfmArtist data)
|
|
|
|
|
{
|
2013-03-05 16:45:25 +01:00
|
|
|
|
var yearFormed = 0;
|
2013-04-10 17:56:36 +02:00
|
|
|
|
|
|
|
|
|
if (data.bio != null)
|
2013-03-05 16:45:25 +01:00
|
|
|
|
{
|
2013-04-10 17:56:36 +02:00
|
|
|
|
Int32.TryParse(data.bio.yearformed, out yearFormed);
|
2013-06-16 00:19:47 +02:00
|
|
|
|
if (!artist.LockedFields.Contains(MetadataFields.Overview))
|
|
|
|
|
{
|
|
|
|
|
artist.Overview = data.bio.content;
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrEmpty(data.bio.placeformed) && !artist.LockedFields.Contains(MetadataFields.ProductionLocations))
|
2013-04-22 06:38:03 +02:00
|
|
|
|
{
|
|
|
|
|
artist.AddProductionLocation(data.bio.placeformed);
|
|
|
|
|
}
|
2013-03-05 16:45:25 +01:00
|
|
|
|
}
|
2013-04-10 17:56:36 +02:00
|
|
|
|
|
2013-05-11 05:43:10 +02:00
|
|
|
|
artist.PremiereDate = yearFormed > 0 ? new DateTime(yearFormed, 1, 1, 0, 0, 0, DateTimeKind.Utc) : (DateTime?)null;
|
2013-03-12 15:27:37 +01:00
|
|
|
|
artist.ProductionYear = yearFormed;
|
2013-06-16 00:19:47 +02:00
|
|
|
|
if (data.tags != null && !artist.LockedFields.Contains(MetadataFields.Tags))
|
2013-03-04 21:03:36 +01:00
|
|
|
|
{
|
2013-05-17 17:22:08 +02:00
|
|
|
|
AddTags(artist, data.tags);
|
2013-03-05 17:48:17 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-03-04 21:03:36 +01:00
|
|
|
|
|
2013-05-27 17:02:16 +02:00
|
|
|
|
public static void ProcessArtistData(MusicArtist source, Artist target)
|
|
|
|
|
{
|
|
|
|
|
target.PremiereDate = source.PremiereDate;
|
|
|
|
|
target.ProductionYear = source.ProductionYear;
|
|
|
|
|
target.Tags = source.Tags.ToList();
|
|
|
|
|
target.Overview = source.Overview;
|
|
|
|
|
target.ProductionLocations = source.ProductionLocations.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 17:48:17 +01:00
|
|
|
|
public static void ProcessAlbumData(BaseItem item, LastfmAlbum data)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(data.mbid)) item.SetProviderId(MetadataProviders.Musicbrainz, data.mbid);
|
|
|
|
|
|
2013-03-12 05:09:31 +01:00
|
|
|
|
var overview = data.wiki != null ? data.wiki.content : null;
|
|
|
|
|
|
2013-06-16 00:19:47 +02:00
|
|
|
|
if (!item.LockedFields.Contains(MetadataFields.Overview))
|
|
|
|
|
{
|
|
|
|
|
item.Overview = overview;
|
|
|
|
|
}
|
2013-04-10 17:56:36 +02:00
|
|
|
|
DateTime release;
|
2013-03-05 17:48:17 +01:00
|
|
|
|
DateTime.TryParse(data.releasedate, out release);
|
|
|
|
|
item.PremiereDate = release;
|
2013-03-12 15:27:37 +01:00
|
|
|
|
item.ProductionYear = release.Year;
|
2013-06-16 00:19:47 +02:00
|
|
|
|
if (data.toptags != null && !item.LockedFields.Contains(MetadataFields.Tags))
|
2013-03-05 17:48:17 +01:00
|
|
|
|
{
|
2013-05-17 17:22:08 +02:00
|
|
|
|
AddTags(item, data.toptags);
|
2013-03-04 21:03:36 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-17 17:22:08 +02:00
|
|
|
|
private static void AddTags(BaseItem item, LastfmTags tags)
|
2013-03-05 17:48:17 +01:00
|
|
|
|
{
|
2013-05-17 17:22:08 +02:00
|
|
|
|
var itemTags = (from tag in tags.tag where !string.IsNullOrEmpty(tag.name) select tag.name).ToList();
|
2013-04-28 07:44:45 +02:00
|
|
|
|
|
2013-05-17 17:22:08 +02:00
|
|
|
|
item.Tags = itemTags;
|
2013-03-05 17:48:17 +01:00
|
|
|
|
}
|
2013-03-04 21:03:36 +01:00
|
|
|
|
}
|
|
|
|
|
}
|