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

fix(web): slow downloads due to visitor data #391

Merged
merged 2 commits into from
Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions src/core/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import Proto from '../proto/index.js';
import type { ICache } from '../types/Cache.js';
import type { FetchFunction } from '../types/PlatformShim.js';
import HTTPClient from '../utils/HTTPClient.js';
import type { DeviceCategory} from '../utils/Utils.js';
import { getRandomUserAgent, InnertubeError, Platform, SessionError } from '../utils/Utils.js';
import type { DeviceCategory } from '../utils/Utils.js';
import { generateRandomString, getRandomUserAgent, InnertubeError, Platform, SessionError } from '../utils/Utils.js';
import type { Credentials, OAuthAuthErrorEventHandler, OAuthAuthEventHandler, OAuthAuthPendingEventHandler } from './OAuth.js';
import OAuth from './OAuth.js';

Expand Down Expand Up @@ -236,7 +236,7 @@ export default class Session extends EventEmitterLike {
}, fetch: FetchFunction = Platform.shim.fetch): Promise<SessionData> {
const url = new URL('/sw.js_data', Constants.URLS.YT_BASE);

let visitor_id = Constants.CLIENTS.WEB.STATIC_VISITOR_ID;
let visitor_id = generateRandomString(11);

if (options.visitor_data) {
const decoded_visitor_data = Proto.decodeVisitorData(options.visitor_data);
Expand Down Expand Up @@ -308,7 +308,7 @@ export default class Session extends EventEmitterLike {
enable_safety_mode: boolean;
visitor_data: string;
}): SessionData {
let visitor_id = Constants.CLIENTS.WEB.STATIC_VISITOR_ID;
let visitor_id = generateRandomString(11);

if (options.visitor_data) {
const decoded_visitor_data = Proto.decodeVisitorData(options.visitor_data);
Expand Down
9 changes: 2 additions & 7 deletions src/core/endpoints/PlayerEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ export const PATH = '/player';
* @returns The payload.
*/
export function build(opts: PlayerEndpointOptions): IPlayerRequest {
const is_android =
opts.client === 'ANDROID' ||
opts.client === 'YTMUSIC_ANDROID' ||
opts.client === 'YTSTUDIO_ANDROID';

return {
playbackContext: {
contentPlaybackContext: {
Expand All @@ -39,8 +34,8 @@ export function build(opts: PlayerEndpointOptions): IPlayerRequest {
...{
client: opts.client,
playlistId: opts.playlist_id,
// Workaround streaming URLs returning 403 when using Android clients.
params: is_android ? '8AEB' : opts.params
// Workaround streaming URLs returning 403 when using Android clients and throttling in web clients.
params: '8AEB'
}
};
}