forked from anime-vsub/app
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add apis * typo * feat: typo * feat: api * add logic `get-quality-by-label.ts` * typo * [WIP]: support multiple server and multiple quality (1080p, 480p?) * fix test * typo `artQuality` * resolve need change * reactive `artQuality` value invalidate `sources` * remove redundant logic
- Loading branch information
1 parent
e555298
commit 316412b
Showing
20 changed files
with
608 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import AjaxPlayerFBParser from "./player-fb" | ||
|
||
describe("player", () => { | ||
test("AjaxPlayerFBParser", () => { | ||
expect( | ||
AjaxPlayerFBParser( | ||
'<h3>Chọn Server:</h3> <a class="btn3dsv active" href="#" data-id="0" data-play="api" data-href="yYIUcEbWNhNTfgVmsy0mGm12d-u_2ogvAIMZCMh3fl1vqtA87eKXLK7ANDBjJKmuweuDgeLYwKrhZmGzGUhnyE_7M9u1pa0YwTYGFTpZiMF2wU96TBvthRucajflBLQy">DU</a><a class="btn3dsv" href="#" data-id="2" data-play="api" data-href="SEAiZc7pSjNkB2hc9Z9HAgcH_OmZzuBHytI_Q51KqtyHg-T0WfhwQAmVV6i4TM4VtHrk09wA6YFztU0wUl4fCw">FB</a><a class="btn3dsv" href="#" data-id="3" data-play="embed" data-href="iJOmPd0bzrHcLIv-vNMUV14kWPVgfuUPYlynlv6lROsyoC3EbhZV21qkjVq8BcApGAiL-Xe4D95_ti5KfeRm2Q">HDX(ADS)</a>' | ||
) | ||
).toEqual({ | ||
id: "2", | ||
play: "api", | ||
hash: "SEAiZc7pSjNkB2hc9Z9HAgcH_OmZzuBHytI_Q51KqtyHg-T0WfhwQAmVV6i4TM4VtHrk09wA6YFztU0wUl4fCw", | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
import { parserDom } from "../__helpers__/parserDom" | ||
|
||
export default function AjaxPlayerFBParser(html: string) { | ||
const $ = parserDom(html) | ||
const a = $("a:eq(1)") | ||
|
||
return { | ||
id: a.attr("data-id")!, | ||
play: a.attr("data-play")!, | ||
hash: a.attr("data-href")!, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type AjaxPlayerFBParser from "src/apis/parser/ajax/player-fb" | ||
import Worker from "src/apis/workers/ajax/player-fb?worker" | ||
import { PostWorker } from "src/apis/wrap-worker" | ||
import { post } from "src/logic/http" | ||
|
||
import { PlayerLink } from "./player-link" | ||
|
||
export async function PlayerFB(episodeId: string) { | ||
const { data: json } = await post("/ajax/player?v=2019a", { | ||
episodeId, | ||
backup: 1, | ||
}) | ||
|
||
const data = JSON.parse(json) | ||
|
||
// eslint-disable-next-line functional/no-throw-statement | ||
if (!data.success) throw new Error("Failed load player facebook") | ||
|
||
const config = await PostWorker<typeof AjaxPlayerFBParser>(Worker, data.html) | ||
|
||
|
||
return await PlayerLink(config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { getQualityByLabel } from "src/logic/get-quality-by-label" | ||
import { post } from "src/logic/http" | ||
|
||
const addProtocolUrl = (file: string) => | ||
file.startsWith("http") ? file : `https:${file}` | ||
|
||
interface PlayerLinkReturn { | ||
readonly link: { | ||
readonly file: string | ||
readonly label: "FHD|HD" | "HD" | "FHD" | `${720 | 360 | 340}p` | ||
readonly qualityCode: ReturnType<typeof getQualityByLabel> | ||
readonly preload?: string | ||
readonly type: | ||
| "hls" | ||
| "aac" | ||
| "f4a" | ||
| "mp4" | ||
| "f4v" | ||
| "m3u" | ||
| "m3u8" | ||
| "m4v" | ||
| "mov" | ||
| "mp3" | ||
| "mpeg" | ||
| "oga" | ||
| "ogg" | ||
| "ogv" | ||
| "vorbis" | ||
| "webm" | ||
| "youtube" | ||
}[] | ||
readonly playTech: "api" | "trailer" | ||
} | ||
export function PlayerLink(config: { | ||
id: string | ||
play: string | ||
hash: string | ||
}): Promise<PlayerLinkReturn> { | ||
const { id, play, hash: link } = config | ||
return post("/ajax/player?v=2019a", { | ||
id, | ||
play, | ||
link, | ||
backuplinks: "1", | ||
}).then(({ data }) => { | ||
// eslint-disable-next-line functional/no-throw-statement | ||
if (!data) throw new Error("unknown_error") | ||
type Writeable<T> = { | ||
-readonly [P in keyof T]: T[P] extends object ? Writeable<T[P]> : T[P] | ||
} | ||
const config = JSON.parse(data) as Writeable<PlayerLinkReturn> | ||
config.link.forEach((item) => { | ||
item.file = addProtocolUrl(item.file) | ||
switch ( | ||
(item.label as typeof item.label | undefined)?.toUpperCase() as | ||
| Uppercase<Exclude<typeof item.label, undefined>> | ||
| undefined | ||
) { | ||
case "HD": | ||
if (item.preload) item.label = "FHD|HD" | ||
break | ||
case undefined: | ||
item.label = "HD" | ||
break | ||
} | ||
item.qualityCode = getQualityByLabel(item.label) | ||
item.type ??= "mp4" | ||
}) | ||
|
||
return config | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import PlayerFB from "src/apis/parser/ajax/player-fb" | ||
import { WrapWorker } from "src/apis/wrap-worker" | ||
|
||
WrapWorker(PlayerFB) |
Oops, something went wrong.