tmdb支持设置baseurl
This commit is contained in:
@@ -22,6 +22,7 @@ export interface AdminConfig {
|
||||
// TMDB配置
|
||||
TMDBApiKey?: string;
|
||||
TMDBProxy?: string;
|
||||
TMDBReverseProxy?: string;
|
||||
BannerDataSource?: string; // 轮播图数据源:TMDB、TX 或 Douban
|
||||
RecommendationDataSource?: string; // 更多推荐数据源:Douban、TMDB、Mixed、MixedSmart
|
||||
// Pansou配置
|
||||
|
||||
@@ -226,6 +226,7 @@ async function getInitConfig(configFile: string, subConfig: {
|
||||
// TMDB配置
|
||||
TMDBApiKey: '',
|
||||
TMDBProxy: '',
|
||||
TMDBReverseProxy: '',
|
||||
// 评论功能开关
|
||||
EnableComments: false,
|
||||
},
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
import { HttpsProxyAgent } from 'https-proxy-agent';
|
||||
import nodeFetch from 'node-fetch';
|
||||
|
||||
// TMDB API 默认 Base URL
|
||||
const DEFAULT_TMDB_BASE_URL = 'https://api.themoviedb.org/3';
|
||||
|
||||
// TMDB API Key 轮询管理
|
||||
let currentKeyIndex = 0;
|
||||
|
||||
@@ -77,13 +80,15 @@ interface TMDBTVAiringTodayResponse {
|
||||
* @param page - 页码
|
||||
* @param region - 地区代码,默认 CN (中国)
|
||||
* @param proxy - 代理服务器地址
|
||||
* @param reverseProxyBaseUrl - 反代 Base URL
|
||||
* @returns 即将上映的电影列表
|
||||
*/
|
||||
export async function getTMDBUpcomingMovies(
|
||||
apiKey: string,
|
||||
page: number = 1,
|
||||
region: string = 'CN',
|
||||
proxy?: string
|
||||
proxy?: string,
|
||||
reverseProxyBaseUrl?: string
|
||||
): Promise<{ code: number; list: TMDBMovie[] }> {
|
||||
try {
|
||||
const actualKey = getNextApiKey(apiKey);
|
||||
@@ -91,7 +96,8 @@ export async function getTMDBUpcomingMovies(
|
||||
return { code: 400, list: [] };
|
||||
}
|
||||
|
||||
const url = `https://api.themoviedb.org/3/movie/upcoming?api_key=${actualKey}&language=zh-CN&page=${page}®ion=${region}`;
|
||||
const baseUrl = reverseProxyBaseUrl || DEFAULT_TMDB_BASE_URL;
|
||||
const url = `${baseUrl}/movie/upcoming?api_key=${actualKey}&language=zh-CN&page=${page}®ion=${region}`;
|
||||
const fetchOptions: any = proxy
|
||||
? {
|
||||
agent: new HttpsProxyAgent(proxy, {
|
||||
@@ -129,12 +135,14 @@ export async function getTMDBUpcomingMovies(
|
||||
* @param apiKey - TMDB API Key
|
||||
* @param page - 页码
|
||||
* @param proxy - 代理服务器地址
|
||||
* @param reverseProxyBaseUrl - 反代 Base URL
|
||||
* @returns 正在播出的电视剧列表
|
||||
*/
|
||||
export async function getTMDBUpcomingTVShows(
|
||||
apiKey: string,
|
||||
page: number = 1,
|
||||
proxy?: string
|
||||
proxy?: string,
|
||||
reverseProxyBaseUrl?: string
|
||||
): Promise<{ code: number; list: TMDBTVShow[] }> {
|
||||
try {
|
||||
const actualKey = getNextApiKey(apiKey);
|
||||
@@ -143,7 +151,8 @@ export async function getTMDBUpcomingTVShows(
|
||||
}
|
||||
|
||||
// 使用 on_the_air 接口获取正在播出的电视剧
|
||||
const url = `https://api.themoviedb.org/3/tv/on_the_air?api_key=${actualKey}&language=zh-CN&page=${page}`;
|
||||
const baseUrl = reverseProxyBaseUrl || DEFAULT_TMDB_BASE_URL;
|
||||
const url = `${baseUrl}/tv/on_the_air?api_key=${actualKey}&language=zh-CN&page=${page}`;
|
||||
const fetchOptions: any = proxy
|
||||
? {
|
||||
agent: new HttpsProxyAgent(proxy, {
|
||||
@@ -180,11 +189,13 @@ export async function getTMDBUpcomingTVShows(
|
||||
* 获取即将上映/播出的内容(电影+电视剧)
|
||||
* @param apiKey - TMDB API Key
|
||||
* @param proxy - 代理服务器地址
|
||||
* @param reverseProxyBaseUrl - 反代 Base URL
|
||||
* @returns 统一格式的即将上映/播出列表
|
||||
*/
|
||||
export async function getTMDBUpcomingContent(
|
||||
apiKey: string,
|
||||
proxy?: string
|
||||
proxy?: string,
|
||||
reverseProxyBaseUrl?: string
|
||||
): Promise<{ code: number; list: TMDBItem[] }> {
|
||||
try {
|
||||
if (!apiKey) {
|
||||
@@ -193,8 +204,8 @@ export async function getTMDBUpcomingContent(
|
||||
|
||||
// 并行获取电影和电视剧数据
|
||||
const [moviesResult, tvShowsResult] = await Promise.all([
|
||||
getTMDBUpcomingMovies(apiKey, 1, 'CN', proxy),
|
||||
getTMDBUpcomingTVShows(apiKey, 1, proxy),
|
||||
getTMDBUpcomingMovies(apiKey, 1, 'CN', proxy, reverseProxyBaseUrl),
|
||||
getTMDBUpcomingTVShows(apiKey, 1, proxy, reverseProxyBaseUrl),
|
||||
]);
|
||||
|
||||
// 检查是否有错误
|
||||
@@ -262,13 +273,15 @@ export async function getTMDBUpcomingContent(
|
||||
* @param mediaType - 媒体类型 (movie 或 tv)
|
||||
* @param mediaId - 媒体ID
|
||||
* @param proxy - 代理服务器地址
|
||||
* @param reverseProxyBaseUrl - 反代 Base URL
|
||||
* @returns YouTube视频key(只返回预告片)
|
||||
*/
|
||||
export async function getTMDBVideos(
|
||||
apiKey: string,
|
||||
mediaType: 'movie' | 'tv',
|
||||
mediaId: number,
|
||||
proxy?: string
|
||||
proxy?: string,
|
||||
reverseProxyBaseUrl?: string
|
||||
): Promise<string | null> {
|
||||
try {
|
||||
const actualKey = getNextApiKey(apiKey);
|
||||
@@ -276,7 +289,8 @@ export async function getTMDBVideos(
|
||||
return null;
|
||||
}
|
||||
|
||||
const url = `https://api.themoviedb.org/3/${mediaType}/${mediaId}/videos?api_key=${actualKey}`;
|
||||
const baseUrl = reverseProxyBaseUrl || DEFAULT_TMDB_BASE_URL;
|
||||
const url = `${baseUrl}/${mediaType}/${mediaId}/videos?api_key=${actualKey}`;
|
||||
const fetchOptions: any = proxy
|
||||
? {
|
||||
agent: new HttpsProxyAgent(proxy, {
|
||||
@@ -314,11 +328,13 @@ export async function getTMDBVideos(
|
||||
* 获取热门内容(电影+电视剧)
|
||||
* @param apiKey - TMDB API Key
|
||||
* @param proxy - 代理服务器地址
|
||||
* @param reverseProxyBaseUrl - 反代 Base URL
|
||||
* @returns 热门内容列表
|
||||
*/
|
||||
export async function getTMDBTrendingContent(
|
||||
apiKey: string,
|
||||
proxy?: string
|
||||
proxy?: string,
|
||||
reverseProxyBaseUrl?: string
|
||||
): Promise<{ code: number; list: TMDBItem[] }> {
|
||||
try {
|
||||
const actualKey = getNextApiKey(apiKey);
|
||||
@@ -327,7 +343,8 @@ export async function getTMDBTrendingContent(
|
||||
}
|
||||
|
||||
// 获取本周热门内容(电影+电视剧)
|
||||
const url = `https://api.themoviedb.org/3/trending/all/week?api_key=${actualKey}&language=zh-CN`;
|
||||
const baseUrl = reverseProxyBaseUrl || DEFAULT_TMDB_BASE_URL;
|
||||
const url = `${baseUrl}/trending/all/week?api_key=${actualKey}&language=zh-CN`;
|
||||
const fetchOptions: any = proxy
|
||||
? {
|
||||
agent: new HttpsProxyAgent(proxy, {
|
||||
@@ -442,12 +459,14 @@ export function getGenreNames(genreIds: number[] = [], limit: number = 2): strin
|
||||
* @param apiKey - TMDB API Key
|
||||
* @param query - 搜索关键词
|
||||
* @param proxy - 代理服务器地址
|
||||
* @param reverseProxyBaseUrl - 反代 Base URL
|
||||
* @returns 搜索结果列表
|
||||
*/
|
||||
export async function searchTMDBMulti(
|
||||
apiKey: string,
|
||||
query: string,
|
||||
proxy?: string
|
||||
proxy?: string,
|
||||
reverseProxyBaseUrl?: string
|
||||
): Promise<{ code: number; results: any[] }> {
|
||||
try {
|
||||
const actualKey = getNextApiKey(apiKey);
|
||||
@@ -455,7 +474,8 @@ export async function searchTMDBMulti(
|
||||
return { code: 400, results: [] };
|
||||
}
|
||||
|
||||
const url = `https://api.themoviedb.org/3/search/multi?api_key=${actualKey}&language=zh-CN&query=${encodeURIComponent(query)}&page=1`;
|
||||
const baseUrl = reverseProxyBaseUrl || DEFAULT_TMDB_BASE_URL;
|
||||
const url = `${baseUrl}/search/multi?api_key=${actualKey}&language=zh-CN&query=${encodeURIComponent(query)}&page=1`;
|
||||
const fetchOptions: any = proxy
|
||||
? {
|
||||
agent: new HttpsProxyAgent(proxy, {
|
||||
@@ -492,12 +512,14 @@ export async function searchTMDBMulti(
|
||||
* @param apiKey - TMDB API Key
|
||||
* @param movieId - 电影ID
|
||||
* @param proxy - 代理服务器地址
|
||||
* @param reverseProxyBaseUrl - 反代 Base URL
|
||||
* @returns 推荐列表
|
||||
*/
|
||||
export async function getTMDBMovieRecommendations(
|
||||
apiKey: string,
|
||||
movieId: number,
|
||||
proxy?: string
|
||||
proxy?: string,
|
||||
reverseProxyBaseUrl?: string
|
||||
): Promise<{ code: number; results: TMDBMovie[] }> {
|
||||
try {
|
||||
const actualKey = getNextApiKey(apiKey);
|
||||
@@ -505,7 +527,8 @@ export async function getTMDBMovieRecommendations(
|
||||
return { code: 400, results: [] };
|
||||
}
|
||||
|
||||
const url = `https://api.themoviedb.org/3/movie/${movieId}/recommendations?api_key=${actualKey}&language=zh-CN&page=1`;
|
||||
const baseUrl = reverseProxyBaseUrl || DEFAULT_TMDB_BASE_URL;
|
||||
const url = `${baseUrl}/movie/${movieId}/recommendations?api_key=${actualKey}&language=zh-CN&page=1`;
|
||||
const fetchOptions: any = proxy
|
||||
? {
|
||||
agent: new HttpsProxyAgent(proxy, {
|
||||
@@ -542,12 +565,14 @@ export async function getTMDBMovieRecommendations(
|
||||
* @param apiKey - TMDB API Key
|
||||
* @param tvId - 电视剧ID
|
||||
* @param proxy - 代理服务器地址
|
||||
* @param reverseProxyBaseUrl - 反代 Base URL
|
||||
* @returns 推荐列表
|
||||
*/
|
||||
export async function getTMDBTVRecommendations(
|
||||
apiKey: string,
|
||||
tvId: number,
|
||||
proxy?: string
|
||||
proxy?: string,
|
||||
reverseProxyBaseUrl?: string
|
||||
): Promise<{ code: number; results: TMDBTVShow[] }> {
|
||||
try {
|
||||
const actualKey = getNextApiKey(apiKey);
|
||||
@@ -555,7 +580,8 @@ export async function getTMDBTVRecommendations(
|
||||
return { code: 400, results: [] };
|
||||
}
|
||||
|
||||
const url = `https://api.themoviedb.org/3/tv/${tvId}/recommendations?api_key=${actualKey}&language=zh-CN&page=1`;
|
||||
const baseUrl = reverseProxyBaseUrl || DEFAULT_TMDB_BASE_URL;
|
||||
const url = `${baseUrl}/tv/${tvId}/recommendations?api_key=${actualKey}&language=zh-CN&page=1`;
|
||||
const fetchOptions: any = proxy
|
||||
? {
|
||||
agent: new HttpsProxyAgent(proxy, {
|
||||
@@ -592,12 +618,14 @@ export async function getTMDBTVRecommendations(
|
||||
* @param apiKey - TMDB API Key
|
||||
* @param movieId - 电影ID
|
||||
* @param proxy - 代理服务器地址
|
||||
* @param reverseProxyBaseUrl - 反代 Base URL
|
||||
* @returns 电影详情
|
||||
*/
|
||||
export async function getTMDBMovieDetails(
|
||||
apiKey: string,
|
||||
movieId: number,
|
||||
proxy?: string
|
||||
proxy?: string,
|
||||
reverseProxyBaseUrl?: string
|
||||
): Promise<{ code: number; details: any }> {
|
||||
try {
|
||||
const actualKey = getNextApiKey(apiKey);
|
||||
@@ -605,7 +633,8 @@ export async function getTMDBMovieDetails(
|
||||
return { code: 400, details: null };
|
||||
}
|
||||
|
||||
const url = `https://api.themoviedb.org/3/movie/${movieId}?api_key=${actualKey}&language=zh-CN`;
|
||||
const baseUrl = reverseProxyBaseUrl || DEFAULT_TMDB_BASE_URL;
|
||||
const url = `${baseUrl}/movie/${movieId}?api_key=${actualKey}&language=zh-CN`;
|
||||
const fetchOptions: any = proxy
|
||||
? {
|
||||
agent: new HttpsProxyAgent(proxy, {
|
||||
@@ -642,12 +671,14 @@ export async function getTMDBMovieDetails(
|
||||
* @param apiKey - TMDB API Key
|
||||
* @param tvId - 电视剧ID
|
||||
* @param proxy - 代理服务器地址
|
||||
* @param reverseProxyBaseUrl - 反代 Base URL
|
||||
* @returns 电视剧详情
|
||||
*/
|
||||
export async function getTMDBTVDetails(
|
||||
apiKey: string,
|
||||
tvId: number,
|
||||
proxy?: string
|
||||
proxy?: string,
|
||||
reverseProxyBaseUrl?: string
|
||||
): Promise<{ code: number; details: any }> {
|
||||
try {
|
||||
const actualKey = getNextApiKey(apiKey);
|
||||
@@ -655,7 +686,8 @@ export async function getTMDBTVDetails(
|
||||
return { code: 400, details: null };
|
||||
}
|
||||
|
||||
const url = `https://api.themoviedb.org/3/tv/${tvId}?api_key=${actualKey}&language=zh-CN`;
|
||||
const baseUrl = reverseProxyBaseUrl || DEFAULT_TMDB_BASE_URL;
|
||||
const url = `${baseUrl}/tv/${tvId}?api_key=${actualKey}&language=zh-CN`;
|
||||
const fetchOptions: any = proxy
|
||||
? {
|
||||
agent: new HttpsProxyAgent(proxy, {
|
||||
|
||||
Reference in New Issue
Block a user