Skip to content

Commit

Permalink
feat: Add MWEB client
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanRT committed Dec 8, 2024
1 parent eaf6d1a commit 4bf125b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
4 changes: 3 additions & 1 deletion examples/auth/custom-oauth2-creds/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ app.get('/', async (_req, res) => {
console.info('Innertube instance is logged in.');

const userInfo = await innertube.account.getInfo();

console.log(await innertube.getBasicInfo('R8vgwMYSQi8', 'ANDROID'));

return res.send({ userInfo });
return res.send({ userInfo });
}

if (!oAuth2Client) {
Expand Down
3 changes: 3 additions & 0 deletions src/core/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ export default class Player {
case 'WEB':
url_components.searchParams.set('cver', Constants.CLIENTS.WEB.VERSION);
break;
case 'MWEB':
url_components.searchParams.set('cver', Constants.CLIENTS.MWEB.VERSION);
break;
case 'WEB_REMIX':
url_components.searchParams.set('cver', Constants.CLIENTS.YTMUSIC.VERSION);
break;
Expand Down
1 change: 1 addition & 0 deletions src/core/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type { OAuth2Tokens, OAuth2AuthErrorEventHandler, OAuth2AuthPendingEventH

export enum ClientType {
WEB = 'WEB',
MWEB = 'MWEB',
KIDS = 'WEB_KIDS',
MUSIC = 'WEB_REMIX',
IOS = 'iOS',
Expand Down
2 changes: 1 addition & 1 deletion src/types/Misc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { SessionOptions } from '../core/index.js';

export type InnerTubeConfig = SessionOptions;
export type InnerTubeClient = 'IOS' | 'WEB' | 'ANDROID' | 'YTMUSIC' | 'YTMUSIC_ANDROID' | 'YTSTUDIO_ANDROID' | 'TV' | 'TV_EMBEDDED' | 'YTKIDS' | 'WEB_EMBEDDED' | 'WEB_CREATOR';
export type InnerTubeClient = 'IOS' | 'WEB' | 'MWEB' | 'ANDROID' | 'YTMUSIC' | 'YTMUSIC_ANDROID' | 'YTSTUDIO_ANDROID' | 'TV' | 'TV_EMBEDDED' | 'YTKIDS' | 'WEB_EMBEDDED' | 'WEB_CREATOR';

export type UploadDate = 'all' | 'hour' | 'today' | 'week' | 'month' | 'year';
export type SearchType = 'all' | 'video' | 'channel' | 'playlist' | 'movie';
Expand Down
8 changes: 7 additions & 1 deletion src/utils/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ export const CLIENTS = Object.freeze({
API_VERSION: 'v1',
STATIC_VISITOR_ID: '6zpwvWUNAco'
},
MWEB: {
NAME_ID: '2',
NAME: 'MWEB',
VERSION: '2.20241205.01.00',
API_VERSION: 'v1'
},
WEB_KIDS: {
NAME_ID: '76',
NAME: 'WEB_KIDS',
Expand Down Expand Up @@ -105,4 +111,4 @@ export const INNERTUBE_HEADERS_BASE = Object.freeze({
'content-type': 'application/json'
});

export const SUPPORTED_CLIENTS = [ 'IOS', 'WEB', 'YTKIDS', 'YTMUSIC', 'ANDROID', 'YTSTUDIO_ANDROID', 'YTMUSIC_ANDROID', 'TV', 'TV_EMBEDDED', 'WEB_EMBEDDED', 'WEB_CREATOR' ];
export const SUPPORTED_CLIENTS = [ 'IOS', 'WEB', 'MWEB', 'YTKIDS', 'YTMUSIC', 'ANDROID', 'YTSTUDIO_ANDROID', 'YTMUSIC_ANDROID', 'TV', 'TV_EMBEDDED', 'WEB_EMBEDDED', 'WEB_CREATOR' ];
6 changes: 6 additions & 0 deletions src/utils/HTTPClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ export default class HTTPClient {
}

switch (client.toUpperCase()) {
case 'MWEB':
ctx.client.clientVersion = Constants.CLIENTS.MWEB.VERSION;
ctx.client.clientName = Constants.CLIENTS.MWEB.NAME;
ctx.client.clientFormFactor = 'SMALL_FORM_FACTOR';
ctx.client.platform = 'MOBILE';
break;
case 'IOS':
ctx.client.deviceMake = 'Apple';
ctx.client.deviceModel = Constants.CLIENTS.IOS.DEVICE_MODEL;
Expand Down

0 comments on commit 4bf125b

Please sign in to comment.