2013-03-04 13:03:36 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2013-03-11 21:09:31 -07:00
|
|
|
|
using System.Text.RegularExpressions;
|
2013-03-04 13:03:36 -07:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-03-05 09:48:17 -07:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2013-03-04 13:03:36 -07:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Providers.Music
|
|
|
|
|
{
|
|
|
|
|
public static class LastfmHelper
|
|
|
|
|
{
|
|
|
|
|
public static string LocalArtistMetaFileName = "MBArtist.json";
|
2013-03-05 09:48:17 -07:00
|
|
|
|
public static string LocalAlbumMetaFileName = "MBAlbum.json";
|
2013-03-04 13:03:36 -07:00
|
|
|
|
|
|
|
|
|
public static void ProcessArtistData(BaseItem artist, LastfmArtist data)
|
|
|
|
|
{
|
2013-03-12 07:09:29 -07:00
|
|
|
|
var overview = data.bio != null ? data.bio.content : null;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(overview))
|
|
|
|
|
{
|
|
|
|
|
overview = StripHtml(overview);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
artist.Overview = overview;
|
|
|
|
|
|
2013-03-05 08:45:25 -07:00
|
|
|
|
var yearFormed = 0;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
yearFormed = Convert.ToInt32(data.bio.yearformed);
|
|
|
|
|
}
|
|
|
|
|
catch (FormatException)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
catch (NullReferenceException)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
catch (OverflowException)
|
|
|
|
|
{
|
|
|
|
|
}
|
2013-03-12 07:27:37 -07:00
|
|
|
|
artist.PremiereDate = yearFormed > 0 ? new DateTime(yearFormed, 1,1) : DateTime.MinValue;
|
|
|
|
|
artist.ProductionYear = yearFormed;
|
2013-03-04 13:03:36 -07:00
|
|
|
|
if (data.tags != null)
|
|
|
|
|
{
|
2013-03-05 09:48:17 -07:00
|
|
|
|
AddGenres(artist, data.tags);
|
|
|
|
|
}
|
|
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(overview))
|
|
|
|
|
{
|
|
|
|
|
overview = StripHtml(overview);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item.Overview = overview;
|
|
|
|
|
|
2013-03-05 09:48:17 -07:00
|
|
|
|
var release = DateTime.MinValue;
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
AddGenres(item, data.toptags);
|
2013-03-04 13:03:36 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-11 21:09:31 -07:00
|
|
|
|
private static string StripHtml(string htmlString)
|
|
|
|
|
{
|
|
|
|
|
// http://stackoverflow.com/questions/1349023/how-can-i-strip-html-from-text-in-net
|
|
|
|
|
const string pattern = @"<(.|\n)*?>";
|
|
|
|
|
return Regex.Replace(htmlString, pattern, string.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 09:48:17 -07:00
|
|
|
|
private static void AddGenres(BaseItem item, LastfmTags tags)
|
|
|
|
|
{
|
|
|
|
|
foreach (var tag in tags.tag)
|
|
|
|
|
{
|
|
|
|
|
item.AddGenre(tag.name);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-03-04 13:03:36 -07:00
|
|
|
|
}
|
|
|
|
|
}
|