私人影库扫描增加季度支持
This commit is contained in:
@@ -79,6 +79,129 @@ export async function searchTMDB(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TMDB 季度信息
|
||||
*/
|
||||
export interface TMDBSeasonInfo {
|
||||
id: number;
|
||||
name: string;
|
||||
season_number: number;
|
||||
episode_count: number;
|
||||
air_date: string | null;
|
||||
poster_path: string | null;
|
||||
overview: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* TMDB 电视剧详情(包含季度列表)
|
||||
*/
|
||||
interface TMDBTVDetails {
|
||||
id: number;
|
||||
name: string;
|
||||
seasons: TMDBSeasonInfo[];
|
||||
number_of_seasons: number;
|
||||
poster_path: string | null;
|
||||
first_air_date: string;
|
||||
overview: string;
|
||||
vote_average: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取电视剧的季度列表
|
||||
*/
|
||||
export async function getTVSeasons(
|
||||
apiKey: string,
|
||||
tvId: number,
|
||||
proxy?: string
|
||||
): Promise<{ code: number; seasons: TMDBSeasonInfo[] | null }> {
|
||||
try {
|
||||
if (!apiKey) {
|
||||
return { code: 400, seasons: null };
|
||||
}
|
||||
|
||||
const url = `https://api.themoviedb.org/3/tv/${tvId}?api_key=${apiKey}&language=zh-CN`;
|
||||
|
||||
const fetchOptions: any = proxy
|
||||
? {
|
||||
agent: new HttpsProxyAgent(proxy, {
|
||||
timeout: 30000,
|
||||
keepAlive: false,
|
||||
}),
|
||||
signal: AbortSignal.timeout(30000),
|
||||
}
|
||||
: {
|
||||
signal: AbortSignal.timeout(15000),
|
||||
};
|
||||
|
||||
const response = await nodeFetch(url, fetchOptions);
|
||||
|
||||
if (!response.ok) {
|
||||
console.error('TMDB 获取电视剧详情失败:', response.status, response.statusText);
|
||||
return { code: response.status, seasons: null };
|
||||
}
|
||||
|
||||
const data: TMDBTVDetails = await response.json() as TMDBTVDetails;
|
||||
|
||||
// 过滤掉特殊季度(如 Season 0 通常是特别篇)
|
||||
const validSeasons = data.seasons.filter((season) => season.season_number > 0);
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
seasons: validSeasons,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('TMDB 获取季度列表异常:', error);
|
||||
return { code: 500, seasons: null };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取电视剧特定季度的详细信息
|
||||
*/
|
||||
export async function getTVSeasonDetails(
|
||||
apiKey: string,
|
||||
tvId: number,
|
||||
seasonNumber: number,
|
||||
proxy?: string
|
||||
): Promise<{ code: number; season: TMDBSeasonInfo | null }> {
|
||||
try {
|
||||
if (!apiKey) {
|
||||
return { code: 400, season: null };
|
||||
}
|
||||
|
||||
const url = `https://api.themoviedb.org/3/tv/${tvId}/season/${seasonNumber}?api_key=${apiKey}&language=zh-CN`;
|
||||
|
||||
const fetchOptions: any = proxy
|
||||
? {
|
||||
agent: new HttpsProxyAgent(proxy, {
|
||||
timeout: 30000,
|
||||
keepAlive: false,
|
||||
}),
|
||||
signal: AbortSignal.timeout(30000),
|
||||
}
|
||||
: {
|
||||
signal: AbortSignal.timeout(15000),
|
||||
};
|
||||
|
||||
const response = await nodeFetch(url, fetchOptions);
|
||||
|
||||
if (!response.ok) {
|
||||
console.error('TMDB 获取季度详情失败:', response.status, response.statusText);
|
||||
return { code: response.status, season: null };
|
||||
}
|
||||
|
||||
const data: TMDBSeasonInfo = await response.json() as TMDBSeasonInfo;
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
season: data,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('TMDB 获取季度详情异常:', error);
|
||||
return { code: 500, season: null };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 TMDB 图片完整 URL
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user