LuanRT / YouTube.js

A JavaScript client for YouTube's private API, known as InnerTube.
https://ytjs.dev
MIT License
3.6k stars 234 forks source link

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

Open twicer-is-coder opened 3 months ago

twicer-is-coder commented 3 months 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 months 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 months 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.