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
|
|
|
|
|
{
|
2013-12-05 17:50:21 +01:00
|
|
|
|
public static void ProcessArtistData(MusicArtist artist, LastfmArtist data)
|
2013-03-04 21:03:36 +01:00
|
|
|
|
{
|
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-11-08 22:22:02 +01:00
|
|
|
|
if (yearFormed > 0)
|
|
|
|
|
{
|
|
|
|
|
artist.PremiereDate = new DateTime(yearFormed, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
|
|
|
|
|
|
|
|
|
artist.ProductionYear = yearFormed;
|
|
|
|
|
}
|
2013-09-06 17:23:20 +02:00
|
|
|
|
|
2013-12-05 17:50:21 +01:00
|
|
|
|
string imageSize;
|
|
|
|
|
artist.LastFmImageUrl = GetImageUrl(data, out imageSize);
|
|
|
|
|
artist.LastFmImageSize = imageSize;
|
2013-09-06 17:23:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-06 17:29:20 +01:00
|
|
|
|
private static string GetImageUrl(IHasLastFmImages data, out string size)
|
2013-09-06 17:23:20 +02:00
|
|
|
|
{
|
2013-11-06 17:29:20 +01:00
|
|
|
|
size = null;
|
|
|
|
|
|
2013-09-06 17:23:20 +02:00
|
|
|
|
if (data.image == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-06 19:26:56 +02:00
|
|
|
|
var validImages = data.image
|
2013-09-06 17:38:22 +02:00
|
|
|
|
.Where(i => !string.IsNullOrWhiteSpace(i.url))
|
2013-09-06 19:26:56 +02:00
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
var img = validImages
|
2013-09-06 17:38:22 +02:00
|
|
|
|
.FirstOrDefault(i => string.Equals(i.size, "mega", StringComparison.OrdinalIgnoreCase)) ??
|
|
|
|
|
data.image.FirstOrDefault(i => string.Equals(i.size, "extralarge", StringComparison.OrdinalIgnoreCase)) ??
|
2013-11-06 17:29:20 +01: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 17:23:20 +02:00
|
|
|
|
data.image.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (img != null)
|
|
|
|
|
{
|
2013-11-06 17:29:20 +01:00
|
|
|
|
size = img.size;
|
2013-09-06 17:23:20 +02:00
|
|
|
|
return img.url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
2013-03-05 17:48:17 +01:00
|
|
|
|
}
|
2013-03-04 21:03:36 +01:00
|
|
|
|
|
2013-03-05 17:48:17 +01:00
|
|
|
|
public static void ProcessAlbumData(BaseItem item, LastfmAlbum data)
|
|
|
|
|
{
|
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-09-02 03:37:44 +02:00
|
|
|
|
|
2013-11-15 16:10:56 +01:00
|
|
|
|
// Only grab the date here if the album doesn't already have one, since id3 tags are preferred
|
2013-12-18 06:44:46 +01:00
|
|
|
|
DateTime release;
|
2013-11-15 16:10:56 +01:00
|
|
|
|
|
2013-12-18 06:44:46 +01:00
|
|
|
|
if (DateTime.TryParse(data.releasedate, out release))
|
|
|
|
|
{
|
|
|
|
|
// Lastfm sends back null as sometimes 1901, other times 0
|
|
|
|
|
if (release.Year > 1901)
|
2013-11-08 22:22:02 +01:00
|
|
|
|
{
|
2013-12-18 06:44:46 +01:00
|
|
|
|
if (!item.PremiereDate.HasValue)
|
2013-11-15 16:10:56 +01:00
|
|
|
|
{
|
|
|
|
|
item.PremiereDate = release;
|
2013-12-18 06:44:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!item.ProductionYear.HasValue)
|
|
|
|
|
{
|
2013-11-15 16:10:56 +01:00
|
|
|
|
item.ProductionYear = release.Year;
|
|
|
|
|
}
|
2013-11-08 22:22:02 +01:00
|
|
|
|
}
|
2013-09-02 03:37:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-06 17:38:22 +02:00
|
|
|
|
var album = (MusicAlbum)item;
|
2013-11-06 17:29:20 +01:00
|
|
|
|
|
|
|
|
|
string imageSize;
|
|
|
|
|
|
|
|
|
|
album.LastFmImageUrl = GetImageUrl(data, out imageSize);
|
|
|
|
|
album.LastFmImageSize = imageSize;
|
2013-03-04 21:03:36 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|