ybd-project-ver1 / ytdl-core

Temporary transfer repository for ybd-project/ytdl-core
MIT License
10 stars 3 forks source link

[New Version] About v6.0.5 #31

Open ybd-project-ver1 opened 6 days ago

ybd-project-ver1 commented 6 days ago

Description

We are currently planning to release v6.0.5 with the following specification changes. Are there any features or requests that you would like to see added?

v6.0.5

Features

Change

Abolition

/ Or /

import { YtdlCore, toPipeableStream } from '@ybd-project/ytdl-core/serverless';



### Bug Fixes
* **YtdlCore:** Various bugs fixed

### Improvement
* **YtdlCore:** Remove unnecessary packages and reduce package size.
Elite commented 6 days ago

@ybd-project-ver1 Can I use this in a userscript without the need for a proxy, if a proxy is absolutely needed will the links generated by this tied to proxy IP or browser IP ?

ybd-project-ver1 commented 6 days ago

@ybd-project-ver1 Can I use this in a userscript without the need for a proxy, if a proxy is absolutely needed will the links generated by this tied to proxy IP or browser IP ?

Whether a proxy is needed or not depends on whether CORS can be bypassed; if CORS can be bypassed, it is not needed. If a proxy is required, the IP is difficult to forge.

Elite commented 6 days ago

Thanks for clarifying, can you pls. share what is the best innertube client as of now to get pre-muxed 360p link and audio only streams and does it require signature decoding and poToken to avoid HTTP403 ?

ybd-project-ver1 commented 6 days ago

Thanks for clarifying, can you pls. share what is the best innertube client as of now to get pre-muxed 360p link and audio only streams and does it require signature decoding and poToken to avoid HTTP403 ?

There are ways to avoid 403s, such as making requests from the same IP or using a proxy. (not always effective) The iOS clients and web clients are currently the most stable clients for retrieving 360p (itag: 18) videos.

Elite commented 6 days ago

Thank you, but I believe my question was unclear. I wanted to ask if, when accessing valid downloadable streams from the WEB or iOS clients, do we need to decrypt the signature or supply the poToken or both?

In my userscript, I am directly accessing the Innertube API, but the iOS links are returning a 403 error when I try to download them. To clarify, these are raw links extracted by my script not from the library. My main question is: Do we need to use the poToken, decrypt the signature, or both to make the links work?

ybd-project-ver1 commented 6 days ago

ytdl-core parses URLs as follows

  1. retrieve formatting information
  2. if the format has a cipher (sig), decrypt it
  3. decrypt the N transform with the URL obtained in 2.
  4. get the URL that can be used. That is all. The actual code is as follows Note that for this cryptanalysis or N-transform decryption, you need to get the latest Base.js from YouTube and get the decryption function from there.
function setDownloadURL(format: YT_StreamingAdaptiveFormat, decipherFunction: string | null, nTransformFunction: string | null) {
    if (!decipherFunction) {
        return;
    }

    const decipher = (url: string): string => {
            const SEARCH_PARAMS = new URLSearchParams('?' + url),
                PARAMS_URL = SEARCH_PARAMS.get('url')?.toString() || '',
                PARAMS_S = SEARCH_PARAMS.get('s');

            if (!PARAMS_S) {
                return PARAMS_URL;
            }

            try {
                const COMPONENTS = new URL(decodeURIComponent(PARAMS_URL)),
                    CONTEXT: Record<string, string> = {};

                CONTEXT[DECIPHER_ARGUMENT] = decodeURIComponent(PARAMS_S);

                COMPONENTS.searchParams.set(SEARCH_PARAMS.get('sp')?.toString() || 'sig', runInNewContext(decipherFunction, CONTEXT));

                return COMPONENTS.toString();
            } catch (err) {
                Logger.debug(`[ Decipher ]: <error>Failed</error> to decipher URL: <error>${err}</error>`);
                return PARAMS_URL;
            }
        },
        nTransform = (url: string): string => {
            const COMPONENTS = new URL(decodeURIComponent(url)),
                N = COMPONENTS.searchParams.get('n');

            if (!N || !nTransformFunction) {
                return url;
            }

            const CONTEXT: Record<string, string> = {};

            CONTEXT[N_ARGUMENT] = N;

            COMPONENTS.searchParams.set('n', runInNewContext(nTransformFunction, CONTEXT));

            return COMPONENTS.toString();
        },
        CIPHER = !format.url,
        VIDEO_URL = format.url || format.signatureCipher || format.cipher;

    if (!VIDEO_URL) {
        return;
    }

    format.url = nTransform(CIPHER ? decipher(VIDEO_URL) : VIDEO_URL);
    delete format.signatureCipher;
    delete format.cipher;
}
Elite commented 6 days ago

@ybd-project-ver1 Amazing, thanks for the help :)