refactor: get visitor data from the API [skip ci]

This commit is contained in:
LuanRT
2022-10-13 16:39:56 -03:00
parent 1b2862c00f
commit 2a78d77aa3
3 changed files with 3 additions and 21 deletions

View File

@@ -1,12 +1,11 @@
import Player from './Player';
import Proto from '../proto/index';
import Actions from './Actions';
import Constants from '../utils/Constants';
import UniversalCache from '../utils/Cache';
import EventEmitterLike from '../utils/EventEmitterLike';
import HTTPClient, { FetchFunction } from '../utils/HTTPClient';
import { DeviceCategory, generateRandomString, getRandomUserAgent, InnertubeError, SessionError } from '../utils/Utils';
import { DeviceCategory, getRandomUserAgent, InnertubeError, SessionError } from '../utils/Utils';
import OAuth, { Credentials, OAuthAuthErrorEventHandler, OAuthAuthEventHandler, OAuthAuthPendingEventHandler } from './OAuth';
export enum ClientType {
@@ -140,16 +139,12 @@ export default class Session extends EventEmitterLike {
const [ [ device_info ], api_key ] = ytcfg;
const id = generateRandomString(11);
const timestamp = Math.floor(Date.now() / 1000);
const visitor_data = Proto.encodeVisitorData(id, timestamp);
const context: Context = {
client: {
hl: device_info[0],
gl: device_info[2],
remoteHost: device_info[3],
visitorData: visitor_data,
visitorData: data[3],
userAgent: device_info[14],
clientName: client_name,
clientVersion: device_info[16],

View File

@@ -1,17 +1,9 @@
import { CLIENTS } from '../utils/Constants';
import { u8ToBase64 } from '../utils/Utils';
import { VideoMetadata } from '../core/Studio';
import { ChannelAnalytics, CreateCommentParams, CreateCommentReplyParams, GetCommentsSectionParams, InnertubePayload, LiveMessageParams, MusicSearchFilter, NotificationPreferences, PeformCommentActionParams, SearchFilter, SoundInfoParams, VisitorData } from './youtube';
import { ChannelAnalytics, CreateCommentParams, CreateCommentReplyParams, GetCommentsSectionParams, InnertubePayload, LiveMessageParams, MusicSearchFilter, NotificationPreferences, PeformCommentActionParams, SearchFilter, SoundInfoParams } from './youtube';
class Proto {
static encodeVisitorData(id: string, timestamp: number) {
const buf = VisitorData.toBinary({
id,
timestamp
});
return encodeURIComponent(u8ToBase64(buf).replace(/\/|\+/g, '_'));
}
static encodeChannelAnalyticsParams(channel_id: string) {
const buf = ChannelAnalytics.toBinary({
params: {

View File

@@ -3,11 +3,6 @@
syntax = "proto2";
package youtube;
message VisitorData {
required string id = 1;
required int32 timestamp = 5;
}
message ChannelAnalytics {
message Params {
required string channel_id = 1001;