feat: add movie logo. close #63

This commit is contained in:
cxfksword 2024-02-03 14:04:52 +08:00
parent 9c0448898a
commit 513a668c40
4 changed files with 157 additions and 71 deletions

View File

@ -39,7 +39,7 @@ namespace Jellyfin.Plugin.MetaShark.Api
var config = Plugin.Instance?.Configuration;
var apiKey = string.IsNullOrEmpty(config?.TmdbApiKey) ? DEFAULT_API_KEY : config.TmdbApiKey;
var host = string.IsNullOrEmpty(config?.TmdbHost) ? DEFAULT_API_HOST : config.TmdbHost;
_tmDbClient = new TMDbClient(apiKey, true, host, null, config.GetTmdbWebProxy());
_tmDbClient = new TMDbClient(apiKey, true, host, null, config?.GetTmdbWebProxy());
_tmDbClient.Timeout = TimeSpan.FromSeconds(10);
// Not really interested in NotFoundException
_tmDbClient.ThrowApiExceptions = false;
@ -597,6 +597,16 @@ namespace Jellyfin.Plugin.MetaShark.Api
return _tmDbClient.GetImageUrl(_tmDbClient.Config.Images.StillSizes[^1], filePath).ToString();
}
public string? GetLogoUrl(string filePath)
{
if (string.IsNullOrEmpty(filePath))
{
return null;
}
return _tmDbClient.GetImageUrl(_tmDbClient.Config.Images.LogoSizes[^1], filePath).ToString();
}
/// <inheritdoc />
public void Dispose()
{

View File

@ -94,9 +94,9 @@
<label class="emby-checkbox-label" for="EnableTmdbBackdrop">
<input id="EnableTmdbBackdrop" name="EnableTmdbBackdrop" type="checkbox"
is="emby-checkbox" />
<span>使用TheMovieDb补全背景图</span>
<span>使用TheMovieDb补全背景图和商标</span>
</label>
<div class="fieldDescription">勾选后当影片在豆瓣找不到背景图时改使用TheMovieDb的补全</div>
<div class="fieldDescription">勾选后,当影片在豆瓣找不到背景图或商标改使用TheMovieDb的补全</div>
</div>
<div class="checkboxContainer checkboxContainer-withDescription">
<label class="emby-checkbox-label" for="EnableTmdbCollection">

View File

@ -36,7 +36,8 @@ namespace Jellyfin.Plugin.MetaShark.Providers
public IEnumerable<ImageType> GetSupportedImages(BaseItem item) => new List<ImageType>
{
ImageType.Primary,
ImageType.Backdrop
ImageType.Backdrop,
ImageType.Logo,
};
/// <inheritdoc />
@ -47,12 +48,13 @@ namespace Jellyfin.Plugin.MetaShark.Providers
this.Log($"GetImages for item: {item.Name} [metaSource]: {metaSource}");
if (metaSource != MetaSource.Tmdb && !string.IsNullOrEmpty(sid))
{
var primary = await this._doubanApi.GetMovieAsync(sid, cancellationToken);
var primary = await this._doubanApi.GetMovieAsync(sid, cancellationToken).ConfigureAwait(false);
if (primary == null || string.IsNullOrEmpty(primary.Img))
{
return Enumerable.Empty<RemoteImageInfo>();
}
var backdropImgs = await GetBackdrop(item, cancellationToken);
var backdropImgs = await this.GetBackdrop(item, cancellationToken).ConfigureAwait(false);
var logoImgs = await this.GetLogos(item, cancellationToken).ConfigureAwait(false);
var res = new List<RemoteImageInfo> {
new RemoteImageInfo
@ -63,6 +65,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers
},
};
res.AddRange(backdropImgs);
res.AddRange(logoImgs);
return res;
}
@ -70,7 +73,8 @@ namespace Jellyfin.Plugin.MetaShark.Providers
if (metaSource == MetaSource.Tmdb && !string.IsNullOrEmpty(tmdbId))
{
var language = item.GetPreferredMetadataLanguage();
var movie = await _tmdbApi
// 设定language会导致图片被过滤这里设为null保持取全部语言图片
var movie = await this._tmdbApi
.GetMovieAsync(tmdbId.ToInt(), null, null, cancellationToken)
.ConfigureAwait(false);
@ -81,37 +85,41 @@ namespace Jellyfin.Plugin.MetaShark.Providers
var remoteImages = new List<RemoteImageInfo>();
for (var i = 0; i < movie.Images.Posters.Count; i++)
{
var poster = movie.Images.Posters[i];
remoteImages.Add(new RemoteImageInfo
{
Url = _tmdbApi.GetPosterUrl(poster.FilePath),
CommunityRating = poster.VoteAverage,
VoteCount = poster.VoteCount,
Width = poster.Width,
Height = poster.Height,
Language = AdjustImageLanguage(poster.Iso_639_1, language),
ProviderName = Name,
remoteImages.AddRange(movie.Images.Posters.Select(x => new RemoteImageInfo {
ProviderName = this.Name,
Url = this._tmdbApi.GetPosterUrl(x.FilePath),
Type = ImageType.Primary,
});
}
CommunityRating = x.VoteAverage,
VoteCount = x.VoteCount,
Width = x.Width,
Height = x.Height,
Language = this.AdjustImageLanguage(x.Iso_639_1, language),
RatingType = RatingType.Score,
}));
for (var i = 0; i < movie.Images.Backdrops.Count; i++)
{
var backdrop = movie.Images.Backdrops[i];
remoteImages.Add(new RemoteImageInfo
{
Url = _tmdbApi.GetPosterUrl(backdrop.FilePath),
CommunityRating = backdrop.VoteAverage,
VoteCount = backdrop.VoteCount,
Width = backdrop.Width,
Height = backdrop.Height,
ProviderName = Name,
remoteImages.AddRange(movie.Images.Backdrops.Select(x => new RemoteImageInfo {
ProviderName = this.Name,
Url = this._tmdbApi.GetBackdropUrl(x.FilePath),
Type = ImageType.Backdrop,
RatingType = RatingType.Score
});
}
CommunityRating = x.VoteAverage,
VoteCount = x.VoteCount,
Width = x.Width,
Height = x.Height,
Language = this.AdjustImageLanguage(x.Iso_639_1, language),
RatingType = RatingType.Score,
}));
remoteImages.AddRange(movie.Images.Logos.Select(x => new RemoteImageInfo {
ProviderName = this.Name,
Url = this._tmdbApi.GetLogoUrl(x.FilePath),
Type = ImageType.Logo,
CommunityRating = x.VoteAverage,
VoteCount = x.VoteCount,
Width = x.Width,
Height = x.Height,
Language = this.AdjustImageLanguage(x.Iso_639_1, language),
RatingType = RatingType.Score,
}));
return remoteImages.OrderByLanguageDescending(language);
}
@ -133,7 +141,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers
// 从豆瓣获取背景图
if (!string.IsNullOrEmpty(sid))
{
var photo = await this._doubanApi.GetWallpaperBySidAsync(sid, cancellationToken);
var photo = await this._doubanApi.GetWallpaperBySidAsync(sid, cancellationToken).ConfigureAwait(false);
if (photo != null && photo.Count > 0)
{
this.Log("GetBackdrop from douban sid: {0}", sid);
@ -187,5 +195,35 @@ namespace Jellyfin.Plugin.MetaShark.Providers
return list;
}
private async Task<IEnumerable<RemoteImageInfo>> GetLogos(BaseItem item, CancellationToken cancellationToken)
{
var tmdbId = item.GetProviderId(MetadataProvider.Tmdb);
var list = new List<RemoteImageInfo>();
var language = item.GetPreferredMetadataLanguage();
if (this.config.EnableTmdbBackdrop && !string.IsNullOrEmpty(tmdbId))
{
var movie = await this._tmdbApi
.GetMovieAsync(tmdbId.ToInt(), language, language, cancellationToken)
.ConfigureAwait(false);
if (movie != null && movie.Images != null)
{
list.AddRange(movie.Images.Logos.Select(x => new RemoteImageInfo {
ProviderName = this.Name,
Url = this._tmdbApi.GetLogoUrl(x.FilePath),
Type = ImageType.Logo,
CommunityRating = x.VoteAverage,
VoteCount = x.VoteCount,
Width = x.Width,
Height = x.Height,
Language = this.AdjustImageLanguage(x.Iso_639_1, language),
RatingType = RatingType.Score,
}));
}
}
return list.OrderByLanguageDescending(language);
}
}
}

View File

@ -36,7 +36,8 @@ namespace Jellyfin.Plugin.MetaShark.Providers
public IEnumerable<ImageType> GetSupportedImages(BaseItem item) => new List<ImageType>
{
ImageType.Primary,
ImageType.Backdrop
ImageType.Backdrop,
ImageType.Logo,
};
/// <inheritdoc />
@ -47,12 +48,13 @@ namespace Jellyfin.Plugin.MetaShark.Providers
this.Log($"GetImages for item: {item.Name} [metaSource]: {metaSource}");
if (metaSource != MetaSource.Tmdb && !string.IsNullOrEmpty(sid))
{
var primary = await this._doubanApi.GetMovieAsync(sid, cancellationToken);
var primary = await this._doubanApi.GetMovieAsync(sid, cancellationToken).ConfigureAwait(false);
if (primary == null || string.IsNullOrEmpty(primary.Img))
{
return Enumerable.Empty<RemoteImageInfo>();
}
var dropback = await GetBackdrop(item, cancellationToken);
var backdropImgs = await this.GetBackdrop(item, cancellationToken).ConfigureAwait(false);
var logoImgs = await this.GetLogos(item, cancellationToken).ConfigureAwait(false);
var res = new List<RemoteImageInfo> {
new RemoteImageInfo
@ -62,7 +64,8 @@ namespace Jellyfin.Plugin.MetaShark.Providers
Type = ImageType.Primary,
},
};
res.AddRange(dropback);
res.AddRange(backdropImgs);
res.AddRange(logoImgs);
return res;
}
@ -70,7 +73,8 @@ namespace Jellyfin.Plugin.MetaShark.Providers
if (metaSource == MetaSource.Tmdb && !string.IsNullOrEmpty(tmdbId))
{
var language = item.GetPreferredMetadataLanguage();
var movie = await _tmdbApi
// 设定language会导致图片被过滤这里设为null保持取全部语言图片
var movie = await this._tmdbApi
.GetSeriesAsync(tmdbId.ToInt(), null, null, cancellationToken)
.ConfigureAwait(false);
@ -81,37 +85,41 @@ namespace Jellyfin.Plugin.MetaShark.Providers
var remoteImages = new List<RemoteImageInfo>();
for (var i = 0; i < movie.Images.Posters.Count; i++)
{
var poster = movie.Images.Posters[i];
remoteImages.Add(new RemoteImageInfo
{
Url = _tmdbApi.GetPosterUrl(poster.FilePath),
CommunityRating = poster.VoteAverage,
VoteCount = poster.VoteCount,
Width = poster.Width,
Height = poster.Height,
Language = AdjustImageLanguage(poster.Iso_639_1, language),
ProviderName = Name,
remoteImages.AddRange(movie.Images.Posters.Select(x => new RemoteImageInfo {
ProviderName = this.Name,
Url = this._tmdbApi.GetPosterUrl(x.FilePath),
Type = ImageType.Primary,
});
}
CommunityRating = x.VoteAverage,
VoteCount = x.VoteCount,
Width = x.Width,
Height = x.Height,
Language = this.AdjustImageLanguage(x.Iso_639_1, language),
RatingType = RatingType.Score,
}));
for (var i = 0; i < movie.Images.Backdrops.Count; i++)
{
var backdrop = movie.Images.Backdrops[i];
remoteImages.Add(new RemoteImageInfo
{
Url = _tmdbApi.GetPosterUrl(backdrop.FilePath),
CommunityRating = backdrop.VoteAverage,
VoteCount = backdrop.VoteCount,
Width = backdrop.Width,
Height = backdrop.Height,
ProviderName = Name,
remoteImages.AddRange(movie.Images.Backdrops.Select(x => new RemoteImageInfo {
ProviderName = this.Name,
Url = this._tmdbApi.GetBackdropUrl(x.FilePath),
Type = ImageType.Backdrop,
RatingType = RatingType.Score
});
}
CommunityRating = x.VoteAverage,
VoteCount = x.VoteCount,
Width = x.Width,
Height = x.Height,
Language = this.AdjustImageLanguage(x.Iso_639_1, language),
RatingType = RatingType.Score,
}));
remoteImages.AddRange(movie.Images.Logos.Select(x => new RemoteImageInfo {
ProviderName = this.Name,
Url = this._tmdbApi.GetLogoUrl(x.FilePath),
Type = ImageType.Logo,
CommunityRating = x.VoteAverage,
VoteCount = x.VoteCount,
Width = x.Width,
Height = x.Height,
Language = this.AdjustImageLanguage(x.Iso_639_1, language),
RatingType = RatingType.Score,
}));
return remoteImages.OrderByLanguageDescending(language);
}
@ -177,8 +185,8 @@ namespace Jellyfin.Plugin.MetaShark.Providers
this.Log("GetBackdrop from tmdb id: {0}", tmdbId);
list.Add(new RemoteImageInfo
{
ProviderName = Name,
Url = _tmdbApi.GetBackdropUrl(movie.BackdropPath),
ProviderName = this.Name,
Url = this._tmdbApi.GetBackdropUrl(movie.BackdropPath),
Type = ImageType.Backdrop,
});
}
@ -187,5 +195,35 @@ namespace Jellyfin.Plugin.MetaShark.Providers
return list;
}
private async Task<IEnumerable<RemoteImageInfo>> GetLogos(BaseItem item, CancellationToken cancellationToken)
{
var tmdbId = item.GetProviderId(MetadataProvider.Tmdb);
var language = item.GetPreferredMetadataLanguage();
var list = new List<RemoteImageInfo>();
if (this.config.EnableTmdbBackdrop && !string.IsNullOrEmpty(tmdbId))
{
var movie = await this._tmdbApi
.GetSeriesAsync(tmdbId.ToInt(), language, language, cancellationToken)
.ConfigureAwait(false);
if (movie != null && movie.Images != null)
{
list.AddRange(movie.Images.Logos.Select(x => new RemoteImageInfo {
ProviderName = this.Name,
Url = this._tmdbApi.GetLogoUrl(x.FilePath),
Type = ImageType.Logo,
CommunityRating = x.VoteAverage,
VoteCount = x.VoteCount,
Width = x.Width,
Height = x.Height,
Language = this.AdjustImageLanguage(x.Iso_639_1, language),
RatingType = RatingType.Score,
}));
}
}
return list.OrderByLanguageDescending(language);
}
}
}