2013-04-10 15:56:36 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-04-24 14:05:47 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2013-03-05 16:48:17 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2013-03-12 22:49:45 +00:00
|
|
|
|
using System;
|
2013-05-17 15:22:08 +00:00
|
|
|
|
using System.Linq;
|
2013-03-04 20:03:36 +00:00
|
|
|
|
|
2013-06-09 16:47:28 +00:00
|
|
|
|
namespace MediaBrowser.Providers.Music
|
2013-03-04 20:03:36 +00:00
|
|
|
|
{
|
|
|
|
|
public static class LastfmHelper
|
|
|
|
|
{
|
|
|
|
|
public static void ProcessArtistData(BaseItem artist, LastfmArtist data)
|
|
|
|
|
{
|
2013-03-05 15:45:25 +00:00
|
|
|
|
var yearFormed = 0;
|
2013-04-10 15:56:36 +00:00
|
|
|
|
|
|
|
|
|
if (data.bio != null)
|
2013-03-05 15:45:25 +00:00
|
|
|
|
{
|
2013-04-10 15:56:36 +00:00
|
|
|
|
Int32.TryParse(data.bio.yearformed, out yearFormed);
|
2013-06-15 22:19:47 +00: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 04:38:03 +00:00
|
|
|
|
{
|
|
|
|
|
artist.AddProductionLocation(data.bio.placeformed);
|
|
|
|
|
}
|
2013-03-05 15:45:25 +00:00
|
|
|
|
}
|
2013-04-10 15:56:36 +00:00
|
|
|
|
|
2013-05-11 03:43:10 +00:00
|
|
|
|
artist.PremiereDate = yearFormed > 0 ? new DateTime(yearFormed, 1, 1, 0, 0, 0, DateTimeKind.Utc) : (DateTime?)null;
|
2013-03-12 14:27:37 +00:00
|
|
|
|
artist.ProductionYear = yearFormed;
|
2013-06-15 22:19:47 +00:00
|
|
|
|
if (data.tags != null && !artist.LockedFields.Contains(MetadataFields.Tags))
|
2013-03-04 20:03:36 +00:00
|
|
|
|
{
|
2013-05-17 15:22:08 +00:00
|
|
|
|
AddTags(artist, data.tags);
|
2013-03-05 16:48:17 +00:00
|
|
|
|
}
|
2013-09-06 15:23:20 +00:00
|
|
|
|
|
|
|
|
|
var musicArtist = artist as MusicArtist;
|
|
|
|
|
|
2013-11-06 16:29:20 +00:00
|
|
|
|
string imageSize;
|
|
|
|
|
|
2013-09-06 15:23:20 +00:00
|
|
|
|
if (musicArtist != null)
|
|
|
|
|
{
|
2013-11-06 16:29:20 +00:00
|
|
|
|
musicArtist.LastFmImageUrl = GetImageUrl(data, out imageSize);
|
|
|
|
|
musicArtist.LastFmImageSize = imageSize;
|
2013-09-06 15:23:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var artistByName = artist as Artist;
|
|
|
|
|
|
|
|
|
|
if (artistByName != null)
|
|
|
|
|
{
|
2013-11-06 16:29:20 +00:00
|
|
|
|
artistByName.LastFmImageUrl = GetImageUrl(data, out imageSize);
|
|
|
|
|
artistByName.LastFmImageSize = imageSize;
|
2013-09-06 15:23:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-06 16:29:20 +00:00
|
|
|
|
private static string GetImageUrl(IHasLastFmImages data, out string size)
|
2013-09-06 15:23:20 +00:00
|
|
|
|
{
|
2013-11-06 16:29:20 +00:00
|
|
|
|
size = null;
|
|
|
|
|
|
2013-09-06 15:23:20 +00:00
|
|
|
|
if (data.image == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-06 17:26:56 +00:00
|
|
|
|
var validImages = data.image
|
2013-09-06 15:38:22 +00:00
|
|
|
|
.Where(i => !string.IsNullOrWhiteSpace(i.url))
|
2013-09-06 17:26:56 +00:00
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
var img = validImages
|
2013-09-06 15:38:22 +00:00
|
|
|
|
.FirstOrDefault(i => string.Equals(i.size, "mega", StringComparison.OrdinalIgnoreCase)) ??
|
|
|
|
|
data.image.FirstOrDefault(i => string.Equals(i.size, "extralarge", StringComparison.OrdinalIgnoreCase)) ??
|
2013-11-06 16:29:20 +00:00
|
|
|
|
data.image.FirstOrDefault(i => string.Equals(i.size, "large", StringComparison.OrdinalIgnoreCase)) ??
|
|
|
|
|
data.image.FirstOrDefault(i => string.Equals(i.size, "medium", StringComparison.OrdinalIgnoreCase)) ??
|
2013-09-06 15:23:20 +00:00
|
|
|
|
data.image.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (img != null)
|
|
|
|
|
{
|
2013-11-06 16:29:20 +00:00
|
|
|
|
size = img.size;
|
2013-09-06 15:23:20 +00:00
|
|
|
|
return img.url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
2013-03-05 16:48:17 +00:00
|
|
|
|
}
|
2013-03-04 20:03:36 +00:00
|
|
|
|
|
2013-05-27 15:02:16 +00: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-11-06 16:29:20 +00:00
|
|
|
|
|
2013-03-05 16:48:17 +00:00
|
|
|
|
public static void ProcessAlbumData(BaseItem item, LastfmAlbum data)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(data.mbid)) item.SetProviderId(MetadataProviders.Musicbrainz, data.mbid);
|
|
|
|
|
|
2013-03-12 04:09:31 +00:00
|
|
|
|
var overview = data.wiki != null ? data.wiki.content : null;
|
|
|
|
|
|
2013-06-15 22:19:47 +00:00
|
|
|
|
if (!item.LockedFields.Contains(MetadataFields.Overview))
|
|
|
|
|
{
|
|
|
|
|
item.Overview = overview;
|
|
|
|
|
}
|
2013-09-02 01:37:44 +00:00
|
|
|
|
|
2013-04-10 15:56:36 +00:00
|
|
|
|
DateTime release;
|
2013-09-02 01:37:44 +00:00
|
|
|
|
|
|
|
|
|
if (DateTime.TryParse(data.releasedate, out release) && release.Year != 1901)
|
|
|
|
|
{
|
|
|
|
|
item.PremiereDate = release;
|
|
|
|
|
item.ProductionYear = release.Year;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 22:19:47 +00:00
|
|
|
|
if (data.toptags != null && !item.LockedFields.Contains(MetadataFields.Tags))
|
2013-03-05 16:48:17 +00:00
|
|
|
|
{
|
2013-05-17 15:22:08 +00:00
|
|
|
|
AddTags(item, data.toptags);
|
2013-03-04 20:03:36 +00:00
|
|
|
|
}
|
2013-09-06 15:38:22 +00:00
|
|
|
|
|
|
|
|
|
var album = (MusicAlbum)item;
|
2013-11-06 16:29:20 +00:00
|
|
|
|
|
|
|
|
|
string imageSize;
|
|
|
|
|
|
|
|
|
|
album.LastFmImageUrl = GetImageUrl(data, out imageSize);
|
|
|
|
|
album.LastFmImageSize = imageSize;
|
2013-03-04 20:03:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-17 15:22:08 +00:00
|
|
|
|
private static void AddTags(BaseItem item, LastfmTags tags)
|
2013-03-05 16:48:17 +00:00
|
|
|
|
{
|
2013-05-17 15:22:08 +00:00
|
|
|
|
var itemTags = (from tag in tags.tag where !string.IsNullOrEmpty(tag.name) select tag.name).ToList();
|
2013-04-28 05:44:45 +00:00
|
|
|
|
|
2013-05-17 15:22:08 +00:00
|
|
|
|
item.Tags = itemTags;
|
2013-03-05 16:48:17 +00:00
|
|
|
|
}
|
2013-03-04 20:03:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|