From b1c7b6b6edb0bce956eda2b2f39f116bf7fcd690 Mon Sep 17 00:00:00 2001 From: Virgil Clyne Date: Fri, 29 Nov 2024 14:39:13 +0800 Subject: [PATCH] feat: Console Update CHANGELOG.md Update setENV.mjs --- CHANGELOG.md | 11 +- src/Composite.Subtitles.response.dev.js | 359 +++++++++++------------ src/Composite.Subtitles.response.js | 325 ++++++++++---------- src/External.Lyrics.response.dev.js | 90 +++--- src/External.Lyrics.response.js | 51 ++-- src/External.Subtitles.response.dev.js | 48 +-- src/Manifest.response.dev.js | 64 ++-- src/Manifest.response.js | 65 ++-- src/Translate.response.dev.js | 70 ++--- src/Translate.response.js | 27 +- src/class/AttrList.mjs | 32 +- src/class/Composite.mjs | 72 ++--- src/class/Translate.mjs | 6 +- src/function/constructSubtitlesQueue.mjs | 30 +- src/function/detectFormat.mjs | 10 +- src/function/detectPlatform.mjs | 6 +- src/function/detectPlaylist.mjs | 6 +- src/function/isStandard.mjs | 9 +- src/function/setCache.mjs | 6 +- src/function/setENV.mjs | 9 +- src/function/setOption.mjs | 6 +- 21 files changed, 648 insertions(+), 654 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61c1a8bf..60ca1e19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ ### 🛠️ Bug Fixes - * 修复 `External.Lyrics.response` 的`网易云音乐`歌词源`逐字歌词`丢失的问题 + * 修复 `$argument` 和 `$persistentStore` 载入顺序颠倒的问题 + * 正确顺序为先读取 `$argument` 再读取 `$persistentStore (BoxJs)` + * 即,有相同键名时,`$persistentStore (BoxJs)` 的值会覆盖 `$argument` 的值 ### 🔣 Dependencies - * 移除了 `External.Lyrics.response` 中的 `@nsnanocat/url` polyfill + * 升级了 `@nsnanocat/url` + * 使用了全新的 `URL` 和 `URLSearchParams` polyfill + * 升级了 `@nsnanocat/util` + * `util` 由 `submodule` 更改为 `package` + * `$platform` 改为 `$app` + * 使用了全新的 `Console` polyfill diff --git a/src/Composite.Subtitles.response.dev.js b/src/Composite.Subtitles.response.dev.js index bbf3911c..6fbeaf0f 100644 --- a/src/Composite.Subtitles.response.dev.js +++ b/src/Composite.Subtitles.response.dev.js @@ -1,4 +1,4 @@ -import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util"; +import { $app, Console, done, fetch, Lodash as _, notification, Storage, wait } from "@nsnanocat/util"; import { URL } from "@nsnanocat/url"; import XML from "./XML/XML.mjs"; import VTT from "./WebVTT/WebVTT.mjs"; @@ -12,206 +12,197 @@ import Composite from "./class/Composite.mjs"; /***************** Processing *****************/ // 解构URL const url = new URL($request.url); -log(`⚠ url: ${url.toJSON()}`, ""); +Console.info(`url: ${url.toJSON()}`); // 获取连接参数 const METHOD = $request.method, HOST = url.hostname, PATH = url.pathname, PATHs = url.pathname.split("/").filter(Boolean); -log(`⚠ METHOD: ${METHOD}, HOST: ${HOST}, PATH: ${PATH}`, ""); +Console.info(`METHOD: ${METHOD}, HOST: ${HOST}, PATH: ${PATH}`); // 解析格式 let FORMAT = ($response.headers?.["Content-Type"] ?? $response.headers?.["content-type"])?.split(";")?.[0]; if (FORMAT === "application/octet-stream" || FORMAT === "text/plain") FORMAT = detectFormat(url, $response?.body, FORMAT); -log(`⚠ FORMAT: ${FORMAT}`, ""); +Console.info(`FORMAT: ${FORMAT}`); (async () => { // 获取平台 const PLATFORM = detectPlatform($request.url); - log(`⚠ PLATFORM: ${PLATFORM}`, ""); + Console.info(`PLATFORM: ${PLATFORM}`); /** * 设置 * @type {{Settings: import('./types').Settings}} */ const { Settings, Caches, Configs } = setENV("DualSubs", [["YouTube", "Netflix", "BiliBili", "Spotify"].includes(PLATFORM) ? PLATFORM : "Universal", "Composite", "API"], database); - log(`⚠ Settings.Switch: ${Settings?.Switch}`, ""); - switch (Settings.Switch) { - case true: - default: { - // 获取字幕类型与语言 - const Type = url.searchParams?.get("subtype") ?? Settings.Type, - Languages = [url.searchParams?.get("lang")?.toUpperCase?.() ?? Settings.Languages[0], (url.searchParams?.get("tlang") ?? Caches?.tlang)?.toUpperCase?.() ?? Settings.Languages[1]]; - log(`⚠ Type: ${Type}, Languages: ${Languages}`, ""); - // 创建空数据 - let body = {}; - // 创建字幕请求队列 - let requests = []; - // 处理类型 - switch (Type) { - case "Official": - log("⚠ 官方字幕", ""); - switch (PLATFORM) { - default: { - // 获取字幕文件地址vtt缓存(map) - const { subtitlesPlaylistURL } = getSubtitlesCache($request.url, Caches.Playlists.Subtitle, Languages); - // 获取字幕播放列表m3u8缓存(map) - const { masterPlaylistURL, subtitlesPlaylistIndex } = getPlaylistCache(subtitlesPlaylistURL, Caches.Playlists.Master, Languages); - // 获取字幕文件地址vtt缓存(map) - const { subtitlesURIArray0, subtitlesURIArray1 } = getSubtitlesArray(masterPlaylistURL, subtitlesPlaylistIndex, Caches.Playlists.Master, Caches.Playlists.Subtitle, Languages); - // 获取官方字幕请求 - if (subtitlesURIArray1.length) { - log(`🚧 subtitlesURIArray1.length: ${subtitlesURIArray1.length}`, ""); - // 获取字幕文件名 - const fileName = PATHs?.[PATHs?.length - 1] ?? getSubtitlesFileName($request.url, PLATFORM); - log(`🚧 fileName: ${fileName}`, ""); - // 构造请求队列 - requests = constructSubtitlesQueue($request, fileName, subtitlesURIArray0, subtitlesURIArray1); - } + // 获取字幕类型与语言 + const Type = url.searchParams?.get("subtype") ?? Settings.Type, + Languages = [url.searchParams?.get("lang")?.toUpperCase?.() ?? Settings.Languages[0], (url.searchParams?.get("tlang") ?? Caches?.tlang)?.toUpperCase?.() ?? Settings.Languages[1]]; + Console.info(`Type: ${Type}, Languages: ${Languages}`); + // 创建空数据 + let body = {}; + // 创建字幕请求队列 + let requests = []; + // 处理类型 + switch (Type) { + case "Official": + Console.info("官方字幕"); + switch (PLATFORM) { + default: { + // 获取字幕文件地址vtt缓存(map) + const { subtitlesPlaylistURL } = getSubtitlesCache($request.url, Caches.Playlists.Subtitle, Languages); + // 获取字幕播放列表m3u8缓存(map) + const { masterPlaylistURL, subtitlesPlaylistIndex } = getPlaylistCache(subtitlesPlaylistURL, Caches.Playlists.Master, Languages); + // 获取字幕文件地址vtt缓存(map) + const { subtitlesURIArray0, subtitlesURIArray1 } = getSubtitlesArray(masterPlaylistURL, subtitlesPlaylistIndex, Caches.Playlists.Master, Caches.Playlists.Subtitle, Languages); + // 获取官方字幕请求 + if (subtitlesURIArray1.length) { + Console.debug(`subtitlesURIArray1.length: ${subtitlesURIArray1.length}`); + // 获取字幕文件名 + const fileName = PATHs?.[PATHs?.length - 1] ?? getSubtitlesFileName($request.url, PLATFORM); + Console.debug(`fileName: ${fileName}`); + // 构造请求队列 + requests = constructSubtitlesQueue($request, fileName, subtitlesURIArray0, subtitlesURIArray1); + } + break; + } + case "YouTube": + Console.info("YouTube"); + switch (url.searchParams.get("tlang")) { + case undefined: + Console.info("未选择翻译语言,跳过"); break; - } - case "YouTube": - log("⚠ YouTube", ""); - switch (url.searchParams.get("tlang")) { - case undefined: - log("⚠ 未选择翻译语言,跳过", ""); + default: + Console.info("已选择翻译语言"); + // 设置参数 + // Settings.Offset = 0; + Settings.Tolerance = 100; + Settings.Position = Settings.Position === "Reverse" ? "Forward" : "Reverse"; // 链接主字幕为翻译字幕,副字幕为原字幕,所以需要翻转一下 + switch (Settings.ShowOnly) { + case true: + Console.info("仅显示翻译后字幕,跳过"); break; - default: - log("⚠ 已选择翻译语言", ""); - // 设置参数 - // Settings.Offset = 0; - Settings.Tolerance = 100; - Settings.Position = Settings.Position === "Reverse" ? "Forward" : "Reverse"; // 链接主字幕为翻译字幕,副字幕为原字幕,所以需要翻转一下 - switch (Settings.ShowOnly) { - case true: - log("⚠ 仅显示翻译后字幕,跳过", ""); - break; - case false: - default: { - log("⚠ 生成双语字幕", ""); - // 获取字幕 - url.searchParams.set("lang", Caches.Playlists.Subtitle.get(url.searchParams.get("v")) || url.searchParams.get("lang")); // 主语言 - url.searchParams.delete("tlang"); // 原字幕 - const request = { - url: url.toString(), - headers: $request.headers, - }; - requests.push(request); - break; - } - } + case false: + default: { + Console.info("生成双语字幕"); + // 获取字幕 + url.searchParams.set("lang", Caches.Playlists.Subtitle.get(url.searchParams.get("v")) || url.searchParams.get("lang")); // 主语言 + url.searchParams.delete("tlang"); // 原字幕 + const request = { + url: url.toString(), + headers: $request.headers, + }; + requests.push(request); + break; + } } - break; - case "Netflix": - log("⚠ Netflix", ""); - break; - case "Bilibili": - log("⚠ Bilibili", ""); - break; } break; - case "Translate": - default: - log("⚠ 翻译字幕", ""); + case "Netflix": + Console.info("Netflix"); break; - case "External": - log("⚠ 外挂字幕", ""); - switch (Settings.SubVendor) { - case "URL": { - const request = { - url: Settings.URL, - headers: { - Accept: "*/*", - "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Mobile/15E148 Safari/604.1", - }, - }; - requests.push(request); - break; - } - } + case "Bilibili": + Console.info("Bilibili"); break; } - // 格式判断 - switch (FORMAT) { - case undefined: // 视为无body - break; - case "application/x-www-form-urlencoded": - case "text/plain": - default: - break; - case "application/x-mpegURL": - case "application/x-mpegurl": - case "application/vnd.apple.mpegurl": - case "audio/mpegurl": - //body = M3U8.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); - //$response.body = M3U8.stringify(body); - break; - case "text/xml": - case "text/html": - case "text/plist": - case "application/xml": - case "application/plist": - case "application/x-plist": - body = XML.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); - await Promise.all( - requests.map(async request => { - const officialSubtitle = await fetch(request).then(response => XML.parse(response.body)); - //log(`🚧 officialSubtitle: ${JSON.stringify(officialSubtitle)}`, ""); - body = new Composite(Settings).timedText(body, officialSubtitle, url.searchParams.get("kind")); - }), - ); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); - $response.body = XML.stringify(body); - break; - case "text/vtt": - case "application/vtt": - body = VTT.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); - await Promise.all( - requests.map(async request => { - const officialSubtitle = await fetch(request).then(response => VTT.parse(response.body)); - //log(`🚧 officialSubtitle: ${JSON.stringify(officialSubtitle)}`, ""); - body = new Composite(Settings).webVTT(body, officialSubtitle); - }), - ); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); - $response.body = VTT.stringify(body); - break; - case "text/json": - case "application/json": - body = JSON.parse($response.body ?? "{}"); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); - await Promise.all( - requests.map(async request => { - const officialSubtitle = await fetch(request).then(response => JSON.parse(response.body)); - //log(`🚧 officialSubtitle: ${JSON.stringify(officialSubtitle)}`, ""); - body = new Composite(Settings).JSON(body, officialSubtitle, url.searchParams.get("kind")); - }), - ); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); - $response.body = JSON.stringify(body); - break; - case "application/protobuf": - case "application/x-protobuf": - case "application/vnd.google.protobuf": - case "application/grpc": - case "application/grpc+proto": - case "application/octet-stream": { - //log(`🚧 $response.body: ${JSON.stringify($response.body)}`, ""); - let rawBody = ($app === "Quantumult X") ? new Uint8Array($response.bodyBytes ?? []) : $response.body ?? new Uint8Array(); - //log(`🚧 isBuffer? ${ArrayBuffer.isView(rawBody)}: ${JSON.stringify(rawBody)}`, ""); - // 写入二进制数据 - //log(`🚧 rawBody: ${JSON.stringify(rawBody)}`, ""); - $response.body = rawBody; + break; + case "Translate": + default: + Console.info("翻译字幕"); + break; + case "External": + Console.info("外挂字幕"); + switch (Settings.SubVendor) { + case "URL": { + const request = { + url: Settings.URL, + headers: { + Accept: "*/*", + "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Mobile/15E148 Safari/604.1", + }, + }; + requests.push(request); break; } } break; - } - case false: + } + // 格式判断 + switch (FORMAT) { + case undefined: // 视为无body + break; + case "application/x-www-form-urlencoded": + case "text/plain": + default: + break; + case "application/x-mpegURL": + case "application/x-mpegurl": + case "application/vnd.apple.mpegurl": + case "audio/mpegurl": + //body = M3U8.parse($response.body); + //Console.debug(`body: ${JSON.stringify(body)}`); + //$response.body = M3U8.stringify(body); + break; + case "text/xml": + case "text/html": + case "text/plist": + case "application/xml": + case "application/plist": + case "application/x-plist": + body = XML.parse($response.body); + //Console.debug(`body: ${JSON.stringify(body)}`); + await Promise.all( + requests.map(async request => { + const officialSubtitle = await fetch(request).then(response => XML.parse(response.body)); + //Console.debug(`officialSubtitle: ${JSON.stringify(officialSubtitle)}`); + body = new Composite(Settings).timedText(body, officialSubtitle, url.searchParams.get("kind")); + }), + ); + //Console.debug(`body: ${JSON.stringify(body)}`); + $response.body = XML.stringify(body); + break; + case "text/vtt": + case "application/vtt": + body = VTT.parse($response.body); + //Console.debug(`body: ${JSON.stringify(body)}`); + await Promise.all( + requests.map(async request => { + const officialSubtitle = await fetch(request).then(response => VTT.parse(response.body)); + //Console.debug(`officialSubtitle: ${JSON.stringify(officialSubtitle)}`); + body = new Composite(Settings).webVTT(body, officialSubtitle); + }), + ); + //Console.debug(`body: ${JSON.stringify(body)}`); + $response.body = VTT.stringify(body); break; + case "text/json": + case "application/json": + body = JSON.parse($response.body ?? "{}"); + //Console.debug(`body: ${JSON.stringify(body)}`); + await Promise.all( + requests.map(async request => { + const officialSubtitle = await fetch(request).then(response => JSON.parse(response.body)); + //Console.debug(`officialSubtitle: ${JSON.stringify(officialSubtitle)}`); + body = new Composite(Settings).JSON(body, officialSubtitle, url.searchParams.get("kind")); + }), + ); + //Console.debug(`body: ${JSON.stringify(body)}`); + $response.body = JSON.stringify(body); + break; + case "application/protobuf": + case "application/x-protobuf": + case "application/vnd.google.protobuf": + case "application/grpc": + case "application/grpc+proto": + case "application/octet-stream": { + //Console.debug(`$response.body: ${JSON.stringify($response.body)}`); + let rawBody = $app === "Quantumult X" ? new Uint8Array($response.bodyBytes ?? []) : ($response.body ?? new Uint8Array()); + //Console.debug(`isBuffer? ${ArrayBuffer.isView(rawBody)}: ${JSON.stringify(rawBody)}`); + // 写入二进制数据 + //Console.debug(`rawBody: ${JSON.stringify(rawBody)}`); + $response.body = rawBody; + break; + } } })() - .catch(e => logError(e)) + .catch(e => Console.error(e)) .finally(() => done($response)); /***************** Function *****************/ @@ -224,7 +215,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); * @return {Promise} { masterPlaylistURL, subtitlesPlaylist, subtitlesPlaylistIndex } */ function getPlaylistCache(url, cache, languages) { - log("☑️ getPlaylistCache", ""); + Console.info("☑️ getPlaylistCache"); let masterPlaylistURL = ""; let subtitlesPlaylist = {}; let subtitlesPlaylistIndex = 0; @@ -236,19 +227,19 @@ function getPlaylistCache(url, cache, languages) { array?.some((object, index) => { if (url.includes(object?.URI || object?.OPTION?.URI || null)) { subtitlesPlaylistIndex = index; - log("🚧 getPlaylistCache", `subtitlesPlaylistIndex: ${subtitlesPlaylistIndex}`, ""); + Console.debug("getPlaylistCache", `subtitlesPlaylistIndex: ${subtitlesPlaylistIndex}`); return true; } else return false; }) ) { masterPlaylistURL = Key; subtitlesPlaylist = Value; - //log(`🚧 getPlaylistCache`, `masterPlaylistURL: ${masterPlaylistURL}`, `subtitlesPlaylist: ${JSON.stringify(subtitlesPlaylist)}`, ""); + //Console.debug(`getPlaylistCache`, `masterPlaylistURL: ${masterPlaylistURL}`, `subtitlesPlaylist: ${JSON.stringify(subtitlesPlaylist)}`); } } }); }); - log("✅ getPlaylistCache", `masterPlaylistURL: ${JSON.stringify(masterPlaylistURL)}`, ""); + Console.info("✅ getPlaylistCache", `masterPlaylistURL: ${JSON.stringify(masterPlaylistURL)}`); return { masterPlaylistURL, subtitlesPlaylist, subtitlesPlaylistIndex }; } @@ -261,7 +252,7 @@ function getPlaylistCache(url, cache, languages) { * @return {Promise} { subtitlesPlaylistURL, subtitles, subtitlesIndex } */ function getSubtitlesCache(url, cache, languages) { - log("☑️ getSubtitlesCache", ""); + Console.info("☑️ getSubtitlesCache"); let subtitlesPlaylistURL = ""; let subtitles = []; let subtitlesIndex = 0; @@ -272,18 +263,18 @@ function getSubtitlesCache(url, cache, languages) { array?.some((string, index) => { if (url.includes(string || null)) { subtitlesIndex = index; - log("🚧 getSubtitlesCache", `subtitlesIndex: ${subtitlesIndex}`, ""); + Console.debug("getSubtitlesCache", `subtitlesIndex: ${subtitlesIndex}`); return true; } else return false; }) ) { subtitlesPlaylistURL = Key; subtitles = Value; - //log(`🚧 getSubtitlesCache, subtitlesPlaylistURL: ${subtitlesPlaylistURL}`, ""); + //Console.debug(`getSubtitlesCache, subtitlesPlaylistURL: ${subtitlesPlaylistURL}`); } } }); - log(`✅ getSubtitlesCache, subtitlesPlaylistURL: ${subtitlesPlaylistURL}`, ""); + Console.info("✅ getSubtitlesCache", `subtitlesPlaylistURL: ${subtitlesPlaylistURL}`); return { subtitlesPlaylistURL, subtitles, subtitlesIndex }; } @@ -298,16 +289,16 @@ function getSubtitlesCache(url, cache, languages) { * @return {Promise} { subtitlesURIArray0, subtitlesURIArray1 } */ function getSubtitlesArray(url, index, playlistsCache, subtitlesCache, languages) { - log("☑️ getSubtitlesArray", ""); + Console.info("☑️ getSubtitlesArray"); const subtitlesPlaylistValue = playlistsCache?.get(url) || {}; const subtitlesPlaylistURL0 = subtitlesPlaylistValue?.[languages[0]]?.[index]?.URL || subtitlesPlaylistValue?.[languages[0]]?.[0]?.URL; const subtitlesPlaylistURL1 = subtitlesPlaylistValue?.[languages[1]]?.[index]?.URL || subtitlesPlaylistValue?.[languages[1]]?.[0]?.URL; - log("🚧 getSubtitlesArray", `subtitlesPlaylistURL0: ${subtitlesPlaylistURL0}, subtitlesPlaylistURL1: ${subtitlesPlaylistURL1}`, ""); + Console.debug("getSubtitlesArray", `subtitlesPlaylistURL0: ${subtitlesPlaylistURL0}, subtitlesPlaylistURL1: ${subtitlesPlaylistURL1}`); // 查找字幕文件地址vtt缓存(map) const subtitlesURIArray0 = subtitlesCache.get(subtitlesPlaylistURL0) || []; const subtitlesURIArray1 = subtitlesCache.get(subtitlesPlaylistURL1) || []; - //log(`🚧 getSubtitlesArray`, `subtitlesURIArray0: ${JSON.stringify(subtitlesURIArray0)}, subtitlesURIArray1: ${JSON.stringify(subtitlesURIArray1)}`, ""); - log("✅ getSubtitlesArray", ""); + //Console.debug(`getSubtitlesArray`, `subtitlesURIArray0: ${JSON.stringify(subtitlesURIArray0)}, subtitlesURIArray1: ${JSON.stringify(subtitlesURIArray1)}`); + Console.info("✅ getSubtitlesArray"); return { subtitlesURIArray0, subtitlesURIArray1 }; } @@ -319,7 +310,7 @@ function getSubtitlesArray(url, index, playlistsCache, subtitlesCache, languages * @return {String<*>} fileName */ function getSubtitlesFileName(url, platform) { - log("☑️ Get Subtitles FileName", `url: ${url}`, ""); + Console.info("☑️ Get Subtitles FileName", `url: ${url}`); let fileName = undefined; switch (platform) { case "Apple": @@ -337,6 +328,6 @@ function getSubtitlesFileName(url, platform) { fileName = null; // Amazon Prime Video HBO_Max不拆分字幕片段 break; } - log("✅ Get Subtitles FileName", `fileName: ${fileName}`, ""); + Console.info("✅ Get Subtitles FileName", `fileName: ${fileName}`); return fileName; } diff --git a/src/Composite.Subtitles.response.js b/src/Composite.Subtitles.response.js index 44a02fcb..103d9e40 100644 --- a/src/Composite.Subtitles.response.js +++ b/src/Composite.Subtitles.response.js @@ -1,4 +1,4 @@ -import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util"; +import { $app, Console, done, fetch, Lodash as _, notification, Storage, wait } from "@nsnanocat/util"; import { URL } from "@nsnanocat/url"; import XML from "./XML/XML.mjs"; import VTT from "./WebVTT/WebVTT.mjs"; @@ -9,190 +9,183 @@ import detectPlatform from "./function/detectPlatform.mjs"; import setCache from "./function/setCache.mjs"; import constructSubtitlesQueue from "./function/constructSubtitlesQueue.mjs"; import Composite from "./class/Composite.mjs"; +Console.debug = () => {}; /***************** Processing *****************/ // 解构URL const url = new URL($request.url); -log(`⚠ url: ${url.toJSON()}`, ""); +Console.info(`url: ${url.toJSON()}`); // 获取连接参数 const METHOD = $request.method, HOST = url.hostname, PATH = url.pathname, PATHs = url.pathname.split("/").filter(Boolean); -log(`⚠ METHOD: ${METHOD}, HOST: ${HOST}, PATH: ${PATH}`, ""); +Console.info(`METHOD: ${METHOD}, HOST: ${HOST}, PATH: ${PATH}`); // 解析格式 let FORMAT = ($response.headers?.["Content-Type"] ?? $response.headers?.["content-type"])?.split(";")?.[0]; if (FORMAT === "application/octet-stream" || FORMAT === "text/plain") FORMAT = detectFormat(url, $response?.body, FORMAT); -log(`⚠ FORMAT: ${FORMAT}`, ""); +Console.info(`FORMAT: ${FORMAT}`); (async () => { // 获取平台 const PLATFORM = detectPlatform($request.url); - log(`⚠ PLATFORM: ${PLATFORM}`, ""); + Console.info(`PLATFORM: ${PLATFORM}`); /** * 设置 * @type {{Settings: import('./types').Settings}} */ const { Settings, Caches, Configs } = setENV("DualSubs", [["YouTube", "Netflix", "BiliBili", "Spotify"].includes(PLATFORM) ? PLATFORM : "Universal", "Composite", "API"], database); - log(`⚠ Settings.Switch: ${Settings?.Switch}`, ""); - switch (Settings.Switch) { - case true: - default: { - // 获取字幕类型与语言 - const Type = url.searchParams?.get("subtype") ?? Settings.Type, - Languages = [url.searchParams?.get("lang")?.toUpperCase?.() ?? Settings.Languages[0], (url.searchParams?.get("tlang") ?? Caches?.tlang)?.toUpperCase?.() ?? Settings.Languages[1]]; - log(`⚠ Type: ${Type}, Languages: ${Languages}`, ""); - // 创建空数据 - let body = {}; - // 创建字幕请求队列 - let requests = []; - // 处理类型 - switch (Type) { - case "Official": - log("⚠ 官方字幕", ""); - switch (PLATFORM) { - default: { - // 获取字幕文件地址vtt缓存(map) - const { subtitlesPlaylistURL } = getSubtitlesCache($request.url, Caches.Playlists.Subtitle, Languages); - // 获取字幕播放列表m3u8缓存(map) - const { masterPlaylistURL, subtitlesPlaylistIndex } = getPlaylistCache(subtitlesPlaylistURL, Caches.Playlists.Master, Languages); - // 获取字幕文件地址vtt缓存(map) - const { subtitlesURIArray0, subtitlesURIArray1 } = getSubtitlesArray(masterPlaylistURL, subtitlesPlaylistIndex, Caches.Playlists.Master, Caches.Playlists.Subtitle, Languages); - // 获取官方字幕请求 - if (subtitlesURIArray1.length) { - log(`🚧 subtitlesURIArray1.length: ${subtitlesURIArray1.length}`, ""); - // 获取字幕文件名 - const fileName = PATHs?.[PATHs?.length - 1] ?? getSubtitlesFileName($request.url, PLATFORM); - log(`🚧 fileName: ${fileName}`, ""); - // 构造请求队列 - requests = constructSubtitlesQueue($request, fileName, subtitlesURIArray0, subtitlesURIArray1); - } + // 获取字幕类型与语言 + const Type = url.searchParams?.get("subtype") ?? Settings.Type, + Languages = [url.searchParams?.get("lang")?.toUpperCase?.() ?? Settings.Languages[0], (url.searchParams?.get("tlang") ?? Caches?.tlang)?.toUpperCase?.() ?? Settings.Languages[1]]; + Console.info(`Type: ${Type}, Languages: ${Languages}`); + // 创建空数据 + let body = {}; + // 创建字幕请求队列 + let requests = []; + // 处理类型 + switch (Type) { + case "Official": + Console.info("官方字幕"); + switch (PLATFORM) { + default: { + // 获取字幕文件地址vtt缓存(map) + const { subtitlesPlaylistURL } = getSubtitlesCache($request.url, Caches.Playlists.Subtitle, Languages); + // 获取字幕播放列表m3u8缓存(map) + const { masterPlaylistURL, subtitlesPlaylistIndex } = getPlaylistCache(subtitlesPlaylistURL, Caches.Playlists.Master, Languages); + // 获取字幕文件地址vtt缓存(map) + const { subtitlesURIArray0, subtitlesURIArray1 } = getSubtitlesArray(masterPlaylistURL, subtitlesPlaylistIndex, Caches.Playlists.Master, Caches.Playlists.Subtitle, Languages); + // 获取官方字幕请求 + if (subtitlesURIArray1.length) { + Console.debug(`subtitlesURIArray1.length: ${subtitlesURIArray1.length}`); + // 获取字幕文件名 + const fileName = PATHs?.[PATHs?.length - 1] ?? getSubtitlesFileName($request.url, PLATFORM); + Console.debug(`fileName: ${fileName}`); + // 构造请求队列 + requests = constructSubtitlesQueue($request, fileName, subtitlesURIArray0, subtitlesURIArray1); + } + break; + } + case "YouTube": + Console.info("YouTube"); + switch (url.searchParams.get("tlang")) { + case undefined: + Console.info("未选择翻译语言,跳过"); break; - } - case "YouTube": - log("⚠ YouTube", ""); - switch (url.searchParams.get("tlang")) { - case undefined: - log("⚠ 未选择翻译语言,跳过", ""); + default: + Console.info("已选择翻译语言"); + // 设置参数 + // Settings.Offset = 0; + Settings.Tolerance = 100; + Settings.Position = Settings.Position === "Reverse" ? "Forward" : "Reverse"; // 链接主字幕为翻译字幕,副字幕为原字幕,所以需要翻转一下 + switch (Settings.ShowOnly) { + case true: + Console.info("仅显示翻译后字幕,跳过"); break; - default: - log("⚠ 已选择翻译语言", ""); - // 设置参数 - // Settings.Offset = 0; - Settings.Tolerance = 100; - Settings.Position = Settings.Position === "Reverse" ? "Forward" : "Reverse"; // 链接主字幕为翻译字幕,副字幕为原字幕,所以需要翻转一下 - switch (Settings.ShowOnly) { - case true: - log("⚠ 仅显示翻译后字幕,跳过", ""); - break; - case false: - default: { - log("⚠ 生成双语字幕", ""); - // 获取字幕 - url.searchParams.set("lang", Caches.Playlists.Subtitle.get(url.searchParams.get("v")) || url.searchParams.get("lang")); // 主语言 - url.searchParams.delete("tlang"); // 原字幕 - const request = { - url: url.toString(), - headers: $request.headers, - }; - requests.push(request); - break; - } - } + case false: + default: { + Console.info("生成双语字幕"); + // 获取字幕 + url.searchParams.set("lang", Caches.Playlists.Subtitle.get(url.searchParams.get("v")) || url.searchParams.get("lang")); // 主语言 + url.searchParams.delete("tlang"); // 原字幕 + const request = { + url: url.toString(), + headers: $request.headers, + }; + requests.push(request); + break; + } } - break; - case "Netflix": - log("⚠ Netflix", ""); - break; - case "Bilibili": - log("⚠ Bilibili", ""); - break; } break; - case "Translate": - default: - log("⚠ 翻译字幕", ""); + case "Netflix": + Console.info("Netflix"); break; - case "External": - log("⚠ 外挂字幕", ""); - switch (Settings.SubVendor) { - case "URL": { - const request = { - url: Settings.URL, - headers: { - Accept: "*/*", - "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Mobile/15E148 Safari/604.1", - }, - }; - requests.push(request); - break; - } - } + case "Bilibili": + Console.info("Bilibili"); break; } - // 格式判断 - switch (FORMAT) { - case undefined: // 视为无body - break; - case "application/x-www-form-urlencoded": - case "text/plain": - default: - break; - case "application/x-mpegURL": - case "application/x-mpegurl": - case "application/vnd.apple.mpegurl": - case "audio/mpegurl": - break; - case "text/xml": - case "text/html": - case "text/plist": - case "application/xml": - case "application/plist": - case "application/x-plist": - body = XML.parse($response.body); - await Promise.all( - requests.map(async request => { - const officialSubtitle = await fetch(request).then(response => XML.parse(response.body)); - body = new Composite(Settings).timedText(body, officialSubtitle, url.searchParams.get("kind")); - }), - ); - $response.body = XML.stringify(body); - break; - case "text/vtt": - case "application/vtt": - body = VTT.parse($response.body); - await Promise.all( - requests.map(async request => { - const officialSubtitle = await fetch(request).then(response => VTT.parse(response.body)); - body = new Composite(Settings).webVTT(body, officialSubtitle); - }), - ); - $response.body = VTT.stringify(body); - break; - case "text/json": - case "application/json": - body = JSON.parse($response.body ?? "{}"); - await Promise.all( - requests.map(async request => { - const officialSubtitle = await fetch(request).then(response => JSON.parse(response.body)); - body = new Composite(Settings).JSON(body, officialSubtitle, url.searchParams.get("kind")); - }), - ); - $response.body = JSON.stringify(body); - break; - case "application/protobuf": - case "application/x-protobuf": - case "application/vnd.google.protobuf": - case "application/grpc": - case "application/grpc+proto": - case "application/octet-stream": + break; + case "Translate": + default: + Console.info("翻译字幕"); + break; + case "External": + Console.info("外挂字幕"); + switch (Settings.SubVendor) { + case "URL": { + const request = { + url: Settings.URL, + headers: { + Accept: "*/*", + "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Mobile/15E148 Safari/604.1", + }, + }; + requests.push(request); break; + } } break; - } - case false: + } + // 格式判断 + switch (FORMAT) { + case undefined: // 视为无body break; + case "application/x-www-form-urlencoded": + case "text/plain": + default: + break; + case "application/x-mpegURL": + case "application/x-mpegurl": + case "application/vnd.apple.mpegurl": + case "audio/mpegurl": + break; + case "text/xml": + case "text/html": + case "text/plist": + case "application/xml": + case "application/plist": + case "application/x-plist": + body = XML.parse($response.body); + await Promise.all( + requests.map(async request => { + const officialSubtitle = await fetch(request).then(response => XML.parse(response.body)); + body = new Composite(Settings).timedText(body, officialSubtitle, url.searchParams.get("kind")); + }), + ); + $response.body = XML.stringify(body); + break; + case "text/vtt": + case "application/vtt": + body = VTT.parse($response.body); + await Promise.all( + requests.map(async request => { + const officialSubtitle = await fetch(request).then(response => VTT.parse(response.body)); + body = new Composite(Settings).webVTT(body, officialSubtitle); + }), + ); + $response.body = VTT.stringify(body); + break; + case "text/json": + case "application/json": + body = JSON.parse($response.body ?? "{}"); + await Promise.all( + requests.map(async request => { + const officialSubtitle = await fetch(request).then(response => JSON.parse(response.body)); + body = new Composite(Settings).JSON(body, officialSubtitle, url.searchParams.get("kind")); + }), + ); + $response.body = JSON.stringify(body); + break; + case "application/protobuf": + case "application/x-protobuf": + case "application/vnd.google.protobuf": + case "application/grpc": + case "application/grpc+proto": + case "application/octet-stream": { + break; + } } })() - .catch(e => logError(e)) + .catch(e => Console.error(e)) .finally(() => done($response)); /***************** Function *****************/ @@ -205,7 +198,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); * @return {Promise} { masterPlaylistURL, subtitlesPlaylist, subtitlesPlaylistIndex } */ function getPlaylistCache(url, cache, languages) { - log("☑️ getPlaylistCache", ""); + Console.info("☑️ getPlaylistCache"); let masterPlaylistURL = ""; let subtitlesPlaylist = {}; let subtitlesPlaylistIndex = 0; @@ -217,19 +210,19 @@ function getPlaylistCache(url, cache, languages) { array?.some((object, index) => { if (url.includes(object?.URI || object?.OPTION?.URI || null)) { subtitlesPlaylistIndex = index; - log("🚧 getPlaylistCache", `subtitlesPlaylistIndex: ${subtitlesPlaylistIndex}`, ""); + Console.debug("getPlaylistCache", `subtitlesPlaylistIndex: ${subtitlesPlaylistIndex}`); return true; } else return false; }) ) { masterPlaylistURL = Key; subtitlesPlaylist = Value; - //log(`🚧 getPlaylistCache`, `masterPlaylistURL: ${masterPlaylistURL}`, `subtitlesPlaylist: ${JSON.stringify(subtitlesPlaylist)}`, ""); + //Console.debug(`getPlaylistCache`, `masterPlaylistURL: ${masterPlaylistURL}`, `subtitlesPlaylist: ${JSON.stringify(subtitlesPlaylist)}`); } } }); }); - log("✅ getPlaylistCache", `masterPlaylistURL: ${JSON.stringify(masterPlaylistURL)}`, ""); + Console.info("✅ getPlaylistCache", `masterPlaylistURL: ${JSON.stringify(masterPlaylistURL)}`); return { masterPlaylistURL, subtitlesPlaylist, subtitlesPlaylistIndex }; } @@ -242,7 +235,7 @@ function getPlaylistCache(url, cache, languages) { * @return {Promise} { subtitlesPlaylistURL, subtitles, subtitlesIndex } */ function getSubtitlesCache(url, cache, languages) { - log("☑️ getSubtitlesCache", ""); + Console.info("☑️ getSubtitlesCache"); let subtitlesPlaylistURL = ""; let subtitles = []; let subtitlesIndex = 0; @@ -253,18 +246,18 @@ function getSubtitlesCache(url, cache, languages) { array?.some((string, index) => { if (url.includes(string || null)) { subtitlesIndex = index; - log("🚧 getSubtitlesCache", `subtitlesIndex: ${subtitlesIndex}`, ""); + Console.debug("getSubtitlesCache", `subtitlesIndex: ${subtitlesIndex}`); return true; } else return false; }) ) { subtitlesPlaylistURL = Key; subtitles = Value; - //log(`🚧 getSubtitlesCache, subtitlesPlaylistURL: ${subtitlesPlaylistURL}`, ""); + //Console.debug(`getSubtitlesCache, subtitlesPlaylistURL: ${subtitlesPlaylistURL}`); } } }); - log(`✅ getSubtitlesCache, subtitlesPlaylistURL: ${subtitlesPlaylistURL}`, ""); + Console.info("✅ getSubtitlesCache", `subtitlesPlaylistURL: ${subtitlesPlaylistURL}`); return { subtitlesPlaylistURL, subtitles, subtitlesIndex }; } @@ -279,16 +272,16 @@ function getSubtitlesCache(url, cache, languages) { * @return {Promise} { subtitlesURIArray0, subtitlesURIArray1 } */ function getSubtitlesArray(url, index, playlistsCache, subtitlesCache, languages) { - log("☑️ getSubtitlesArray", ""); + Console.info("☑️ getSubtitlesArray"); const subtitlesPlaylistValue = playlistsCache?.get(url) || {}; const subtitlesPlaylistURL0 = subtitlesPlaylistValue?.[languages[0]]?.[index]?.URL || subtitlesPlaylistValue?.[languages[0]]?.[0]?.URL; const subtitlesPlaylistURL1 = subtitlesPlaylistValue?.[languages[1]]?.[index]?.URL || subtitlesPlaylistValue?.[languages[1]]?.[0]?.URL; - log("🚧 getSubtitlesArray", `subtitlesPlaylistURL0: ${subtitlesPlaylistURL0}, subtitlesPlaylistURL1: ${subtitlesPlaylistURL1}`, ""); + Console.debug("getSubtitlesArray", `subtitlesPlaylistURL0: ${subtitlesPlaylistURL0}, subtitlesPlaylistURL1: ${subtitlesPlaylistURL1}`); // 查找字幕文件地址vtt缓存(map) const subtitlesURIArray0 = subtitlesCache.get(subtitlesPlaylistURL0) || []; const subtitlesURIArray1 = subtitlesCache.get(subtitlesPlaylistURL1) || []; - //log(`🚧 getSubtitlesArray`, `subtitlesURIArray0: ${JSON.stringify(subtitlesURIArray0)}, subtitlesURIArray1: ${JSON.stringify(subtitlesURIArray1)}`, ""); - log("✅ getSubtitlesArray", ""); + //Console.debug(`getSubtitlesArray`, `subtitlesURIArray0: ${JSON.stringify(subtitlesURIArray0)}, subtitlesURIArray1: ${JSON.stringify(subtitlesURIArray1)}`); + Console.info("✅ getSubtitlesArray"); return { subtitlesURIArray0, subtitlesURIArray1 }; } @@ -300,7 +293,7 @@ function getSubtitlesArray(url, index, playlistsCache, subtitlesCache, languages * @return {String<*>} fileName */ function getSubtitlesFileName(url, platform) { - log("☑️ Get Subtitles FileName", `url: ${url}`, ""); + Console.info("☑️ Get Subtitles FileName", `url: ${url}`); let fileName = undefined; switch (platform) { case "Apple": @@ -318,6 +311,6 @@ function getSubtitlesFileName(url, platform) { fileName = null; // Amazon Prime Video HBO_Max不拆分字幕片段 break; } - log("✅ Get Subtitles FileName", `fileName: ${fileName}`, ""); + Console.info("✅ Get Subtitles FileName", `fileName: ${fileName}`); return fileName; } diff --git a/src/External.Lyrics.response.dev.js b/src/External.Lyrics.response.dev.js index 845dd505..3b920dd0 100644 --- a/src/External.Lyrics.response.dev.js +++ b/src/External.Lyrics.response.dev.js @@ -1,4 +1,4 @@ -import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util"; +import { $app, Console, done, fetch, Lodash as _, notification, Storage, wait } from "@nsnanocat/util"; import LRC from "./LRC/LRC.mjs"; import database from "./database/index.mjs"; import setENV from "./function/setENV.mjs"; @@ -9,17 +9,17 @@ import { ColorLyricsResponse } from "./protobuf/spotify/lyrics/Lyrics.js"; /***************** Processing *****************/ // 解构URL const url = new URL($request.url); -log(`⚠ url: ${url.toJSON()}`, ""); +Console.info(`url: ${url.toJSON()}`); // 获取连接参数 const PATHs = url.pathname.split("/").filter(Boolean); -log(`⚠ PATHs: ${PATHs}`, ""); +Console.info(`PATHs: ${PATHs}`); // 解析格式 const FORMAT = ($response.headers?.["Content-Type"] ?? $response.headers?.["content-type"] ?? $request.headers?.Accept ?? $request.headers?.accept)?.split(";")?.[0]; -log(`⚠ FORMAT: ${FORMAT}`, ""); +Console.info(`FORMAT: ${FORMAT}`); (async () => { // 获取平台 const PLATFORM = detectPlatform($request.url); - log(`⚠ PLATFORM: ${PLATFORM}`, ""); + Console.info(`PLATFORM: ${PLATFORM}`); /** * 设置 * @type {{Settings: import('./types').Settings}} @@ -28,12 +28,12 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); // 获取字幕类型与语言 const Type = url.searchParams?.get("subtype") ?? Settings.Type, Languages = [url.searchParams?.get("lang")?.toUpperCase?.() ?? Settings.Languages[0], (url.searchParams?.get("tlang") ?? Caches?.tlang)?.toUpperCase?.() ?? Settings.Languages[1]]; - log(`⚠ Type: ${Type}, Languages: ${Languages}`, ""); + Console.info(`Type: ${Type}, Languages: ${Languages}`); // 查询缓存 const trackId = PATHs?.[3]; - log(`🚧 trackId: ${trackId}`, ""); + Console.debug(`trackId: ${trackId}`); const trackInfo = Caches.Metadatas.Tracks.get(trackId); - log(`🚧 trackInfo: ${JSON.stringify(trackInfo)}`, ""); + Console.debug(`trackInfo: ${JSON.stringify(trackInfo)}`); // 创建空数据 let body = {}; // 格式判断 @@ -49,7 +49,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); case "application/vnd.apple.mpegurl": case "audio/mpegurl": //body = M3U8.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); //$response.body = M3U8.stringify(body); break; case "text/xml": @@ -59,19 +59,19 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); case "application/plist": case "application/x-plist": //body = XML.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); //$response.body = XML.stringify(body); break; case "text/vtt": case "application/vtt": //body = VTT.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); //$response.body = VTT.stringify(body); break; case "text/json": case "application/json": body = JSON.parse($response.body ?? "{}"); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); switch (PLATFORM) { case "YouTube": break; @@ -81,7 +81,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); $response.status = $app === "Quantumult X" ? "HTTP/1.1 200 OK" : 200; break; } - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); $response.body = JSON.stringify(body); break; case "application/protobuf": @@ -90,9 +90,9 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); case "application/grpc": case "application/grpc+proto": case "application/octet-stream": { - //log(`🚧 $response.body: ${JSON.stringify($response.body)}`, ""); + //Console.debug(`$response.body: ${JSON.stringify($response.body)}`); let rawBody = $app === "Quantumult X" ? new Uint8Array($response.bodyBytes ?? []) : ($response.body ?? new Uint8Array()); - //log(`🚧 isBuffer? ${ArrayBuffer.isView(rawBody)}: ${JSON.stringify(rawBody)}`, ""); + //Console.debug(`isBuffer? ${ArrayBuffer.isView(rawBody)}: ${JSON.stringify(rawBody)}`); switch (FORMAT) { case "application/protobuf": case "application/x-protobuf": @@ -103,10 +103,10 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); } case "Spotify": { body = ColorLyricsResponse.fromBinary(rawBody); - log(`🚧 body: ${JSON.stringify(body)}`, ""); + Console.debug(`body: ${JSON.stringify(body)}`); /* let UF = UnknownFieldHandler.list(body); - log(`🚧 UF: ${JSON.stringify(UF)}`, ""); + Console.debug(`UF: ${JSON.stringify(UF)}`); if (UF) { UF = UF.map(uf => { //uf.no; // 22 @@ -114,7 +114,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); // use the binary reader to decode the raw data: let reader = new BinaryReader(uf.data); let addedNumber = reader.int32(); // 7777 - log(`🚧 no: ${uf.no}, wireType: ${uf.wireType}, reader: ${reader}, addedNumber: ${addedNumber}`, ""); + Console.debug(`no: ${uf.no}, wireType: ${uf.wireType}, reader: ${reader}, addedNumber: ${addedNumber}`); }); }; */ @@ -134,7 +134,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); body.lyrics.fullscreenAction = 0; if (!$response?.headers?.["Content-Type"] && $response?.headers?.["content-type"]) $response.headers["Content-Type"] = FORMAT; $response.status = $app === "Quantumult X" ? "HTTP/1.1 200 OK" : 200; - log(`🚧 body: ${JSON.stringify(body)}`, ""); + Console.debug(`body: ${JSON.stringify(body)}`); rawBody = ColorLyricsResponse.toBinary(body); break; } @@ -145,7 +145,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); break; } // 写入二进制数据 - //log(`🚧 rawBody: ${JSON.stringify(rawBody)}`, ""); + //Console.debug(`rawBody: ${JSON.stringify(rawBody)}`); $response.body = rawBody; break; } @@ -154,18 +154,18 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); if (trackInfo?.NeteaseMusic?.id ?? trackInfo?.QQMusic?.mid) { Caches.Metadatas.Tracks.set(trackInfo.id, trackInfo); // 格式化缓存 - log(`🚧 Caches.Metadatas.Tracks: ${JSON.stringify([...Caches.Metadatas.Tracks.entries()])}`, ""); + Console.debug(`Caches.Metadatas.Tracks: ${JSON.stringify([...Caches.Metadatas.Tracks.entries()])}`); Caches.Metadatas.Tracks = setCache(Caches.Metadatas.Tracks, Settings.CacheSize); // 写入持久化储存 Storage.setItem(`@DualSubs.${PLATFORM}.Caches.Metadatas.Tracks`, Caches.Metadatas.Tracks); } })() - .catch(e => logError(e)) + .catch(e => Console.error(e)) .finally(() => done($response)); /***************** Function *****************/ async function injectionLyric(vendor = "NeteaseMusic", trackInfo = {}, body = $response.body, platform) { - log("☑️ Injection Lyric", `vendor: ${vendor}, trackInfo: ${JSON.stringify(trackInfo)}`, ""); + Console.info("☑️ Injection Lyric", `vendor: ${vendor}, trackInfo: ${JSON.stringify(trackInfo)}`); const UAPool = [ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36", // 13.5% "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36", // 6.6% @@ -242,7 +242,7 @@ async function injectionLyric(vendor = "NeteaseMusic", trackInfo = {}, body = $r body.lyrics.providerDisplayName = `网易云音乐 - ${externalLyric?.lyricUser ?? "未知"}`; body.colors.background = -8249806; // 网易红 8527410 #821E32 rgb(130,30,50) //body.colors.background = -55775; // 网易红 16721441 #FF2621 rgb(255,38,33) - log(`🚧 body.lyrics.lines: ${JSON.stringify(body.lyrics.lines)}`, ""); + Console.debug(`body.lyrics.lines: ${JSON.stringify(body.lyrics.lines)}`); break; case "QQMusic": default: @@ -250,7 +250,7 @@ async function injectionLyric(vendor = "NeteaseMusic", trackInfo = {}, body = $r body.lyrics.providerLyricsId = trackInfo?.QQMusic?.mid?.toString?.(); body.lyrics.providerDisplayName = `QQ音乐 - ${externalLyric?.lyricUser ?? "未知"}`; body.colors.background = -11038189; // QQ音乐绿 5739027 #579213 rgb(87,146,19) - log(`🚧 body.lyrics.lines: ${JSON.stringify(body.lyrics.lines)}`, ""); + Console.debug(`body.lyrics.lines: ${JSON.stringify(body.lyrics.lines)}`); break; } // 填充逐字或逐句歌词 @@ -298,13 +298,13 @@ async function injectionLyric(vendor = "NeteaseMusic", trackInfo = {}, body = $r case "YouTube": break; } - log("✅ Injection Lyric", ""); - log("🚧 Injection Lyric", `body: ${JSON.stringify(body)}`, ""); + Console.debug("Injection Lyric", `body: ${JSON.stringify(body)}`); + Console.info("✅ Injection Lyric"); return body; } async function searchTrack(vendor = "NeteaseMusic", keyword = "", UAPool = []) { - log("☑️ Search Track", `vendor: ${vendor}, keyword: ${keyword}`, ""); + Console.info("☑️ Search Track", `vendor: ${vendor}, keyword: ${keyword}`); const Request = { headers: { Accept: "application/json", @@ -319,7 +319,7 @@ async function searchTrack(vendor = "NeteaseMusic", keyword = "", UAPool = []) { searchUrl.searchParams.set("limit", 1); searchUrl.searchParams.set("offset", 0); searchUrl.searchParams.set("s", keyword); - log(`🚧 searchUrl: ${searchUrl.toJSON()}`, ""); + Console.debug(`searchUrl: ${searchUrl.toJSON()}`); Request.url = searchUrl.toString(); Request.headers.Referer = "https://music.163.com"; Request.headers.Cookie = "os=ios; __remember_me=true; NMTID=xxx"; @@ -344,7 +344,7 @@ async function searchTrack(vendor = "NeteaseMusic", keyword = "", UAPool = []) { searchUrl.searchParams.set("limit", 1); searchUrl.searchParams.set("offset", 0); searchUrl.searchParams.set("keywords", keyword); - log(`🚧 searchUrl: ${searchUrl.toJSON()}`, ""); + Console.debug(`searchUrl: ${searchUrl.toJSON()}`); Request.url = searchUrl.toString(); Request.headers.Referer = "https://music.163.com"; const Result = await fetch(Request).then(response => JSON.parse(response.body)); @@ -357,7 +357,7 @@ async function searchTrack(vendor = "NeteaseMusic", keyword = "", UAPool = []) { case "QQMusic": default: { const searchUrl = new URL("https://c.y.qq.com/cgi-bin/musicu.fcg"); - log(`🚧 searchUrl: ${searchUrl.toJSON()}`, ""); + Console.debug(`searchUrl: ${searchUrl.toJSON()}`); Request.url = searchUrl.toString(); Request.headers.Referer = "https://c.y.qq.com"; Request.body = JSON.stringify({ @@ -386,7 +386,7 @@ async function searchTrack(vendor = "NeteaseMusic", keyword = "", UAPool = []) { searchUrl.searchParams.set("n", 1); searchUrl.searchParams.set("w", keyword); searchUrl.searchParams.set("remoteplace", "txt.yqq.song"); - log(`🚧 searchUrl: ${searchUrl.toJSON()}`, ""); + Console.debug(`searchUrl: ${searchUrl.toJSON()}`); Request.url = searchUrl.toString(); /* const searchUrl = { @@ -412,7 +412,7 @@ async function searchTrack(vendor = "NeteaseMusic", keyword = "", UAPool = []) { //"platform": 'yqq.json', } }; - log(`🚧 searchUrl: ${JSON.stringify(searchUrl)}`, ""); + Console.debug(`searchUrl: ${JSON.stringify(searchUrl)}`); Request.url = URI.stringify(searchUrl); */ Request.headers.Referer = "https://c.y.qq.com"; @@ -424,12 +424,12 @@ async function searchTrack(vendor = "NeteaseMusic", keyword = "", UAPool = []) { break; } } - log("✅ Search Track", `trackInfo: ${JSON.stringify(trackInfo)}`, ""); + Console.info("✅ Search Track", `trackInfo: ${JSON.stringify(trackInfo)}`); return trackInfo; } async function searchLyric(vendor = "NeteaseMusic", trackId = undefined, UAPool = []) { - log("☑️ Search Lyric", `vendor: ${vendor}, trackId: ${trackId}`, ""); + Console.info("☑️ Search Lyric", `vendor: ${vendor}, trackId: ${trackId}`); const Request = { headers: { Accept: "application/json", @@ -444,12 +444,12 @@ async function searchLyric(vendor = "NeteaseMusic", trackId = undefined, UAPool lyricUrl.searchParams.set("lv", -1); lyricUrl.searchParams.set("yv", -1); lyricUrl.searchParams.set("tv", -1); - log(`🚧 lyricUrl: ${lyricUrl.toJSON()}`, ""); + Console.debug(`lyricUrl: ${lyricUrl.toJSON()}`); Request.url = lyricUrl.toString(); Request.headers.Referer = "https://music.163.com"; Request.headers.Cookie = "os=ios; __remember_me=true; NMTID=xxx"; const Result = await fetch(Request).then(response => JSON.parse(response.body)); - log(`🚧 Result: ${JSON.stringify(Result)}`, ""); + Console.debug(`Result: ${JSON.stringify(Result)}`); Lyrics.lyric = Result?.lrc?.lyric; Lyrics.tlyric = Result?.ytlrc?.lyric ?? Result?.tlyric?.lyric; Lyrics.klyric = Result?.yrc?.lyric ?? Result?.klyric?.lyric; @@ -467,11 +467,11 @@ async function searchLyric(vendor = "NeteaseMusic", trackId = undefined, UAPool ]; const lyricUrl = new URL(`https://${HostPool[Math.floor(Math.random() * HostPool.length)]}/lyric/new`); lyricUrl.searchParams.set("id", trackId); // trackInfo.NeteaseMusic.id - log(`🚧 lyricUrl: ${lyricUrl.toJSON()}`, ""); + Console.debug(`lyricUrl: ${lyricUrl.toJSON()}`); Request.url = lyricUrl.toString(); Request.headers.Referer = "https://music.163.com"; const Result = await fetch(Request).then(response => JSON.parse(response.body)); - log(`🚧 Result: ${JSON.stringify(Result)}`, ""); + Console.debug(`Result: ${JSON.stringify(Result)}`); Lyrics.lyric = Result?.lrc?.lyric; Lyrics.tlyric = Result?.ytlrc?.lyric ?? Result?.tlyric?.lyric; Lyrics.klyric = Result?.yrc?.lyric ?? Result?.klyric?.lyric; @@ -486,7 +486,7 @@ async function searchLyric(vendor = "NeteaseMusic", trackId = undefined, UAPool lyricUrl.searchParams.set("format", "json"); lyricUrl.searchParams.set("nobase64", 1); lyricUrl.searchParams.set("songmid", trackId); // trackInfo.QQMusic.mid - log(`🚧 lyricUrl: ${lyricUrl.toJSON()}`, ""); + Console.debug(`lyricUrl: ${lyricUrl.toJSON()}`); Request.url = lyricUrl.toString(); Request.headers.Referer = "https://lyric.music.qq.com"; const Result = await fetch(Request).then(response => JSON.parse(response.body)); @@ -498,8 +498,8 @@ async function searchLyric(vendor = "NeteaseMusic", trackId = undefined, UAPool break; } } - log("🚧 Search Lyric", `Lyrics: ${JSON.stringify(Lyrics)}`, ""); - log("✅ Search Lyric", ""); + Console.debug("Search Lyric", `Lyrics: ${JSON.stringify(Lyrics)}`); + Console.info("✅ Search Lyric"); return Lyrics; } @@ -542,11 +542,11 @@ function combineText(originText, transText, ShowOnly = false, position = "Forwar * @return {Array<*>} target */ function chunk(source, length) { - log("⚠ Chunk Array", ""); + Console.info("☑️ Chunk Array"); let index = 0, target = []; while (index < source.length) target.push(source.slice(index, (index += length))); - //log(`🎉 Chunk Array`, `target: ${JSON.stringify(target)}`, ""); + //Console.info("✅ Chunk Array", `target: ${JSON.stringify(target)}`); return target; } @@ -562,7 +562,7 @@ function chunk(source, length) { * @return {Promise<*>} */ async function retry(fn, retriesLeft = 5, interval = 1000, exponential = false) { - log(`☑️ retry, 剩余重试次数:${retriesLeft}`, `时间间隔:${interval}ms`); + Console.info("☑️ retry", `剩余重试次数:${retriesLeft}`, `时间间隔:${interval}ms`); try { const val = await fn(); return val; diff --git a/src/External.Lyrics.response.js b/src/External.Lyrics.response.js index ad255520..f050017b 100644 --- a/src/External.Lyrics.response.js +++ b/src/External.Lyrics.response.js @@ -1,4 +1,4 @@ -import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util"; +import { $app, Console, done, fetch, Lodash as _, notification, Storage, wait } from "@nsnanocat/util"; import LRC from "./LRC/LRC.mjs"; import database from "./database/index.mjs"; import setENV from "./function/setENV.mjs"; @@ -6,20 +6,21 @@ import detectPlatform from "./function/detectPlatform.mjs"; import setCache from "./function/setCache.mjs"; import { BrowseResponse } from "./protobuf/google/protos/youtube/api/innertube/BrowseResponse.js"; import { ColorLyricsResponse } from "./protobuf/spotify/lyrics/Lyrics.js"; +Console.debug = () => {}; /***************** Processing *****************/ // 解构URL const url = new URL($request.url); -log(`⚠ url: ${url.toJSON()}`, ""); +Console.info(`url: ${url.toJSON()}`); // 获取连接参数 const PATHs = url.pathname.split("/").filter(Boolean); -log(`⚠ PATHs: ${PATHs}`, ""); +Console.info(`PATHs: ${PATHs}`); // 解析格式 const FORMAT = ($response.headers?.["Content-Type"] ?? $response.headers?.["content-type"] ?? $request.headers?.Accept ?? $request.headers?.accept)?.split(";")?.[0]; -log(`⚠ FORMAT: ${FORMAT}`, ""); +Console.info(`FORMAT: ${FORMAT}`); (async () => { // 获取平台 const PLATFORM = detectPlatform($request.url); - log(`⚠ PLATFORM: ${PLATFORM}`, ""); + Console.info(`PLATFORM: ${PLATFORM}`); /** * 设置 * @type {{Settings: import('./types').Settings}} @@ -28,12 +29,12 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); // 获取字幕类型与语言 const Type = url.searchParams?.get("subtype") ?? Settings.Type, Languages = [url.searchParams?.get("lang")?.toUpperCase?.() ?? Settings.Languages[0], (url.searchParams?.get("tlang") ?? Caches?.tlang)?.toUpperCase?.() ?? Settings.Languages[1]]; - log(`⚠ Type: ${Type}, Languages: ${Languages}`, ""); + Console.info(`Type: ${Type}, Languages: ${Languages}`); // 查询缓存 const trackId = PATHs?.[3]; - log(`🚧 trackId: ${trackId}`, ""); + Console.debug(`trackId: ${trackId}`); const trackInfo = Caches.Metadatas.Tracks.get(trackId); - log(`🚧 trackInfo: ${JSON.stringify(trackInfo)}`, ""); + Console.debug(`trackInfo: ${JSON.stringify(trackInfo)}`); // 创建空数据 let body = {}; // 格式判断 @@ -49,7 +50,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); case "application/vnd.apple.mpegurl": case "audio/mpegurl": //body = M3U8.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); //$response.body = M3U8.stringify(body); break; case "text/xml": @@ -59,19 +60,19 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); case "application/plist": case "application/x-plist": //body = XML.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); //$response.body = XML.stringify(body); break; case "text/vtt": case "application/vtt": //body = VTT.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); //$response.body = VTT.stringify(body); break; case "text/json": case "application/json": body = JSON.parse($response.body ?? "{}"); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); switch (PLATFORM) { case "YouTube": break; @@ -81,7 +82,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); $response.status = $app === "Quantumult X" ? "HTTP/1.1 200 OK" : 200; break; } - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); $response.body = JSON.stringify(body); break; case "application/protobuf": @@ -126,7 +127,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); break; } // 写入二进制数据 - //log(`🚧 rawBody: ${JSON.stringify(rawBody)}`, ""); + //Console.debug(`rawBody: ${JSON.stringify(rawBody)}`); $response.body = rawBody; break; } @@ -135,18 +136,18 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); if (trackInfo?.NeteaseMusic?.id ?? trackInfo?.QQMusic?.mid) { Caches.Metadatas.Tracks.set(trackInfo.id, trackInfo); // 格式化缓存 - log(`🚧 Caches.Metadatas.Tracks: ${JSON.stringify([...Caches.Metadatas.Tracks.entries()])}`, ""); + Console.debug(`Caches.Metadatas.Tracks: ${JSON.stringify([...Caches.Metadatas.Tracks.entries()])}`); Caches.Metadatas.Tracks = setCache(Caches.Metadatas.Tracks, Settings.CacheSize); // 写入持久化储存 Storage.setItem(`@DualSubs.${PLATFORM}.Caches.Metadatas.Tracks`, Caches.Metadatas.Tracks); } })() - .catch(e => logError(e)) + .catch(e => Console.error(e)) .finally(() => done($response)); /***************** Function *****************/ async function injectionLyric(vendor = "NeteaseMusic", trackInfo = {}, body = $response.body, platform) { - log("☑️ Injection Lyric", `vendor: ${vendor}, trackInfo: ${JSON.stringify(trackInfo)}`, ""); + Console.info("☑️ Injection Lyric", `vendor: ${vendor}, trackInfo: ${JSON.stringify(trackInfo)}`); const UAPool = [ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36", // 13.5% "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36", // 6.6% @@ -269,12 +270,12 @@ async function injectionLyric(vendor = "NeteaseMusic", trackInfo = {}, body = $r case "YouTube": break; } - log("✅ Injection Lyric", ""); + Console.info("✅ Injection Lyric"); return body; } async function searchTrack(vendor = "NeteaseMusic", keyword = "", UAPool = []) { - log("☑️ Search Track", `vendor: ${vendor}, keyword: ${keyword}`, ""); + Console.info("☑️ Search Track", `vendor: ${vendor}, keyword: ${keyword}`); const Request = { headers: { Accept: "application/json", @@ -347,12 +348,12 @@ async function searchTrack(vendor = "NeteaseMusic", keyword = "", UAPool = []) { break; } } - log("✅ Search Track", `trackInfo: ${JSON.stringify(trackInfo)}`, ""); + Console.info("✅ Search Track", `trackInfo: ${JSON.stringify(trackInfo)}`); return trackInfo; } async function searchLyric(vendor = "NeteaseMusic", trackId = undefined, UAPool = []) { - log("☑️ Search Lyric", `vendor: ${vendor}, trackId: ${trackId}`, ""); + Console.info("☑️ Search Lyric", `vendor: ${vendor}, trackId: ${trackId}`); const Request = { headers: { Accept: "application/json", @@ -416,7 +417,7 @@ async function searchLyric(vendor = "NeteaseMusic", trackId = undefined, UAPool break; } } - log("✅ Search Lyric", ""); + Console.info("✅ Search Lyric"); return Lyrics; } @@ -459,11 +460,11 @@ function combineText(originText, transText, ShowOnly = false, position = "Forwar * @return {Array<*>} target */ function chunk(source, length) { - log("⚠ Chunk Array", ""); + Console.info("☑️ Chunk Array"); let index = 0, target = []; while (index < source.length) target.push(source.slice(index, (index += length))); - //log(`🎉 Chunk Array`, `target: ${JSON.stringify(target)}`, ""); + //Console.info("✅ Chunk Array", `target: ${JSON.stringify(target)}`); return target; } @@ -479,7 +480,7 @@ function chunk(source, length) { * @return {Promise<*>} */ async function retry(fn, retriesLeft = 5, interval = 1000, exponential = false) { - log(`☑️ retry, 剩余重试次数:${retriesLeft}`, `时间间隔:${interval}ms`); + Console.info("☑️ retry", `剩余重试次数:${retriesLeft}`, `时间间隔:${interval}ms`); try { const val = await fn(); return val; diff --git a/src/External.Subtitles.response.dev.js b/src/External.Subtitles.response.dev.js index f717aab0..9fc2532f 100644 --- a/src/External.Subtitles.response.dev.js +++ b/src/External.Subtitles.response.dev.js @@ -1,4 +1,4 @@ -import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util"; +import { $app, Console, done, fetch, Lodash as _, notification, Storage, wait } from "@nsnanocat/util"; import { URL } from "@nsnanocat/url"; import XML from "./XML/XML.mjs"; import VTT from "./WebVTT/WebVTT.mjs"; @@ -10,47 +10,47 @@ import Composite from "./function/Composite.mjs"; /***************** Processing *****************/ // 解构URL const url = new URL($request.url); -log(`⚠ url: ${url.toJSON()}`, ""); +Console.info(`url: ${url.toJSON()}`); // 获取连接参数 const METHOD = $request.method, HOST = url.hostname, PATH = url.pathname, PATHs = url.pathname.split("/").filter(Boolean); -log(`⚠ METHOD: ${METHOD}, HOST: ${HOST}, PATH: ${PATH}`, ""); +Console.info(`METHOD: ${METHOD}, HOST: ${HOST}, PATH: ${PATH}`); // 解析格式 let FORMAT = ($response.headers?.["Content-Type"] ?? $response.headers?.["content-type"])?.split(";")?.[0]; if (FORMAT === "application/octet-stream" || FORMAT === "text/plain") FORMAT = detectFormat(URL, $response?.body, FORMAT); -log(`⚠ FORMAT: ${FORMAT}`, ""); +Console.info(`FORMAT: ${FORMAT}`); (async () => { // 获取平台 const PLATFORM = detectPlatform($request.url); - log(`⚠ PLATFORM: ${PLATFORM}`, ""); + Console.info(`PLATFORM: ${PLATFORM}`); /** * 设置 * @type {{Settings: import('./types').Settings}} */ const { Settings, Caches, Configs } = setENV("DualSubs", [["YouTube", "Netflix", "BiliBili", "Spotify"].includes(PLATFORM) ? PLATFORM : "Universal", "External", "API"], database); - log(`⚠ Settings.Switch: ${Settings?.Switch}`, ""); + Console.info(`Settings.Switch: ${Settings?.Switch}`); switch (Settings.Switch) { case true: default: // 获取字幕类型与语言 const Type = url.searchParams?.get("subtype") ?? Settings.Type, Languages = [url.searchParams?.get("lang")?.toUpperCase?.() ?? Settings.Languages[0], (url.searchParams?.get("tlang") ?? Caches?.tlang)?.toUpperCase?.() ?? Settings.Languages[1]]; - log(`⚠ Type: ${Type}, Languages: ${Languages}`, ""); + Console.info(`Type: ${Type}, Languages: ${Languages}`); // 创建字幕请求队列 let body = {}; // 处理类型 switch (Type) { case "Official": - log("⚠ 官方字幕", ""); + Console.info("官方字幕"); break; case "Translate": default: - log("⚠ 翻译字幕", ""); + Console.info("翻译字幕"); break; case "External": - log("⚠ 外挂字幕", ""); + Console.info("外挂字幕"); switch (Settings.SubVendor) { case "URL": request = { @@ -79,7 +79,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); case "application/vnd.apple.mpegurl": case "audio/mpegurl": //body = M3U8.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); //$response.body = M3U8.stringify(body); break; case "text/xml": @@ -89,31 +89,31 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); case "application/plist": case "application/x-plist": body = XML.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); externalSubtitle = XML.parse(externalSubtitle); - //log(`🚧 externalSubtitle: ${JSON.stringify(externalSubtitle)}`, ""); + //Console.debug(`externalSubtitle: ${JSON.stringify(externalSubtitle)}`); body = Composite(body, externalSubtitle, FORMAT, URL.query?.kind, Settings.Offset, Settings.Tolerance, Settings.Position); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); $response.body = XML.stringify(body); break; case "text/vtt": case "application/vtt": body = VTT.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); externalSubtitle = VTT.parse(externalSubtitle); - //log(`🚧 externalSubtitle: ${JSON.stringify(externalSubtitle)}`, ""); + //Console.debug(`externalSubtitle: ${JSON.stringify(externalSubtitle)}`); body = Composite(body, externalSubtitle, FORMAT, URL.query?.kind, Settings.Offset, Settings.Tolerance, Settings.Position); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); $response.body = VTT.stringify(body); break; case "text/json": case "application/json": body = JSON.parse($response.body ?? "{}"); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); externalSubtitle = JSON.parse(externalSubtitle); - //log(`🚧 externalSubtitle: ${JSON.stringify(externalSubtitle)}`, ""); + //Console.debug(`externalSubtitle: ${JSON.stringify(externalSubtitle)}`); body = Composite(body, externalSubtitle, FORMAT, URL.query?.kind, Settings.Offset, Settings.Tolerance, Settings.Position); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); $response.body = JSON.stringify(body); break; case "application/protobuf": @@ -122,11 +122,11 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); case "application/grpc": case "application/grpc+proto": case "application/octet-stream": - //log(`🚧 $response.body: ${JSON.stringify($response.body)}`, ""); + //Console.debug(`$response.body: ${JSON.stringify($response.body)}`); //let rawBody = ($app === "Quantumult X") ? new Uint8Array($response.bodyBytes ?? []) : $response.body ?? new Uint8Array(); - //log(`🚧 isBuffer? ${ArrayBuffer.isView(rawBody)}: ${JSON.stringify(rawBody)}`, ""); + //Console.debug(`isBuffer? ${ArrayBuffer.isView(rawBody)}: ${JSON.stringify(rawBody)}`); // 写入二进制数据 - //log(`🚧 rawBody: ${JSON.stringify(rawBody)}`, ""); + //Console.debug(`rawBody: ${JSON.stringify(rawBody)}`); //$response.body = rawBody; break; } @@ -135,5 +135,5 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); break; } })() - .catch(e => logError(e)) + .catch(e => Console.error(e)) .finally(() => done($response)); diff --git a/src/Manifest.response.dev.js b/src/Manifest.response.dev.js index 4dace98f..cfdad4ba 100644 --- a/src/Manifest.response.dev.js +++ b/src/Manifest.response.dev.js @@ -1,4 +1,4 @@ -import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util"; +import { $app, Console, done, fetch, Lodash as _, notification, Storage, wait } from "@nsnanocat/util"; import { URL } from "@nsnanocat/url"; import M3U8 from "./EXTM3U/EXTM3U.mjs"; import AttrList from "./class/AttrList.mjs"; @@ -12,16 +12,16 @@ import aPath from "./function/aPath.mjs"; /***************** Processing *****************/ // 解构URL const url = new URL($request.url); -log(`⚠ url: ${url.toJSON()}`, ""); +Console.info(`url: ${url.toJSON()}`); // 获取连接参数 const PATHs = url.pathname.split("/").filter(Boolean); -log(`⚠ PATHs: ${PATHs}`, ""); +Console.info(`PATHs: ${PATHs}`); // 解析格式 const FORMAT = ($response.headers?.["Content-Type"] ?? $response.headers?.["content-type"])?.split(";")?.[0]; -log(`⚠ FORMAT: ${FORMAT}`, ""); +Console.info(`FORMAT: ${FORMAT}`); // 获取平台 const PLATFORM = detectPlatform($request.url); -log(`⚠ PLATFORM: ${PLATFORM}`, ""); +Console.info(`PLATFORM: ${PLATFORM}`); (async () => { /** * 设置 @@ -31,7 +31,7 @@ log(`⚠ PLATFORM: ${PLATFORM}`, ""); // 获取字幕类型与语言 const Type = url.searchParams?.get("subtype") ?? Settings.Type, Languages = [url.searchParams?.get("lang")?.toUpperCase?.() ?? Settings.Languages[0], (url.searchParams?.get("tlang") ?? Caches?.tlang)?.toUpperCase?.() ?? Settings.Languages[1]]; - log(`⚠ Type: ${Type}, Languages: ${Languages}`, ""); + Console.info(`Type: ${Type}, Languages: ${Languages}`); // 兼容性判断 const { standard: STANDARD, device: DEVICE } = isStandard(url, $request.headers, PLATFORM); // 创建空数据 @@ -51,7 +51,7 @@ log(`⚠ PLATFORM: ${PLATFORM}`, ""); case "audio/mpegurl": // 序列化M3U8 body = M3U8.parse($response.body); - //log(`🚧 M3U8.parse($response.body): ${JSON.stringify(body)}`, ""); + //Console.debug(`M3U8.parse($response.body): ${JSON.stringify(body)}`); // 获取播放列表类型 switch (detectPlaylist(body)) { case "Multivariant Playlist": { @@ -74,7 +74,7 @@ log(`⚠ PLATFORM: ${PLATFORM}`, ""); // 处理类型 switch (Type) { case "Official": { - log("⚠ 官方字幕", ""); + Console.info("官方字幕"); // 获取字幕播放列表m3u8缓存(map) const { subtitlesPlaylist, subtitlesPlaylistIndex } = getPlaylistCache($request.url, Caches.Playlists.Master, Languages[0]) ?? getPlaylistCache($request.url, Caches.Playlists.Master, Languages[1]); // 写入字幕文件地址vtt缓存(map) @@ -88,10 +88,10 @@ log(`⚠ PLATFORM: ${PLATFORM}`, ""); } case "Translate": default: - log("⚠ 翻译字幕", ""); + Console.info("翻译字幕"); break; case "External": - log("⚠ 外挂字幕", ""); + Console.info("外挂字幕"); break; } // WebVTT.m3u8加参数 @@ -123,19 +123,19 @@ log(`⚠ PLATFORM: ${PLATFORM}`, ""); case "application/plist": case "application/x-plist": //body = XML.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); //$response.body = XML.stringify(body); break; case "text/vtt": case "application/vtt": //body = VTT.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); //$response.body = VTT.stringify(body); break; case "text/json": case "application/json": { body = JSON.parse($response.body ?? "{}"); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); // 读取已存数据 const playlistCache = Caches.Playlists.Master.get($request.url) || {}; // 判断平台 @@ -145,7 +145,7 @@ log(`⚠ PLATFORM: ${PLATFORM}`, ""); // 获取特定语言的字幕 playlistCache[Languages[0]] = new AttrList(FORMAT, PLATFORM).get($request.url, body, "subtitleUrls", Configs.Languages[Languages[0]]); playlistCache[Languages[1]] = new AttrList(FORMAT, PLATFORM).get($request.url, body, "subtitleUrls", Configs.Languages[Languages[1]]); - //log(`🚧 playlistCache[Languages[0]]: ${JSON.stringify(playlistCache[Languages[0]])}`, ""); + //Console.debug(`playlistCache[Languages[0]]: ${JSON.stringify(playlistCache[Languages[0]])}`); body.subtitleUrls = new AttrList(FORMAT, PLATFORM).set(body.subtitleUrls, playlistCache, Settings.Types, Languages, STANDARD, DEVICE); } break; @@ -156,7 +156,7 @@ log(`⚠ PLATFORM: ${PLATFORM}`, ""); Caches.Playlists.Master = setCache(Caches.Playlists.Master, Settings.CacheSize); // 写入持久化储存 Storage.setItem(`@DualSubs.${"Composite"}.Caches.Playlists.Master`, Caches.Playlists.Master); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); $response.body = JSON.stringify(body); break; } @@ -169,7 +169,7 @@ log(`⚠ PLATFORM: ${PLATFORM}`, ""); break; } })() - .catch(e => logError(e)) + .catch(e => Console.error(e)) .finally(() => done($response)); /***************** Function *****************/ @@ -182,31 +182,31 @@ log(`⚠ PLATFORM: ${PLATFORM}`, ""); * @return {Promise} { masterPlaylistURL, subtitlesPlaylist, subtitlesPlaylistIndex } */ function getPlaylistCache(url, cache, language) { - log(`☑️ getPlaylistCache, language: ${language}`, ""); + Console.info("☑️ getPlaylistCache", `language: ${language}`); let masterPlaylistURL = ""; let subtitlesPlaylist = {}; let subtitlesPlaylistIndex = 0; cache?.forEach((Value, Key) => { - //log(`🚧 getPlaylistCache, Key: ${Key}, Value: ${JSON.stringify(Value)}`, ""); + //Console.debug(`getPlaylistCache, Key: ${Key}, Value: ${JSON.stringify(Value)}`); if (Array.isArray(Value?.[language])) { const array = Value?.[language]; - //log(`🚧 getPlaylistCache`, `array: ${JSON.stringify(array)}`, ""); + //Console.debug(`getPlaylistCache`, `array: ${JSON.stringify(array)}`); if ( array?.some((object, index) => { if (url.includes(object?.URI ?? object?.OPTION?.URI ?? null)) { subtitlesPlaylistIndex = index; - log("🚧 getPlaylistCache", `subtitlesPlaylistIndex: ${subtitlesPlaylistIndex}`, ""); + Console.debug("getPlaylistCache", `subtitlesPlaylistIndex: ${subtitlesPlaylistIndex}`); return true; } else return false; }) ) { masterPlaylistURL = Key; subtitlesPlaylist = Value; - //log(`🚧 getPlaylistCache`, `masterPlaylistURL: ${masterPlaylistURL}`, `subtitlesPlaylist: ${JSON.stringify(subtitlesPlaylist)}`, ""); + //Console.debug(`getPlaylistCache`, `masterPlaylistURL: ${masterPlaylistURL}`, `subtitlesPlaylist: ${JSON.stringify(subtitlesPlaylist)}`); } } }); - log("✅ getPlaylistCache", `masterPlaylistURL: ${JSON.stringify(masterPlaylistURL)}`, ""); + Console.info("✅ getPlaylistCache", `masterPlaylistURL: ${JSON.stringify(masterPlaylistURL)}`); return { masterPlaylistURL, subtitlesPlaylist, subtitlesPlaylistIndex }; } @@ -221,22 +221,22 @@ function getPlaylistCache(url, cache, language) { * @return {Promise} { masterPlaylistURL, subtitlesPlaylist, subtitlesPlaylistIndex } */ async function setSubtitlesCache(cache, playlist, language, index = 0, platform = "Universal") { - log(`☑️ setSubtitlesCache, language: ${language}, index: ${index}`, ""); + Console.info("☑️ setSubtitlesCache", `language: ${language}, index: ${index}`); await Promise.all( playlist?.[language]?.map(async (val, ind, arr) => { - //log(`🚧 setSubtitlesCache, ind: ${ind}, val: ${JSON.stringify(val)}`, ""); + //Console.debug(`setSubtitlesCache, ind: ${ind}, val: ${JSON.stringify(val)}`); if ((arr[index] && ind === index) || !arr[index]) { // 查找字幕文件地址vtt缓存(map) let subtitlesURLarray = cache.get(val.URL) ?? []; - //log(`🚧 setSubtitlesCache`, `subtitlesURLarray: ${JSON.stringify(subtitlesURLarray)}`, ""); - //log(`🚧 setSubtitlesCache`, `val?.URL: ${val?.URL}`, ""); + //Console.debug(`setSubtitlesCache`, `subtitlesURLarray: ${JSON.stringify(subtitlesURLarray)}`); + //Console.debug(`setSubtitlesCache`, `val?.URL: ${val?.URL}`); // 获取字幕文件地址vtt/ttml缓存(按语言) if (subtitlesURLarray.length === 0) subtitlesURLarray = await getSubtitles(val?.URL, $request.headers, platform); - //log(`🚧 setSubtitlesCache`, `subtitlesURLarray: ${JSON.stringify(subtitlesURLarray)}`, ""); + //Console.debug(`setSubtitlesCache`, `subtitlesURLarray: ${JSON.stringify(subtitlesURLarray)}`); // 写入字幕文件地址vtt/ttml缓存到map if (subtitlesURLarray.length !== 0) cache = cache.set(val.URL, subtitlesURLarray); - //log(`✅ setSubtitlesCache`, `subtitlesURLarray: ${JSON.stringify(cache.get(val?.URL))}`, ""); - log("✅ setSubtitlesCache", `val?.URL: ${val?.URL}`, ""); + //Console.debug(`subtitlesURLarray: ${JSON.stringify(cache.get(val?.URL))}`); + Console.info("✅ setSubtitlesCache", `val?.URL: ${val?.URL}`); } }), ); @@ -252,9 +252,9 @@ async function setSubtitlesCache(cache, playlist, language, index = 0, platform * @return {Promise<*>} */ async function getSubtitles(url, headers, platform) { - log("☑️ Get Subtitle *.vtt *.ttml URLs", ""); + Console.info("☑️ Get Subtitle *.vtt *.ttml URLs"); let subtitles = await fetch(url, { headers: headers }).then((response, error) => { - //log(`🚧 Get Subtitle *.vtt *.ttml URLs`, `response: ${JSON.stringify(response)}`, ""); + //Console.debug(`Get Subtitle *.vtt *.ttml URLs`, `response: ${JSON.stringify(response)}`); const subtitlePlayList = M3U8.parse(response.body); return subtitlePlayList .filter(({ URI }) => /^.+\.((web)?vtt|ttml2?|xml|smi)(\?.+)?$/.test(URI)) @@ -278,6 +278,6 @@ async function getSubtitles(url, headers, platform) { default: break; } - log(`✅ Get Subtitle *.vtt *.ttml URLs, subtitles: ${subtitles}`, ""); + Console.info("✅ Get Subtitle *.vtt *.ttml URLs", `subtitles: ${subtitles}`); return subtitles; } diff --git a/src/Manifest.response.js b/src/Manifest.response.js index 4dace98f..3a6e5b7f 100644 --- a/src/Manifest.response.js +++ b/src/Manifest.response.js @@ -1,4 +1,4 @@ -import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util"; +import { $app, Console, done, fetch, Lodash as _, notification, Storage, wait } from "@nsnanocat/util"; import { URL } from "@nsnanocat/url"; import M3U8 from "./EXTM3U/EXTM3U.mjs"; import AttrList from "./class/AttrList.mjs"; @@ -9,19 +9,20 @@ import isStandard from "./function/isStandard.mjs"; import detectPlaylist from "./function/detectPlaylist.mjs"; import setCache from "./function/setCache.mjs"; import aPath from "./function/aPath.mjs"; +Console.debug = () => {}; /***************** Processing *****************/ // 解构URL const url = new URL($request.url); -log(`⚠ url: ${url.toJSON()}`, ""); +Console.info(`url: ${url.toJSON()}`); // 获取连接参数 const PATHs = url.pathname.split("/").filter(Boolean); -log(`⚠ PATHs: ${PATHs}`, ""); +Console.info(`PATHs: ${PATHs}`); // 解析格式 const FORMAT = ($response.headers?.["Content-Type"] ?? $response.headers?.["content-type"])?.split(";")?.[0]; -log(`⚠ FORMAT: ${FORMAT}`, ""); +Console.info(`FORMAT: ${FORMAT}`); // 获取平台 const PLATFORM = detectPlatform($request.url); -log(`⚠ PLATFORM: ${PLATFORM}`, ""); +Console.info(`PLATFORM: ${PLATFORM}`); (async () => { /** * 设置 @@ -31,7 +32,7 @@ log(`⚠ PLATFORM: ${PLATFORM}`, ""); // 获取字幕类型与语言 const Type = url.searchParams?.get("subtype") ?? Settings.Type, Languages = [url.searchParams?.get("lang")?.toUpperCase?.() ?? Settings.Languages[0], (url.searchParams?.get("tlang") ?? Caches?.tlang)?.toUpperCase?.() ?? Settings.Languages[1]]; - log(`⚠ Type: ${Type}, Languages: ${Languages}`, ""); + Console.info(`Type: ${Type}, Languages: ${Languages}`); // 兼容性判断 const { standard: STANDARD, device: DEVICE } = isStandard(url, $request.headers, PLATFORM); // 创建空数据 @@ -51,7 +52,7 @@ log(`⚠ PLATFORM: ${PLATFORM}`, ""); case "audio/mpegurl": // 序列化M3U8 body = M3U8.parse($response.body); - //log(`🚧 M3U8.parse($response.body): ${JSON.stringify(body)}`, ""); + //Console.debug(`M3U8.parse($response.body): ${JSON.stringify(body)}`); // 获取播放列表类型 switch (detectPlaylist(body)) { case "Multivariant Playlist": { @@ -74,7 +75,7 @@ log(`⚠ PLATFORM: ${PLATFORM}`, ""); // 处理类型 switch (Type) { case "Official": { - log("⚠ 官方字幕", ""); + Console.info("官方字幕"); // 获取字幕播放列表m3u8缓存(map) const { subtitlesPlaylist, subtitlesPlaylistIndex } = getPlaylistCache($request.url, Caches.Playlists.Master, Languages[0]) ?? getPlaylistCache($request.url, Caches.Playlists.Master, Languages[1]); // 写入字幕文件地址vtt缓存(map) @@ -88,10 +89,10 @@ log(`⚠ PLATFORM: ${PLATFORM}`, ""); } case "Translate": default: - log("⚠ 翻译字幕", ""); + Console.info("翻译字幕"); break; case "External": - log("⚠ 外挂字幕", ""); + Console.info("外挂字幕"); break; } // WebVTT.m3u8加参数 @@ -123,19 +124,19 @@ log(`⚠ PLATFORM: ${PLATFORM}`, ""); case "application/plist": case "application/x-plist": //body = XML.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); //$response.body = XML.stringify(body); break; case "text/vtt": case "application/vtt": //body = VTT.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); //$response.body = VTT.stringify(body); break; case "text/json": case "application/json": { body = JSON.parse($response.body ?? "{}"); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); // 读取已存数据 const playlistCache = Caches.Playlists.Master.get($request.url) || {}; // 判断平台 @@ -145,7 +146,7 @@ log(`⚠ PLATFORM: ${PLATFORM}`, ""); // 获取特定语言的字幕 playlistCache[Languages[0]] = new AttrList(FORMAT, PLATFORM).get($request.url, body, "subtitleUrls", Configs.Languages[Languages[0]]); playlistCache[Languages[1]] = new AttrList(FORMAT, PLATFORM).get($request.url, body, "subtitleUrls", Configs.Languages[Languages[1]]); - //log(`🚧 playlistCache[Languages[0]]: ${JSON.stringify(playlistCache[Languages[0]])}`, ""); + //Console.debug(`playlistCache[Languages[0]]: ${JSON.stringify(playlistCache[Languages[0]])}`); body.subtitleUrls = new AttrList(FORMAT, PLATFORM).set(body.subtitleUrls, playlistCache, Settings.Types, Languages, STANDARD, DEVICE); } break; @@ -156,7 +157,7 @@ log(`⚠ PLATFORM: ${PLATFORM}`, ""); Caches.Playlists.Master = setCache(Caches.Playlists.Master, Settings.CacheSize); // 写入持久化储存 Storage.setItem(`@DualSubs.${"Composite"}.Caches.Playlists.Master`, Caches.Playlists.Master); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); $response.body = JSON.stringify(body); break; } @@ -169,7 +170,7 @@ log(`⚠ PLATFORM: ${PLATFORM}`, ""); break; } })() - .catch(e => logError(e)) + .catch(e => Console.error(e)) .finally(() => done($response)); /***************** Function *****************/ @@ -182,31 +183,31 @@ log(`⚠ PLATFORM: ${PLATFORM}`, ""); * @return {Promise} { masterPlaylistURL, subtitlesPlaylist, subtitlesPlaylistIndex } */ function getPlaylistCache(url, cache, language) { - log(`☑️ getPlaylistCache, language: ${language}`, ""); + Console.info("☑️ getPlaylistCache", `language: ${language}`); let masterPlaylistURL = ""; let subtitlesPlaylist = {}; let subtitlesPlaylistIndex = 0; cache?.forEach((Value, Key) => { - //log(`🚧 getPlaylistCache, Key: ${Key}, Value: ${JSON.stringify(Value)}`, ""); + //Console.debug(`getPlaylistCache, Key: ${Key}, Value: ${JSON.stringify(Value)}`); if (Array.isArray(Value?.[language])) { const array = Value?.[language]; - //log(`🚧 getPlaylistCache`, `array: ${JSON.stringify(array)}`, ""); + //Console.debug(`getPlaylistCache`, `array: ${JSON.stringify(array)}`); if ( array?.some((object, index) => { if (url.includes(object?.URI ?? object?.OPTION?.URI ?? null)) { subtitlesPlaylistIndex = index; - log("🚧 getPlaylistCache", `subtitlesPlaylistIndex: ${subtitlesPlaylistIndex}`, ""); + Console.debug("getPlaylistCache", `subtitlesPlaylistIndex: ${subtitlesPlaylistIndex}`); return true; } else return false; }) ) { masterPlaylistURL = Key; subtitlesPlaylist = Value; - //log(`🚧 getPlaylistCache`, `masterPlaylistURL: ${masterPlaylistURL}`, `subtitlesPlaylist: ${JSON.stringify(subtitlesPlaylist)}`, ""); + //Console.debug(`getPlaylistCache`, `masterPlaylistURL: ${masterPlaylistURL}`, `subtitlesPlaylist: ${JSON.stringify(subtitlesPlaylist)}`); } } }); - log("✅ getPlaylistCache", `masterPlaylistURL: ${JSON.stringify(masterPlaylistURL)}`, ""); + Console.info("✅ getPlaylistCache", `masterPlaylistURL: ${JSON.stringify(masterPlaylistURL)}`); return { masterPlaylistURL, subtitlesPlaylist, subtitlesPlaylistIndex }; } @@ -221,22 +222,22 @@ function getPlaylistCache(url, cache, language) { * @return {Promise} { masterPlaylistURL, subtitlesPlaylist, subtitlesPlaylistIndex } */ async function setSubtitlesCache(cache, playlist, language, index = 0, platform = "Universal") { - log(`☑️ setSubtitlesCache, language: ${language}, index: ${index}`, ""); + Console.info("☑️ setSubtitlesCache", `language: ${language}, index: ${index}`); await Promise.all( playlist?.[language]?.map(async (val, ind, arr) => { - //log(`🚧 setSubtitlesCache, ind: ${ind}, val: ${JSON.stringify(val)}`, ""); + //Console.debug(`setSubtitlesCache, ind: ${ind}, val: ${JSON.stringify(val)}`); if ((arr[index] && ind === index) || !arr[index]) { // 查找字幕文件地址vtt缓存(map) let subtitlesURLarray = cache.get(val.URL) ?? []; - //log(`🚧 setSubtitlesCache`, `subtitlesURLarray: ${JSON.stringify(subtitlesURLarray)}`, ""); - //log(`🚧 setSubtitlesCache`, `val?.URL: ${val?.URL}`, ""); + //Console.debug(`setSubtitlesCache`, `subtitlesURLarray: ${JSON.stringify(subtitlesURLarray)}`); + //Console.debug(`setSubtitlesCache`, `val?.URL: ${val?.URL}`); // 获取字幕文件地址vtt/ttml缓存(按语言) if (subtitlesURLarray.length === 0) subtitlesURLarray = await getSubtitles(val?.URL, $request.headers, platform); - //log(`🚧 setSubtitlesCache`, `subtitlesURLarray: ${JSON.stringify(subtitlesURLarray)}`, ""); + //Console.debug(`setSubtitlesCache`, `subtitlesURLarray: ${JSON.stringify(subtitlesURLarray)}`); // 写入字幕文件地址vtt/ttml缓存到map if (subtitlesURLarray.length !== 0) cache = cache.set(val.URL, subtitlesURLarray); - //log(`✅ setSubtitlesCache`, `subtitlesURLarray: ${JSON.stringify(cache.get(val?.URL))}`, ""); - log("✅ setSubtitlesCache", `val?.URL: ${val?.URL}`, ""); + //Console.debug(`subtitlesURLarray: ${JSON.stringify(cache.get(val?.URL))}`); + Console.info("✅ setSubtitlesCache", `val?.URL: ${val?.URL}`); } }), ); @@ -252,9 +253,9 @@ async function setSubtitlesCache(cache, playlist, language, index = 0, platform * @return {Promise<*>} */ async function getSubtitles(url, headers, platform) { - log("☑️ Get Subtitle *.vtt *.ttml URLs", ""); + Console.info("☑️ Get Subtitle *.vtt *.ttml URLs"); let subtitles = await fetch(url, { headers: headers }).then((response, error) => { - //log(`🚧 Get Subtitle *.vtt *.ttml URLs`, `response: ${JSON.stringify(response)}`, ""); + //Console.debug(`Get Subtitle *.vtt *.ttml URLs`, `response: ${JSON.stringify(response)}`); const subtitlePlayList = M3U8.parse(response.body); return subtitlePlayList .filter(({ URI }) => /^.+\.((web)?vtt|ttml2?|xml|smi)(\?.+)?$/.test(URI)) @@ -278,6 +279,6 @@ async function getSubtitles(url, headers, platform) { default: break; } - log(`✅ Get Subtitle *.vtt *.ttml URLs, subtitles: ${subtitles}`, ""); + Console.info("✅ Get Subtitle *.vtt *.ttml URLs", `subtitles: ${subtitles}`); return subtitles; } diff --git a/src/Translate.response.dev.js b/src/Translate.response.dev.js index 632fc473..a5dd25a1 100644 --- a/src/Translate.response.dev.js +++ b/src/Translate.response.dev.js @@ -1,4 +1,4 @@ -import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util"; +import { $app, Console, done, fetch, Lodash as _, notification, Storage, wait } from "@nsnanocat/util"; import { URL } from "@nsnanocat/url"; import XML from "./XML/XML.mjs"; import VTT from "./WebVTT/WebVTT.mjs"; @@ -14,18 +14,18 @@ import { WireType, UnknownFieldHandler, reflectionMergePartial, MESSAGE_TYPE, Me /***************** Processing *****************/ // 解构URL const url = new URL($request.url); -log(`⚠ url: ${url.toJSON()}`, ""); +Console.info(`url: ${url.toJSON()}`); // 获取连接参数 const PATHs = url.pathname.split("/").filter(Boolean); -log(`⚠ PATHs: ${PATHs}`, ""); +Console.info(`PATHs: ${PATHs}`); // 解析格式 let FORMAT = ($response.headers?.["Content-Type"] ?? $response.headers?.["content-type"])?.split(";")?.[0]; if (FORMAT === "application/octet-stream" || FORMAT === "text/plain") FORMAT = detectFormat(url, $response?.body, FORMAT); -log(`⚠ FORMAT: ${FORMAT}`, ""); +Console.info(`FORMAT: ${FORMAT}`); (async () => { // 获取平台 const PLATFORM = detectPlatform($request.url); - log(`⚠ PLATFORM: ${PLATFORM}`, ""); + Console.info(`PLATFORM: ${PLATFORM}`); /** * 设置 * @type {{Settings: import('./types').Settings}} @@ -34,7 +34,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); // 获取字幕类型与语言 const Type = url.searchParams?.get("subtype") ?? Settings.Type, Languages = [url.searchParams?.get("lang")?.toUpperCase?.() ?? Settings.Languages[0], (url.searchParams?.get("tlang") ?? Caches?.tlang)?.toUpperCase?.() ?? Settings.Languages[1]]; - log(`⚠ Type: ${Type}, Languages: ${Languages}`, ""); + Console.info(`Type: ${Type}, Languages: ${Languages}`); // 创建空数据 let body = {}; // 格式判断 @@ -50,7 +50,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); case "application/vnd.apple.mpegurl": case "audio/mpegurl": //body = M3U8.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); //$response.body = M3U8.stringify(body); break; case "text/xml": @@ -60,7 +60,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); case "application/plist": case "application/x-plist": { body = XML.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); const breakLine = body?.tt ? "
" : body?.timedtext ? " " : " "; if (body?.timedtext?.head?.wp?.[1]?.["@rc"]) body.timedtext.head.wp[1]["@rc"] = "1"; let paragraph = body?.tt?.body?.div?.p ?? body?.timedtext?.body?.p; @@ -95,28 +95,28 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); else if (span?.["#"]) span["#"] = combineText(span["#"], translation?.[i], Settings?.ShowOnly, Settings?.Position, breakLine); return para; }); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); $response.body = XML.stringify(body); break; } case "text/vtt": case "application/vtt": { body = VTT.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); const fullText = body?.body.map(item => (item?.text ?? "\u200b")?.replace(/<\/?[^<>]+>/g, "")); const translation = await Translator(Settings.Vendor, Settings.Method, fullText, Languages, Settings?.[Settings?.Vendor], Settings?.Times, Settings?.Interval, Settings?.Exponential); body.body = body.body.map((item, i) => { item.text = combineText(item?.text ?? "\u200b", translation?.[i], Settings?.ShowOnly, Settings?.Position); return item; }); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); $response.body = VTT.stringify(body); break; } case "text/json": case "application/json": { body = JSON.parse($response.body ?? "{}"); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); switch (PLATFORM) { case "YouTube": { if (body?.events) { @@ -160,7 +160,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); Languages[0] = body?.lyrics?.language === "z1" ? "ZH-HANT" : body?.lyrics?.language ? body?.lyrics?.language.toUpperCase() : "AUTO"; const fullText = body.lyrics.lines.map(line => line?.words ?? "\u200b"); const translation = await Translator(Settings.Vendor, Settings.Method, fullText, Languages, Settings?.[Settings?.Vendor], Settings?.Times, Settings?.Interval, Settings?.Exponential); - log(`🚧 $request.headers["app-platform"]: ${$request?.headers?.["app-platform"]}`, ""); + Console.debug(`$request.headers["app-platform"]: ${$request?.headers?.["app-platform"]}`); switch ($request?.headers?.["app-platform"] ?? $request?.headers?.["App-Platform"]) { case "OSX": // macOS App 暂不支持翻译功能 case "Win32_x86_64": // Windows App 暂不支持翻译功能 @@ -203,7 +203,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); break; } } - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); $response.body = JSON.stringify(body); break; } @@ -213,9 +213,9 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); case "application/grpc": case "application/grpc+proto": case "application/octet-stream": { - //log(`🚧 $response.body: ${JSON.stringify($response.body)}`, ""); + //Console.debug(`$response.body: ${JSON.stringify($response.body)}`); let rawBody = $app === "Quantumult X" ? new Uint8Array($response.bodyBytes ?? []) : ($response.body ?? new Uint8Array()); - //log(`🚧 isBuffer? ${ArrayBuffer.isView(rawBody)}: ${JSON.stringify(rawBody)}`, ""); + //Console.debug(`isBuffer? ${ArrayBuffer.isView(rawBody)}: ${JSON.stringify(rawBody)}`); switch (FORMAT) { case "application/protobuf": case "application/x-protobuf": @@ -223,11 +223,11 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); switch (PLATFORM) { case "YouTube": { body = BrowseResponse.fromBinary(rawBody); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); - log(`🚧 contents: ${JSON.stringify(body?.contents)}`, ""); - log(`🚧 continuationContents: ${JSON.stringify(body?.continuationContents)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); + Console.debug(`contents: ${JSON.stringify(body?.contents)}`); + Console.debug(`continuationContents: ${JSON.stringify(body?.continuationContents)}`); let UF = UnknownFieldHandler.list(body); - //log(`🚧 UF: ${JSON.stringify(UF)}`, ""); + //Console.debug(`UF: ${JSON.stringify(UF)}`); if (UF) { UF = UF.map(uf => { //uf.no; // 22 @@ -235,7 +235,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); // use the binary reader to decode the raw data: const reader = new BinaryReader(uf.data); const addedNumber = reader.int32(); // 7777 - log(`🚧 no: ${uf.no}, wireType: ${uf.wireType}, reader: ${reader}, addedNumber: ${addedNumber}`, ""); + Console.debug(`no: ${uf.no}, wireType: ${uf.wireType}, reader: ${reader}, addedNumber: ${addedNumber}`); }); } Languages[0] = "AUTO"; @@ -268,18 +268,18 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); }), ); } - //log(`🚧 body: ${JSON.stringify(body)}`, ""); - log(`🚧 contents: ${JSON.stringify(body?.contents)}`, ""); - log(`🚧 continuationContents: ${JSON.stringify(body?.continuationContents)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`); + Console.debug(`contents: ${JSON.stringify(body?.contents)}`); + Console.debug(`continuationContents: ${JSON.stringify(body?.continuationContents)}`); rawBody = BrowseResponse.toBinary(body); break; } case "Spotify": { body = ColorLyricsResponse.fromBinary(rawBody); - log(`🚧 body: ${JSON.stringify(body)}`, ""); + Console.debug(`body: ${JSON.stringify(body)}`); /* let UF = UnknownFieldHandler.list(body); - //log(`🚧 UF: ${JSON.stringify(UF)}`, ""); + //Console.debug(`UF: ${JSON.stringify(UF)}`); if (UF) { UF = UF.map(uf => { //uf.no; // 22 @@ -287,7 +287,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); // use the binary reader to decode the raw data: let reader = new BinaryReader(uf.data); let addedNumber = reader.int32(); // 7777 - log(`🚧 no: ${uf.no}, wireType: ${uf.wireType}, reader: ${reader}, addedNumber: ${addedNumber}`, ""); + Console.debug(`no: ${uf.no}, wireType: ${uf.wireType}, reader: ${reader}, addedNumber: ${addedNumber}`); }); }; */ @@ -305,7 +305,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); language: Languages[1].toLowerCase(), lines: translation, }); - log(`🚧 body: ${JSON.stringify(body)}`, ""); + Console.debug(`body: ${JSON.stringify(body)}`); rawBody = ColorLyricsResponse.toBinary(body); break; } @@ -321,7 +321,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); } } })() - .catch(e => logError(e)) + .catch(e => Console.error(e)) .finally(() => done($response)); /***************** Function *****************/ @@ -342,7 +342,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); * @return {Promise<*>} */ async function Translator(vendor = "Google", method = "Part", text = [], [source = "AUTO", target = "ZH"], API = {}, times = 3, interval = 100, exponential = true) { - log(`☑️ Translator, vendor: ${vendor}, method: ${method}, [source, target]: ${[source, target]}`, ""); + Console.info("☑️ Translator", `vendor: ${vendor}, method: ${method}, [source, target]: ${[source, target]}`); // 翻译长度设置 let length = 127; switch (vendor) { @@ -375,8 +375,8 @@ async function Translator(vendor = "Google", method = "Part", text = [], [source Translation = await Promise.all(text.map(async row => await retry(() => new Translate({ Source: source, Target: target, API: API })[vendor](row), times, interval, exponential))); break; } - //log(`✅ Translator, Translation: ${JSON.stringify(Translation)}`, ""); - log("✅ Translator", ""); + //Console.debug(`Translation: ${JSON.stringify(Translation)}`); + Console.info("✅ Translator"); return Translation; } @@ -419,11 +419,11 @@ function combineText(originText, transText, ShowOnly = false, position = "Forwar * @return {Array<*>} target */ function chunk(source, length) { - log("⚠ Chunk Array", ""); + Console.info("☑️ Chunk Array"); let index = 0, target = []; while (index < source.length) target.push(source.slice(index, (index += length))); - //log(`🎉 Chunk Array`, `target: ${JSON.stringify(target)}`, ""); + //Console.info("✅ Chunk Array", `target: ${JSON.stringify(target)}`); return target; } @@ -439,7 +439,7 @@ function chunk(source, length) { * @return {Promise<*>} */ async function retry(fn, retriesLeft = 5, interval = 1000, exponential = false) { - log(`☑️ retry, 剩余重试次数:${retriesLeft}`, `时间间隔:${interval}ms`); + Console.info("☑️ retry", `剩余重试次数:${retriesLeft}`, `时间间隔:${interval}ms`); try { const val = await fn(); return val; diff --git a/src/Translate.response.js b/src/Translate.response.js index 28e66a07..753ede65 100644 --- a/src/Translate.response.js +++ b/src/Translate.response.js @@ -1,4 +1,4 @@ -import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util"; +import { $app, Console, done, fetch, Lodash as _, notification, Storage, wait } from "@nsnanocat/util"; import { URL } from "@nsnanocat/url"; import XML from "./XML/XML.mjs"; import VTT from "./WebVTT/WebVTT.mjs"; @@ -10,21 +10,22 @@ import setCache from "./function/setCache.mjs"; import Translate from "./class/Translate.mjs"; import { BrowseResponse } from "./protobuf/google/protos/youtube/api/innertube/BrowseResponse.js"; import { ColorLyricsResponse } from "./protobuf/spotify/lyrics/Lyrics.js"; +Console.debug = () => {}; /***************** Processing *****************/ // 解构URL const url = new URL($request.url); -log(`⚠ url: ${url.toJSON()}`, ""); +Console.info(`url: ${url.toJSON()}`); // 获取连接参数 const PATHs = url.pathname.split("/").filter(Boolean); -log(`⚠ PATHs: ${PATHs}`, ""); +Console.info(`PATHs: ${PATHs}`); // 解析格式 let FORMAT = ($response.headers?.["Content-Type"] ?? $response.headers?.["content-type"])?.split(";")?.[0]; if (FORMAT === "application/octet-stream" || FORMAT === "text/plain") FORMAT = detectFormat(url, $response?.body, FORMAT); -log(`⚠ FORMAT: ${FORMAT}`, ""); +Console.info(`FORMAT: ${FORMAT}`); (async () => { // 获取平台 const PLATFORM = detectPlatform($request.url); - log(`⚠ PLATFORM: ${PLATFORM}`, ""); + Console.info(`PLATFORM: ${PLATFORM}`); /** * 设置 * @type {{Settings: import('./types').Settings}} @@ -33,7 +34,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); // 获取字幕类型与语言 const Type = url.searchParams?.get("subtype") ?? Settings.Type, Languages = [url.searchParams?.get("lang")?.toUpperCase?.() ?? Settings.Languages[0], (url.searchParams?.get("tlang") ?? Caches?.tlang)?.toUpperCase?.() ?? Settings.Languages[1]]; - log(`⚠ Type: ${Type}, Languages: ${Languages}`, ""); + Console.info(`Type: ${Type}, Languages: ${Languages}`); // 创建空数据 let body = {}; // 格式判断 @@ -253,7 +254,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); } } })() - .catch(e => logError(e)) + .catch(e => Console.error(e)) .finally(() => done($response)); /***************** Function *****************/ @@ -274,7 +275,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); * @return {Promise<*>} */ async function Translator(vendor = "Google", method = "Part", text = [], [source = "AUTO", target = "ZH"], API = {}, times = 3, interval = 100, exponential = true) { - log(`☑️ Translator, vendor: ${vendor}, method: ${method}, [source, target]: ${[source, target]}`, ""); + Console.info("☑️ Translator", `vendor: ${vendor}, method: ${method}, [source, target]: ${[source, target]}`); // 翻译长度设置 let length = 127; switch (vendor) { @@ -307,8 +308,8 @@ async function Translator(vendor = "Google", method = "Part", text = [], [source Translation = await Promise.all(text.map(async row => await retry(() => new Translate({ Source: source, Target: target, API: API })[vendor](row), times, interval, exponential))); break; } - //log(`✅ Translator, Translation: ${JSON.stringify(Translation)}`, ""); - log("✅ Translator", ""); + //Console.debug(`Translation: ${JSON.stringify(Translation)}`); + Console.info("✅ Translator"); return Translation; } @@ -351,11 +352,11 @@ function combineText(originText, transText, ShowOnly = false, position = "Forwar * @return {Array<*>} target */ function chunk(source, length) { - log("⚠ Chunk Array", ""); + Console.info("☑️ Chunk Array"); let index = 0, target = []; while (index < source.length) target.push(source.slice(index, (index += length))); - //log(`🎉 Chunk Array`, `target: ${JSON.stringify(target)}`, ""); + //Console.info("✅ Chunk Array", `target: ${JSON.stringify(target)}`); return target; } @@ -371,7 +372,7 @@ function chunk(source, length) { * @return {Promise<*>} */ async function retry(fn, retriesLeft = 5, interval = 1000, exponential = false) { - log(`☑️ retry, 剩余重试次数:${retriesLeft}`, `时间间隔:${interval}ms`); + Console.info("☑️ retry", `剩余重试次数:${retriesLeft}`, `时间间隔:${interval}ms`); try { const val = await fn(); return val; diff --git a/src/class/AttrList.mjs b/src/class/AttrList.mjs index a29bf9a6..66ff7cfa 100644 --- a/src/class/AttrList.mjs +++ b/src/class/AttrList.mjs @@ -1,4 +1,4 @@ -import { log } from "@nsnanocat/util"; +import { Console } from "@nsnanocat/util"; import setOption from "../function/setOption.mjs"; import aPath from "../function/aPath.mjs"; @@ -9,7 +9,7 @@ export default class AttrList { this.format = format; this.platform = platform; //Object.assign(this, options) - log(`\n🟧 ${this.Name} v${this.Version} format: ${this.format} platform: ${this.platform}\n`) + Console.log(`🟧 ${this.Name} v${this.Version}`, `format: ${this.format}`, `platform: ${this.platform}`) } /** @@ -22,7 +22,7 @@ export default class AttrList { * @return {Array} datas */ get(url = "", file = [], type = "", langCodes = []) { - log(`☑️ Get Attribute List, type: ${type}, langCodes: ${langCodes}`); + Console.log("☑️ Get Attribute List", `type: ${type}`, `langCodes: ${langCodes}`); let matchList = []; // 格式判断 switch (this.format) { @@ -34,10 +34,10 @@ export default class AttrList { .filter(item => item?.TAG === "#EXT-X-MEDIA") // 过滤标签 .filter(item => item?.OPTION?.TYPE === type) // 过滤类型 .filter(item => item?.OPTION?.FORCED !== "YES"); // 过滤强制内容 - //log(`🚧 attrList: ${JSON.stringify(attrList)}`, ""); + //Console.debug(`attrList: ${JSON.stringify(attrList)}`); //查询是否有符合语言的内容 for (let langcode of langCodes) { - log(`🚧 Get Attribute List, for (let ${langcode} of langcodes)`, ""); + Console.debug(`Get Attribute List, for (let ${langcode} of langcodes)`); matchList = attrList.filter(item => item?.OPTION?.LANGUAGE?.toLowerCase() === langcode?.toLowerCase()); if (matchList.length !== 0) break; }; @@ -54,7 +54,7 @@ export default class AttrList { let attrList = file?.[type] ?? []; //查询是否有符合语言的内容 for (let langcode of langCodes) { - log(`🚧 Get Attribute List, for (let ${langcode} of langcodes)`, ""); + Console.debug(`Get Attribute List, for (let ${langcode} of langcodes)`); matchList = attrList.filter(item => item?.languageCode?.toLowerCase() === langcode?.toLowerCase()); if (matchList.length !== 0) break; }; @@ -68,7 +68,7 @@ export default class AttrList { break; }; }; - log(`✅ Get Attribute List, matchList: ${JSON.stringify(matchList)}`, ""); + Console.info(`✅ Get Attribute List, matchList: ${JSON.stringify(matchList)}`); return matchList; }; @@ -87,11 +87,11 @@ export default class AttrList { types = (standard == true) ? types : [types.at(-1)]; const playlists1 = playlists?.[languages?.[0]]; const playlists2 = playlists?.[languages?.[1]]; - //if (playlists1?.length !== 0) log(`🚧 Set Attribute List, 有主字幕语言(源语言)字幕`); + //if (playlists1?.length !== 0) Console.debug(`Set Attribute List, 有主字幕语言(源语言)字幕`); //else types = types.filter(e => e !== "Translate"); // 无源语言字幕时删除翻译字幕选项 - //if (playlists2?.length !== 0) log(`🚧 Set Attribute List, 有副字幕语言(目标语言)字幕`); + //if (playlists2?.length !== 0) Console.debug(`Set Attribute List, 有副字幕语言(目标语言)字幕`); //else types = types.filter(e => e !== "Official"); // 无目标语言字幕时删除官方字幕选项 - log(`☑️ Set Attribute List, types: ${types}`, ""); + Console.log("☑️ Set Attribute List", `types: ${types}`); // 格式判断 switch (this.format) { case "application/x-mpegURL": @@ -101,7 +101,7 @@ export default class AttrList { playlists1?.forEach(playlist1 => { const index1 = file.findIndex(item => item?.OPTION?.URI === playlist1.OPTION.URI); // 主语言(源语言)字幕位置 types.forEach(type => { - log(`🚧 Set Attribute List, type: ${type}`, ""); + Console.debug(`Set Attribute List, type: ${type}`); let option; switch (type) { case "Official": @@ -150,7 +150,7 @@ export default class AttrList { playlists1?.forEach(playlist1 => { const index1 = file.findIndex(item => item?.timedTextTrackId === playlist1.timedTextTrackId); // 主语言(源语言)字幕位置 types.forEach(type => { - log(`🚧 Set Attribute List, type: ${type}`); + Console.debug(`Set Attribute List, type: ${type}`); let option; switch (type) { case "Official": @@ -163,7 +163,7 @@ export default class AttrList { const symbol = (option.url.includes("?")) ? "&" : "?"; option.url += `${symbol}subtype=${type}`; option.url += `&lang=${languages[0]}`; - //log(`🚧 option: ${JSON.stringify(option)}`, ""); + //Console.debug(`option: ${JSON.stringify(option)}`); }; }); break; @@ -176,7 +176,7 @@ export default class AttrList { const symbol = (playlist1.url.includes("?")) ? "&" : "?"; option.url += `${symbol}subtype=${type}`; option.url += `&lang=${playlist1.languageCode.toUpperCase()}`; - //log(`🚧 option: ${JSON.stringify(option)}`, ""); + //Console.debug(`option: ${JSON.stringify(option)}`); break; }; if (option) file.splice(index1 + (standard ? 1 : 0), 0, option); @@ -188,8 +188,8 @@ export default class AttrList { break; }; }; - //log(`✅ Set Attribute List, file: ${JSON.stringify(file)}`); - log(`✅ Set Attribute List`); + //Console.info(`✅ Set Attribute List, file: ${JSON.stringify(file)}`); + Console.info(`✅ Set Attribute List`); return file; }; } diff --git a/src/class/Composite.mjs b/src/class/Composite.mjs index 93a436f3..cd81c1ee 100644 --- a/src/class/Composite.mjs +++ b/src/class/Composite.mjs @@ -1,4 +1,4 @@ -import { log } from "@nsnanocat/util"; +import { Console } from "@nsnanocat/util"; /** * Composite Subtitles @@ -18,14 +18,14 @@ export default class Composite { this.Tolerance = 0; this.Position = "Forward"; Object.assign(this, options) - log(`\n🟧 ${this.Name} v${this.Version}\n`) + Console.log(`🟧 ${this.Name} v${this.Version}`) } JSON(Sub1 = {}, Sub2 = {}, Kind = "captions", Offset = this.Offset, Tolerance = this.Tolerance, Position = this.Position) { - log(`☑️ Composite JSON Subtitles\nOffset:${Offset}, Tolerance:${Tolerance}, Position:${Position}`, ""); + Console.log("☑️ Composite JSON Subtitles", `Offset:${Offset}`, `Tolerance:${Tolerance}`, `Position:${Position}`); //let DualSub = Position.includes("Reverse") ? Sub2 : Sub1 let DualSub = Sub1; - //log(`🚧 let DualSub内容: ${JSON.stringify(DualSub)}`, ""); + //Console.debug(`let DualSub内容: ${JSON.stringify(DualSub)}`); // 有序数列 用不着排序 //FirstSub.body.sort((x, y) => x - y); //SecondSub.body.sort((x, y) => x - y); @@ -35,7 +35,7 @@ export default class Composite { switch (Kind) { case "asr": // 自动生成字幕转普通字幕 - log(`☑️ DualSub是自动生成字幕`, ""); + Console.info("DualSub是自动生成字幕"); index0 = 1, index1 = 1, index2 = 1; Sub1.events = Sub1.events.map(event => { if (event?.segs) { @@ -56,18 +56,18 @@ export default class Composite { default: // 处理普通字幕 while (index1 < length1 && index2 < length2) { - //log(`🚧 index1/length1: ${index1}/${length1}, index2/length2: ${index2}/${length2}`, ""); + //Console.debug(`index1/length1: ${index1}/${length1}, index2/length2: ${index2}/${length2}`); const timeStamp1 = Sub1.events[index1].tStartMs, timeStamp2 = Sub2.events[index2].tStartMs; - //log(`🚧 timeStamp1: ${timeStamp1}, timeStamp2: ${timeStamp2}`, ""); + //Console.debug(`timeStamp1: ${timeStamp1}, timeStamp2: ${timeStamp2}`); const timeStamp1Next = Sub1.events[index1 + 1]?.tStartMs ?? timeStamp1, timeStamp2Next = Sub2.events[index2 + 1]?.tStartMs ?? timeStamp2; if (Math.abs(timeStamp1 - timeStamp2) <= Tolerance) { //index0 = (Position === "Reverse") ? index2 : index1; index0 = index1; // 处理普通字幕 const text1 = Sub1.events[index1]?.segs?.[0].utf8 ?? "", text2 = Sub2.events[index2]?.segs?.[0].utf8 ?? ""; - //log(`🚧 text1: ${text1}, text2: ${text2}`, ""); + //Console.debug(`text1: ${text1}, text2: ${text2}`); DualSub.events[index0].segs = [{ "utf8": ((Position === "Reverse") ? `${text2}\n${text1}` : `${text1}\n${text2}`).trim() }]; - //log(`🚧 DualSub.events[index0].segs[0].utf8: ${DualSub.events[index0].segs[0].utf8}`, ""); + //Console.debug(` DualSub.events[index0].segs[0].utf8: ${DualSub.events[index0].segs[0].utf8}`); //DualSub.body[index0].tStartMs = (Position === "Reverse") ? timeStamp2 : timeStamp1; //DualSub.body[index0].index = (Position === "Reverse") ? index2 : index1; }; @@ -79,16 +79,16 @@ export default class Composite { }; }; }; - //log(`✅ Composite JSON Subtitles, DualSub内容: ${JSON.stringify(DualSub)}`, ""); - log(`✅ Composite JSON Subtitles`, ""); + //Console.info(`✅ Composite JSON Subtitles, DualSub内容: ${JSON.stringify(DualSub)}`); + Console.info("✅ Composite JSON Subtitles"); return DualSub; }; timedText(Sub1 = {}, Sub2 = {}, Kind = "captions", Offset = this.Offset, Tolerance = this.Tolerance, Position = this.Position) { - log(`☑️ Composite timedText Subtitles\nOffset:${Offset}, Tolerance:${Tolerance}, Position:${Position}`, ""); + Console.log("☑️ Composite timedText Subtitles", `Offset: ${Offset}`, `Tolerance: ${Tolerance}`, `Position: ${Position}`); //let DualSub = Position.includes("Reverse") ? Sub2 : Sub1 let DualSub = Sub1; - //log(`🚧 let DualSub内容: ${JSON.stringify(DualSub)}`, ""); + //Console.debug(`let DualSub内容: ${JSON.stringify(DualSub)}`); // 有序数列 用不着排序 //FirstSub.body.sort((x, y) => x - y); //SecondSub.body.sort((x, y) => x - y); @@ -98,7 +98,7 @@ export default class Composite { switch (Kind) { case "asr": // 自动生成字幕转普通字幕 - log(`☑️ DualSub是自动生成字幕`, ""); + Console.info("DualSub是自动生成字幕"); DualSub.timedtext.head.wp[1]["@rc"] = "1"; Sub1.timedtext.body.p = Sub1.timedtext.body.p.map(para => { if (para?.s) { @@ -123,18 +123,18 @@ export default class Composite { default: // 处理普通字幕 while (index1 < length1 && index2 < length2) { - //log(`🚧 index1/length1: ${index1}/${length1}, index2/length2: ${index2}/${length2}`, ""); + //Console.debug(`index1/length1: ${index1}/${length1}, index2/length2: ${index2}/${length2}`); const timeStamp1 = parseInt(Sub1.timedtext.body.p[index1]["@t"], 10), timeStamp2 = parseInt(Sub2.timedtext.body.p[index2]["@t"], 10); - //log(`🚧 timeStamp1: ${timeStamp1}, timeStamp2: ${timeStamp2}`, ""); + //Console.debug(`timeStamp1: ${timeStamp1}, timeStamp2: ${timeStamp2}`); const timeStamp1Next = parseInt(Sub1.timedtext.body.p[index1 + 1]?.["@t"] ?? timeStamp1, 10), timeStamp2Next = parseInt(Sub2.timedtext.body.p[index2 + 1]?.["@t"] ?? timeStamp2, 10); if (Math.abs(timeStamp1 - timeStamp2) <= Tolerance) { //index0 = (Position === "Reverse") ? index2 : index1; index0 = index1; // 处理普通字幕 const text1 = Sub1.timedtext.body.p[index1]?.["#"] ?? "", text2 = Sub2.timedtext.body.p[index2]?.["#"] ?? ""; - //log(`🚧 text1: ${text1}, text2: ${text2}`, ""); + //Console.debug(`text1: ${text1}, text2: ${text2}`); DualSub.timedtext.body.p[index0]["#"] = ((Position === "Reverse") ? `${text2} ${text1}` : `${text1} ${text2}`).trim(); - //log(`🚧 DualSub.timedtext.body.p[index0]["#"]: ${DualSub.timedtext.body.p[index0]["#"]}`, ""); + //Console.debug(`DualSub.timedtext.body.p[index0]["#"]: ${DualSub.timedtext.body.p[index0]["#"]}`); //DualSub.timedtext.body.p[index0]["@t"] = (Position === "Reverse") ? timeStamp2 : timeStamp1; //DualSub.timedtext.body.p[index0].index = (Position === "Reverse") ? index2 : index1; }; @@ -147,16 +147,16 @@ export default class Composite { }; break; }; - //log(`✅ Composite timedText Subtitles, DualSub内容: ${JSON.stringify(DualSub)}`, ""); - log(`✅ Composite timedText Subtitles`, ""); + //Console.debug(`DualSub内容: ${JSON.stringify(DualSub)}`); + Console.info("✅ Composite timedText Subtitles"); return DualSub; }; webVTT(Sub1 = {}, Sub2 = {}, Offset = this.Offset, Tolerance = this.Tolerance, Position = this.Position) { - log(`☑️ Composite webVTT Subtitles\nOffset:${Offset}, Tolerance:${Tolerance}, Position:${Position}`, ""); + Console.log("☑️ Composite webVTT Subtitles", `Offset: ${Offset}`, `Tolerance: ${Tolerance}`, `Position: ${Position}`); //let DualSub = Position.includes("Reverse") ? Sub2 : Sub1 let DualSub = Sub1; - //log(`🚧 let DualSub内容: ${JSON.stringify(DualSub)}`, ""); + //Console.debug(`let DualSub内容: ${JSON.stringify(DualSub)}`); // 有序数列 用不着排序 //FirstSub.body.sort((x, y) => x - y); //SecondSub.body.sort((x, y) => x - y); @@ -164,19 +164,19 @@ export default class Composite { // 双指针法查找两个数组中的相同元素 const length1 = Sub1?.body?.length, length2 = Sub2?.body?.length; while (index1 < length1 && index2 < length2) { - //log(`🚧 index1/length1: ${index1}/${length1}, index2/length2: ${index2}/${length2}`, ""); + //Console.debug(`index1/length1: ${index1}/${length1}, index2/length2: ${index2}/${length2}`); const timeStamp1 = Sub1.body[index1].timeStamp, timeStamp2 = Sub2.body[index2].timeStamp; - //log(`🚧 timeStamp1: ${timeStamp1}, timeStamp2: ${timeStamp2}`, ""); + //Console.debug(`timeStamp1: ${timeStamp1}, timeStamp2: ${timeStamp2}`); const timeStamp1Next = Sub1.body[index1 + 1]?.timeStamp ?? timeStamp1, timeStamp2Next = Sub2.body[index2 + 1]?.timeStamp ?? timeStamp2; // 处理普通字幕 const text1 = Sub1.body[index1]?.text ?? "", text2 = Sub2.body[index2]?.text ?? ""; - //log(`🚧 text1: ${text1}, text2: ${text2}`, ""); + //Console.debug(`text1: ${text1}, text2: ${text2}`); if (Math.abs(timeStamp1 - timeStamp2) <= Tolerance) { //index0 = (Position === "Reverse") ? index2 : index1; index0 = index1; // 处理普通字幕 DualSub.body[index0].text = ((Position === "Reverse") ? `${text2}\n${text1}` : `${text1}\n${text2}`).trim(); - //log(`🚧 index0: ${index0}, text: ${DualSub.body[index0].text}`, ""); + //Console.debug(`index0: ${index0}, text: ${DualSub.body[index0].text}`); //DualSub.body[index0].timeStamp = (Position === "Reverse") ? timeStamp2 : timeStamp1; //DualSub.body[index0].index = (Position === "Reverse") ? index2 : index1; } @@ -187,17 +187,17 @@ export default class Composite { else { index1++; index2++ }; }; }; - //log(`✅ Composite webVTT Subtitles, DualSub内容: ${JSON.stringify(DualSub)}`, ""); - log(`✅ Composite webVTT Subtitles`, ""); + //Console.debug(`DualSub内容: ${JSON.stringify(DualSub)}`); + Console.info("✅ Composite webVTT Subtitles"); return DualSub; }; spotifyLyric(Lyric1 = [], Lyric2 = [], Offset = this.Offset, Tolerance = this.Tolerance, Position = this.Position) { - log(`☑️ Composite Spotify Lyrics\nOffset:${Offset}, Tolerance:${Tolerance}, Position:${Position}`, ""); + Console.log("☑️ Composite Spotify Lyrics", `Offset: ${Offset}`, `Tolerance: ${Tolerance}`, `Position: ${Position}`); //let Lyric = Position.includes("Reverse") ? Lyric2 : Lyric1 let Lyric = Lyric1; - //log(`🚧 let Lyric: ${JSON.stringify(Lyric)}`, ""); + //Console.debug(`let Lyric: ${JSON.stringify(Lyric)}`); // 有序数列 用不着排序 //FirstSub.body.sort((x, y) => x - y); //SecondSub.body.sort((x, y) => x - y); @@ -205,13 +205,13 @@ export default class Composite { // 双指针法查找两个数组中的相同元素 const length1 = Lyric1?.length, length2 = Lyric2?.length; while (index1 < length1 && index2 < length2) { - //log(`🚧 index1/length1: ${index1}/${length1}, index2/length2: ${index2}/${length2}`, ""); + //Console.debug(`index1/length1: ${index1}/${length1}, index2/length2: ${index2}/${length2}`); const timeStamp1 = Lyric1[index1].startTimeMs, timeStamp2 = Lyric2[index2].startTimeMs + Offset; - //log(`🚧 timeStamp1: ${timeStamp1}, timeStamp2: ${timeStamp2}`, ""); + //Console.debug(`timeStamp1: ${timeStamp1}, timeStamp2: ${timeStamp2}`); const timeStamp1Next = Lyric1[index1 + 1]?.startTimeMs ?? timeStamp1, timeStamp2Next = Lyric2[index2 + 1]?.startTimeMs + this.Offset ?? timeStamp2; // 处理普通字幕 const text1 = Lyric1[index1]?.words ?? "", text2 = Lyric2[index2]?.words ?? ""; - //log(`🚧 text1: ${text1}, text2: ${text2}`, ""); + //Console.debug(`text1: ${text1}, text2: ${text2}`); if (Math.abs(timeStamp1 - timeStamp2) <= Tolerance) { //index0 = (Position === "Reverse") ? index2 : index1; index0 = index1; @@ -219,7 +219,7 @@ export default class Composite { Lyric[index0].words = ((Position === "Reverse") ? `${text2}\n${text1}` : `${text1}\n${text2}`).trim(); Lyric[index0].owords = text1.trim(); Lyric[index0].twords = text2.trim(); - //log(`🚧 index0: ${index0}, words: ${Lyric[index0].words}`, ""); + //Console.debug(`index0: ${index0}, words: ${Lyric[index0].words}`); //Lyric[index0].startTimeMs = (Position === "Reverse") ? timeStamp2 : timeStamp1; //Lyric[index0].index = (Position === "Reverse") ? index2 : index1; } @@ -230,8 +230,8 @@ export default class Composite { else { index1++; index2++ }; }; }; - //log(`✅ Composite Spotify Lyrics, Lyric: ${JSON.stringify(Lyric)}`, ""); - log(`✅ Composite Spotify Lyrics`, ""); + //Console.info(`✅ Composite Spotify Lyrics, Lyric: ${JSON.stringify(Lyric)}`); + Console.info(`✅ Composite Spotify Lyrics`); return Lyric; }; }; diff --git a/src/class/Translate.mjs b/src/class/Translate.mjs index 0d27e36a..9ba18e37 100644 --- a/src/class/Translate.mjs +++ b/src/class/Translate.mjs @@ -1,11 +1,11 @@ -import { fetch, log } from "@nsnanocat/util"; +import { Console, fetch } from "@nsnanocat/util"; import MD5 from 'crypto-js/md5.js'; export default class Translate { constructor(options = {}) { this.Name = "Translate"; this.Version = "1.0.6"; - log(`\n🟧 ${this.Name} v${this.Version}\n`); + Console.log(`🟧 ${this.Name} v${this.Version}`); this.Source = "AUTO"; this.Target = "ZH"; this.API = {}; @@ -260,7 +260,7 @@ export default class Translate { const body = JSON.parse(response.body); return body?.trans_result?.map(item => item?.dst ?? `翻译失败, vendor: ${"BaiduFanyi"}`); }) - .catch(error => Promise.reject(log(error))); + .catch(error => Promise.reject(Console.error(error))); }; async YoudaoAI(text = [], source = this.Source, target = this.Target, api = this.API) { diff --git a/src/function/constructSubtitlesQueue.mjs b/src/function/constructSubtitlesQueue.mjs index d5f01eb3..e4d769ac 100644 --- a/src/function/constructSubtitlesQueue.mjs +++ b/src/function/constructSubtitlesQueue.mjs @@ -1,4 +1,4 @@ -import { log } from "@nsnanocat/util"; +import { Console } from "@nsnanocat/util"; /** * Construct Subtitles Queue @@ -9,19 +9,19 @@ import { log } from "@nsnanocat/util"; * @return {Array<*>} Subtitles Requests Queue */ export default function constructSubtitlesQueue(request, fileName, VTTs1 = [], VTTs2 = []) { - log(`☑️ Construct Subtitles Queue, fileName: ${fileName}`, ""); + Console.log("☑️ Construct Subtitles Queue", `fileName: ${fileName}`); const requests = []; - log(`🚧 Construct Subtitles Queue, VTTs1.length: ${VTTs1.length}, VTTs2.length: ${VTTs2.length}`, "") - //log(`🚧 Construct Subtitles Queue, VTTs1: ${JSON.stringify(VTTs1)}, VTTs2.length: ${JSON.stringify(VTTs2)}`, "") + Console.debug(`VTTs1.length: ${VTTs1.length}`, `VTTs2.length: ${VTTs2.length}`); + //Console.debug(`VTTs1: ${JSON.stringify(VTTs1)}`, `VTTs2.length: ${JSON.stringify(VTTs2)}`); // 查询当前字幕在原字幕队列中的位置 const Index1 = VTTs1.findIndex(item => item?.includes(fileName)); - log(`🚧 Construct Subtitles Queue, Index1: ${Index1}`, ""); + Console.debug(`Index1: ${Index1}`); switch (VTTs2.length) { case 0: // 长度为0,无须计算 - log("⚠ Construct Subtitles Queue, 长度为 0", "") + Console.info("长度为 0"); break; case 1: { // 长度为1,无须计算 - log("⚠ Construct Subtitles Queue, 长度为 1", "") + log("长度为 1"); const request2 = { "url": VTTs2[0], "headers": request.headers @@ -30,7 +30,7 @@ export default function constructSubtitlesQueue(request, fileName, VTTs1 = [], V break; } case VTTs1.length: { // 长度相等,一一对应,无须计算 - log("⚠ Construct Subtitles Queue, 长度相等", "") + Console.info("长度相等"); const request2 = { "url": VTTs2[Index1], "headers": request.headers @@ -39,24 +39,24 @@ export default function constructSubtitlesQueue(request, fileName, VTTs1 = [], V break; } default: { // 长度不等,需要计算 - log("⚠ Construct Subtitles Queue, 长度不等,需要计算", "") + Console.info("长度不等,需要计算"); // 计算当前字幕在原字幕队列中的百分比 const Position1 = (Index1 + 1) / VTTs1.length; // 从 0 开始计数,所以要加 1 - log(`🚧 Construct Subtitles Queue, Position1: ${Position1}, Index2: ${Index1}/${VTTs1.length}`, ""); + Console.debug(`Position1: ${Position1}`, `Index2: ${Index1}/${VTTs1.length}`); // 根据百分比计算当前字幕在新字幕队列中的位置 //let Index2 = VTTs2.findIndex(item => item.includes(fileName)); const Index2 = Math.round(Position1 * VTTs2.length - 1); // 从 0 开始计数,所以要减 1 - log(`🚧 Construct Subtitles Queue, Position2: ${Position1}, Index2: ${Index2}/${VTTs2.length}`, ""); + Console.debug(`Position2: ${Position1}`, `Index2: ${Index2}/${VTTs2.length}`); // 获取两字幕队列长度差值 const diffLength = Math.abs(VTTs2.length - VTTs1.length); // 获取当前字幕在新字幕队列中的前后1个字幕 //const BeginIndex = (Index2 - 1 < 0) ? 0 : Index2 - 1, EndIndex = Index2 + 1; const BeginIndex = Math.min(Index1, Index2); const EndIndex = Math.max(Index1, Index2); - log(`🚧 Construct Subtitles Queue, diffLength: ${diffLength}, BeginIndex: ${BeginIndex}, EndIndex: ${EndIndex}`, ""); + Console.debug(`diffLength: ${diffLength}`, `BeginIndex: ${BeginIndex}`, `EndIndex: ${EndIndex}`); const nearlyVTTs = VTTs2.slice(Math.max(0, BeginIndex - diffLength), Math.max(EndIndex, EndIndex + diffLength) + 1) // slice 不取 EndIndex 本身 //const nearlyVTTs = VTTs2.slice(BeginIndex, EndIndex + 1); // slice 不取 EndIndex 本身 - log(`🚧 Construct Subtitles Queue, nearlyVTTs: ${JSON.stringify(nearlyVTTs)}`, ""); + Console.debug(`nearlyVTTs: ${JSON.stringify(nearlyVTTs)}`); nearlyVTTs.forEach(url => { const request2 = { "url": url, @@ -76,7 +76,7 @@ export default function constructSubtitlesQueue(request, fileName, VTTs1 = [], V break; } }; - //log(`🚧 Construct Subtitles Queue, requests: ${JSON.stringify(requests)}`, ""); - log("✅ Construct Subtitles Queue", ""); + //Console.debug(`requests: ${JSON.stringify(requests)}`); + Console.log("✅ Construct Subtitles Queue"); return requests; }; diff --git a/src/function/detectFormat.mjs b/src/function/detectFormat.mjs index a9d883f2..68cbf897 100644 --- a/src/function/detectFormat.mjs +++ b/src/function/detectFormat.mjs @@ -1,4 +1,4 @@ -import { log } from "@nsnanocat/util"; +import { Console } from "@nsnanocat/util"; /** * detect Format @@ -8,7 +8,7 @@ import { log } from "@nsnanocat/util"; * @return {String} format - format */ export default function detectFormat(url, body, format = undefined) { - log(`☑️ detectFormat, format: ${url.format || url.searchParams.get("fmt") || url.searchParams.get("format")}`, ""); + Console.log("☑️ detectFormat", `format: ${url.format || url.searchParams.get("fmt") || url.searchParams.get("format")}`); switch (url.format || url.searchParams.get("fmt") || url.searchParams.get("format")) { case "txt": format = "text/plain"; @@ -37,8 +37,8 @@ export default function detectFormat(url, body, format = undefined) { break; case undefined: const HEADER = body?.substring?.(0, 6).trim?.(); - //log(`🚧 detectFormat, HEADER: ${HEADER}`, ""); - //log(`🚧 detectFormat, HEADER?.substring?.(0, 1): ${HEADER?.substring?.(0, 1)}`, ""); + //Console.debug(`HEADER: ${HEADER}`); + //Console.debug(`HEADER?.substring?.(0, 1): ${HEADER?.substring?.(0, 1)}`); switch (HEADER) { case " { switch (item.TAG) { @@ -24,6 +24,6 @@ export default function detectPlaylist(m3u8 = {}) { break; }; }); - log(`✅ detectPlaylist, type: ${type}`, ""); + Console.log("✅ detectPlaylist", `type: ${type}`); return type; }; diff --git a/src/function/isStandard.mjs b/src/function/isStandard.mjs index e4f56b59..cba609cc 100644 --- a/src/function/isStandard.mjs +++ b/src/function/isStandard.mjs @@ -1,5 +1,4 @@ - -import { log } from "@nsnanocat/util"; +import { Console } from "@nsnanocat/util"; /** * is Standard? @@ -11,10 +10,10 @@ import { log } from "@nsnanocat/util"; * @return {Promise<*>} */ export default function isStandard(url = new URL(), headers = {}, platform = "Universal") { - log("☑️ is Standard?", ""); + Console.log("☑️ is Standard?"); // 判断设备类型 const UA = headers["user-agent"] ?? headers["User-Agent"]; - log(`🚧 is Standard?, UA: ${UA}`, ""); + Console.debug(`is Standard?, UA: ${UA}`); let device = UA.includes("Mozilla/5.0") ? "Web" : UA.includes("iPhone") ? "iPhone" : UA.includes("iPad") ? "iPad" @@ -74,6 +73,6 @@ export default function isStandard(url = new URL(), headers = {}, platform = "Un standard = true; break; }; - log(`✅ is Standard?, standard: ${standard}, device: ${device}`, ""); + Console.log("✅ is Standard?", `standard: ${standard}`, `device: ${device}`); return {standard, device}; }; diff --git a/src/function/setCache.mjs b/src/function/setCache.mjs index 87743cce..0db48880 100644 --- a/src/function/setCache.mjs +++ b/src/function/setCache.mjs @@ -1,4 +1,4 @@ -import { log } from "@nsnanocat/util"; +import { Console } from "@nsnanocat/util"; /** * Set Cache @@ -8,9 +8,9 @@ import { log } from "@nsnanocat/util"; * @return {Boolean} isSaved */ export default function setCache(cache, cacheSize = 100) { - log(`☑️ Set Cache, cacheSize: ${cacheSize}`, ""); + Console.log("☑️ Set Cache", `cacheSize: ${cacheSize}`); cache = Array.from(cache || []); // Map转Array cache = cache.slice(-cacheSize); // 限制缓存大小 - log("✅ Set Cache", ""); + Console.log("✅ Set Cache"); return cache; }; diff --git a/src/function/setENV.mjs b/src/function/setENV.mjs index e778170a..ea507a3e 100644 --- a/src/function/setENV.mjs +++ b/src/function/setENV.mjs @@ -1,4 +1,4 @@ -import { Lodash as _, getStorage, log } from '@nsnanocat/util' +import { Console, getStorage, Lodash as _ } from "@nsnanocat/util"; /** * Set Environment Variables @@ -9,13 +9,13 @@ import { Lodash as _, getStorage, log } from '@nsnanocat/util' * @return {Object} { Settings, Caches, Configs } */ export default function setENV(name, platforms, database) { - log("☑️ Set Environment Variables", ""); + Console.log("☑️ Set Environment Variables"); const { Settings, Caches, Configs } = getStorage(name, platforms, database); /***************** Settings *****************/ if (!Array.isArray(Settings?.Types)) Settings.Types = (Settings.Types) ? [Settings.Types] : []; // 只有一个选项时,无逗号分隔 - log(`✅ Set Environment Variables, Settings: ${typeof Settings}, Settings内容: ${JSON.stringify(Settings)}`, ""); + Console.debug(`typeof Settings: ${typeof Settings}`, `Settings: ${JSON.stringify(Settings)}`); /***************** Caches *****************/ - //log(`✅ Set Environment Variables, Caches: ${typeof Caches}, Caches内容: ${JSON.stringify(Caches)}`, ""); + //Console.debug(`typeof Caches: ${typeof Caches}`, `Caches: ${JSON.stringify(Caches)}`); if (typeof Caches?.Playlists !== "object" || Array.isArray(Caches?.Playlists)) Caches.Playlists = {}; // 创建Playlists缓存 Caches.Playlists.Master = new Map(JSON.parse(Caches?.Playlists?.Master || "[]")); // Strings转Array转Map Caches.Playlists.Subtitle = new Map(JSON.parse(Caches?.Playlists?.Subtitle || "[]")); // Strings转Array转Map @@ -23,5 +23,6 @@ export default function setENV(name, platforms, database) { if (typeof Caches?.Metadatas !== "object" || Array.isArray(Caches?.Metadatas)) Caches.Metadatas = {}; // 创建Playlists缓存 if (typeof Caches?.Metadatas?.Tracks !== "object") Caches.Metadatas.Tracks = new Map(JSON.parse(Caches?.Metadatas?.Tracks || "[]")); // Strings转Array转Map /***************** Configs *****************/ + Console.log("✅ Set Environment Variables"); return { Settings, Caches, Configs }; }; diff --git a/src/function/setOption.mjs b/src/function/setOption.mjs index 41e6387e..9da687a4 100644 --- a/src/function/setOption.mjs +++ b/src/function/setOption.mjs @@ -1,4 +1,4 @@ -import { log } from "@nsnanocat/util"; +import { Console } from "@nsnanocat/util"; /** * Set DualSubs Subtitle Options @@ -13,7 +13,7 @@ import { log } from "@nsnanocat/util"; * @return {Promise<*>} */ export default function setOption(playlist1 = {}, playlist2 = {}, type = "", platform = "", standard = true, device = "iPhone") { - log(`☑️ Set DualSubs Subtitle Option, type: ${type}`, ""); + Console.log("☑️ Set DualSubs Subtitle Option", `type: ${type}`); const NAME1 = playlist1?.OPTION?.NAME.trim(), NAME2 = playlist2?.OPTION?.NAME.trim(); const LANGUAGE1 = playlist1?.OPTION?.LANGUAGE.trim(), LANGUAGE2 = playlist2?.OPTION?.LANGUAGE.trim(); // 复制此语言选项 @@ -86,6 +86,6 @@ export default function setOption(playlist1 = {}, playlist2 = {}, type = "", pla newOption.OPTION.AUTOSELECT = "YES"; // 兼容性修正 if (!standard) newOption.OPTION.DEFAULT = "YES"; - log(`✅ Set DualSubs Subtitle Option, newOption: ${JSON.stringify(newOption)}`, ""); + Console.log("✅ Set DualSubs Subtitle Option", `newOption: ${JSON.stringify(newOption)}`); return newOption; };