| import { Hono, type Context } from "hono"; |
| import { NS_error } from "../../../../packages/lib/helpers/client/error"; |
| import { sValidator } from "@hono/standard-validator"; |
| import { NS_promise } from "../../../../packages/lib/helpers/client/promise"; |
| import { NS_general_crawl } from "../../../../packages/lib/validator/general-crawl"; |
| import { hono_validator_callback } from "../lib/misc"; |
| import { NS_runtime } from "../../../../packages/lib/env.runtime"; |
| import { NS_flickystream_scraper } from "../../../../packages/lib/scraper/flickystream/exe"; |
| import { NS_scrape_post_processing } from "../../../../packages/lib/scraper/_post-processing/generic"; |
| import { T_prop_tmdb } from "../../../../packages/lib/helpers/server/streamify/lib-helper"; |
|
|
| const APP_ENV = () => NS_runtime.ENV_VAR_DB?.APP_ENV || process.env.APP_ENV; |
| const APP_ORIGIN = () => |
| NS_runtime.ENV_VAR_DB?.APP_ORIGIN || process.env.APP_ORIGIN; |
| const REPO_ORIGIN = () => |
| NS_runtime.ENV_VAR_DB?.REPO_ORIGIN || process.env.REPO_ORIGIN; |
|
|
| const subRouter = new Hono().basePath("/flickystream"); |
|
|
| subRouter.post( |
| "/scrape-playback", |
| sValidator("json", NS_general_crawl.route_schema.v, hono_validator_callback), |
| async (ctx) => { |
| const REQ0 = ctx.req.url; |
| const REQ_ORIGIN = APP_ORIGIN() || new URL(REQ0).origin; |
| const REQ_headers = ctx.req.raw.headers; |
|
|
| const req_signal = ctx.req.raw.signal; |
|
|
| const body = ctx.req.valid("json"); |
|
|
| const { film_type, id, id_type, headless, use, post_processing } = body; |
|
|
| const portal_url = new URL( |
| `/player/${film_type}/${id}${film_type === "tv" ? `/${body.season}/${body.episode}` : ""}`, |
| "https://flickystream.su" |
| ); |
|
|
| const tmdb: T_prop_tmdb = { |
| id, |
| type: film_type, |
| season: (body as any).season, |
| episode: (body as any).episode |
| }; |
|
|
| const [E_, R_] = await NS_promise.F_catch_promise({ |
| promise: NS_flickystream_scraper.runner({ |
| portal_url, |
| tmdb, |
| use: { |
| tool: use, |
| browser: { |
| headless |
| } |
| }, |
| thread_signal: req_signal |
| }) |
| }); |
|
|
| if (E_) { |
| const { status, message } = NS_error.F_collect_error_status_n_message({ |
| ERR: E_ |
| }); |
|
|
| return ctx.json({ error: message }, status); |
| } |
|
|
| let metadata = R_; |
|
|
| if (metadata && post_processing && REPO_ORIGIN() && id_type === "tmdb") { |
| const [E__, R__] = await NS_promise.F_catch_promise({ |
| promise: NS_scrape_post_processing.construct({ |
| portal: "flickystream", |
| pre_metadata: metadata, |
| tmdb: { |
| id, |
| type: film_type, |
| season: (body as any).season, |
| episode: (body as any).episode |
| }, |
| processing_payload: post_processing |
| }) |
| }); |
|
|
| if (R__?.metadata) { |
| metadata = R__.metadata as any; |
| } |
| } |
|
|
| return ctx.json({ data: metadata }); |
| } |
| ); |
|
|
| export const FlickystreamRouter = subRouter; |
|
|