| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using MediaBrowser.Controller.Entities; |
| | 4 | | using MediaBrowser.Controller.Entities.Movies; |
| | 5 | | using MediaBrowser.Controller.Entities.TV; |
| | 6 | | using MediaBrowser.Controller.Providers; |
| | 7 | | using MediaBrowser.Model.Entities; |
| | 8 | | using TMDbLib.Objects.TvShows; |
| | 9 | |
|
| | 10 | | namespace MediaBrowser.Providers.Plugins.Tmdb; |
| | 11 | |
|
| | 12 | | /// <summary> |
| | 13 | | /// External URLs for TMDb. |
| | 14 | | /// </summary> |
| | 15 | | public class TmdbExternalUrlProvider : IExternalUrlProvider |
| | 16 | | { |
| | 17 | | /// <inheritdoc/> |
| 21 | 18 | | public string Name => "TMDB"; |
| | 19 | |
|
| | 20 | | /// <inheritdoc/> |
| | 21 | | public IEnumerable<string> GetExternalUrls(BaseItem item) |
| | 22 | | { |
| | 23 | | switch (item) |
| | 24 | | { |
| | 25 | | case Series: |
| | 26 | | if (item.TryGetProviderId(MetadataProvider.Tmdb, out var externalId)) |
| | 27 | | { |
| | 28 | | yield return TmdbUtils.BaseTmdbUrl + $"tv/{externalId}"; |
| | 29 | | } |
| | 30 | |
|
| | 31 | | break; |
| | 32 | | case Season season: |
| | 33 | | if (season.Series.TryGetProviderId(MetadataProvider.Tmdb, out var seriesExternalId)) |
| | 34 | | { |
| | 35 | | var orderString = season.Series.DisplayOrder; |
| | 36 | | var seasonNumber = season.IndexNumber; |
| | 37 | | if (string.IsNullOrEmpty(orderString) && seasonNumber is not null) |
| | 38 | | { |
| | 39 | | // Default order is airdate |
| | 40 | | yield return TmdbUtils.BaseTmdbUrl + $"tv/{seriesExternalId}/season/{seasonNumber}"; |
| | 41 | | } |
| | 42 | |
|
| | 43 | | if (Enum.TryParse<TvGroupType>(season.Series.DisplayOrder, out var order)) |
| | 44 | | { |
| | 45 | | if (order.Equals(TvGroupType.OriginalAirDate) && seasonNumber is not null) |
| | 46 | | { |
| | 47 | | yield return TmdbUtils.BaseTmdbUrl + $"tv/{seriesExternalId}/season/{seasonNumber}"; |
| | 48 | | } |
| | 49 | | } |
| | 50 | | } |
| | 51 | |
|
| | 52 | | break; |
| | 53 | | case Episode episode: |
| | 54 | | if (episode.Series.TryGetProviderId(MetadataProvider.Imdb, out seriesExternalId)) |
| | 55 | | { |
| | 56 | | var orderString = episode.Series.DisplayOrder; |
| | 57 | | var seasonNumber = episode.Season?.IndexNumber; |
| | 58 | | var episodeNumber = episode.IndexNumber; |
| | 59 | | if (string.IsNullOrEmpty(orderString) && seasonNumber is not null && episodeNumber is not null) |
| | 60 | | { |
| | 61 | | // Default order is airdate |
| | 62 | | yield return TmdbUtils.BaseTmdbUrl + $"tv/{seriesExternalId}/season/{seasonNumber}/episode/{epis |
| | 63 | | } |
| | 64 | |
|
| | 65 | | if (Enum.TryParse<TvGroupType>(orderString, out var order)) |
| | 66 | | { |
| | 67 | | if (order.Equals(TvGroupType.OriginalAirDate) && seasonNumber is not null && episodeNumber is no |
| | 68 | | { |
| | 69 | | yield return TmdbUtils.BaseTmdbUrl + $"tv/{seriesExternalId}/season/{seasonNumber}/episode/{ |
| | 70 | | } |
| | 71 | | } |
| | 72 | | } |
| | 73 | |
|
| | 74 | | break; |
| | 75 | | case Movie: |
| | 76 | | if (item.TryGetProviderId(MetadataProvider.Tmdb, out externalId)) |
| | 77 | | { |
| | 78 | | yield return TmdbUtils.BaseTmdbUrl + $"movie/{externalId}"; |
| | 79 | | } |
| | 80 | |
|
| | 81 | | break; |
| | 82 | | case Person: |
| | 83 | | if (item.TryGetProviderId(MetadataProvider.Tmdb, out externalId)) |
| | 84 | | { |
| | 85 | | yield return TmdbUtils.BaseTmdbUrl + $"person/{externalId}"; |
| | 86 | | } |
| | 87 | |
|
| | 88 | | break; |
| | 89 | | case BoxSet: |
| | 90 | | if (item.TryGetProviderId(MetadataProvider.Tmdb, out externalId)) |
| | 91 | | { |
| | 92 | | yield return TmdbUtils.BaseTmdbUrl + $"collection/{externalId}"; |
| | 93 | | } |
| | 94 | |
|
| | 95 | | break; |
| | 96 | | } |
| | 97 | | } |
| | 98 | | } |