Skip to content

Commit 1eba64a

Browse files
committed
fix videolinks b64 decode
1 parent 09e14a8 commit 1eba64a

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@typedanimetools/kodikwrapper",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "A kodikapi.com wrapper for Node.JS",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/videolinks.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import axios from "axios";
22
import { ArrayAsObject } from "./utils";
33

4-
export const linkPlayerRegex = /^(?<protocol>http[s]?:|)\/\/(?<host>[a-z0-9]+\.[a-z]+)\/(?<type>serial|video)\/(?<id>\d+)\/(?<hash>[0-9a-z]+)\/(?<quality>\d+p)$/;
4+
export const linkPlayerRegex = /^(?<protocol>http[s]?:|)\/\/(?<host>[a-z0-9]+\.[a-z]+)\/(?<type>video|seria|season)\/(?<id>\d+)\/(?<hash>[0-9a-z]+)\/(?<quality>\d+p)$/;
55

66
export interface ParsedLink {
77
type: string;
@@ -20,9 +20,9 @@ export interface Source {
2020
type: string;
2121
}
2222
export type VideoLinksTypes = Record<
23-
"links",
23+
"links",
2424
Record<
25-
"720" | "480" | "360" | "240" | string,
25+
"720" | "480" | "360" | "240" | string,
2626
Source[]
2727
>
2828
>
@@ -65,16 +65,16 @@ export async function parseLink(
6565
type: ""
6666
};
6767
const linkParams = linkPlayerRegex.exec(params.link)!;
68-
if(!linkParams.groups) throw new Error(`cannot get "groups" from "linkParams"`);
68+
if (!linkParams.groups) throw new Error(`cannot get "groups" from "linkParams"`);
6969
Object.assign(data, linkParams.groups);
70-
if(params.extended) {
70+
if (params.extended) {
7171
try {
7272
const page = await axios.get<string>(`${linkParams.groups.protocol.length === 0 ? "https:" : ""}${params.link}`);
7373
const pageMatch = page.data.match(/iframe\.src\s*=\s*"(?<url>[^"]+)";/);
74-
if(!pageMatch?.groups?.url) throw "ывзаыхвахывха че за";
74+
if (!pageMatch?.groups?.url) throw "ывзаыхвахывха че за";
7575
const extFields = new URL("https:" + pageMatch.groups.url);
76-
const obj = Array.from(extFields.searchParams).reduce((p, [k,v]) => (p[k]=v, p), {} as Record<string, string>);
77-
return {...data, ...obj};
76+
const obj = Array.from(extFields.searchParams).reduce((p, [k, v]) => (p[k] = v, p), {} as Record<string, string>);
77+
return { ...data, ...obj };
7878
} catch (error) {
7979
throw new ParseError("cannot get extended fields")
8080
};
@@ -98,23 +98,33 @@ export interface GetLinksParams {
9898
}
9999

100100
export async function getLinks(params: GetLinksParams): Promise<VideoLinksParsed> {
101-
101+
102102
params.extended = params.extended || false;
103103
params.host = "host" in params ? params.host : "https://kodik.cc"
104-
104+
105105
const parsedLink = await parseLink({
106106
...params,
107107
extended: true
108108
});
109109
const rawVideoLinksResponse = await axios.post<VideoLinksTypes>("https://aniqit.com/gvi", null, {
110110
params: parsedLink
111111
});
112-
const videoLinks = Object.entries(rawVideoLinksResponse.data.links).reduce((response, [q, src]) => {
113-
response.links[q] = src
114-
return response
115-
}, {links: {}} as VideoLinksTypes);
112+
const videoLinks = Object
113+
.entries(rawVideoLinksResponse.data.links)
114+
.reduce(
115+
(response, qualityVariant) => (
116+
response[qualityVariant[0]] = qualityVariant[1]
117+
.map(
118+
sourceVariant => (
119+
{
120+
...sourceVariant,
121+
src: Buffer.from(sourceVariant.src.split("").reverse().join(""), "base64").toString()
122+
}
123+
)
124+
),
125+
response), {} as VideoLinksTypes["links"]);
116126
return {
117-
...videoLinks,
118-
...(params.extended ? {params} : {})
127+
links: videoLinks,
128+
...(params.extended ? { params } : {})
119129
}
120130
}

0 commit comments

Comments
 (0)