From 2ccabcf10a79077849fce20c190038d8a987605f Mon Sep 17 00:00:00 2001 From: cxfksword <718792+cxfksword@users.noreply.github.com> Date: Sat, 18 Feb 2023 16:01:59 +0800 Subject: [PATCH] Optimize code --- .../Providers/MovieProvider.cs | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Jellyfin.Plugin.MetaShark/Providers/MovieProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/MovieProvider.cs index 45293d6..d82dfc2 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/MovieProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/MovieProvider.cs @@ -149,18 +149,11 @@ namespace Jellyfin.Plugin.MetaShark.Providers // 通过imdb获取电影系列信息 if (this.config.EnableTmdbCollection && !string.IsNullOrEmpty(tmdbId)) { - try + var collectionName = await this.GetBelongsToCollection(info, tmdbId, cancellationToken).ConfigureAwait(false); + if (!string.IsNullOrEmpty(collectionName)) { - var movieResult = await _tmdbApi - .GetMovieAsync(Convert.ToInt32(tmdbId, CultureInfo.InvariantCulture), info.MetadataLanguage, info.MetadataLanguage, cancellationToken) - .ConfigureAwait(false); - if (movieResult != null && movieResult.BelongsToCollection != null) - { - movie.CollectionName = movieResult.BelongsToCollection.Name; - } + movie.CollectionName = collectionName; } - catch (Exception ex) - { } } @@ -318,6 +311,20 @@ namespace Jellyfin.Plugin.MetaShark.Providers } + private async Task GetBelongsToCollection(MovieInfo info, string tmdbId, CancellationToken cancellationToken) + { + + var movieResult = await _tmdbApi + .GetMovieAsync(Convert.ToInt32(tmdbId, CultureInfo.InvariantCulture), info.MetadataLanguage, info.MetadataLanguage, cancellationToken) + .ConfigureAwait(false); + if (movieResult != null && movieResult.BelongsToCollection != null) + { + return movieResult.BelongsToCollection.Name; + } + + return null; + } + ///