Skip to content

Commit

Permalink
feat: add large poster configuration and optimize image handle. close #…
Browse files Browse the repository at this point in the history
…59 close #61
  • Loading branch information
cxfksword committed Dec 30, 2023
1 parent 54fd425 commit f5cf162
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public class PluginConfiguration : BasePluginConfiguration
/// </summary>
public bool EnableDoubanAvoidRiskControl { get; set; } = false;
/// <summary>
/// 豆瓣海报使用大图
/// </summary>
public bool EnableDoubanLargePoster { get; set; } = false;
/// <summary>
/// 豆瓣背景图使用原图
/// </summary>
public bool EnableDoubanBackdropRaw { get; set; } = false;
Expand Down
10 changes: 10 additions & 0 deletions Jellyfin.Plugin.MetaShark/Configuration/configPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ <h3>豆瓣</h3>
可为空,填写jellyfin访问域名(有端口时要加上端口),只有使用了Nginx代理、Docker部署或启用了HTTPS,并且豆瓣图片无法显示时,才需要填写
</div>
</div>
<div class="checkboxContainer checkboxContainer-withDescription">
<label class="emby-checkbox-label" for="EnableDoubanLargePoster">
<input id="EnableDoubanLargePoster" name="EnableDoubanLargePoster" type="checkbox"
is="emby-checkbox" />
<span>海报使用大图</span>
</label>
</div>
<div class="checkboxContainer checkboxContainer-withDescription">
<label class="emby-checkbox-label" for="EnableDoubanBackdropRaw">
<input id="EnableDoubanBackdropRaw" name="EnableDoubanBackdropRaw" type="checkbox"
Expand Down Expand Up @@ -165,6 +172,7 @@ <h3>TheMovieDb</h3>
document.querySelector('#DoubanCookies').value = config.DoubanCookies;
document.querySelector('#DoubanImageProxyBaseUrl').value = config.DoubanImageProxyBaseUrl;
document.querySelector('#EnableDoubanAvoidRiskControl').checked = config.EnableDoubanAvoidRiskControl;
document.querySelector('#EnableDoubanLargePoster').checked = config.EnableDoubanLargePoster;
document.querySelector('#EnableDoubanBackdropRaw').checked = config.EnableDoubanBackdropRaw;

document.querySelector('#EnableTmdb').checked = config.EnableTmdb;
Expand Down Expand Up @@ -193,6 +201,7 @@ <h3>TheMovieDb</h3>
config.DoubanCookies = document.querySelector('#DoubanCookies').value;
config.DoubanImageProxyBaseUrl = document.querySelector('#DoubanImageProxyBaseUrl').value;
config.EnableDoubanAvoidRiskControl = document.querySelector('#EnableDoubanAvoidRiskControl').checked;
config.EnableDoubanLargePoster = document.querySelector('#EnableDoubanLargePoster').checked;
config.EnableDoubanBackdropRaw = document.querySelector('#EnableDoubanBackdropRaw').checked;

config.EnableTmdb = document.querySelector('#EnableTmdb').checked;
Expand Down Expand Up @@ -221,6 +230,7 @@ <h3>TheMovieDb</h3>
changeProxyDisplay();
});


function changeProxyDisplay() {
let proxyType = document.querySelector('#TmdbProxyType').value;
if (proxyType) {
Expand Down
19 changes: 19 additions & 0 deletions Jellyfin.Plugin.MetaShark/Model/DoubanSubject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ public string ImgMiddle
}
}

[JsonIgnore]
public string ImgLarge
{
get
{
return this.Img.Replace("s_ratio_poster", "l");
}
}

[JsonIgnore]
public string[] Genres
{
Expand Down Expand Up @@ -155,6 +164,16 @@ public string? DisplayOriginalName
return null;
}
}

[JsonIgnore]
public string ImgMiddle
{
get
{
return this.Img.Replace("/raw/", "/m/").Replace("/s_ratio_poster/", "/m/");
}
}

}

public class DoubanPhoto
Expand Down
47 changes: 18 additions & 29 deletions Jellyfin.Plugin.MetaShark/Providers/BaseProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,53 +471,32 @@ protected string GetProxyImageUrl(string url)

protected string GetLocalProxyImageUrl(string url)
{
var baseUrl = Plugin.Instance?.GetLocalApiBaseUrl();
if (!string.IsNullOrEmpty(config.DoubanImageProxyBaseUrl))
var baseUrl = Plugin.Instance?.GetLocalApiBaseUrl() ?? string.Empty;
if (!string.IsNullOrWhiteSpace(config.DoubanImageProxyBaseUrl))
{
baseUrl = config.DoubanImageProxyBaseUrl.TrimEnd('/');
}
if (!string.IsNullOrEmpty(baseUrl))
{
var encodedUrl = HttpUtility.UrlEncode(url);
return $"{baseUrl}/plugin/metashark/proxy/image/?url={encodedUrl}";
}

return this.GetProxyImageUrl(url);
var encodedUrl = HttpUtility.UrlEncode(url);
return $"{baseUrl}/plugin/metashark/proxy/image/?url={encodedUrl}";
}

private string GetBaseUrl()
{
// 配置优先
if (!string.IsNullOrEmpty(this.config.DoubanImageProxyBaseUrl))
if (!string.IsNullOrWhiteSpace(config.DoubanImageProxyBaseUrl))
{
return this.config.DoubanImageProxyBaseUrl.TrimEnd('/');
}

// http请求时,获取请求的host (nginx代理/docker中部署时,没配置透传host时,本方式会有问题)
// TODO:http请求时,获取请求的host (nginx代理/docker中部署时,没配置透传host时,本方式会有问题)
// 除自动扫描之外都会执行这里,修改图片功能图片是直接下载,不走插件图片代理处理函数,host拿不到就下载不了
if (Plugin.Instance != null && this._httpContextAccessor.HttpContext != null)
{
// 特殊处理下搜索请求,直接使用相对链接,可以减少使用nginx代理但不透传host的问题
var userAgent = this._httpContextAccessor.HttpContext.Request.Headers.UserAgent.ToString();
var fromWeb = userAgent.Contains("Chrome") || userAgent.Contains("Safari");
var fromItemSearch = this._httpContextAccessor.HttpContext.Request.Path.ToString().Contains("/RemoteSearch");
if (fromWeb && fromItemSearch)
{
// 处理通过nginx反向代理后,url加了subpath访问的情况
var subpath = string.Empty;
var baseUrl = Plugin.Instance.GetApiBaseUrl(this._httpContextAccessor.HttpContext.Request);
var uri = new UriBuilder(baseUrl);
if (!string.IsNullOrEmpty(uri.Path) && uri.Path != "/")
{
subpath = "/" + uri.Path.Trim('/');
}

return subpath;
}

return Plugin.Instance.GetApiBaseUrl(this._httpContextAccessor.HttpContext.Request);
}

// 自动扫描刷新时,直接使用本地地址
// 自动扫描刷新时,直接使用本地地址(127.0.0.1)
return Plugin.Instance?.GetLocalApiBaseUrl() ?? string.Empty;
}

Expand Down Expand Up @@ -573,7 +552,17 @@ public string MapCrewToPersonType(Crew crew)

return string.Empty;
}


protected string GetDoubanPoster(DoubanSubject subject)
{
if (string.IsNullOrEmpty(subject.Img)) {
return string.Empty;
}

var url = config.EnableDoubanLargePoster ? subject.ImgLarge : subject.ImgMiddle;
return this.GetProxyImageUrl(url);
}

protected string GetOriginalFileName(ItemLookupInfo info)
{
Expand Down
4 changes: 2 additions & 2 deletions Jellyfin.Plugin.MetaShark/Providers/MovieImageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, Cancell
if (metaSource != MetaSource.Tmdb && !string.IsNullOrEmpty(sid))
{
var primary = await this._doubanApi.GetMovieAsync(sid, cancellationToken);
if (primary == null || string.IsNullOrEmpty(primary.ImgMiddle))
if (primary == null || string.IsNullOrEmpty(primary.Img))
{
return Enumerable.Empty<RemoteImageInfo>();
}
Expand All @@ -58,7 +58,7 @@ public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, Cancell
new RemoteImageInfo
{
ProviderName = this.Name,
Url = this.GetProxyImageUrl(primary.ImgMiddle),
Url = this.GetDoubanPoster(primary),
Type = ImageType.Primary,
},
};
Expand Down
2 changes: 1 addition & 1 deletion Jellyfin.Plugin.MetaShark/Providers/SeasonImageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, Cancell
new RemoteImageInfo
{
ProviderName = primary.Name,
Url = this.GetProxyImageUrl(primary.ImgMiddle),
Url = this.GetDoubanPoster(primary),
Type = ImageType.Primary,
},
};
Expand Down
1 change: 1 addition & 0 deletions Jellyfin.Plugin.MetaShark/Providers/SeasonProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public async Task<MetadataResult<Season>> GetMetadata(SeasonInfo info, Cancellat
ProviderIds = new Dictionary<string, string> { { DoubanProviderId, c.Id } },
}));

this.Log($"GetSeasonMetaData of douban [sid]: {seasonSid}");
return result;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Jellyfin.Plugin.MetaShark/Providers/SeriesImageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, Cancell
if (metaSource != MetaSource.Tmdb && !string.IsNullOrEmpty(sid))
{
var primary = await this._doubanApi.GetMovieAsync(sid, cancellationToken);
if (primary == null || string.IsNullOrEmpty(primary.ImgMiddle))
if (primary == null || string.IsNullOrEmpty(primary.Img))
{
return Enumerable.Empty<RemoteImageInfo>();
}
Expand All @@ -58,7 +58,7 @@ public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, Cancell
new RemoteImageInfo
{
ProviderName = this.Name,
Url = this.GetProxyImageUrl(primary.ImgMiddle),
Url = this.GetDoubanPoster(primary),
Type = ImageType.Primary,
},
};
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jellyfin电影元数据插件,影片信息只要从豆瓣获取,并由TheMov

国外访问:https://github.com/cxfksword/jellyfin-plugin-metashark/releases/download/manifest/manifest.json

> 如果无法访问,可以直接从 [Release](https://github.com/cxfksword/jellyfin-plugin-metashark/releases) 页面下载,并解压到 jellyfin 插件目录中使用
> 如果都无法访问,可以直接从 [Release](https://github.com/cxfksword/jellyfin-plugin-metashark/releases) 页面下载,并解压到 jellyfin 插件目录中使用
## 如何使用

Expand All @@ -36,6 +36,8 @@ jellyfin电影元数据插件,影片信息只要从豆瓣获取,并由TheMov

> 🚨假如需要刮削大量电影,请到插件配置中打开防封禁功能,避免频繁请求豆瓣导致被封IP(封IP需要等6小时左右才能恢复访问)
> :fire:遇到图片显示不出来时,请到插件配置中配置jellyfin访问域名
## How to build

1. Clone or download this repository
Expand Down

0 comments on commit f5cf162

Please sign in to comment.