TvdbSeasonIdentityProvider.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System.Threading.Tasks;
  2. using MediaBrowser.Controller.Providers;
  3. using MediaBrowser.Model.Entities;
  4. namespace MediaBrowser.Providers.TV
  5. {
  6. public class TvdbSeasonIdentityProvider : IItemIdentityProvider<SeasonInfo>
  7. {
  8. public static readonly string FullIdKey = MetadataProviders.Tvdb + "-Full";
  9. public Task Identify(SeasonInfo info)
  10. {
  11. string tvdbSeriesId;
  12. if (!info.SeriesProviderIds.TryGetValue(MetadataProviders.Tvdb.ToString(), out tvdbSeriesId) || string.IsNullOrEmpty(tvdbSeriesId) || info.IndexNumber == null)
  13. {
  14. return Task.FromResult<object>(null);
  15. }
  16. if (string.IsNullOrEmpty(info.GetProviderId(FullIdKey)))
  17. {
  18. var id = string.Format("{0}:{1}", tvdbSeriesId, info.IndexNumber.Value);
  19. info.SetProviderId(FullIdKey, id);
  20. }
  21. return Task.FromResult<object>(null);
  22. }
  23. public static TvdbSeasonIdentity? ParseIdentity(string id)
  24. {
  25. try
  26. {
  27. var parts = id.Split(':');
  28. return new TvdbSeasonIdentity(parts[0], int.Parse(parts[1]));
  29. }
  30. catch
  31. {
  32. return null;
  33. }
  34. }
  35. }
  36. public struct TvdbSeasonIdentity
  37. {
  38. public string SeriesId { get; private set; }
  39. public int Index { get; private set; }
  40. public TvdbSeasonIdentity(string id)
  41. : this()
  42. {
  43. this = TvdbSeasonIdentityProvider.ParseIdentity(id).Value;
  44. }
  45. public TvdbSeasonIdentity(string seriesId, int index)
  46. : this()
  47. {
  48. SeriesId = seriesId;
  49. Index = index;
  50. }
  51. }
  52. }