Skip to content

Commit

Permalink
feat(VideoInfo): support iOS client
Browse files Browse the repository at this point in the history
  • Loading branch information
ronnie-codes committed Aug 8, 2023
1 parent 0dda97e commit 0fec1cb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Innertube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import type { DownloadOptions, FormatOptions } from './utils/FormatUtils.js';

export type InnertubeConfig = SessionOptions;

export type InnerTubeClient = 'WEB' | 'ANDROID' | 'YTMUSIC_ANDROID' | 'YTMUSIC' | 'YTSTUDIO_ANDROID' | 'TV_EMBEDDED' | 'YTKIDS'
export type InnerTubeClient = 'WEB' | 'iOS' | 'ANDROID' | 'YTMUSIC_ANDROID' | 'YTMUSIC' | 'YTSTUDIO_ANDROID' | 'TV_EMBEDDED' | 'YTKIDS';

export type SearchFilters = Partial<{
upload_date: 'all' | 'hour' | 'today' | 'week' | 'month' | 'year';
Expand Down
6 changes: 6 additions & 0 deletions src/utils/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export const OAUTH = Object.freeze({
})
});
export const CLIENTS = Object.freeze({
iOS: {
NAME: 'iOS',
VERSION: '18.06.35',
USER_AGENT: 'com.google.ios.youtube/18.06.35 (iPhone; CPU iPhone OS 14_4 like Mac OS X; en_US)',
DEVICE_MODEL: 'iPhone10,6'
},
WEB: {
NAME: 'WEB',
VERSION: '2.20230622.06.00',
Expand Down
11 changes: 10 additions & 1 deletion src/utils/HTTPClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export default class HTTPClient {
if (Platform.shim.server) {
if (n_body.context.client.clientName === 'ANDROID' || n_body.context.client.clientName === 'ANDROID_MUSIC') {
request_headers.set('User-Agent', Constants.CLIENTS.ANDROID.USER_AGENT);
} else if (n_body.context.client.clientName === 'iOS') {
request_headers.set('User-Agent', Constants.CLIENTS.iOS.USER_AGENT);
}
}

Expand Down Expand Up @@ -139,7 +141,8 @@ export default class HTTPClient {
// Check if 2xx
if (response.ok) {
return response;
} throw new InnertubeError(`Request to ${response.url} failed with status ${response.status}`, await response.text());
}
throw new InnertubeError(`Request to ${response.url} failed with status ${response.status}`, await response.text());
}

#adjustContext(ctx: Context, client: string): void {
Expand All @@ -157,6 +160,12 @@ export default class HTTPClient {
}

switch (client) {
case 'iOS':
ctx.client.deviceModel = Constants.CLIENTS.iOS.DEVICE_MODEL;
ctx.client.clientVersion = Constants.CLIENTS.iOS.VERSION;
ctx.client.clientName = Constants.CLIENTS.iOS.NAME;
ctx.client.platform = 'MOBILE';
break;
case 'YTMUSIC':
ctx.client.clientVersion = Constants.CLIENTS.YTMUSIC.VERSION;
ctx.client.clientName = Constants.CLIENTS.YTMUSIC.NAME;
Expand Down

0 comments on commit 0fec1cb

Please sign in to comment.