Skip to content

Commit

Permalink
build: @nsnanocat/url
Browse files Browse the repository at this point in the history
  • Loading branch information
VirgilClyne committed Nov 10, 2024
1 parent 73fb814 commit d56a2e2
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
### 🔣 Dependencies
* 升级了 `@nsnanocat/util`
* `$platform` 改为 `$app`
* 增加了 `@nsnanocat/url`
* 使用了全新的 `URL``URLSearchParams` polyfill

### 🔄 Other Changes
Expand Down
11 changes: 9 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dualsubs/universal",
"version": "1.6.4",
"version": "1.6.5",
"organizationName": "🍿️ DualSubs",
"displayName": "🍿️ DualSubs: 🔣 Universal",
"description": "流媒体平台字幕增强及双语模块\n如需恢复TV完整支持\n请配合“ iRingo: 📺 TV”使用",
Expand Down Expand Up @@ -46,6 +46,7 @@
"node-polyfill-webpack-plugin": "^4.0.0"
},
"dependencies": {
"@nsnanocat/url": "^1.0.1",
"@nsnanocat/util": "^1.4.7",
"crypto-js": "^4.2.0",
"text-encoding": "^0.7.0"
Expand Down
3 changes: 2 additions & 1 deletion src/Composite.Subtitles.response.dev.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { $app, URL, Lodash as _, Storage, fetch, notification, log, logError, wait, done, getScript, runScript } from "@nsnanocat/util";
import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util";
import { URL } from "@nsnanocat/url";
import XML from "./XML/XML.mjs";
import VTT from "./WebVTT/WebVTT.mjs";
import database from "./database/index.mjs";
Expand Down
3 changes: 2 additions & 1 deletion src/Composite.Subtitles.response.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { $app, URL, Lodash as _, Storage, fetch, notification, log, logError, wait, done, getScript, runScript } from "@nsnanocat/util";
import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util";
import { URL } from "@nsnanocat/url";
import XML from "./XML/XML.mjs";
import VTT from "./WebVTT/WebVTT.mjs";
import database from "./database/index.mjs";
Expand Down
1 change: 1 addition & 0 deletions src/External.Lyrics.response.dev.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util";
import { URL } from "@nsnanocat/url";
import LRC from "./LRC/LRC.mjs";
import database from "./database/index.mjs";
import setENV from "./function/setENV.mjs";
Expand Down
1 change: 1 addition & 0 deletions src/External.Lyrics.response.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util";
import { URL } from "@nsnanocat/url";
import LRC from "./LRC/LRC.mjs";
import database from "./database/index.mjs";
import setENV from "./function/setENV.mjs";
Expand Down
39 changes: 22 additions & 17 deletions src/External.Subtitles.response.dev.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { $app, URL, Lodash as _, Storage, fetch, notification, log, logError, wait, done, getScript, runScript } from "@nsnanocat/util";
import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util";
import { URL } from "@nsnanocat/url";
import XML from "./XML/XML.mjs";
import VTT from "./WebVTT/WebVTT.mjs";
import database from "./database/index.mjs";
Expand All @@ -11,8 +12,11 @@ import Composite from "./function/Composite.mjs";
const url = new URL($request.url);
log(`⚠ 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}` , "");
const METHOD = $request.method,
HOST = url.hostname,
PATH = url.pathname,
PATHs = url.pathname.split("/").filter(Boolean);
log(`⚠ 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);
Expand All @@ -25,13 +29,14 @@ log(`⚠ FORMAT: ${FORMAT}`, "");
* 设置
* @type {{Settings: import('./types').Settings}}
*/
const { Settings, Caches, Configs } = setENV("DualSubs", [(["YouTube", "Netflix", "BiliBili", "Spotify"].includes(PLATFORM)) ? PLATFORM : "Universal", "External", "API"], database);
const { Settings, Caches, Configs } = setENV("DualSubs", [["YouTube", "Netflix", "BiliBili", "Spotify"].includes(PLATFORM) ? PLATFORM : "Universal", "External", "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]];
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 = {};
Expand All @@ -49,18 +54,18 @@ log(`⚠ FORMAT: ${FORMAT}`, "");
switch (Settings.SubVendor) {
case "URL":
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"
}
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",
},
};
break;
};
}
break;
};
}
// 创建字幕Object
let externalSubtitle = await fetch(request).then(response => response.body);;
let externalSubtitle = await fetch(request).then(response => response.body);
// 格式判断
switch (FORMAT) {
case undefined: // 视为无body
Expand Down Expand Up @@ -124,11 +129,11 @@ log(`⚠ FORMAT: ${FORMAT}`, "");
//log(`🚧 rawBody: ${JSON.stringify(rawBody)}`, "");
//$response.body = rawBody;
break;
};
}
break;
case false:
break;
};
}
})()
.catch((e) => logError(e))
.finally(() => done($response))
.catch(e => logError(e))
.finally(() => done($response));
3 changes: 2 additions & 1 deletion src/Manifest.response.dev.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { $app, URL, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util";
import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util";
import { URL } from "@nsnanocat/url";
import M3U8 from "./EXTM3U/EXTM3U.mjs";
import AttrList from "./class/AttrList.mjs";
import database from "./database/index.mjs";
Expand Down
3 changes: 2 additions & 1 deletion src/Manifest.response.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { $app, URL, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util";
import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util";
import { URL } from "@nsnanocat/url";
import M3U8 from "./EXTM3U/EXTM3U.mjs";
import AttrList from "./class/AttrList.mjs";
import database from "./database/index.mjs";
Expand Down
3 changes: 2 additions & 1 deletion src/Translate.response.dev.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { $app, URL, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util";
import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util";
import { URL } from "@nsnanocat/url";
import XML from "./XML/XML.mjs";
import VTT from "./WebVTT/WebVTT.mjs";
import database from "./database/index.mjs";
Expand Down
3 changes: 2 additions & 1 deletion src/Translate.response.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { $app, URL, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util";
import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util";
import { URL } from "@nsnanocat/url";
import XML from "./XML/XML.mjs";
import VTT from "./WebVTT/WebVTT.mjs";
import database from "./database/index.mjs";
Expand Down

0 comments on commit d56a2e2

Please sign in to comment.