feat: merge year handle into api

This commit is contained in:
shinya
2025-07-11 12:38:46 +08:00
parent 868ec2d5aa
commit 6817ada00a
5 changed files with 18 additions and 27 deletions

View File

@@ -486,7 +486,7 @@ function PlayPageClient() {
setNeedPrefer(false);
setCurrentSource(preferredSource.source);
setCurrentId(preferredSource.id);
setVideoYear(preferredSource.year || 'unknown');
setVideoYear(preferredSource.year);
// 替换URL参数
const newUrl = new URL(window.location.href);
@@ -507,13 +507,11 @@ function PlayPageClient() {
source: currentSource,
id: currentId,
fallbackTitle: searchTitle || videoTitleRef.current.trim(),
fallbackYear:
videoYearRef.current === 'unknown' ? '' : videoYearRef.current,
});
// 更新状态保存详情
setVideoTitle(detailData.title || videoTitleRef.current);
setVideoYear(detailData.year || 'unknown');
setVideoYear(detailData.year);
setVideoCover(detailData.poster);
setDetail(detailData);
@@ -525,7 +523,7 @@ function PlayPageClient() {
// 清理URL参数移除index参数
if (searchParams.has('index')) {
const newUrl = new URL(window.location.href);
newUrl.searchParams.set('year', detailData.year || 'unknown');
newUrl.searchParams.set('year', detailData.year);
newUrl.searchParams.set(
'title',
detailData.title || videoTitleRef.current
@@ -661,10 +659,7 @@ function PlayPageClient() {
result.title.toLowerCase() ===
videoTitleRef.current.toLowerCase() &&
(videoYearRef.current
? videoYearRef.current === 'unknown'
? result.year === ''
: result.year.toLowerCase() ===
videoYearRef.current.toLowerCase()
? result.year.toLowerCase() === videoYearRef.current.toLowerCase()
: true) &&
(detailRef.current
? (detailRef.current.episodes.length === 1 &&
@@ -725,8 +720,6 @@ function PlayPageClient() {
source: newSource,
id: newId,
fallbackTitle: searchTitle || newTitle.trim(),
fallbackYear:
videoYearRef.current === 'unknown' ? '' : videoYearRef.current,
});
// 尝试跳转到当前正在播放的集数
@@ -749,11 +742,11 @@ function PlayPageClient() {
const newUrl = new URL(window.location.href);
newUrl.searchParams.set('source', newSource);
newUrl.searchParams.set('id', newId);
newUrl.searchParams.set('year', newDetail.year || 'unknown');
newUrl.searchParams.set('year', newDetail.year);
window.history.replaceState({}, '', newUrl.toString());
setVideoTitle(newDetail.title || newTitle);
setVideoYear(newDetail.year || 'unknown');
setVideoYear(newDetail.year);
setVideoCover(newDetail.poster);
setCurrentSource(newSource);
setCurrentId(newId);
@@ -925,7 +918,7 @@ function PlayPageClient() {
await savePlayRecord(currentSourceRef.current, currentIdRef.current, {
title: videoTitleRef.current,
source_name: detailRef.current?.source_name || '',
year: detailRef.current?.year || 'unknown',
year: detailRef.current?.year,
cover: detailRef.current?.poster || '',
index: currentEpisodeIndexRef.current + 1, // 转换为1基索引
total_episodes: detailRef.current?.episodes.length || 1,
@@ -939,7 +932,7 @@ function PlayPageClient() {
console.log('播放进度已保存:', {
title: videoTitleRef.current,
episode: currentEpisodeIndexRef.current + 1,
year: detailRef.current?.year || 'unknown',
year: detailRef.current?.year,
progress: `${Math.floor(currentTime)}/${Math.floor(duration)}`,
});
} catch (err) {
@@ -1013,7 +1006,7 @@ function PlayPageClient() {
{
title: videoTitleRef.current,
source_name: detailRef.current?.source_name || '',
year: detailRef.current?.year || 'unknown',
year: detailRef.current?.year,
cover: detailRef.current?.poster || '',
total_episodes: detailRef.current?.episodes.length || 1,
save_time: Date.now(),

View File

@@ -40,7 +40,7 @@ function SearchPageClient() {
const aggregatedResults = useMemo(() => {
const map = new Map<string, SearchResult[]>();
searchResults.forEach((item) => {
// 使用 title + year + type 作为键,year 不存在则使用 'unknown'
// 使用 title + year + type 作为键year 必然存在,但依然兜底 'unknown'
const key = `${item.title}-${item.year || 'unknown'}-${
item.episodes.length === 1 ? 'movie' : 'tv'
}`;

View File

@@ -96,9 +96,7 @@ export default function VideoCard({
aggregateData?.mostFrequentDoubanId ?? douban_id
);
const actualEpisodes = aggregateData?.mostFrequentEpisodes ?? episodes;
const actualYear = isAggregate
? aggregateData?.first.year || 'unknown'
: year;
const actualYear = aggregateData?.first.year ?? year;
const actualQuery = query || '';
const actualSearchType = isAggregate
? aggregateData?.first.episodes.length === 1

View File

@@ -84,7 +84,9 @@ export async function searchFromApi(
source: apiSite.key,
source_name: apiName,
class: item.vod_class,
year: item.vod_year ? item.vod_year.match(/\d{4}/)?.[0] || '' : '',
year: item.vod_year
? item.vod_year.match(/\d{4}/)?.[0] || ''
: 'unknown',
desc: cleanHtmlTags(item.vod_content || ''),
type_name: item.type_name,
douban_id: item.vod_douban_id,
@@ -154,7 +156,7 @@ export async function searchFromApi(
class: item.vod_class,
year: item.vod_year
? item.vod_year.match(/\d{4}/)?.[0] || ''
: '',
: 'unknown',
desc: cleanHtmlTags(item.vod_content || ''),
type_name: item.type_name,
douban_id: item.vod_douban_id,
@@ -261,7 +263,7 @@ export async function getDetailFromApi(
type: videoDetail.type_name,
year: videoDetail.vod_year
? videoDetail.vod_year.match(/\d{4}/)?.[0] || ''
: '',
: 'unknown',
area: videoDetail.vod_area,
director: videoDetail.vod_director,
actor: videoDetail.vod_actor,
@@ -330,7 +332,7 @@ async function handleSpecialSourceDetail(
// 提取年份
const yearMatch = html.match(/>(\d{4})</);
const yearText = yearMatch ? yearMatch[1] : '';
const yearText = yearMatch ? yearMatch[1] : 'unknown';
return {
code: 200,

View File

@@ -16,7 +16,6 @@ interface FetchVideoDetailOptions {
source: string;
id: string;
fallbackTitle?: string;
fallbackYear?: string;
}
/**
@@ -28,7 +27,6 @@ export async function fetchVideoDetail({
source,
id,
fallbackTitle = '',
fallbackYear = '',
}: FetchVideoDetailOptions): Promise<VideoDetail> {
// 优先通过搜索接口查找精确匹配
if (fallbackTitle) {
@@ -67,7 +65,7 @@ export async function fetchVideoDetail({
source: data?.videoInfo?.source || source,
source_name: data?.videoInfo?.source_name || '',
class: data?.videoInfo?.remarks || '',
year: data?.videoInfo?.year || fallbackYear || '',
year: data?.videoInfo?.year || 'unknown',
desc: data?.videoInfo?.desc || '',
type_name: data?.videoInfo?.type || '',
} as VideoDetail;