From a41a752c2bbaddae9aa9bfec1b019d0ca6343113 Mon Sep 17 00:00:00 2001 From: renxia Date: Thu, 29 Jun 2023 14:51:02 +0800 Subject: [PATCH] =?UTF-8?q?wip:=20=E6=96=B0=E5=A2=9E=E9=83=A8=E5=88=86?= =?UTF-8?q?=E8=B5=84=E6=BA=90API=E7=AB=99=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cli.ts | 4 +- src/lib/video-search.ts | 15 +++-- test/remote-config-prepare.json | 102 ++++++++++++++++++++++++++++++++ test/remote-config.json | 33 ++++++++--- 4 files changed, 139 insertions(+), 15 deletions(-) create mode 100644 test/remote-config-prepare.json diff --git a/src/cli.ts b/src/cli.ts index c372525..8204ce1 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -48,9 +48,9 @@ program .command('search [keyword]') .alias('s') .option('-u,--url ', '影视搜索的接口地址(m3u8采集站标准接口)') - .option('-F, --force', `是否强制`) + .option('-R,--remote-config-url ', '自定义远程配置加载地址。默认从主仓库配置读取') .description('m3u8视频在线搜索与下载') - .action(async (keyword, options: { url?: string[] }) => { + .action(async (keyword, options: { url?: string[]; remoteConfigUrl?: string }) => { VideoSerachAndDL(keyword, options, getOptions()); }); diff --git a/src/lib/video-search.ts b/src/lib/video-search.ts index 56c0d3c..792d510 100644 --- a/src/lib/video-search.ts +++ b/src/lib/video-search.ts @@ -14,6 +14,8 @@ export interface VSOptions { /** 播放地址缓存 */ api?: string[]; force?: boolean; + /** 远程配置的请求地址 */ + remoteConfigUrl?: string; } /** @@ -33,7 +35,7 @@ export interface VSOptions { export class VideoSearch { public apiMap = new Map(); public get api() { - return [...this.apiMap.values()]; + return [...this.apiMap.values()].reverse(); } constructor(protected options: VSOptions = {}) { if (!options.api?.length) options.api = []; @@ -106,7 +108,8 @@ export class VideoSearch { } if (needUpdate) { - const url = 'https://ghproxy.com/raw.githubusercontent.com/lzwme/m3u8-dl/main/test/remote-config.json'; + const url = + this.options.remoteConfigUrl || 'https://ghproxy.com/raw.githubusercontent.com/lzwme/m3u8-dl/main/test/remote-config.json'; const { data } = await req.get( url, null, @@ -141,7 +144,11 @@ export class VideoSearch { } } -export async function VideoSerachAndDL(keyword: string, options: { url?: string[] }, baseOpts: CliOptions): Promise { +export async function VideoSerachAndDL( + keyword: string, + options: { url?: string[]; remoteConfigUrl?: string }, + baseOpts: CliOptions +): Promise { const cache = stor.get(); if (cache.latestSearchDL?.keyword) { const p = await prompt<{ k: boolean }>({ @@ -158,7 +165,7 @@ export async function VideoSerachAndDL(keyword: string, options: { url?: string[ } const vs = new VideoSearch(); - await vs.updateOptions({ api: options.url || [], force: baseOpts.force }); + await vs.updateOptions({ api: options.url || [], force: baseOpts.force, remoteConfigUrl: options.remoteConfigUrl }); const apis = vs.api; let apiUrl = options.url?.length ? { url: options.url[0] } : apis[0]; diff --git a/test/remote-config-prepare.json b/test/remote-config-prepare.json new file mode 100644 index 0000000..a0cd4f3 --- /dev/null +++ b/test/remote-config-prepare.json @@ -0,0 +1,102 @@ +{ + "apiSites": [ + { + "desc": "天堂", + "url": "http://vipmv.cc/api.php/provide/vod/", + "home": "http://vipmv.cc" + }, + { + "desc": "快车", + "home": "http://kuaichezy.com", + "url": "https://caiji.kczyapi.com/api.php/provide/vod/" + }, + { + "desc": "天空", + "home": "https://tiankongzy.com", + "url": "https://api.tiankongapi.com/api.php/provide/vod/" + }, + { + "desc": "飞速", + "home": "https://fszy2.com", + "url": "https://www.feisuzyapi.com/api.php/provide/vod/" + }, + { + "desc": "卧龙", + "home": "http://wolongzy.cc", + "url": "https://collect.wolongzy.cc/api.php/provide/vod/" + }, + { + "desc": "无尽", + "home": "https://wujinzy.net", + "url": "https://api.wujinapi.me/api.php/provide/vod/" + }, + { + "desc": "金鹰", + "home": "https://jyzyapi.com", + "url": "https://jyzyapi.com/provide/vod/", + "enable": 1 + }, + { + "desc": "金鹰备用1", + "home": "http://jyzy1.com", + "url": "https://jyzy1.com/provide/vod/", + "enable": 0 + }, + { + "desc": "金鹰备用2", + "home": "http://jinyingzy.com", + "url": "https://jyzyapi.com/provide/vod/", + "enable": 0 + }, + { + "desc": "新浪", + "home": "https://www.xinlangzy.com", + "url": "https://api.xinlangapi.com/xinlangapi.php/provide/vod/" + }, + { + "desc": "光速", + "home": "https://guangsuzy.com", + "url": "https://api.guangsuapi.com/api.php/provide/vod/" + }, + { + "desc": "闪电", + "home": "https://www.shan05.com", + "url": "https://sdzyapi.com/api.php/provide/vod/" + }, + { + "desc": "apibdzy(百度云资源)", + "home": "https://bdyunzy.com", + "url": "https://api.apibdzy.com/api.php/provide/vod/" + }, + { + "desc": "U酷", + "home": "https://ukuzy0.com", + "url": "https://api.ukuapi.com/api.php/provide/vod/" + }, + { + "desc": "CK资源", + "home": "https://www.ckzy1.com/", + "url": "https://ckzy.me/api.php/provide/vod/" + }, + { + "desc": "量子", + "home": "http://lzizy.net", + "url": "https://cj.lziapi.com/api.php/provide/vod/" + }, + { + "desc": "速播", + "home": "https://www.subozy1.com", + "url": "https://subocaiji.com/api.php/provide/vod/" + }, + { + "desc": "红牛", + "home": "https://hongniuzy.net/help/", + "url": "https://www.hongniuzy2.com/api.php/provide/vod/" + }, + { + "desc": "6U", + "url": "http://www.6uapi.cc/api.php/provide/vod/", + "home": "http://www.6uzy.cc" + } + ] +} diff --git a/test/remote-config.json b/test/remote-config.json index 0bd97e1..f0cbbf5 100644 --- a/test/remote-config.json +++ b/test/remote-config.json @@ -1,19 +1,34 @@ { "apiSites": [ { - "url": "https://jyzyapi.com/provide/vod/", - "desc": "金鹰", - "enable": 1 + "desc": "天堂", + "url": "http://vipmv.cc/api.php/provide/vod/", + "home": "http://vipmv.cc" }, { - "url": "https://jyzy1.com/provide/vod/", - "desc": "金鹰备用1", - "enable": 0 + "desc": "快车", + "home": "http://kuaichezy.com", + "url": "https://caiji.kczyapi.com/api.php/provide/vod/" }, { - "url": "https://api.xinlangapi.com/xinlangapi.php/provide/vod/", - "desc": "新浪API", - "enable": 1 + "desc": "天空", + "home": "https://tiankongzy.com", + "url": "https://api.tiankongapi.com/api.php/provide/vod/" + }, + { + "desc": "飞速", + "home": "https://fszy2.com", + "url": "https://www.feisuzyapi.com/api.php/provide/vod/" + }, + { + "desc": "卧龙", + "home": "http://wolongzy.cc", + "url": "https://collect.wolongzy.cc/api.php/provide/vod/" + }, + { + "desc": "无尽", + "home": "https://wujinzy.net", + "url": "https://api.wujinapi.me/api.php/provide/vod/" } ] }