wyzie-lib 2.1.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/main.d.ts +35 -0
- package/lib/main.js +84 -0
- package/lib/main.umd.cjs +88 -0
- package/package.json +21 -17
- package/dist/wyzie-lib.cjs.js +0 -12
- package/dist/wyzie-lib.es.js +0 -77
- package/dist/wyzie-lib.iife.js +0 -12
- package/dist/wyzie-lib.umd.js +0 -12
package/lib/main.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare function parseToVTT(subtitleUrl: string): Promise<string>;
|
|
2
|
+
|
|
3
|
+
export declare interface QueryParams {
|
|
4
|
+
id: string;
|
|
5
|
+
season?: number;
|
|
6
|
+
episode?: number;
|
|
7
|
+
language?: string;
|
|
8
|
+
format?: string;
|
|
9
|
+
hi?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export declare function searchSubtitles(params: SearchSubtitlesParams): Promise<SubtitleData[]>;
|
|
13
|
+
|
|
14
|
+
export declare interface SearchSubtitlesParams {
|
|
15
|
+
tmdb_id?: number;
|
|
16
|
+
imdb_id?: number;
|
|
17
|
+
season?: number;
|
|
18
|
+
episode?: number;
|
|
19
|
+
language?: string;
|
|
20
|
+
format?: string;
|
|
21
|
+
hi?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export declare type SubtitleData = {
|
|
25
|
+
id: string;
|
|
26
|
+
url: string;
|
|
27
|
+
format: string;
|
|
28
|
+
isHearingImpaired: boolean;
|
|
29
|
+
flagUrl: string;
|
|
30
|
+
media: string;
|
|
31
|
+
display: string;
|
|
32
|
+
language: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { }
|
package/lib/main.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
async function constructUrl({
|
|
2
|
+
tmdb_id,
|
|
3
|
+
imdb_id,
|
|
4
|
+
season,
|
|
5
|
+
episode,
|
|
6
|
+
language,
|
|
7
|
+
format,
|
|
8
|
+
hi
|
|
9
|
+
}) {
|
|
10
|
+
const url = new URL("https://sub.wyzie.ru/search");
|
|
11
|
+
const queryParams = {
|
|
12
|
+
id: String(tmdb_id || imdb_id),
|
|
13
|
+
season,
|
|
14
|
+
episode,
|
|
15
|
+
language,
|
|
16
|
+
format,
|
|
17
|
+
hi
|
|
18
|
+
};
|
|
19
|
+
Object.entries(queryParams).forEach(([key, value]) => {
|
|
20
|
+
if (value !== void 0) {
|
|
21
|
+
url.searchParams.append(key, value);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return url;
|
|
25
|
+
}
|
|
26
|
+
async function fetchSubtitles(url) {
|
|
27
|
+
const response = await fetch(url.toString());
|
|
28
|
+
if (!response.ok) {
|
|
29
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
30
|
+
}
|
|
31
|
+
return response.json();
|
|
32
|
+
}
|
|
33
|
+
async function searchSubtitles(params) {
|
|
34
|
+
try {
|
|
35
|
+
const url = await constructUrl(params);
|
|
36
|
+
return await fetchSubtitles(url);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
throw new Error(`Error fetching subtitles: ${error}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function parseToVTT(subtitleUrl) {
|
|
42
|
+
try {
|
|
43
|
+
const response = await fetch(subtitleUrl);
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
throw new Error(`Failed to fetch subtitle content: ${response.status}`);
|
|
46
|
+
}
|
|
47
|
+
const content = await response.text();
|
|
48
|
+
const normalizedContent = content.replace(/\r\n|\r/g, "\n").trim();
|
|
49
|
+
const blocks = normalizedContent.split(/\n\n+/);
|
|
50
|
+
const timestampRegex = /^\d{1,2}:\d{2}:\d{2}[,.]\d{3}\s*-->\s*\d{1,2}:\d{2}:\d{2}[,.]\d{3}$/;
|
|
51
|
+
const hasValidSRTFormat = blocks.some((block) => {
|
|
52
|
+
const lines = block.split("\n").map((line) => line.trim());
|
|
53
|
+
return lines.some((line) => timestampRegex.test(line));
|
|
54
|
+
});
|
|
55
|
+
if (!hasValidSRTFormat) {
|
|
56
|
+
throw new Error("Invalid subtitle format: not SRT");
|
|
57
|
+
}
|
|
58
|
+
const vttLines = ["WEBVTT", ""];
|
|
59
|
+
for (const block of blocks) {
|
|
60
|
+
const lines = block.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
|
|
61
|
+
if (lines.length < 2)
|
|
62
|
+
continue;
|
|
63
|
+
const timestampIndex = lines.findIndex((line) => timestampRegex.test(line));
|
|
64
|
+
if (timestampIndex === -1)
|
|
65
|
+
continue;
|
|
66
|
+
const textLines = lines.slice(timestampIndex + 1).filter((line) => !/^\d+$/.test(line));
|
|
67
|
+
if (textLines.length === 0)
|
|
68
|
+
continue;
|
|
69
|
+
let timestampLine = lines[timestampIndex];
|
|
70
|
+
timestampLine = timestampLine.replace(/[,.](?=\s*-->)/, "").replace(/[,.]$/, "").replace(/,(\d{3})/g, ".$1");
|
|
71
|
+
vttLines.push(`${timestampLine}
|
|
72
|
+
${textLines.join("\n")}
|
|
73
|
+
`);
|
|
74
|
+
}
|
|
75
|
+
return vttLines.join("\n").replace(/\n{3,}/g, "\n\n").trim() + "\n\n";
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.error("Error in parseToVTT:", error);
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
parseToVTT,
|
|
83
|
+
searchSubtitles
|
|
84
|
+
};
|
package/lib/main.umd.cjs
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
(function(global, factory) {
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.main = {}));
|
|
3
|
+
})(this, function(exports2) {
|
|
4
|
+
"use strict";
|
|
5
|
+
async function constructUrl({
|
|
6
|
+
tmdb_id,
|
|
7
|
+
imdb_id,
|
|
8
|
+
season,
|
|
9
|
+
episode,
|
|
10
|
+
language,
|
|
11
|
+
format,
|
|
12
|
+
hi
|
|
13
|
+
}) {
|
|
14
|
+
const url = new URL("https://sub.wyzie.ru/search");
|
|
15
|
+
const queryParams = {
|
|
16
|
+
id: String(tmdb_id || imdb_id),
|
|
17
|
+
season,
|
|
18
|
+
episode,
|
|
19
|
+
language,
|
|
20
|
+
format,
|
|
21
|
+
hi
|
|
22
|
+
};
|
|
23
|
+
Object.entries(queryParams).forEach(([key, value]) => {
|
|
24
|
+
if (value !== void 0) {
|
|
25
|
+
url.searchParams.append(key, value);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return url;
|
|
29
|
+
}
|
|
30
|
+
async function fetchSubtitles(url) {
|
|
31
|
+
const response = await fetch(url.toString());
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
34
|
+
}
|
|
35
|
+
return response.json();
|
|
36
|
+
}
|
|
37
|
+
async function searchSubtitles(params) {
|
|
38
|
+
try {
|
|
39
|
+
const url = await constructUrl(params);
|
|
40
|
+
return await fetchSubtitles(url);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
throw new Error(`Error fetching subtitles: ${error}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function parseToVTT(subtitleUrl) {
|
|
46
|
+
try {
|
|
47
|
+
const response = await fetch(subtitleUrl);
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
throw new Error(`Failed to fetch subtitle content: ${response.status}`);
|
|
50
|
+
}
|
|
51
|
+
const content = await response.text();
|
|
52
|
+
const normalizedContent = content.replace(/\r\n|\r/g, "\n").trim();
|
|
53
|
+
const blocks = normalizedContent.split(/\n\n+/);
|
|
54
|
+
const timestampRegex = /^\d{1,2}:\d{2}:\d{2}[,.]\d{3}\s*-->\s*\d{1,2}:\d{2}:\d{2}[,.]\d{3}$/;
|
|
55
|
+
const hasValidSRTFormat = blocks.some((block) => {
|
|
56
|
+
const lines = block.split("\n").map((line) => line.trim());
|
|
57
|
+
return lines.some((line) => timestampRegex.test(line));
|
|
58
|
+
});
|
|
59
|
+
if (!hasValidSRTFormat) {
|
|
60
|
+
throw new Error("Invalid subtitle format: not SRT");
|
|
61
|
+
}
|
|
62
|
+
const vttLines = ["WEBVTT", ""];
|
|
63
|
+
for (const block of blocks) {
|
|
64
|
+
const lines = block.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
|
|
65
|
+
if (lines.length < 2)
|
|
66
|
+
continue;
|
|
67
|
+
const timestampIndex = lines.findIndex((line) => timestampRegex.test(line));
|
|
68
|
+
if (timestampIndex === -1)
|
|
69
|
+
continue;
|
|
70
|
+
const textLines = lines.slice(timestampIndex + 1).filter((line) => !/^\d+$/.test(line));
|
|
71
|
+
if (textLines.length === 0)
|
|
72
|
+
continue;
|
|
73
|
+
let timestampLine = lines[timestampIndex];
|
|
74
|
+
timestampLine = timestampLine.replace(/[,.](?=\s*-->)/, "").replace(/[,.]$/, "").replace(/,(\d{3})/g, ".$1");
|
|
75
|
+
vttLines.push(`${timestampLine}
|
|
76
|
+
${textLines.join("\n")}
|
|
77
|
+
`);
|
|
78
|
+
}
|
|
79
|
+
return vttLines.join("\n").replace(/\n{3,}/g, "\n\n").trim() + "\n\n";
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error("Error in parseToVTT:", error);
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports2.parseToVTT = parseToVTT;
|
|
86
|
+
exports2.searchSubtitles = searchSubtitles;
|
|
87
|
+
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
88
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wyzie-lib",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"icon": "https://i.postimg.cc/L5ppKYC5/cclogo.png",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -15,36 +15,40 @@
|
|
|
15
15
|
"scraper",
|
|
16
16
|
"subtitle scraper"
|
|
17
17
|
],
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
18
|
+
"type": "module",
|
|
19
|
+
"main": "./lib/main.js",
|
|
20
|
+
"types": "./lib/main.d.ts",
|
|
21
21
|
"files": [
|
|
22
|
-
"
|
|
22
|
+
"./lib"
|
|
23
23
|
],
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|
|
26
|
-
"import":
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
"import": {
|
|
27
|
+
"types": "./lib/main.d.ts",
|
|
28
|
+
"default": "./lib/main.js"
|
|
29
|
+
},
|
|
30
|
+
"require": {
|
|
31
|
+
"types": "./lib/main.d.ts",
|
|
32
|
+
"default": "./lib/main.umd.cjs"
|
|
33
|
+
}
|
|
29
34
|
}
|
|
30
35
|
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/itzcozi/wyzie-lib.git"
|
|
39
|
+
},
|
|
31
40
|
"devDependencies": {
|
|
32
|
-
"@eslint/js": "^9.17.0",
|
|
33
|
-
"eslint": "^9.17.0",
|
|
34
|
-
"eslint-config-prettier": "^9.1.0",
|
|
35
|
-
"eslint-plugin-import": "^2.31.0",
|
|
36
|
-
"eslint-plugin-prettier": "^5.2.1",
|
|
37
41
|
"globals": "^15.14.0",
|
|
38
42
|
"prettier": "^3.4.2",
|
|
39
43
|
"typescript": "^5.7.2",
|
|
40
|
-
"
|
|
41
|
-
"vite": "^4.
|
|
44
|
+
"vite": "^4.5.5",
|
|
45
|
+
"vite-plugin-dts": "^4.4.0",
|
|
46
|
+
"vitest": "^2.1.8"
|
|
42
47
|
},
|
|
43
48
|
"scripts": {
|
|
44
49
|
"dev": "vite",
|
|
45
50
|
"build": "vite build && tsc",
|
|
46
|
-
"
|
|
47
|
-
"lint:fix": "eslint --fix src",
|
|
51
|
+
"test": "npx vitest",
|
|
48
52
|
"format": "prettier --log-level warn --write \"{src/**/*.{ts,js,html,css},*.{ts,js,html,css,json,md,xml}}\"",
|
|
49
53
|
"preview": "vite preview"
|
|
50
54
|
}
|
package/dist/wyzie-lib.cjs.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});async function p({tmdb_id:e,imdb_id:t,season:u,episode:d,language:c,format:a,hi:f}){const o=new URL("https://sub.wyzie.ru/search"),i={id:String(e||t),season:u,episode:d,language:c,format:a,hi:f};return Object.entries(i).forEach(([r,n])=>{n!==void 0&&o.searchParams.append(r,n)}),o}async function m(e){const t=await fetch(e.toString());if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);return t.json()}async function T(e){try{const t=await p(e);return await m(t)}catch(t){throw new Error(`Error fetching subtitles: ${t}`)}}async function w(e){try{const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch subtitle content: ${t.status}`);const c=(await t.text()).replace(/\r\n|\r/g,`
|
|
2
|
-
`).trim().split(/\n\n+/),a=/^\d{1,2}:\d{2}:\d{2}[,.]\d{3}\s*-->\s*\d{1,2}:\d{2}:\d{2}[,.]\d{3}$/;if(!c.some(i=>i.split(`
|
|
3
|
-
`).map(n=>n.trim()).some(n=>a.test(n))))throw new Error("Invalid subtitle format: not SRT");const o=["WEBVTT",""];for(const i of c){const r=i.split(`
|
|
4
|
-
`).map(s=>s.trim()).filter(s=>s.length>0);if(r.length<2)continue;const n=r.findIndex(s=>a.test(s));if(n===-1)continue;const h=r.slice(n+1).filter(s=>!/^\d+$/.test(s));if(h.length===0)continue;let l=r[n];l=l.replace(/[,.](?=\s*-->)/,"").replace(/[,.]$/,"").replace(/,(\d{3})/g,".$1"),o.push(`${l}
|
|
5
|
-
${h.join(`
|
|
6
|
-
`)}
|
|
7
|
-
`)}return o.join(`
|
|
8
|
-
`).replace(/\n{3,}/g,`
|
|
9
|
-
|
|
10
|
-
`).trim()+`
|
|
11
|
-
|
|
12
|
-
`}catch(t){throw console.error("Error in parseToVTT:",t),t}}exports.parseToVTT=w;exports.searchSubtitles=T;
|
package/dist/wyzie-lib.es.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
async function p({
|
|
2
|
-
tmdb_id: e,
|
|
3
|
-
imdb_id: t,
|
|
4
|
-
season: u,
|
|
5
|
-
episode: f,
|
|
6
|
-
language: c,
|
|
7
|
-
format: a,
|
|
8
|
-
hi: h
|
|
9
|
-
}) {
|
|
10
|
-
const o = new URL("https://sub.wyzie.ru/search"), i = {
|
|
11
|
-
id: String(e || t),
|
|
12
|
-
season: u,
|
|
13
|
-
episode: f,
|
|
14
|
-
language: c,
|
|
15
|
-
format: a,
|
|
16
|
-
hi: h
|
|
17
|
-
};
|
|
18
|
-
return Object.entries(i).forEach(([r, n]) => {
|
|
19
|
-
n !== void 0 && o.searchParams.append(r, n);
|
|
20
|
-
}), o;
|
|
21
|
-
}
|
|
22
|
-
async function m(e) {
|
|
23
|
-
const t = await fetch(e.toString());
|
|
24
|
-
if (!t.ok)
|
|
25
|
-
throw new Error(`HTTP error! status: ${t.status}`);
|
|
26
|
-
return t.json();
|
|
27
|
-
}
|
|
28
|
-
async function w(e) {
|
|
29
|
-
try {
|
|
30
|
-
const t = await p(e);
|
|
31
|
-
return await m(t);
|
|
32
|
-
} catch (t) {
|
|
33
|
-
throw new Error(`Error fetching subtitles: ${t}`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
async function T(e) {
|
|
37
|
-
try {
|
|
38
|
-
const t = await fetch(e);
|
|
39
|
-
if (!t.ok)
|
|
40
|
-
throw new Error(`Failed to fetch subtitle content: ${t.status}`);
|
|
41
|
-
const c = (await t.text()).replace(/\r\n|\r/g, `
|
|
42
|
-
`).trim().split(/\n\n+/), a = /^\d{1,2}:\d{2}:\d{2}[,.]\d{3}\s*-->\s*\d{1,2}:\d{2}:\d{2}[,.]\d{3}$/;
|
|
43
|
-
if (!c.some((i) => i.split(`
|
|
44
|
-
`).map((n) => n.trim()).some((n) => a.test(n))))
|
|
45
|
-
throw new Error("Invalid subtitle format: not SRT");
|
|
46
|
-
const o = ["WEBVTT", ""];
|
|
47
|
-
for (const i of c) {
|
|
48
|
-
const r = i.split(`
|
|
49
|
-
`).map((s) => s.trim()).filter((s) => s.length > 0);
|
|
50
|
-
if (r.length < 2)
|
|
51
|
-
continue;
|
|
52
|
-
const n = r.findIndex((s) => a.test(s));
|
|
53
|
-
if (n === -1)
|
|
54
|
-
continue;
|
|
55
|
-
const d = r.slice(n + 1).filter((s) => !/^\d+$/.test(s));
|
|
56
|
-
if (d.length === 0)
|
|
57
|
-
continue;
|
|
58
|
-
let l = r[n];
|
|
59
|
-
l = l.replace(/[,.](?=\s*-->)/, "").replace(/[,.]$/, "").replace(/,(\d{3})/g, ".$1"), o.push(`${l}
|
|
60
|
-
${d.join(`
|
|
61
|
-
`)}
|
|
62
|
-
`);
|
|
63
|
-
}
|
|
64
|
-
return o.join(`
|
|
65
|
-
`).replace(/\n{3,}/g, `
|
|
66
|
-
|
|
67
|
-
`).trim() + `
|
|
68
|
-
|
|
69
|
-
`;
|
|
70
|
-
} catch (t) {
|
|
71
|
-
throw console.error("Error in parseToVTT:", t), t;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
export {
|
|
75
|
-
T as parseToVTT,
|
|
76
|
-
w as searchSubtitles
|
|
77
|
-
};
|
package/dist/wyzie-lib.iife.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
var WyzieLib=function(c){"use strict";async function p({tmdb_id:e,imdb_id:t,season:f,episode:d,language:a,format:l,hi:h}){const o=new URL("https://sub.wyzie.ru/search"),i={id:String(e||t),season:f,episode:d,language:a,format:l,hi:h};return Object.entries(i).forEach(([r,n])=>{n!==void 0&&o.searchParams.append(r,n)}),o}async function T(e){const t=await fetch(e.toString());if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);return t.json()}async function w(e){try{const t=await p(e);return await T(t)}catch(t){throw new Error(`Error fetching subtitles: ${t}`)}}async function b(e){try{const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch subtitle content: ${t.status}`);const a=(await t.text()).replace(/\r\n|\r/g,`
|
|
2
|
-
`).trim().split(/\n\n+/),l=/^\d{1,2}:\d{2}:\d{2}[,.]\d{3}\s*-->\s*\d{1,2}:\d{2}:\d{2}[,.]\d{3}$/;if(!a.some(i=>i.split(`
|
|
3
|
-
`).map(n=>n.trim()).some(n=>l.test(n))))throw new Error("Invalid subtitle format: not SRT");const o=["WEBVTT",""];for(const i of a){const r=i.split(`
|
|
4
|
-
`).map(s=>s.trim()).filter(s=>s.length>0);if(r.length<2)continue;const n=r.findIndex(s=>l.test(s));if(n===-1)continue;const m=r.slice(n+1).filter(s=>!/^\d+$/.test(s));if(m.length===0)continue;let u=r[n];u=u.replace(/[,.](?=\s*-->)/,"").replace(/[,.]$/,"").replace(/,(\d{3})/g,".$1"),o.push(`${u}
|
|
5
|
-
${m.join(`
|
|
6
|
-
`)}
|
|
7
|
-
`)}return o.join(`
|
|
8
|
-
`).replace(/\n{3,}/g,`
|
|
9
|
-
|
|
10
|
-
`).trim()+`
|
|
11
|
-
|
|
12
|
-
`}catch(t){throw console.error("Error in parseToVTT:",t),t}}return c.parseToVTT=b,c.searchSubtitles=w,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"}),c}({});
|
package/dist/wyzie-lib.umd.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
(function(n,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(n=typeof globalThis<"u"?globalThis:n||self,i(n.WyzieLib={}))})(this,function(n){"use strict";async function i({tmdb_id:r,imdb_id:t,season:d,episode:p,language:l,format:u,hi:h}){const c=new URL("https://sub.wyzie.ru/search"),a={id:String(r||t),season:d,episode:p,language:l,format:u,hi:h};return Object.entries(a).forEach(([o,e])=>{e!==void 0&&c.searchParams.append(o,e)}),c}async function T(r){const t=await fetch(r.toString());if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);return t.json()}async function w(r){try{const t=await i(r);return await T(t)}catch(t){throw new Error(`Error fetching subtitles: ${t}`)}}async function b(r){try{const t=await fetch(r);if(!t.ok)throw new Error(`Failed to fetch subtitle content: ${t.status}`);const l=(await t.text()).replace(/\r\n|\r/g,`
|
|
2
|
-
`).trim().split(/\n\n+/),u=/^\d{1,2}:\d{2}:\d{2}[,.]\d{3}\s*-->\s*\d{1,2}:\d{2}:\d{2}[,.]\d{3}$/;if(!l.some(a=>a.split(`
|
|
3
|
-
`).map(e=>e.trim()).some(e=>u.test(e))))throw new Error("Invalid subtitle format: not SRT");const c=["WEBVTT",""];for(const a of l){const o=a.split(`
|
|
4
|
-
`).map(s=>s.trim()).filter(s=>s.length>0);if(o.length<2)continue;const e=o.findIndex(s=>u.test(s));if(e===-1)continue;const m=o.slice(e+1).filter(s=>!/^\d+$/.test(s));if(m.length===0)continue;let f=o[e];f=f.replace(/[,.](?=\s*-->)/,"").replace(/[,.]$/,"").replace(/,(\d{3})/g,".$1"),c.push(`${f}
|
|
5
|
-
${m.join(`
|
|
6
|
-
`)}
|
|
7
|
-
`)}return c.join(`
|
|
8
|
-
`).replace(/\n{3,}/g,`
|
|
9
|
-
|
|
10
|
-
`).trim()+`
|
|
11
|
-
|
|
12
|
-
`}catch(t){throw console.error("Error in parseToVTT:",t),t}}n.parseToVTT=b,n.searchSubtitles=w,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
|