Skip to content

Commit

Permalink
fix(ytmusic): use static visitor id to avoid empty API responses
Browse files Browse the repository at this point in the history
Fixes #279
  • Loading branch information
LuanRT committed Mar 9, 2023
1 parent b2253df commit f9754f5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/core/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Actions from './Actions.js';
import Player from './Player.js';

import HTTPClient from '../utils/HTTPClient.js';
import { Platform, DeviceCategory, generateRandomString, getRandomUserAgent, InnertubeError, SessionError } from '../utils/Utils.js';
import { Platform, DeviceCategory, getRandomUserAgent, InnertubeError, SessionError } from '../utils/Utils.js';
import OAuth, { Credentials, OAuthAuthErrorEventHandler, OAuthAuthEventHandler, OAuthAuthPendingEventHandler } from './OAuth.js';
import Proto from '../proto/index.js';
import { ICache } from '../types/Cache.js';
Expand Down Expand Up @@ -232,7 +232,7 @@ export default class Session extends EventEmitterLike {
'user-agent': getRandomUserAgent('desktop'),
'accept': '*/*',
'referer': 'https://www.youtube.com/sw.js',
'cookie': `PREF=tz=${options.time_zone.replace('/', '.')}`
'cookie': `PREF=tz=${options.time_zone.replace('/', '.')};VISITOR_INFO1_LIVE=${Constants.CLIENTS.WEB.STATIC_VISITOR_ID};`
}
});

Expand Down Expand Up @@ -294,7 +294,7 @@ export default class Session extends EventEmitterLike {
client_name: string;
enable_safety_mode: boolean
}): SessionData {
const id = generateRandomString(11);
const id = Constants.CLIENTS.WEB.STATIC_VISITOR_ID;
const timestamp = Math.floor(Date.now() / 1000);

const context: Context = {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export const CLIENTS = Object.freeze({
NAME: 'WEB',
VERSION: '2.20230104.01.00',
API_KEY: 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8',
API_VERSION: 'v1'
API_VERSION: 'v1',
STATIC_VISITOR_ID: '6zpwvWUNAco'
},
WEB_KIDS: {
NAME: 'WEB_KIDS',
Expand Down

0 comments on commit f9754f5

Please sign in to comment.