jellyfin/MediaBrowser.Providers/TV/TvdbSeasonIdentityProvider.cs

60 lines
1.7 KiB
C#
Raw Normal View History

using System.Threading.Tasks;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Providers.TV
{
2015-09-19 14:25:19 -07:00
public class TvdbSeasonIdentityProvider : IItemIdentityProvider<SeasonInfo>
{
2015-09-19 14:25:19 -07:00
public static readonly string FullIdKey = MetadataProviders.Tvdb + "-Full";
public Task Identify(SeasonInfo info)
{
string tvdbSeriesId;
if (!info.SeriesProviderIds.TryGetValue(MetadataProviders.Tvdb.ToString(), out tvdbSeriesId) || string.IsNullOrEmpty(tvdbSeriesId) || info.IndexNumber == null)
{
2015-09-19 14:25:19 -07:00
return Task.FromResult<object>(null);
}
2015-09-19 14:25:19 -07:00
if (string.IsNullOrEmpty(info.GetProviderId(FullIdKey)))
{
2015-09-19 14:25:19 -07:00
var id = string.Format("{0}:{1}", tvdbSeriesId, info.IndexNumber.Value);
info.SetProviderId(FullIdKey, id);
}
return Task.FromResult<object>(null);
}
2015-09-19 14:25:19 -07:00
public static TvdbSeasonIdentity? ParseIdentity(string id)
{
try
{
var parts = id.Split(':');
return new TvdbSeasonIdentity(parts[0], int.Parse(parts[1]));
}
catch
{
return null;
}
}
2015-09-19 14:25:19 -07:00
}
public struct TvdbSeasonIdentity
{
public string SeriesId { get; private set; }
public int Index { get; private set; }
2015-09-19 15:56:59 -07:00
public TvdbSeasonIdentity(string id)
: this()
{
this = TvdbSeasonIdentityProvider.ParseIdentity(id).Value;
}
2015-09-19 14:25:19 -07:00
public TvdbSeasonIdentity(string seriesId, int index)
2015-09-19 15:56:59 -07:00
: this()
2015-09-19 14:25:19 -07:00
{
SeriesId = seriesId;
Index = index;
}
}
}