GUI-STUDIO commited on
Commit ·
d650b92
1
Parent(s): c41e39d
Add proxima fallback support and refactor scraper structure
Browse filesReorganizes scraper files into a generic folder structure and adds fail_back support for proxima proxy handling. Updates ffmpeg v2 validator and router to handle proxy fallback attempts. Adds valibot dependency. Updates showtime.ts to use function calls for credentials and repository configuration instead of direct values.
- package.json +2 -1
- src/sub-router/ffmpeg/v2.ts +103 -6
- src/sub-router/ffmpeg/validator-v2.ts +8 -7
- src/sub-router/showtime.ts +4 -4
package.json
CHANGED
|
@@ -46,7 +46,8 @@
|
|
| 46 |
"random-string-generator": "^1.0.7",
|
| 47 |
"random-word-slugs": "^0.1.7",
|
| 48 |
"txtgen": "^3.0.7",
|
| 49 |
-
"user-agents": "^2.1.4"
|
|
|
|
| 50 |
},
|
| 51 |
"devDependencies": {
|
| 52 |
"bun-types": "latest",
|
|
|
|
| 46 |
"random-string-generator": "^1.0.7",
|
| 47 |
"random-word-slugs": "^0.1.7",
|
| 48 |
"txtgen": "^3.0.7",
|
| 49 |
+
"user-agents": "^2.1.4",
|
| 50 |
+
"valibot": "^1.4.2"
|
| 51 |
},
|
| 52 |
"devDependencies": {
|
| 53 |
"bun-types": "latest",
|
src/sub-router/ffmpeg/v2.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { offline_store } from "../../lib/offline-store";
|
|
| 9 |
import { NS_validator_v2, T_live, T_playback } from "./validator-v2";
|
| 10 |
import UserAgent from "user-agents";
|
| 11 |
import { NS_runtime } from "../../../../../../packages/lib/env.runtime";
|
|
|
|
| 12 |
|
| 13 |
const APP_ACCOUNT_ABC = () =>
|
| 14 |
NS_runtime.ENV_VAR_DB?.APP_ACCOUNT_ABC || process.env.APP_ACCOUNT_ABC;
|
|
@@ -110,13 +111,105 @@ const sub_router = new Elysia({ prefix: "/ffmpeg/v2" }).post(
|
|
| 110 |
.join("");
|
| 111 |
})();
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
// RUN RAW PROBE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
const [E_, R_] = await NS_promise.F_catch_promise({
|
| 115 |
-
promise:
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
});
|
| 121 |
|
| 122 |
if (E_) {
|
|
@@ -134,7 +227,11 @@ const sub_router = new Elysia({ prefix: "/ffmpeg/v2" }).post(
|
|
| 134 |
})();
|
| 135 |
|
| 136 |
if (!live) {
|
| 137 |
-
return {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
}
|
| 139 |
|
| 140 |
const clean_metadata = NS_ffmpeg_v2.F_scan_raw_probe_metadata({
|
|
|
|
| 9 |
import { NS_validator_v2, T_live, T_playback } from "./validator-v2";
|
| 10 |
import UserAgent from "user-agents";
|
| 11 |
import { NS_runtime } from "../../../../../../packages/lib/env.runtime";
|
| 12 |
+
import { NS_unpack_proxima } from "../../../../../../packages/lib/helpers/server/proxima/unpack";
|
| 13 |
|
| 14 |
const APP_ACCOUNT_ABC = () =>
|
| 15 |
NS_runtime.ENV_VAR_DB?.APP_ACCOUNT_ABC || process.env.APP_ACCOUNT_ABC;
|
|
|
|
| 111 |
.join("");
|
| 112 |
})();
|
| 113 |
|
| 114 |
+
// decoded proxima
|
| 115 |
+
const dencoded_px = await (async () => {
|
| 116 |
+
const _ = new URL(playback.url);
|
| 117 |
+
|
| 118 |
+
if (!_.pathname.startsWith("/proxima") || !playback.fail_back) {
|
| 119 |
+
return;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
const encoded_data = _.pathname.split("/").slice(-1)[0];
|
| 123 |
+
|
| 124 |
+
if (!encoded_data) return;
|
| 125 |
+
|
| 126 |
+
const [E_, R_] = await NS_promise.F_catch_promise({
|
| 127 |
+
promise: NS_unpack_proxima.F_unpack_proxima_endpoint_n_commands({
|
| 128 |
+
proxima_encoded: encoded_data
|
| 129 |
+
})
|
| 130 |
+
});
|
| 131 |
+
|
| 132 |
+
if (!R_) return;
|
| 133 |
+
|
| 134 |
+
const decoded_proxy_endpoint = R_.decoded_proxy_endpoint;
|
| 135 |
+
const decoded_proxy_commands = R_.decoded_proxy_commands;
|
| 136 |
+
|
| 137 |
+
if (!decoded_proxy_endpoint) return;
|
| 138 |
+
|
| 139 |
+
const target = decoded_proxy_endpoint;
|
| 140 |
+
|
| 141 |
+
const headers = (() => {
|
| 142 |
+
const _h = decoded_proxy_commands?.headers;
|
| 143 |
+
|
| 144 |
+
if (_h && NS_misc.is_plain_object(_h)) {
|
| 145 |
+
return {
|
| 146 |
+
..._h,
|
| 147 |
+
"User-Agent": (playback as any)?.headers?.["User-Agent"]
|
| 148 |
+
};
|
| 149 |
+
}
|
| 150 |
+
})();
|
| 151 |
+
|
| 152 |
+
return {
|
| 153 |
+
target,
|
| 154 |
+
headers
|
| 155 |
+
};
|
| 156 |
+
})();
|
| 157 |
+
|
| 158 |
// RUN RAW PROBE
|
| 159 |
+
async function run(arg0: { playback: T_playback }) {
|
| 160 |
+
const { playback } = arg0;
|
| 161 |
+
|
| 162 |
+
const [E_, R_] = await NS_promise.F_catch_promise({
|
| 163 |
+
promise: NS_ffmpeg_v2.F_probe_t1({
|
| 164 |
+
context: ctx,
|
| 165 |
+
playback,
|
| 166 |
+
timeout
|
| 167 |
+
})
|
| 168 |
+
});
|
| 169 |
+
|
| 170 |
+
if (E_) throw E_;
|
| 171 |
+
|
| 172 |
+
return R_;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
const [E_, R_] = await NS_promise.F_catch_promise({
|
| 176 |
+
promise: (async () => {
|
| 177 |
+
const og_playback = { ...playback };
|
| 178 |
+
|
| 179 |
+
let fail_back = false;
|
| 180 |
+
|
| 181 |
+
if (playback.fail_back && dencoded_px?.target) {
|
| 182 |
+
playback.headers = dencoded_px.headers;
|
| 183 |
+
playback.url = dencoded_px.target.toString();
|
| 184 |
+
|
| 185 |
+
fail_back = true;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
let [E_, R_] = await NS_promise.F_catch_promise({
|
| 189 |
+
promise: run({ playback })
|
| 190 |
+
});
|
| 191 |
+
|
| 192 |
+
if (E_ && fail_back) {
|
| 193 |
+
(playback as any).fail_back = true;
|
| 194 |
+
|
| 195 |
+
playback.headers = og_playback.headers;
|
| 196 |
+
playback.url = og_playback.url;
|
| 197 |
+
|
| 198 |
+
if (APP_ENV() === "dev") {
|
| 199 |
+
console.log("RUNNING FAIL BACK");
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
[E_, R_] = await NS_promise.F_catch_promise({
|
| 203 |
+
promise: run({ playback })
|
| 204 |
+
});
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
if (E_) {
|
| 208 |
+
throw E_;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
return R_;
|
| 212 |
+
})()
|
| 213 |
});
|
| 214 |
|
| 215 |
if (E_) {
|
|
|
|
| 227 |
})();
|
| 228 |
|
| 229 |
if (!live) {
|
| 230 |
+
return {
|
| 231 |
+
qLevel,
|
| 232 |
+
fail_back: (playback as any).fail_back,
|
| 233 |
+
...probe_metadata
|
| 234 |
+
};
|
| 235 |
}
|
| 236 |
|
| 237 |
const clean_metadata = NS_ffmpeg_v2.F_scan_raw_probe_metadata({
|
src/sub-router/ffmpeg/validator-v2.ts
CHANGED
|
@@ -7,13 +7,9 @@ const playback = t.Object(
|
|
| 7 |
errorMessage: "Invalid playback url"
|
| 8 |
}),
|
| 9 |
headers: t.Optional(
|
| 10 |
-
t.
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
additionalProperties: true,
|
| 14 |
-
errorMessage: "Invalid playback headers"
|
| 15 |
-
}
|
| 16 |
-
)
|
| 17 |
),
|
| 18 |
type: t.Union([t.Literal("hls"), t.Literal("video")], {
|
| 19 |
errorMessage: "Invalid playback type: expected HLS or VIDEO"
|
|
@@ -33,6 +29,11 @@ const playback = t.Object(
|
|
| 33 |
error: () =>
|
| 34 |
"ideal runtime must be a positive integer greater than zero"
|
| 35 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
)
|
| 37 |
},
|
| 38 |
{ errorMessage: "Invalid playback data" }
|
|
|
|
| 7 |
errorMessage: "Invalid playback url"
|
| 8 |
}),
|
| 9 |
headers: t.Optional(
|
| 10 |
+
t.Record(t.String(), t.Any(), {
|
| 11 |
+
error: () => "Invalid playback headers"
|
| 12 |
+
})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
),
|
| 14 |
type: t.Union([t.Literal("hls"), t.Literal("video")], {
|
| 15 |
errorMessage: "Invalid playback type: expected HLS or VIDEO"
|
|
|
|
| 29 |
error: () =>
|
| 30 |
"ideal runtime must be a positive integer greater than zero"
|
| 31 |
})
|
| 32 |
+
),
|
| 33 |
+
fail_back: t.Optional(
|
| 34 |
+
t.Union([t.Literal(1), t.Literal(0)], {
|
| 35 |
+
errorMessage: "Invalid failback, Expected binary boolean"
|
| 36 |
+
})
|
| 37 |
)
|
| 38 |
},
|
| 39 |
{ errorMessage: "Invalid playback data" }
|
src/sub-router/showtime.ts
CHANGED
|
@@ -14,7 +14,7 @@ import path from "node:path";
|
|
| 14 |
import ky from "ky";
|
| 15 |
import * as hub from "@huggingface/hub";
|
| 16 |
import { NS_mongo_db_record_factory } from "../../../../../packages/db/index";
|
| 17 |
-
import { NS_bucket,
|
| 18 |
import { NS_runtime } from "../../../../../packages/lib/env.runtime";
|
| 19 |
|
| 20 |
const APP_ENV = () => NS_runtime.ENV_VAR_DB?.APP_ENV || process.env.APP_ENV;
|
|
@@ -396,7 +396,7 @@ async function F_handle_process(arg0: {
|
|
| 396 |
|
| 397 |
const cache_folder = `cache/${sbe_id}`;
|
| 398 |
|
| 399 |
-
const S3Dir = path.join(STORAGE_ROOT, `${cache_folder}`);
|
| 400 |
|
| 401 |
const tmp_file_name = `${Date.now()}${picture_quality && picture_quality.trim() ? `-${picture_quality.trim()}` : ""}-${output_destination}`;
|
| 402 |
|
|
@@ -1197,8 +1197,8 @@ async function F_handle_process(arg0: {
|
|
| 1197 |
|
| 1198 |
const [E_, R_] = await NS_promise.F_catch_promise({
|
| 1199 |
promise: hub.uploadFiles({
|
| 1200 |
-
repo,
|
| 1201 |
-
accessToken:
|
| 1202 |
files: [
|
| 1203 |
{
|
| 1204 |
path: file_path,
|
|
|
|
| 14 |
import ky from "ky";
|
| 15 |
import * as hub from "@huggingface/hub";
|
| 16 |
import { NS_mongo_db_record_factory } from "../../../../../packages/db/index";
|
| 17 |
+
import { NS_bucket, STORAGE_ROOT,bucket_credentials, hf_repo } from "../lib/bucket";
|
| 18 |
import { NS_runtime } from "../../../../../packages/lib/env.runtime";
|
| 19 |
|
| 20 |
const APP_ENV = () => NS_runtime.ENV_VAR_DB?.APP_ENV || process.env.APP_ENV;
|
|
|
|
| 396 |
|
| 397 |
const cache_folder = `cache/${sbe_id}`;
|
| 398 |
|
| 399 |
+
const S3Dir = path.join(STORAGE_ROOT(), `${cache_folder}`);
|
| 400 |
|
| 401 |
const tmp_file_name = `${Date.now()}${picture_quality && picture_quality.trim() ? `-${picture_quality.trim()}` : ""}-${output_destination}`;
|
| 402 |
|
|
|
|
| 1197 |
|
| 1198 |
const [E_, R_] = await NS_promise.F_catch_promise({
|
| 1199 |
promise: hub.uploadFiles({
|
| 1200 |
+
repo: hf_repo(),
|
| 1201 |
+
accessToken: bucket_credentials().accessToken,
|
| 1202 |
files: [
|
| 1203 |
{
|
| 1204 |
path: file_path,
|