Skip to content

Instantly share code, notes, and snippets.

@DemoJameson
Last active March 22, 2026 12:44
Show Gist options
  • Select an option

  • Save DemoJameson/3746238870be44d10be3c3f608770d23 to your computer and use it in GitHub Desktop.

Select an option

Save DemoJameson/3746238870be44d10be3c3f608770d23 to your computer and use it in GitHub Desktop.
修复Infuse图片语言地区错误
// 获取响应体
let body = $response.body;
// 获取 Loon 插件面板传入的文本参数
let preferredLanguage = "zh-CN";
if (typeof $argument !== "undefined" && $argument.trim() !== "" && $argument !== "{preferredLanguage}") {
preferredLanguage = $argument.trim();
}
try {
let obj = JSON.parse(body);
// 确保响应体包含 images 字段
if (obj && obj.images) {
let targetLang = null;
let targetRegion = null;
// 解析用户输入的语言代码 (例如从 "zh-CN" 提取 lang="zh", region="CN")
const match = preferredLanguage.match(/([a-zA-Z]{2})(?:-([a-zA-Z]{2}))?/);
if (match) {
targetLang = match[1] ? match[1].toLowerCase() : null;
targetRegion = match[2] ? match[2].toUpperCase() : null;
}
// 提取成功后执行打分排序
if (targetLang) {
const sortImages = (a, b) => {
const getScore = (item) => {
let score = 0;
const itemLang = item.iso_639_1 ? item.iso_639_1.toLowerCase() : null;
const itemRegion = item.iso_3166_1 ? item.iso_3166_1.toUpperCase() : null;
if (itemLang === targetLang) {
// 语言和地区双重精确匹配 (2分)
if (targetRegion && itemRegion === targetRegion) {
score = 2;
}
// 仅语言匹配 (1分)
else {
score = 1;
}
}
return score;
};
return getScore(b) - getScore(a);
};
// 批量应用排序逻辑到海报、背景和 Logo
const imageTypes = ['logos', 'posters', 'backdrops'];
imageTypes.forEach(type => {
if (Array.isArray(obj.images[type])) {
obj.images[type].sort(sortImages);
}
});
// 将修改后的对象转回 JSON 字符串
body = JSON.stringify(obj);
}
}
// 返回修改后的 body
$done({ body });
} catch (e) {
console.log("TMDB 图片自定义排序脚本错误: " + e);
$done({});
}
#!name=修复Infuse图片语言地区错误
#!desc=将TMDB响应中的图片按插件指定的语言排序
#!icon=https://raw.githubusercontent.com/Koolson/Qure/master/IconSet/Color/Infuse.png
#!homepage=https://gist.githubusercontent.com/DemoJameson/3746238870be44d10be3c3f608770d23
#!openUrl=https://apps.apple.com/app/id1136220934
#!author=DemoJameson
[Script]
# 拦截 TMDB 电影详情 API,开启 requires-body 以修改响应
http-response ^https:\/\/api\.themoviedb\.org\/3\/(tv|movie)\/\d+ script-path=https://gist.githubusercontent.com/DemoJameson/3746238870be44d10be3c3f608770d23/raw/fix_infuse_image_language.js, requires-body=true, timeout=10, tag=themoviedb.org
http-response ^https:\/\/api\.tmdb\.org\/3\/(tv|movie)\/\d+ script-path=https://gist.githubusercontent.com/DemoJameson/3746238870be44d10be3c3f608770d23/raw/fix_infuse_image_language.js, requires-body=true, timeout=10, tag=tmdb.org
[MITM]
# 必须配置 MITM 才能解密 HTTPS 流量并执行脚本
hostname = api.themoviedb.org
[Argument]
preferredLanguage = input, "zh-CN", tag=首选图片语言, desc=输入目标语言代码(如 zh-CN, zh-TW)。默认为 zh-CN。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment