LuanRT / YouTube.js

A wrapper around YouTube's internal API — reverse engineering InnerTube
https://www.npmjs.com/package/youtubei.js
MIT License
3.48k stars 219 forks source link

<10.2.0> <Failed to request player id> #709

Open twicer-is-coder opened 1 month ago

twicer-is-coder commented 1 month ago

Steps to reproduce

const basicInfo = await yt.getBasicInfo(videoId);

Failure Logs

Failed to request player id

Expected behavior

Should return basic info.

Current behavior

Throwing error: Failed to request player id.

Version

Default

Anything else?

I am importing from "youtubei.js/cf-worker".

Checklist

benank commented 2 weeks ago

I ran into the same issue and was able to solve it by adding extra headers for the Youtube iframe request:

Innertube.create({
        client_type: ClientType.TV_EMBEDDED,
        retrieve_player: false,
        generate_session_locally: true,
        device_category: 'mobile',
        fetch: async (input, init) => {
            init ??= {};
            init.headers ??= {};

            const headers = init.headers as Record<string, string>;
            if (input.toString().includes('iframe')) {
                headers['User-Agent'] = yt?.session.context.client.userAgent ?? '';
                headers['X-Goog-Visitor-Id'] = yt?.session.context.client.visitorData ?? '';
                headers['X-Youtube-Client-Version'] = yt?.session.context.client.clientVersion ?? '';
                headers['X-Youtube-Client-Name'] = yt?.session.context.client.clientName ?? '';
                headers['Origin'] = 'https://www.youtube.com';
            }

            init.headers = {
                ...init?.headers,
                ...headers
            };

            return await fetch(input, init);
        }
    })
twicer-is-coder commented 2 weeks ago
client_type: ClientType.TV_EMBEDDED,
      retrieve_player: false,
      generate_session_locally: true,
      device_category: 'mobile',

I tried this, with these settings it always failed with "message: Request to https://www.youtube.com/youtubei/v1/pla…prettyPrint=false&alt=json failed with status 404". Specially using this client type.