node-ytdl-core icon indicating copy to clipboard operation
node-ytdl-core copied to clipboard

Improve video details extraction by using innertube API

Open WaqasIbrahim opened this issue 4 years ago • 5 comments

YouTube is slowly migrating to their new innertube API and we should consider using the new API for consitent and reliable results. youtube-dl is already using this new API.

Examples:

curl --location --request POST 'https://www.youtube.com/youtubei/v1/player?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8' \
--header 'Content-Type: application/json' \
--data-raw '{
    "context": {
        "client": {
            "clientName": "WEB",
            "clientVersion": "2.20210623.00.00"
        }
    },
    "videoId": "vKJpN5FAeF4"
}'

An age restricted video that does not work with get_video_info route.

curl --location --request POST 'https://www.youtube.com/youtubei/v1/player?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8' \
--header 'Content-Type: application/json' \
--data-raw '{
    "context": {
        "client": {
            "clientName": "WEB_EMBEDDED_PLAYER",
            "clientVersion": "1.20210623.1.0"
        }
    },
    "videoId": "HtVdAasjOgU"
}'

The API key and client version can be extracted from watch or embed page.

WaqasIbrahim avatar Jun 27 '21 13:06 WaqasIbrahim

I published an innertube library two days ago. The biggest issues I found was that innertube would happily deliver ciphered streams that would not play (403) when deciphered (solved when your post request includes a valid playback context with the correct signature timestamp from the player). Also when making a logged-in request (bypassing age-restriction), you need to supply a SAPISIDHASH, which is another obfuscated function from the yt player. So it is tricky to depend only on the innertube, unless you are emulating exactly what is happening in the browser.

gatecrasher777 avatar Aug 12 '21 19:08 gatecrasher777

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 12 '21 14:10 stale[bot]

In the getInfo pipeline only the html watch page seems to be working at present. The json watch page request is ignored by YT and the get_video_info call returns 410 errors. Inevitably, a move to the innerube api is needed. For these reasons this issue should not become stale.

gatecrasher777 avatar Oct 16 '21 06:10 gatecrasher777

@gatecrasher777 the JSON watch page works, you just need to use specific cookies (in Europe you also need to send the cookies that get created when you accept the GDPR popup), you don't have to be logged in to YouTube. The JSON watch page is used by YouTube when you accept a viewer discretion popup.

screenshot of viewer discretion

absidue avatar Jan 12 '22 22:01 absidue