feat: add stitle and stype, optimize prefer choose

This commit is contained in:
shinya
2025-07-11 01:51:53 +08:00
parent e18dc3787f
commit 367ad8aa48
7 changed files with 140 additions and 46 deletions

View File

@@ -12,6 +12,7 @@ interface VideoCardProps {
id?: string;
source?: string;
title?: string;
query?: string;
poster?: string;
episodes?: number;
source_name?: string;
@@ -28,6 +29,7 @@ interface VideoCardProps {
export default function VideoCard({
id,
title = '',
query = '',
poster = '',
episodes,
source,
@@ -54,7 +56,6 @@ export default function VideoCard({
const countMap = new Map<string | number, number>();
const episodeCountMap = new Map<number, number>();
const yearCountMap = new Map<string, number>();
items.forEach((item) => {
if (item.douban_id && item.douban_id !== 0) {
@@ -64,10 +65,6 @@ export default function VideoCard({
if (len > 0) {
episodeCountMap.set(len, (episodeCountMap.get(len) || 0) + 1);
}
if (item.year?.trim()) {
const yearStr = item.year.trim();
yearCountMap.set(yearStr, (yearCountMap.get(yearStr) || 0) + 1);
}
});
const getMostFrequent = <T extends string | number>(
@@ -88,7 +85,6 @@ export default function VideoCard({
first: items[0],
mostFrequentDoubanId: getMostFrequent(countMap),
mostFrequentEpisodes: getMostFrequent(episodeCountMap) || 0,
mostFrequentYear: getMostFrequent(yearCountMap),
};
}, [isAggregate, items]);
@@ -100,7 +96,14 @@ export default function VideoCard({
aggregateData?.mostFrequentDoubanId ?? douban_id
);
const actualEpisodes = aggregateData?.mostFrequentEpisodes ?? episodes;
const actualYear = aggregateData?.mostFrequentYear ?? year;
const actualYear =
(isAggregate ? aggregateData?.first.year : year) || 'unknown';
const actualQuery = query || '';
const actualSearchType = isAggregate
? aggregateData?.first.episodes.length === 1
? 'movie'
: 'tv'
: '';
// 获取收藏状态
useEffect(() => {
@@ -176,7 +179,9 @@ export default function VideoCard({
actualTitle
)}${actualYear ? `&year=${actualYear}` : ''}${
isAggregate ? '&prefer=true' : ''
}`
}${
actualQuery ? `&stitle=${encodeURIComponent(actualQuery.trim())}` : ''
}${actualSearchType ? `&stype=${actualSearchType}` : ''}`
);
}
}, [
@@ -187,6 +192,8 @@ export default function VideoCard({
actualTitle,
actualYear,
isAggregate,
actualQuery,
actualSearchType,
]);
const config = useMemo(() => {