Skip to content

Commit

Permalink
[WIP]: Support other server (#111)
Browse files Browse the repository at this point in the history
* 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
tachibana-shin authored Apr 24, 2023
1 parent e555298 commit 316412b
Show file tree
Hide file tree
Showing 20 changed files with 608 additions and 320 deletions.
15 changes: 15 additions & 0 deletions src/apis/parser/ajax/player-fb.spec.ts
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",
})
})
})
13 changes: 13 additions & 0 deletions src/apis/parser/ajax/player-fb.ts
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")!,
}
}
4 changes: 2 additions & 2 deletions src/apis/parser/phim/[id]/[chap].ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function PhimIdChap(html: string) {
hash: $item.attr("data-hash")!,

name: $item.text().trim(),
}
} as const
})
.toArray()
const [day, hour, minus] =
Expand All @@ -32,7 +32,7 @@ export default function PhimIdChap(html: string) {
const poster = $(".TPostBg img").attr("src")!

return {
chaps,
chaps: chaps as Readonly<typeof chaps>,
update: !day
? null
: ([dayTextToNum(day.toLowerCase()), +hour, +minus] as [
Expand Down
23 changes: 23 additions & 0 deletions src/apis/runs/ajax/player-fb.ts
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)
}
72 changes: 72 additions & 0 deletions src/apis/runs/ajax/player-link.ts
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
})
}
4 changes: 4 additions & 0 deletions src/apis/workers/ajax/player-fb.ts
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)
Loading

0 comments on commit 316412b

Please sign in to comment.