wyzie-lib 2.0.9 → 2.1.1

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.
@@ -1,14 +1,12 @@
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(`
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(`
8
6
  `)}
9
-
10
- `}return u.replace(/\n{3,}/g,`
7
+ `)}return o.join(`
8
+ `).replace(/\n{3,}/g,`
11
9
 
12
10
  `).trim()+`
13
11
 
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;
12
+ `}catch(t){throw console.error("Error in parseToVTT:",t),t}}exports.parseToVTT=w;exports.searchSubtitles=T;
@@ -1,65 +1,68 @@
1
- async function d({
1
+ async function p({
2
2
  tmdb_id: e,
3
3
  imdb_id: t,
4
- season: r,
5
- episode: s,
6
- language: u,
7
- format: f,
4
+ season: u,
5
+ episode: f,
6
+ language: c,
7
+ format: a,
8
8
  hi: h
9
9
  }) {
10
- const c = new URL("https://sub.wyzie.ru/search"), o = {
10
+ const o = new URL("https://sub.wyzie.ru/search"), i = {
11
11
  id: String(e || t),
12
- season: r,
13
- episode: s,
14
- language: u,
15
- format: f,
12
+ season: u,
13
+ episode: f,
14
+ language: c,
15
+ format: a,
16
16
  hi: h
17
17
  };
18
- return Object.entries(o).forEach(([i, a]) => {
19
- a !== void 0 && c.searchParams.append(i, a);
20
- }), c;
18
+ return Object.entries(i).forEach(([r, n]) => {
19
+ n !== void 0 && o.searchParams.append(r, n);
20
+ }), o;
21
21
  }
22
- async function p(e) {
22
+ async function m(e) {
23
23
  const t = await fetch(e.toString());
24
24
  if (!t.ok)
25
25
  throw new Error(`HTTP error! status: ${t.status}`);
26
26
  return t.json();
27
27
  }
28
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) {
29
37
  try {
30
38
  const t = await fetch(e);
31
39
  if (!t.ok)
32
40
  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)
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)
46
51
  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)
52
+ const n = r.findIndex((s) => a.test(s));
53
+ if (n === -1)
51
54
  continue;
52
- const a = o.slice(i + 1).filter((n) => !/^\d+$/.test(n)).filter((n) => n.length > 0);
53
- if (a.length === 0)
55
+ const d = r.slice(n + 1).filter((s) => !/^\d+$/.test(s));
56
+ if (d.length === 0)
54
57
  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
+ let l = r[n];
59
+ l = l.replace(/[,.](?=\s*-->)/, "").replace(/[,.]$/, "").replace(/,(\d{3})/g, ".$1"), o.push(`${l}
60
+ ${d.join(`
58
61
  `)}
59
-
60
- `;
62
+ `);
61
63
  }
62
- return u.replace(/\n{3,}/g, `
64
+ return o.join(`
65
+ `).replace(/\n{3,}/g, `
63
66
 
64
67
  `).trim() + `
65
68
 
@@ -68,18 +71,7 @@ ${a.join(`
68
71
  throw console.error("Error in parseToVTT:", t), t;
69
72
  }
70
73
  }
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
74
  export {
84
- g as searchSubtitles
75
+ T as parseToVTT,
76
+ w as searchSubtitles
85
77
  };
@@ -1,14 +1,12 @@
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(`
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(`
8
6
  `)}
9
-
10
- `}return u.replace(/\n{3,}/g,`
7
+ `)}return o.join(`
8
+ `).replace(/\n{3,}/g,`
11
9
 
12
10
  `).trim()+`
13
11
 
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}({});
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}({});
@@ -1,14 +1,12 @@
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(`
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(`
8
6
  `)}
9
-
10
- `}return d.replace(/\n{3,}/g,`
7
+ `)}return c.join(`
8
+ `).replace(/\n{3,}/g,`
11
9
 
12
10
  `).trim()+`
13
11
 
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"})});
12
+ `}catch(t){throw console.error("Error in parseToVTT:",t),t}}n.parseToVTT=b,n.searchSubtitles=w,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wyzie-lib",
3
- "version": "2.0.9",
3
+ "version": "2.1.1",
4
4
  "icon": "https://i.postimg.cc/L5ppKYC5/cclogo.png",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -18,6 +18,7 @@
18
18
  "main": "dist/wyzie-lib.cjs.js",
19
19
  "module": "dist/wyzie-lib.es.js",
20
20
  "browser": "dist/wyzie-lib.iife.js",
21
+ "type": "module",
21
22
  "files": [
22
23
  "dist"
23
24
  ],
@@ -38,7 +39,8 @@
38
39
  "prettier": "^3.4.2",
39
40
  "typescript": "^5.7.2",
40
41
  "typescript-eslint": "^8.19.0",
41
- "vite": "^4.5.5"
42
+ "vite": "^4.5.5",
43
+ "vitest": "^2.1.8"
42
44
  },
43
45
  "scripts": {
44
46
  "dev": "vite",
@@ -1,7 +0,0 @@
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
- }>;
@@ -1,4 +0,0 @@
1
- import { SearchSubtitlesParams, SubtitleData, QueryParams } from "./types";
2
- import { searchSubtitles } from "./funcs";
3
- export { searchSubtitles };
4
- export type { SubtitleData, SearchSubtitlesParams, QueryParams };
@@ -1,28 +0,0 @@
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
- }