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