wyzie-lib 2.0.6 → 2.0.8

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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Wyzie Lib is a package made for easily implementing [Wyzie Subs](https://sub.wyzie.ru) into your
4
4
  project without all the fuss. [Read our source code!](https://github.com/itzcozi/wyzie-lib)
5
5
 
6
- <sup>2.0 Out Now!</sup>
6
+ <sup>New VTT Parser!</sup>
7
7
 
8
8
  ## Features
9
9
 
@@ -34,11 +34,19 @@ yarn add wyzie-lib
34
34
  ## Usage
35
35
 
36
36
  ```ts
37
- import { type SubtitleData, searchSubtitles } from "wyzie-lib";
37
+ import { type SubtitleData, searchSubtitles, parseToVTT } from "wyzie-lib";
38
38
 
39
- // IMDB is faster then TMDB due to less API calls behind the scenes
40
- const data: SubtitleData[] = await searchSubtitles({ tmdb_id: 286217 });
41
- console.log(data[0]); // Prints the object of the first subtitle provided in the search
39
+ const params = { tmdb_id: 286217 };
40
+
41
+ // Fetches all subtitles for the media with the TMDB ID 286217
42
+ // -----------------------------------------------------------
43
+ const data: SubtitleData[] = await searchSubtitles(params);
44
+ console.log(data[0].id); // Prints the ID of the first subtitle object
45
+
46
+ // Converts the first subtitle to VTT format using the previous parameters provided
47
+ // --------------------------------------------------------------------------------
48
+ const vttContent = await parseToVTT(params, 0); // Use the first subtitle URL for convenience
49
+ console.log(vttContent); // Prints the raw VTT content
42
50
  ```
43
51
 
44
52
  ### Parameters
@@ -62,35 +70,35 @@ console.log(data[0]); // Prints the object of the first subtitle provided in the
62
70
  ```ts
63
71
  interface SearchSubtitlesParams {
64
72
  // Parameters for the searchSubtitles() function
65
- tmdb_id?: number; // Parsed automatically by the API to recognize if its TMDB or IMDB
66
- imdb_id?: number; // Parsed automatically by the API to recognize if its TMDB or IMDB
73
+ tmdb_id?: number; // Parsed automatically by the API to recognize if its TMDB or IMDB
74
+ imdb_id?: number; // Parsed automatically by the API to recognize if its TMDB or IMDB
67
75
  season?: number;
68
- episode?: number; // Season is required if episode is provided
69
- language?: string; // ISO 3166 code
70
- format?: string; // Subtitle file format
71
- hi?: boolean; // If the subtitle is hearing impaired
76
+ episode?: number; // Season is required if episode is provided
77
+ language?: string; // ISO 3166 code
78
+ format?: string; // Subtitle file format
79
+ hi?: boolean; // If the subtitle is hearing impaired
72
80
  }
73
81
 
74
82
  interface QueryParams {
75
83
  // Parameters for the wyzie-subs API
76
- id: string; // (Required) The TMDB or IMDB ID of the movie or TV show
77
- season?: number; // The season of the TV show (Required if episode is provided)
78
- episode?: number; // The episode of the TV show (Required if season is provided)
79
- language?: string; // ISO 3166 code
80
- format?: string; // Subtitle file format
81
- hi?: boolean; // If the subtitle is hearing impaired
84
+ id: string; // (Required) The TMDB or IMDB ID of the movie or TV show
85
+ season?: number; // The season of the TV show (Required if episode is provided)
86
+ episode?: number; // The episode of the TV show (Required if season is provided)
87
+ language?: string; // ISO 3166 code
88
+ format?: string; // Subtitle file format
89
+ hi?: boolean; // If the subtitle is hearing impaired
82
90
  }
83
91
 
84
92
  type SubtitleData = {
85
93
  // Data returned by the API
86
- id: string; // Unique ID of the subtitle from opensubtitles
87
- url: string; // Direct download link of the subtitle
88
- format: string; // Subtitle file format
94
+ id: string; // Unique ID of the subtitle from opensubtitles
95
+ url: string; // Direct download link of the subtitle
96
+ format: string; // Subtitle file format
89
97
  isHearingImpaired: boolean; // If the subtitle is hearing impaired
90
- flagUrl: string; // Flag of the language
91
- media: string; // Media name of the subtitle
92
- display: string; // Actual name of the language
93
- language: string; // ISO 3166 code
98
+ flagUrl: string; // Flag of the language
99
+ media: string; // Media name of the subtitle
100
+ display: string; // Actual name of the language
101
+ language: string; // ISO 3166 code
94
102
  };
95
103
  ```
96
104
 
@@ -0,0 +1,7 @@
1
+ import { SearchSubtitlesParams, SubtitleData } from "./types";
2
+ export declare function searchSubtitles(params: SearchSubtitlesParams & {
3
+ parseVTT?: boolean;
4
+ }): Promise<SubtitleData[] | {
5
+ subtitles: SubtitleData[];
6
+ vttContent: string;
7
+ }>;
@@ -0,0 +1,4 @@
1
+ import { SearchSubtitlesParams, SubtitleData, QueryParams } from "./types";
2
+ import { searchSubtitles } from "./funcs";
3
+ export { searchSubtitles };
4
+ export type { SubtitleData, SearchSubtitlesParams, QueryParams };
@@ -0,0 +1,28 @@
1
+ export interface SearchSubtitlesParams {
2
+ tmdb_id?: number;
3
+ imdb_id?: number;
4
+ season?: number;
5
+ episode?: number;
6
+ language?: string;
7
+ format?: string;
8
+ hi?: boolean;
9
+ parseVTT?: boolean;
10
+ }
11
+ export type SubtitleData = {
12
+ id: string;
13
+ url: string;
14
+ format: string;
15
+ isHearingImpaired: boolean;
16
+ flagUrl: string;
17
+ media: string;
18
+ display: string;
19
+ language: string;
20
+ };
21
+ export interface QueryParams {
22
+ id: string;
23
+ season?: number;
24
+ episode?: number;
25
+ language?: string;
26
+ format?: string;
27
+ hi?: boolean;
28
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});async function h({tmdb_id:n,imdb_id:t,season:r,episode:o,language:u,format:f,hi:d}){const c=new URL("https://sub.wyzie.ru/search"),s={id:String(n||t),season:r,episode:o,language:u,format:f,hi:d};return Object.entries(s).forEach(([i,a])=>{a!==void 0&&c.searchParams.append(i,a)}),c}async function p(n){const t=await fetch(n.toString());if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);return t.json()}async function w(n){try{const t=await fetch(n);if(!t.ok)throw new Error(`Failed to fetch subtitle content: ${t.status}`);const o=(await t.text()).replace(/\r\n/g,`
2
+ `).replace(/\r/g,`
3
+ `).trim();let u=`WEBVTT
4
+
5
+ `;const f=o.split(/\n\n+/);for(const c of f){if(!c.trim())continue;const s=c.split(`
6
+ `).map(e=>e.trim()).filter(e=>e.length>0);if(s.length<2)continue;const i=s.findIndex(e=>/^\d{1,2}:\d{2}(?::\d{2})?[,\.]\d{3}(?:\.|,)?\s*-->\s*\d{1,2}:\d{2}(?::\d{2})?[,\.]\d{3}(?:\.|,)?$/.test(e));if(i===-1)continue;const a=s.slice(i+1).filter(e=>!/^\d+$/.test(e)).filter(e=>e.length>0);if(a.length===0)continue;let l=s[i];l=l.replace(/[,.](?=\s*-->)/,"").replace(/[,.]$/,""),l=l.replace(/,(\d{3})/g,".$1"),u+=`${l}
7
+ ${a.join(`
8
+ `)}
9
+
10
+ `}return u.replace(/\n{3,}/g,`
11
+
12
+ `).trim()+`
13
+
14
+ `}catch(t){throw console.error("Error in parseToVTT:",t),t}}async function g(n){try{const t=await h(n),r=await p(t);if(n.parseVTT&&r.length>0){const o=await w(r[0].url);return{subtitles:r,vttContent:o}}return r}catch(t){throw new Error(`Error fetching subtitles: ${t}`)}}exports.searchSubtitles=g;
@@ -0,0 +1,85 @@
1
+ async function d({
2
+ tmdb_id: e,
3
+ imdb_id: t,
4
+ season: r,
5
+ episode: s,
6
+ language: u,
7
+ format: f,
8
+ hi: h
9
+ }) {
10
+ const c = new URL("https://sub.wyzie.ru/search"), o = {
11
+ id: String(e || t),
12
+ season: r,
13
+ episode: s,
14
+ language: u,
15
+ format: f,
16
+ hi: h
17
+ };
18
+ return Object.entries(o).forEach(([i, a]) => {
19
+ a !== void 0 && c.searchParams.append(i, a);
20
+ }), c;
21
+ }
22
+ async function p(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 fetch(e);
31
+ if (!t.ok)
32
+ throw new Error(`Failed to fetch subtitle content: ${t.status}`);
33
+ const s = (await t.text()).replace(/\r\n/g, `
34
+ `).replace(/\r/g, `
35
+ `).trim();
36
+ let u = `WEBVTT
37
+
38
+ `;
39
+ const f = s.split(/\n\n+/);
40
+ for (const c of f) {
41
+ if (!c.trim())
42
+ continue;
43
+ const o = c.split(`
44
+ `).map((n) => n.trim()).filter((n) => n.length > 0);
45
+ if (o.length < 2)
46
+ continue;
47
+ const i = o.findIndex(
48
+ (n) => /^\d{1,2}:\d{2}(?::\d{2})?[,\.]\d{3}(?:\.|,)?\s*-->\s*\d{1,2}:\d{2}(?::\d{2})?[,\.]\d{3}(?:\.|,)?$/.test(n)
49
+ );
50
+ if (i === -1)
51
+ continue;
52
+ const a = o.slice(i + 1).filter((n) => !/^\d+$/.test(n)).filter((n) => n.length > 0);
53
+ if (a.length === 0)
54
+ continue;
55
+ let l = o[i];
56
+ l = l.replace(/[,.](?=\s*-->)/, "").replace(/[,.]$/, ""), l = l.replace(/,(\d{3})/g, ".$1"), u += `${l}
57
+ ${a.join(`
58
+ `)}
59
+
60
+ `;
61
+ }
62
+ return u.replace(/\n{3,}/g, `
63
+
64
+ `).trim() + `
65
+
66
+ `;
67
+ } catch (t) {
68
+ throw console.error("Error in parseToVTT:", t), t;
69
+ }
70
+ }
71
+ async function g(e) {
72
+ try {
73
+ const t = await d(e), r = await p(t);
74
+ if (e.parseVTT && r.length > 0) {
75
+ const s = await w(r[0].url);
76
+ return { subtitles: r, vttContent: s };
77
+ }
78
+ return r;
79
+ } catch (t) {
80
+ throw new Error(`Error fetching subtitles: ${t}`);
81
+ }
82
+ }
83
+ export {
84
+ g as searchSubtitles
85
+ };
@@ -0,0 +1,14 @@
1
+ var WyzieLib=function(f){"use strict";async function p({tmdb_id:e,imdb_id:t,season:r,episode:s,language:u,format:d,hi:h}){const c=new URL("https://sub.wyzie.ru/search"),o={id:String(e||t),season:r,episode:s,language:u,format:d,hi:h};return Object.entries(o).forEach(([i,a])=>{a!==void 0&&c.searchParams.append(i,a)}),c}async function w(e){const t=await fetch(e.toString());if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);return t.json()}async function g(e){try{const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch subtitle content: ${t.status}`);const s=(await t.text()).replace(/\r\n/g,`
2
+ `).replace(/\r/g,`
3
+ `).trim();let u=`WEBVTT
4
+
5
+ `;const d=s.split(/\n\n+/);for(const c of d){if(!c.trim())continue;const o=c.split(`
6
+ `).map(n=>n.trim()).filter(n=>n.length>0);if(o.length<2)continue;const i=o.findIndex(n=>/^\d{1,2}:\d{2}(?::\d{2})?[,\.]\d{3}(?:\.|,)?\s*-->\s*\d{1,2}:\d{2}(?::\d{2})?[,\.]\d{3}(?:\.|,)?$/.test(n));if(i===-1)continue;const a=o.slice(i+1).filter(n=>!/^\d+$/.test(n)).filter(n=>n.length>0);if(a.length===0)continue;let l=o[i];l=l.replace(/[,.](?=\s*-->)/,"").replace(/[,.]$/,""),l=l.replace(/,(\d{3})/g,".$1"),u+=`${l}
7
+ ${a.join(`
8
+ `)}
9
+
10
+ `}return u.replace(/\n{3,}/g,`
11
+
12
+ `).trim()+`
13
+
14
+ `}catch(t){throw console.error("Error in parseToVTT:",t),t}}async function b(e){try{const t=await p(e),r=await w(t);if(e.parseVTT&&r.length>0){const s=await g(r[0].url);return{subtitles:r,vttContent:s}}return r}catch(t){throw new Error(`Error fetching subtitles: ${t}`)}}return f.searchSubtitles=b,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"}),f}({});
@@ -0,0 +1,14 @@
1
+ (function(o,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(o=typeof globalThis<"u"?globalThis:o||self,i(o.WyzieLib={}))})(this,function(o){"use strict";async function i({tmdb_id:n,imdb_id:t,season:r,episode:c,language:d,format:h,hi:p}){const a=new URL("https://sub.wyzie.ru/search"),s={id:String(n||t),season:r,episode:c,language:d,format:h,hi:p};return Object.entries(s).forEach(([l,u])=>{u!==void 0&&a.searchParams.append(l,u)}),a}async function w(n){const t=await fetch(n.toString());if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);return t.json()}async function T(n){try{const t=await fetch(n);if(!t.ok)throw new Error(`Failed to fetch subtitle content: ${t.status}`);const c=(await t.text()).replace(/\r\n/g,`
2
+ `).replace(/\r/g,`
3
+ `).trim();let d=`WEBVTT
4
+
5
+ `;const h=c.split(/\n\n+/);for(const a of h){if(!a.trim())continue;const s=a.split(`
6
+ `).map(e=>e.trim()).filter(e=>e.length>0);if(s.length<2)continue;const l=s.findIndex(e=>/^\d{1,2}:\d{2}(?::\d{2})?[,\.]\d{3}(?:\.|,)?\s*-->\s*\d{1,2}:\d{2}(?::\d{2})?[,\.]\d{3}(?:\.|,)?$/.test(e));if(l===-1)continue;const u=s.slice(l+1).filter(e=>!/^\d+$/.test(e)).filter(e=>e.length>0);if(u.length===0)continue;let f=s[l];f=f.replace(/[,.](?=\s*-->)/,"").replace(/[,.]$/,""),f=f.replace(/,(\d{3})/g,".$1"),d+=`${f}
7
+ ${u.join(`
8
+ `)}
9
+
10
+ `}return d.replace(/\n{3,}/g,`
11
+
12
+ `).trim()+`
13
+
14
+ `}catch(t){throw console.error("Error in parseToVTT:",t),t}}async function b(n){try{const t=await i(n),r=await w(t);if(n.parseVTT&&r.length>0){const c=await T(r[0].url);return{subtitles:r,vttContent:c}}return r}catch(t){throw new Error(`Error fetching subtitles: ${t}`)}}o.searchSubtitles=b,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wyzie-lib",
3
- "version": "2.0.6",
3
+ "version": "2.0.8",
4
4
  "icon": "https://i.postimg.cc/L5ppKYC5/cclogo.png",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -29,15 +29,15 @@
29
29
  }
30
30
  },
31
31
  "devDependencies": {
32
- "@eslint/js": "^9.14.0",
33
- "eslint": "^9.14.0",
32
+ "@eslint/js": "^9.17.0",
33
+ "eslint": "^9.17.0",
34
34
  "eslint-config-prettier": "^9.1.0",
35
35
  "eslint-plugin-import": "^2.31.0",
36
36
  "eslint-plugin-prettier": "^5.2.1",
37
- "globals": "^15.12.0",
38
- "prettier": "^3.3.3",
39
- "typescript": "^5.6.3",
40
- "typescript-eslint": "^8.14.0",
37
+ "globals": "^15.14.0",
38
+ "prettier": "^3.4.2",
39
+ "typescript": "^5.7.2",
40
+ "typescript-eslint": "^8.19.0",
41
41
  "vite": "^4.5.5"
42
42
  },
43
43
  "scripts": {