From f1c9d78ab9818eabe624c6651d669d0a9b37ff25 Mon Sep 17 00:00:00 2001 From: JQ <81431263+scampower3@users.noreply.github.com> Date: Sun, 3 Nov 2024 23:09:54 +0800 Subject: [PATCH] Increase robustness of retrieving tmdb id (again) (#194) --- Jellyfin.Plugin.Tvdb/Providers/TvdbMovieProvider.cs | 4 +++- Jellyfin.Plugin.Tvdb/Providers/TvdbPersonProvider.cs | 4 +++- Jellyfin.Plugin.Tvdb/Providers/TvdbSeriesProvider.cs | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Jellyfin.Plugin.Tvdb/Providers/TvdbMovieProvider.cs b/Jellyfin.Plugin.Tvdb/Providers/TvdbMovieProvider.cs index 30f6724..5b223d4 100644 --- a/Jellyfin.Plugin.Tvdb/Providers/TvdbMovieProvider.cs +++ b/Jellyfin.Plugin.Tvdb/Providers/TvdbMovieProvider.cs @@ -421,7 +421,9 @@ private void MapMovieToResult(MetadataResult result, MovieExtendedRecord movie.SetProviderIdIfHasValue(MetadataProvider.Zap2It, zap2ItId); var tmdbId = tvdbMovie.RemoteIds?.FirstOrDefault(x => string.Equals(x.SourceName, "TheMovieDB.com", StringComparison.OrdinalIgnoreCase))?.Id.ToString(); - movie.SetProviderIdIfHasValue(MetadataProvider.Tmdb, tmdbId); + // Sometimes, tvdb will return tmdbid as {tmdbid}-{title} like in the tmdb url. Grab the tmdbid only. + var tmdbIdLeft = StringExtensions.LeftPart(tmdbId, '-').ToString(); + movie.SetProviderIdIfHasValue(MetadataProvider.Tmdb, tmdbIdLeft); if (DateTime.TryParse(tvdbMovie.First_release.Date, out var date)) { diff --git a/Jellyfin.Plugin.Tvdb/Providers/TvdbPersonProvider.cs b/Jellyfin.Plugin.Tvdb/Providers/TvdbPersonProvider.cs index e9f9c4e..0bf5dd4 100644 --- a/Jellyfin.Plugin.Tvdb/Providers/TvdbPersonProvider.cs +++ b/Jellyfin.Plugin.Tvdb/Providers/TvdbPersonProvider.cs @@ -354,7 +354,9 @@ private void MapPersonToResult(MetadataResult result, PeopleExtendedReco person.SetProviderIdIfHasValue(MetadataProvider.Zap2It, zap2ItId); var tmdbId = tvdbPerson.RemoteIds?.FirstOrDefault(x => string.Equals(x.SourceName, "TheMovieDB.com", StringComparison.OrdinalIgnoreCase))?.Id.ToString(); - person.SetProviderIdIfHasValue(MetadataProvider.Tmdb, tmdbId); + // Sometimes, tvdb will return tmdbid as {tmdbid}-{title} like in the tmdb url. Grab the tmdbid only. + var tmdbIdLeft = StringExtensions.LeftPart(tmdbId, '-').ToString(); + person.SetProviderIdIfHasValue(MetadataProvider.Tmdb, tmdbIdLeft); if (!string.IsNullOrWhiteSpace(tvdbPerson.BirthPlace)) { diff --git a/Jellyfin.Plugin.Tvdb/Providers/TvdbSeriesProvider.cs b/Jellyfin.Plugin.Tvdb/Providers/TvdbSeriesProvider.cs index 68720ff..0b0609d 100644 --- a/Jellyfin.Plugin.Tvdb/Providers/TvdbSeriesProvider.cs +++ b/Jellyfin.Plugin.Tvdb/Providers/TvdbSeriesProvider.cs @@ -481,7 +481,9 @@ private void MapSeriesToResult(MetadataResult result, SeriesExtendedReco series.SetProviderIdIfHasValue(MetadataProvider.Zap2It, zap2ItId); var tmdbId = tvdbSeries.RemoteIds?.FirstOrDefault(x => string.Equals(x.SourceName, "TheMovieDB.com", StringComparison.OrdinalIgnoreCase))?.Id.ToString(); - series.SetProviderIdIfHasValue(MetadataProvider.Tmdb, tmdbId); + // Sometimes, tvdb will return tmdbid as {tmdbid}-{title} like in the tmdb url. Grab the tmdbid only. + var tmdbIdLeft = StringExtensions.LeftPart(tmdbId, '-').ToString(); + series.SetProviderIdIfHasValue(MetadataProvider.Tmdb, tmdbIdLeft); if (Enum.TryParse(tvdbSeries.Status.Name, true, out SeriesStatus seriesStatus)) {