wyzie-lib 2.2.4 → 2.2.6

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.
@@ -0,0 +1,117 @@
1
+ define(["exports"], function(exports) {
2
+ "use strict";
3
+ const config = {
4
+ baseUrl: "https://sub.wyzie.ru"
5
+ };
6
+ function configure(options) {
7
+ if (options.baseUrl) {
8
+ config.baseUrl = options.baseUrl.replace(/\/$/, "");
9
+ }
10
+ }
11
+ async function constructUrl({
12
+ tmdb_id,
13
+ imdb_id,
14
+ season,
15
+ episode,
16
+ encoding,
17
+ language,
18
+ format,
19
+ source,
20
+ hi,
21
+ ...extraParams
22
+ }) {
23
+ if (!tmdb_id && !imdb_id) {
24
+ throw new Error("Either tmdb_id or imdb_id must be provided.");
25
+ }
26
+ const hasSeason = season !== void 0;
27
+ const hasEpisode = episode !== void 0;
28
+ if (hasSeason && !hasEpisode || !hasSeason && hasEpisode) {
29
+ throw new Error("Season and episode must be provided together or omitted together.");
30
+ }
31
+ const url = new URL(`${config.baseUrl}/search`);
32
+ const queryParams = {
33
+ id: String(tmdb_id || imdb_id),
34
+ season,
35
+ episode,
36
+ encoding: Array.isArray(encoding) ? encoding.join(",") : encoding,
37
+ language: Array.isArray(language) ? language.join(",") : language,
38
+ format: Array.isArray(format) ? format.join(",") : format,
39
+ source: Array.isArray(source) ? source.join(",") : source,
40
+ hi
41
+ };
42
+ Object.entries(queryParams).forEach(([key, value]) => {
43
+ if (value !== void 0) {
44
+ url.searchParams.append(key, String(value));
45
+ }
46
+ });
47
+ Object.entries(extraParams).forEach(([key, value]) => {
48
+ if (value !== void 0) {
49
+ if (Array.isArray(value)) {
50
+ url.searchParams.append(key, value.join(","));
51
+ } else {
52
+ url.searchParams.append(key, String(value));
53
+ }
54
+ }
55
+ });
56
+ return url;
57
+ }
58
+ async function fetchSubtitles(url) {
59
+ const response = await fetch(url.toString());
60
+ if (!response.ok) {
61
+ throw new Error(`HTTP error! status: ${response.status}`);
62
+ }
63
+ return response.json();
64
+ }
65
+ async function searchSubtitles(params) {
66
+ try {
67
+ const url = await constructUrl(params);
68
+ return await fetchSubtitles(url);
69
+ } catch (error) {
70
+ throw new Error(`Error fetching subtitles: ${error}`);
71
+ }
72
+ }
73
+ async function parseToVTT(subtitleUrl) {
74
+ try {
75
+ const response = await fetch(subtitleUrl);
76
+ if (!response.ok) {
77
+ throw new Error(`Failed to fetch subtitle content: ${response.status}`);
78
+ }
79
+ const content = await response.text();
80
+ const normalizedContent = content.replace(/\r\n|\r/g, "\n").trim();
81
+ const blocks = normalizedContent.split(/\n\n+/);
82
+ const timestampRegex = /^\d{1,2}:\d{2}:\d{2}[,.]\d{3}\s*-->\s*\d{1,2}:\d{2}:\d{2}[,.]\d{3}$/;
83
+ const hasValidSRTFormat = blocks.some((block) => {
84
+ const lines = block.split("\n").map((line) => line.trim());
85
+ return lines.some((line) => timestampRegex.test(line));
86
+ });
87
+ if (!hasValidSRTFormat) {
88
+ throw new Error("Invalid subtitle format: not SRT");
89
+ }
90
+ const vttLines = ["WEBVTT", ""];
91
+ for (const block of blocks) {
92
+ const lines = block.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
93
+ if (lines.length < 2)
94
+ continue;
95
+ const timestampIndex = lines.findIndex((line) => timestampRegex.test(line));
96
+ if (timestampIndex === -1)
97
+ continue;
98
+ const textLines = lines.slice(timestampIndex + 1).filter((line) => !/^\d+$/.test(line));
99
+ if (textLines.length === 0)
100
+ continue;
101
+ let timestampLine = lines[timestampIndex];
102
+ timestampLine = timestampLine.replace(/[,.](?=\s*-->)/, "").replace(/[,.]$/, "").replace(/,(\d{3})/g, ".$1");
103
+ vttLines.push(`${timestampLine}
104
+ ${textLines.join("\n")}
105
+ `);
106
+ }
107
+ return vttLines.join("\n").replace(/\n{3,}/g, "\n\n").trim() + "\n\n";
108
+ } catch (error) {
109
+ console.error("Error in parseToVTT:", error);
110
+ throw error;
111
+ }
112
+ }
113
+ exports.configure = configure;
114
+ exports.parseToVTT = parseToVTT;
115
+ exports.searchSubtitles = searchSubtitles;
116
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
117
+ });
package/lib/main.cjs ADDED
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const config = {
4
+ baseUrl: "https://sub.wyzie.ru"
5
+ };
6
+ function configure(options) {
7
+ if (options.baseUrl) {
8
+ config.baseUrl = options.baseUrl.replace(/\/$/, "");
9
+ }
10
+ }
11
+ async function constructUrl({
12
+ tmdb_id,
13
+ imdb_id,
14
+ season,
15
+ episode,
16
+ encoding,
17
+ language,
18
+ format,
19
+ source,
20
+ hi,
21
+ ...extraParams
22
+ }) {
23
+ if (!tmdb_id && !imdb_id) {
24
+ throw new Error("Either tmdb_id or imdb_id must be provided.");
25
+ }
26
+ const hasSeason = season !== void 0;
27
+ const hasEpisode = episode !== void 0;
28
+ if (hasSeason && !hasEpisode || !hasSeason && hasEpisode) {
29
+ throw new Error("Season and episode must be provided together or omitted together.");
30
+ }
31
+ const url = new URL(`${config.baseUrl}/search`);
32
+ const queryParams = {
33
+ id: String(tmdb_id || imdb_id),
34
+ season,
35
+ episode,
36
+ encoding: Array.isArray(encoding) ? encoding.join(",") : encoding,
37
+ language: Array.isArray(language) ? language.join(",") : language,
38
+ format: Array.isArray(format) ? format.join(",") : format,
39
+ source: Array.isArray(source) ? source.join(",") : source,
40
+ hi
41
+ };
42
+ Object.entries(queryParams).forEach(([key, value]) => {
43
+ if (value !== void 0) {
44
+ url.searchParams.append(key, String(value));
45
+ }
46
+ });
47
+ Object.entries(extraParams).forEach(([key, value]) => {
48
+ if (value !== void 0) {
49
+ if (Array.isArray(value)) {
50
+ url.searchParams.append(key, value.join(","));
51
+ } else {
52
+ url.searchParams.append(key, String(value));
53
+ }
54
+ }
55
+ });
56
+ return url;
57
+ }
58
+ async function fetchSubtitles(url) {
59
+ const response = await fetch(url.toString());
60
+ if (!response.ok) {
61
+ throw new Error(`HTTP error! status: ${response.status}`);
62
+ }
63
+ return response.json();
64
+ }
65
+ async function searchSubtitles(params) {
66
+ try {
67
+ const url = await constructUrl(params);
68
+ return await fetchSubtitles(url);
69
+ } catch (error) {
70
+ throw new Error(`Error fetching subtitles: ${error}`);
71
+ }
72
+ }
73
+ async function parseToVTT(subtitleUrl) {
74
+ try {
75
+ const response = await fetch(subtitleUrl);
76
+ if (!response.ok) {
77
+ throw new Error(`Failed to fetch subtitle content: ${response.status}`);
78
+ }
79
+ const content = await response.text();
80
+ const normalizedContent = content.replace(/\r\n|\r/g, "\n").trim();
81
+ const blocks = normalizedContent.split(/\n\n+/);
82
+ const timestampRegex = /^\d{1,2}:\d{2}:\d{2}[,.]\d{3}\s*-->\s*\d{1,2}:\d{2}:\d{2}[,.]\d{3}$/;
83
+ const hasValidSRTFormat = blocks.some((block) => {
84
+ const lines = block.split("\n").map((line) => line.trim());
85
+ return lines.some((line) => timestampRegex.test(line));
86
+ });
87
+ if (!hasValidSRTFormat) {
88
+ throw new Error("Invalid subtitle format: not SRT");
89
+ }
90
+ const vttLines = ["WEBVTT", ""];
91
+ for (const block of blocks) {
92
+ const lines = block.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
93
+ if (lines.length < 2)
94
+ continue;
95
+ const timestampIndex = lines.findIndex((line) => timestampRegex.test(line));
96
+ if (timestampIndex === -1)
97
+ continue;
98
+ const textLines = lines.slice(timestampIndex + 1).filter((line) => !/^\d+$/.test(line));
99
+ if (textLines.length === 0)
100
+ continue;
101
+ let timestampLine = lines[timestampIndex];
102
+ timestampLine = timestampLine.replace(/[,.](?=\s*-->)/, "").replace(/[,.]$/, "").replace(/,(\d{3})/g, ".$1");
103
+ vttLines.push(`${timestampLine}
104
+ ${textLines.join("\n")}
105
+ `);
106
+ }
107
+ return vttLines.join("\n").replace(/\n{3,}/g, "\n\n").trim() + "\n\n";
108
+ } catch (error) {
109
+ console.error("Error in parseToVTT:", error);
110
+ throw error;
111
+ }
112
+ }
113
+ exports.configure = configure;
114
+ exports.parseToVTT = parseToVTT;
115
+ exports.searchSubtitles = searchSubtitles;
package/lib/main.d.ts CHANGED
@@ -1,3 +1,19 @@
1
+ /**
2
+ * Type for the configuration options for the library.
3
+ */
4
+ export declare type ConfigurationOptions = {
5
+ /** The API's hostname (default: sub.wyzie.ru) */
6
+ baseUrl: string;
7
+ };
8
+
9
+ /**
10
+ * Configure the library settings.
11
+ *
12
+ * @param {ConfigurationOptions} options - Config options for the library.
13
+ * @throws {Error} Throws an error if the baseUrl is not provided.
14
+ */
15
+ export declare function configure(options: ConfigurationOptions): void;
16
+
1
17
  /**
2
18
  * Parses subtitle content from a URL to VTT format.
3
19
  *
@@ -61,8 +77,10 @@ export declare type SearchSubtitlesParams = (
61
77
  format?: string | string[];
62
78
  /** Determines if you get hearing impaired subtitles. */
63
79
  hi?: boolean;
64
- /** The source where the subtitle where be scraped. */
65
- source?: string;
80
+ /** The source where the subtitle will be scraped. Accepts a single value or a list. */
81
+ source?: string | string[];
82
+ /** Additional parameters that can be used for filtering or other purposes. */
83
+ [key: string]: any;
66
84
  } & (
67
85
  /** The number of the desired season you want subtitles for. */
68
86
  {
@@ -97,8 +115,8 @@ export declare type SubtitleData = {
97
115
  display: string;
98
116
  /** ISO 3166 code; Example: en (2 alphabetic letters). */
99
117
  language: string;
100
- /** The subtitle's source. */
101
- source: number;
118
+ /** The subtitle's source (ex: subdl, subf2m, opensubtitles). */
119
+ source?: string | string[];
102
120
  };
103
121
 
104
122
  export { }
@@ -0,0 +1,118 @@
1
+ var main = function(exports) {
2
+ "use strict";
3
+ const config = {
4
+ baseUrl: "https://sub.wyzie.ru"
5
+ };
6
+ function configure(options) {
7
+ if (options.baseUrl) {
8
+ config.baseUrl = options.baseUrl.replace(/\/$/, "");
9
+ }
10
+ }
11
+ async function constructUrl({
12
+ tmdb_id,
13
+ imdb_id,
14
+ season,
15
+ episode,
16
+ encoding,
17
+ language,
18
+ format,
19
+ source,
20
+ hi,
21
+ ...extraParams
22
+ }) {
23
+ if (!tmdb_id && !imdb_id) {
24
+ throw new Error("Either tmdb_id or imdb_id must be provided.");
25
+ }
26
+ const hasSeason = season !== void 0;
27
+ const hasEpisode = episode !== void 0;
28
+ if (hasSeason && !hasEpisode || !hasSeason && hasEpisode) {
29
+ throw new Error("Season and episode must be provided together or omitted together.");
30
+ }
31
+ const url = new URL(`${config.baseUrl}/search`);
32
+ const queryParams = {
33
+ id: String(tmdb_id || imdb_id),
34
+ season,
35
+ episode,
36
+ encoding: Array.isArray(encoding) ? encoding.join(",") : encoding,
37
+ language: Array.isArray(language) ? language.join(",") : language,
38
+ format: Array.isArray(format) ? format.join(",") : format,
39
+ source: Array.isArray(source) ? source.join(",") : source,
40
+ hi
41
+ };
42
+ Object.entries(queryParams).forEach(([key, value]) => {
43
+ if (value !== void 0) {
44
+ url.searchParams.append(key, String(value));
45
+ }
46
+ });
47
+ Object.entries(extraParams).forEach(([key, value]) => {
48
+ if (value !== void 0) {
49
+ if (Array.isArray(value)) {
50
+ url.searchParams.append(key, value.join(","));
51
+ } else {
52
+ url.searchParams.append(key, String(value));
53
+ }
54
+ }
55
+ });
56
+ return url;
57
+ }
58
+ async function fetchSubtitles(url) {
59
+ const response = await fetch(url.toString());
60
+ if (!response.ok) {
61
+ throw new Error(`HTTP error! status: ${response.status}`);
62
+ }
63
+ return response.json();
64
+ }
65
+ async function searchSubtitles(params) {
66
+ try {
67
+ const url = await constructUrl(params);
68
+ return await fetchSubtitles(url);
69
+ } catch (error) {
70
+ throw new Error(`Error fetching subtitles: ${error}`);
71
+ }
72
+ }
73
+ async function parseToVTT(subtitleUrl) {
74
+ try {
75
+ const response = await fetch(subtitleUrl);
76
+ if (!response.ok) {
77
+ throw new Error(`Failed to fetch subtitle content: ${response.status}`);
78
+ }
79
+ const content = await response.text();
80
+ const normalizedContent = content.replace(/\r\n|\r/g, "\n").trim();
81
+ const blocks = normalizedContent.split(/\n\n+/);
82
+ const timestampRegex = /^\d{1,2}:\d{2}:\d{2}[,.]\d{3}\s*-->\s*\d{1,2}:\d{2}:\d{2}[,.]\d{3}$/;
83
+ const hasValidSRTFormat = blocks.some((block) => {
84
+ const lines = block.split("\n").map((line) => line.trim());
85
+ return lines.some((line) => timestampRegex.test(line));
86
+ });
87
+ if (!hasValidSRTFormat) {
88
+ throw new Error("Invalid subtitle format: not SRT");
89
+ }
90
+ const vttLines = ["WEBVTT", ""];
91
+ for (const block of blocks) {
92
+ const lines = block.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
93
+ if (lines.length < 2)
94
+ continue;
95
+ const timestampIndex = lines.findIndex((line) => timestampRegex.test(line));
96
+ if (timestampIndex === -1)
97
+ continue;
98
+ const textLines = lines.slice(timestampIndex + 1).filter((line) => !/^\d+$/.test(line));
99
+ if (textLines.length === 0)
100
+ continue;
101
+ let timestampLine = lines[timestampIndex];
102
+ timestampLine = timestampLine.replace(/[,.](?=\s*-->)/, "").replace(/[,.]$/, "").replace(/,(\d{3})/g, ".$1");
103
+ vttLines.push(`${timestampLine}
104
+ ${textLines.join("\n")}
105
+ `);
106
+ }
107
+ return vttLines.join("\n").replace(/\n{3,}/g, "\n\n").trim() + "\n\n";
108
+ } catch (error) {
109
+ console.error("Error in parseToVTT:", error);
110
+ throw error;
111
+ }
112
+ }
113
+ exports.configure = configure;
114
+ exports.parseToVTT = parseToVTT;
115
+ exports.searchSubtitles = searchSubtitles;
116
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
117
+ return exports;
118
+ }({});
package/lib/main.js CHANGED
@@ -1,3 +1,11 @@
1
+ const config = {
2
+ baseUrl: "https://sub.wyzie.ru"
3
+ };
4
+ function configure(options) {
5
+ if (options.baseUrl) {
6
+ config.baseUrl = options.baseUrl.replace(/\/$/, "");
7
+ }
8
+ }
1
9
  async function constructUrl({
2
10
  tmdb_id,
3
11
  imdb_id,
@@ -7,9 +15,18 @@ async function constructUrl({
7
15
  language,
8
16
  format,
9
17
  source,
10
- hi
18
+ hi,
19
+ ...extraParams
11
20
  }) {
12
- const url = new URL("https://sub.wyzie.ru/search");
21
+ if (!tmdb_id && !imdb_id) {
22
+ throw new Error("Either tmdb_id or imdb_id must be provided.");
23
+ }
24
+ const hasSeason = season !== void 0;
25
+ const hasEpisode = episode !== void 0;
26
+ if (hasSeason && !hasEpisode || !hasSeason && hasEpisode) {
27
+ throw new Error("Season and episode must be provided together or omitted together.");
28
+ }
29
+ const url = new URL(`${config.baseUrl}/search`);
13
30
  const queryParams = {
14
31
  id: String(tmdb_id || imdb_id),
15
32
  season,
@@ -25,6 +42,15 @@ async function constructUrl({
25
42
  url.searchParams.append(key, String(value));
26
43
  }
27
44
  });
45
+ Object.entries(extraParams).forEach(([key, value]) => {
46
+ if (value !== void 0) {
47
+ if (Array.isArray(value)) {
48
+ url.searchParams.append(key, value.join(","));
49
+ } else {
50
+ url.searchParams.append(key, String(value));
51
+ }
52
+ }
53
+ });
28
54
  return url;
29
55
  }
30
56
  async function fetchSubtitles(url) {
@@ -83,6 +109,7 @@ ${textLines.join("\n")}
83
109
  }
84
110
  }
85
111
  export {
112
+ configure,
86
113
  parseToVTT,
87
114
  searchSubtitles
88
115
  };
package/lib/main.umd.cjs CHANGED
@@ -2,6 +2,14 @@
2
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
3
  })(this, function(exports2) {
4
4
  "use strict";
5
+ const config = {
6
+ baseUrl: "https://sub.wyzie.ru"
7
+ };
8
+ function configure(options) {
9
+ if (options.baseUrl) {
10
+ config.baseUrl = options.baseUrl.replace(/\/$/, "");
11
+ }
12
+ }
5
13
  async function constructUrl({
6
14
  tmdb_id,
7
15
  imdb_id,
@@ -11,9 +19,18 @@
11
19
  language,
12
20
  format,
13
21
  source,
14
- hi
22
+ hi,
23
+ ...extraParams
15
24
  }) {
16
- const url = new URL("https://sub.wyzie.ru/search");
25
+ if (!tmdb_id && !imdb_id) {
26
+ throw new Error("Either tmdb_id or imdb_id must be provided.");
27
+ }
28
+ const hasSeason = season !== void 0;
29
+ const hasEpisode = episode !== void 0;
30
+ if (hasSeason && !hasEpisode || !hasSeason && hasEpisode) {
31
+ throw new Error("Season and episode must be provided together or omitted together.");
32
+ }
33
+ const url = new URL(`${config.baseUrl}/search`);
17
34
  const queryParams = {
18
35
  id: String(tmdb_id || imdb_id),
19
36
  season,
@@ -29,6 +46,15 @@
29
46
  url.searchParams.append(key, String(value));
30
47
  }
31
48
  });
49
+ Object.entries(extraParams).forEach(([key, value]) => {
50
+ if (value !== void 0) {
51
+ if (Array.isArray(value)) {
52
+ url.searchParams.append(key, value.join(","));
53
+ } else {
54
+ url.searchParams.append(key, String(value));
55
+ }
56
+ }
57
+ });
32
58
  return url;
33
59
  }
34
60
  async function fetchSubtitles(url) {
@@ -86,6 +112,7 @@ ${textLines.join("\n")}
86
112
  throw error;
87
113
  }
88
114
  }
115
+ exports2.configure = configure;
89
116
  exports2.parseToVTT = parseToVTT;
90
117
  exports2.searchSubtitles = searchSubtitles;
91
118
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wyzie-lib",
3
- "version": "2.2.4",
3
+ "version": "2.2.6",
4
4
  "icon": "https://i.postimg.cc/L5ppKYC5/cclogo.png",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -31,19 +31,19 @@
31
31
  },
32
32
  "require": {
33
33
  "types": "./lib/main.d.ts",
34
- "default": "./lib/main.umd.cjs"
34
+ "default": "./lib/main.cjs"
35
35
  },
36
36
  "umd": {
37
37
  "types": "./lib/main.d.ts",
38
- "default": "./lib/main.umd.js"
38
+ "default": "./lib/main.umd.cjs"
39
39
  },
40
40
  "es": {
41
41
  "types": "./lib/main.d.ts",
42
- "default": "./lib/main.es.js"
42
+ "default": "./lib/main.js"
43
43
  },
44
44
  "cjs": {
45
45
  "types": "./lib/main.d.ts",
46
- "default": "./lib/main.cjs.js"
46
+ "default": "./lib/main.cjs"
47
47
  },
48
48
  "iife": {
49
49
  "types": "./lib/main.d.ts",
@@ -60,7 +60,7 @@
60
60
  "url": "git+https://github.com/itzcozi/wyzie-lib.git"
61
61
  },
62
62
  "devDependencies": {
63
- "prettier": "^3.5.3",
63
+ "prettier": "^3.6.0",
64
64
  "typescript": "^5.8.3",
65
65
  "vite": "^4.5.14",
66
66
  "vite-plugin-dts": "^4.5.4",