Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ 🧹 ] Editorconfig , Querystring Replacement , Shorter Test Video #9

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion deps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export {default as querystring} from "https://esm.sh/[email protected]";
export { humanStr as parseTimestamp } from "https://raw.githubusercontent.com/fent/node-m3u8stream/master/src/parse-time.ts";
export * as sax from "https://deno.land/x/[email protected]/src/sax.ts";
export { default as m3u8stream } from "https://esm.sh/[email protected]";
4 changes: 2 additions & 2 deletions src/info.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { querystring, sax } from "../deps.ts";
import { sax } from "../deps.ts";
import { Cache } from "./cache.ts";
import * as sig from "./sig.ts";
import * as urlUtils from "./url_utils.ts";
Expand Down Expand Up @@ -416,7 +416,7 @@ const getVideoInfoPage = async (id: string, options: GetInfoOptions) => {
url.searchParams.set("cver", `7${cver.substr(1)}`);
url.searchParams.set("html5", "1");
let body = await request(url.toString(), options).then((e) => e.text());
let info = querystring.decode(body);
let info = Object.fromEntries([ ... new URLSearchParams(body).entries() ]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can simply do Object.fromEntries(new URLSearchParams(body))

info.player_response = findPlayerResponse("get_video_info", info);
return info;
};
Expand Down
6 changes: 4 additions & 2 deletions src/info_extras.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseTimestamp, querystring as qs } from "../deps.ts";
import { parseTimestamp } from "../deps.ts";
import * as utils from "./utils.ts";

const BASE_URL = "https://www.youtube.com/watch?v=";
Expand Down Expand Up @@ -223,7 +223,9 @@ export const getRelatedVideos = (info: any) => {
try {
rvsParams = info.response.webWatchNextResponseExtensionData.relatedVideoArgs
.split(",")
.map((e: any) => qs.parse(e));
.map((e: any) => new URLSearchParams(e))
.map(( params ) => [ ... params.entries() ] )
.map(( params ) => Object.fromEntries(params) );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI this is an array, not a lazy iterator where chained maps can combine for less time complexity. This is going to iterate over the params 3 * n times. Just do

.map((e: any) => Object.fromEntries(new URLSearchParams(e)))

} catch (err) {
// Do nothing.
}
Expand Down
11 changes: 5 additions & 6 deletions src/sig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { querystring } from "../deps.ts";
import { Cache } from "./cache.ts";
import { between, cutAfterJSON } from "./utils.ts";
import { request } from "./request.ts";
Expand Down Expand Up @@ -100,12 +99,12 @@ export function setDownloadURL(
nTransformScript: ((ncode: string) => string) | undefined
) {
const decipher = (url: string) => {
const args = querystring.parse(url) as any;
if (!args.s || !decipherScript) return args.url;
const components = new URL(decodeURIComponent(args.url));
const args = new URLSearchParams(url) as any;
if (!args.has('s') || !decipherScript) return args.get('url');
const components = new URL(decodeURIComponent(args.get('url')));
components.searchParams.set(
args.sp ? args.sp : "signature",
decipherScript(decodeURIComponent(args.s))
args.has('sp') ? args.get('sp') : "signature",
decipherScript(decodeURIComponent(args.get('s')))
);
return components.toString();
};
Expand Down