Skip to content

Commit

Permalink
feat: 增加搜索线程参数设置项
Browse files Browse the repository at this point in the history
1.搜索线程默认不限制,当站点较多时可进行适当调整。
2.电影信息卡片增加TMDB分级信息;

close #2069
  • Loading branch information
ronggang committed Dec 26, 2024
1 parent 9b6356f commit 4cf4253
Show file tree
Hide file tree
Showing 9 changed files with 323 additions and 416 deletions.
5 changes: 4 additions & 1 deletion resource/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@
"saveTip": "Save torrents",
"collection": "Collection",
"searching": "Searching, please wait...",
"waiting": "waiting...",
"cancelSearch": "Cancel search",
"showCheckbox": "Multiple selection",
"titleMiddleEllipsis": "Title Middle Ellipsis",
Expand Down Expand Up @@ -517,7 +518,7 @@
"autoRefreshUserDataTip4": "times after failure,",
"autoRefreshUserDataTip5": "minute apart",
"autoRefreshByAlarmTip1": "Using the new version refresh method, more stable, requires corresponding authorization(Chromium Only) (Beta)",
"autoBackupDataTip1": "Automatically backup user data when the browser is openBeta",
"autoBackupDataTip1": "Automatically backup user data when the browser is open (Beta)",
"autoBackupDataTip2": "Auto upload after ",
"autoBackupDataTip3": "automatically refreshes",
"autoBackupDataTip4": "Backup to",
Expand All @@ -526,6 +527,7 @@
"showMovieInfoCardOnSearch": "Show movie and rating information when searching by IMDb number",
"getMovieInformationBeforeSearching": "When entering a search keyword, load relevant information from Douban for pre-selection",
"autoSearchWhenSwitchSolution": "When changing search solution, re-search immediately",
"searchThreads": "Number of search threads: When the number of websites in the search plan exceeds the limit, it will wait. (By default, there is no limit; the larger the number, the more memory it consumes.):",
"maxMovieInformationCount": "Maximum display number of entries (1-20):",
"searchModeForItem": "When clicking on a pre-selected item:",
"showToolbarOnContentPage": "Enable site page plugin icons and toolbars (such as one-click downloads, etc.)",
Expand Down Expand Up @@ -1109,6 +1111,7 @@
"type": "Type: ",
"pubdate": "Pubdate: ",
"duration": "Duration: ",
"rated": "Content Rating",
"ratings": {
"douban": "Douban {average} ({numRaters})",
"imdb": "IMDb {average} ({numRaters})",
Expand Down
3 changes: 3 additions & 0 deletions resource/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@
"saveTip": "下载种子文件到本地",
"collection": "收藏",
"searching": "正在搜索中,请稍候……",
"waiting": "等待中……",
"cancelSearch": "取消搜索",
"showCheckbox": "多选",
"titleMiddleEllipsis": "标题中间省略",
Expand Down Expand Up @@ -520,6 +521,7 @@
"showMovieInfoCardOnSearch": "当以 IMDb 编号搜索时显示电影及评分信息",
"getMovieInformationBeforeSearching": "当输入搜索关键字时,从豆瓣加载相关信息以供预选",
"autoSearchWhenSwitchSolution": "当搜索方案切换时,立即触发搜索",
"searchThreads": "搜索线程数量,当搜索方案的网站数量超出时会进行等待(默认不限制,数量越大,占用内存越多):",
"maxMovieInformationCount": "最多显示条目(1-20):",
"searchModeForItem": "当点击预选条目时:",
"showToolbarOnContentPage": "启用站点页面助手图标和工具栏(如一键下载等)",
Expand Down Expand Up @@ -1105,6 +1107,7 @@
"type": "类型:",
"pubdate": "上映:",
"duration": "片长:",
"rated": "分级",
"ratings": {
"douban": "豆瓣 {average} 共 {numRaters} 人参与评价",
"imdb": "IMDb {average} 共 {numRaters} 人参与评价",
Expand Down
81 changes: 80 additions & 1 deletion src/background/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class Config {
rows: 50,
// 搜索超时
timeout: 30000,
saveKey: true
saveKey: true,
threads: 0
},
// 连接下载服务器超时时间(毫秒)
connectClientTimeout: 30000,
Expand Down Expand Up @@ -115,6 +116,23 @@ class Config {

public uiOptions: UIOptions = {};

// 参数类型定义,防止因类型错误导致的各种隐藏Bug
private optionsTypeRule = {
connectClientTimeout: 'number',
exceedSize: 'number',
search: {
rows: 'number',
timeout: 'number',
threads: 'number'
},
downloadFailedFailedRetryCount: 'number',
downloadFailedFailedRetryInterval: 'number',
batchDownloadInterval: 'number',
beforeSearchingOptions: {
maxMovieInformationCount: 'number'
},
}

/**
* 保存配置
* @param options 配置信息
Expand All @@ -126,6 +144,61 @@ class Config {
this.localStorage.set(this.name, this.cleaningOptions(this.options));
}

/**
* 根据指定的规则转换对象的值
* @param obj
* @param rules
* @returns
*/
public transformObjectProperties(obj: any, rules: any) {
// 检查输入是否为对象
if (obj && typeof obj === 'object' && !Array.isArray(obj)) {
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
const value = obj[key];
const rule = rules[key];

if (rule) {
if (typeof rule === 'string') {
// 如果规则是简单类型名,转换当前属性
obj[key] = this.castValueToType(value, rule);
} else if (typeof rule === 'function') {
// 如果规则是函数,调用函数进行转换
obj[key] = rule(value);
} else if (typeof rule === 'object' && !Array.isArray(rule)) {
// 如果规则是对象,递归检查子对象
obj[key] = this.transformObjectProperties(value, rule);
}
}
}
}
}
return obj;
}

/**
* 根据类型名称进行类型转换
* @param value
* @param type
* @returns
*/
public castValueToType(value: any, type: string) {
switch (type.toLowerCase()) {
case 'string':
return String(value);
case 'number':
return Number(value);
case 'boolean':
return Boolean(value);
case 'object':
return value !== null && typeof value === 'object' ? value : {};
case 'array':
return Array.isArray(value) ? value : [value];
default:
return value; // 保持原值
}
}

/**
* 获取站点图标并缓存
*/
Expand Down Expand Up @@ -288,6 +361,9 @@ class Config {
});
}

// 转换已定义类型的值
_options = this.transformObjectProperties(_options, this.optionsTypeRule);

return _options;
}

Expand Down Expand Up @@ -468,6 +544,9 @@ class Config {
this.getFavicons();
}

// 转换已定义类型的值
this.options = this.transformObjectProperties(this.options, this.optionsTypeRule);

console.log(this.options);
}

Expand Down
2 changes: 2 additions & 0 deletions src/interface/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export interface SearchOptions {
tags?: string[];
timeout?: number;
saveKey?: boolean;
// 搜索线程数量,即同时可进行搜索的网站数量
threads?: number;
}

export interface IApiKey {
Expand Down
15 changes: 12 additions & 3 deletions src/options/components/MovieInfoCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
'grey--text',
$vuetify.breakpoint.mdAndUp ? 'title' : 'caption',
]">({{ info.year || info.attrs.year[0] }})</span>
<v-chip v-if="info.tmdb && info.tmdb.tmdbContentRating" label outline small class="pl-0 ml-3"
:title='$t("movieInfoCard.rated")'>{{
info.tmdb.tmdbContentRating }}</v-chip>
</div>
</v-card-title>
<v-img :src="info.image || info.pic.normal" class="ml-3 mb-3" contain :max-height="maxHeight"
Expand Down Expand Up @@ -160,7 +163,7 @@
rel="noopener noreferrer nofollow">IMDb {{ ratings.imdbRating }}</v-btn>

<!-- TMDB评分 -->
<v-btn v-if="info.tmdb && info.tmdb.vote_average" color="cyan darken-1" :href="info.tmdbURL" target="_blank"
<v-btn v-if="info.tmdb && info.tmdb.vote_average" class="tmdbStyle" :href="info.tmdbURL" target="_blank"
rel="noopener noreferrer nofollow">TMDB {{ info.tmdbAverage }}%</v-btn>

<!-- 烂番茄新鲜度 -->
Expand All @@ -175,8 +178,8 @@

<!-- Metacritic评分 -->
<v-btn v-if="metascore > 0" :color="metascore > 60 ? 'success' : metascore > 40 ? 'warning' : 'error'
" :href="`https://www.metacritic.com/search/${info.originalTitle || info.title}`"
target="_blank" rel="noopener noreferrer nofollow" style="min-width: unset">
" :href="`https://www.metacritic.com/search/${info.originalTitle || info.title}`" target="_blank"
rel="noopener noreferrer nofollow" style="min-width: unset">
<v-avatar size="20" class="mr-2">
<img src="https://upload.wikimedia.org/wikipedia/commons/f/f2/Metacritic_M.png" />
</v-avatar>
Expand Down Expand Up @@ -417,4 +420,10 @@ export default Vue.extend({
color: #ccc;
}
}
// TMDB标准配色
// @see https://www.themoviedb.org/about/logos-attribution
.tmdbStyle {
background: linear-gradient(90deg, #90cea1, #01b4e4) !important;
}
</style>
Loading

0 comments on commit 4cf4253

Please sign in to comment.