jellyfin/MediaBrowser.Providers/Music/LastfmHelper.cs

73 lines
2.6 KiB
C#
Raw Normal View History

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;
using System;
using System.Linq;
2013-06-09 09:47:28 -07:00
namespace MediaBrowser.Providers.Music
{
public static class LastfmHelper
{
public static void ProcessArtistData(BaseItem artist, LastfmArtist data)
{
2013-03-05 08:45:25 -07:00
var yearFormed = 0;
if (data.bio != null)
2013-03-05 08:45:25 -07:00
{
Int32.TryParse(data.bio.yearformed, out yearFormed);
if (!artist.LockedFields.Contains(MetadataFields.Overview))
{
artist.Overview = data.bio.content;
}
if (!string.IsNullOrEmpty(data.bio.placeformed) && !artist.LockedFields.Contains(MetadataFields.ProductionLocations))
2013-04-21 21:38:03 -07:00
{
artist.AddProductionLocation(data.bio.placeformed);
}
2013-03-05 08:45:25 -07:00
}
artist.PremiereDate = yearFormed > 0 ? new DateTime(yearFormed, 1, 1, 0, 0, 0, DateTimeKind.Utc) : (DateTime?)null;
artist.ProductionYear = yearFormed;
if (data.tags != null && !artist.LockedFields.Contains(MetadataFields.Tags))
{
AddTags(artist, data.tags);
2013-03-05 09:48:17 -07: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 09:48:17 -07:00
public static void ProcessAlbumData(BaseItem item, LastfmAlbum data)
{
if (!string.IsNullOrWhiteSpace(data.mbid)) item.SetProviderId(MetadataProviders.Musicbrainz, data.mbid);
var overview = data.wiki != null ? data.wiki.content : null;
if (!item.LockedFields.Contains(MetadataFields.Overview))
{
item.Overview = overview;
}
DateTime release;
2013-03-05 09:48:17 -07:00
DateTime.TryParse(data.releasedate, out release);
item.PremiereDate = release;
item.ProductionYear = release.Year;
if (data.toptags != null && !item.LockedFields.Contains(MetadataFields.Tags))
2013-03-05 09:48:17 -07:00
{
AddTags(item, data.toptags);
}
}
private static void AddTags(BaseItem item, LastfmTags tags)
2013-03-05 09:48:17 -07:00
{
var itemTags = (from tag in tags.tag where !string.IsNullOrEmpty(tag.name) select tag.name).ToList();
item.Tags = itemTags;
2013-03-05 09:48:17 -07:00
}
}
}