TvdbSeasonIdentityProvider.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. if (id == null)
  26. {
  27. return null;
  28. }
  29. try
  30. {
  31. var parts = id.Split(':');
  32. return new TvdbSeasonIdentity(parts[0], int.Parse(parts[1]));
  33. }
  34. catch
  35. {
  36. return null;
  37. }
  38. }
  39. }
  40. public struct TvdbSeasonIdentity
  41. {
  42. public string SeriesId { get; private set; }
  43. public int Index { get; private set; }
  44. public TvdbSeasonIdentity(string id)
  45. : this()
  46. {
  47. this = TvdbSeasonIdentityProvider.ParseIdentity(id).Value;
  48. }
  49. public TvdbSeasonIdentity(string seriesId, int index)
  50. : this()
  51. {
  52. SeriesId = seriesId;
  53. Index = index;
  54. }
  55. }
  56. }