Skip to content

Commit d0549a5

Browse files
committed
[YouTube] Update client versions and use a real version for the iOS client
The iOS version can be got easily in fact, by looking at the What's New section of the App Store' app page.
1 parent d7e678a commit d0549a5

File tree

1 file changed

+38
-24
lines changed

1 file changed

+38
-24
lines changed

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private YoutubeParsingHelper() {
134134
public static final String CONTENT_CHECK_OK = "contentCheckOk";
135135

136136
/**
137-
* A parameter which may be send by official clients named {@code racyCheckOk}.
137+
* A parameter which may be sent by official clients named {@code racyCheckOk}.
138138
*
139139
* <p>
140140
* What this parameter does is not really known, but it seems to be linked to sensitive
@@ -146,50 +146,60 @@ private YoutubeParsingHelper() {
146146
/**
147147
* The client version for InnerTube requests with the {@code WEB} client, used as the last
148148
* fallback if the extraction of the real one failed.
149-
*
150-
* You can get it directly either into YouTube pages or the service worker JavaScript file
151-
* ({@code https://www.youtube.com/sw.js}) (also applies for YouTube Music).
152149
*/
153-
private static final String HARDCODED_CLIENT_VERSION = "2.20220315.01.00";
150+
private static final String HARDCODED_CLIENT_VERSION = "2.20220809.02.00";
151+
152+
/**
153+
* The InnerTube API key which should be used by YouTube's desktop website, used as a fallback
154+
* if the extraction of the real one failed.
155+
*/
154156
private static final String HARDCODED_KEY = "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8";
155157

156158
/**
157-
* The InnerTube API key used by the {@code ANDROID} client. Found with the help of
158-
* reverse-engineering app network requests.
159+
* The hardcoded client version of the Android app used for InnerTube requests with this
160+
* client.
161+
*
162+
* <p>
163+
* It can be extracted by getting the latest release version of the app in an APK repository
164+
* such as <a href="https://www.apkmirror.com/apk/google-inc/youtube/">APKMirror</a>.
165+
* </p>
159166
*/
160-
private static final String ANDROID_YOUTUBE_KEY = "AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w";
167+
private static final String ANDROID_YOUTUBE_CLIENT_VERSION = "17.31.35";
161168

162169
/**
163-
* The InnerTube API key used by the {@code iOS} client. Found with the help of
170+
* The InnerTube API key used by the {@code ANDROID} client. Found with the help of
164171
* reverse-engineering app network requests.
165172
*/
166-
private static final String IOS_YOUTUBE_KEY = "AIzaSyB-63vPrdThhKuerbB2N_l7Kwwcxj6yUAc";
173+
private static final String ANDROID_YOUTUBE_KEY = "AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w";
167174

168175
/**
169-
* The hardcoded client version of the Android app used for InnerTube requests with this
176+
* The hardcoded client version of the iOS app used for InnerTube requests with this
170177
* client.
171178
*
172179
* <p>
173-
* It can be extracted by getting the latest release version of the app in an APK repository
174-
* such as APKMirror.
180+
* It can be extracted by getting the latest release version of the app on
181+
* <a href="https://apps.apple.com/us/app/youtube-watch-listen-stream/id544007664/">the App
182+
* Store page of the YouTube app</a>, in the {@code What’s New} section.
175183
* </p>
176-
*
177-
* @implNote This version is also used for the {@code iOS} client, as getting the app version
178-
* without an iPhone device is not so easily.
179184
*/
180-
private static final String MOBILE_YOUTUBE_CLIENT_VERSION = "17.10.35";
185+
private static final String IOS_YOUTUBE_CLIENT_VERSION = "17.31.4";
181186

182187
/**
183-
* The hardcoded client version of the Android app used for InnerTube requests with this
184-
* client.
188+
* The InnerTube API key used by the {@code iOS} client. Found with the help of
189+
* reverse-engineering app network requests.
190+
*/
191+
private static final String IOS_YOUTUBE_KEY = "AIzaSyB-63vPrdThhKuerbB2N_l7Kwwcxj6yUAc";
192+
193+
/**
194+
* The hardcoded client version used for InnerTube requests with the TV HTML5 embed client.
185195
*/
186196
private static final String TVHTML5_SIMPLY_EMBED_CLIENT_VERSION = "2.0";
187197

188198
private static String clientVersion;
189199
private static String key;
190200

191201
private static final String[] HARDCODED_YOUTUBE_MUSIC_KEY =
192-
{"AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30", "67", "1.20220309.01.00"};
202+
{"AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30", "67", "1.20220808.01.00"};
193203
private static String[] youtubeMusicKey;
194204

195205
private static boolean keyAndVersionExtracted = false;
@@ -1171,7 +1181,7 @@ public static JsonBuilder<JsonObject> prepareAndroidMobileJsonBuilder(
11711181
.object("context")
11721182
.object("client")
11731183
.value("clientName", "ANDROID")
1174-
.value("clientVersion", MOBILE_YOUTUBE_CLIENT_VERSION)
1184+
.value("clientVersion", ANDROID_YOUTUBE_CLIENT_VERSION)
11751185
.value("platform", "MOBILE")
11761186
.value("hl", localization.getLocalizationCode())
11771187
.value("gl", contentCountry.getCountryCode())
@@ -1194,7 +1204,7 @@ public static JsonBuilder<JsonObject> prepareIosMobileJsonBuilder(
11941204
.object("context")
11951205
.object("client")
11961206
.value("clientName", "IOS")
1197-
.value("clientVersion", MOBILE_YOUTUBE_CLIENT_VERSION)
1207+
.value("clientVersion", IOS_YOUTUBE_CLIENT_VERSION)
11981208
// Device model is required to get 60fps streams
11991209
.value("deviceModel", IOS_DEVICE_MODEL)
12001210
.value("platform", "MOBILE")
@@ -1271,8 +1281,10 @@ public static byte[] createDesktopPlayerBody(
12711281
* Get the user-agent string used as the user-agent for InnerTube requests with the Android
12721282
* client.
12731283
*
1284+
* <p>
12741285
* If the {@link Localization} provided is {@code null}, fallbacks to
12751286
* {@link Localization#DEFAULT the default one}.
1287+
* </p>
12761288
*
12771289
* @param localization the {@link Localization} to set in the user-agent
12781290
* @return the Android user-agent used for InnerTube requests with the Android client,
@@ -1281,7 +1293,7 @@ public static byte[] createDesktopPlayerBody(
12811293
@Nonnull
12821294
public static String getAndroidUserAgent(@Nullable final Localization localization) {
12831295
// Spoofing an Android 12 device with the hardcoded version of the Android app
1284-
return "com.google.android.youtube/" + MOBILE_YOUTUBE_CLIENT_VERSION
1296+
return "com.google.android.youtube/" + ANDROID_YOUTUBE_CLIENT_VERSION
12851297
+ " (Linux; U; Android 12; "
12861298
+ (localization != null ? localization : Localization.DEFAULT).getCountryCode()
12871299
+ ") gzip";
@@ -1291,8 +1303,10 @@ public static String getAndroidUserAgent(@Nullable final Localization localizati
12911303
* Get the user-agent string used as the user-agent for InnerTube requests with the iOS
12921304
* client.
12931305
*
1306+
* <p>
12941307
* If the {@link Localization} provided is {@code null}, fallbacks to
12951308
* {@link Localization#DEFAULT the default one}.
1309+
* </p>
12961310
*
12971311
* @param localization the {@link Localization} to set in the user-agent
12981312
* @return the iOS user-agent used for InnerTube requests with the iOS client, depending on the
@@ -1301,7 +1315,7 @@ public static String getAndroidUserAgent(@Nullable final Localization localizati
13011315
@Nonnull
13021316
public static String getIosUserAgent(@Nullable final Localization localization) {
13031317
// Spoofing an iPhone running iOS 15.4 with the hardcoded mobile client version
1304-
return "com.google.ios.youtube/" + MOBILE_YOUTUBE_CLIENT_VERSION
1318+
return "com.google.ios.youtube/" + IOS_YOUTUBE_CLIENT_VERSION
13051319
+ "(" + IOS_DEVICE_MODEL + "; U; CPU iOS 15_4 like Mac OS X; "
13061320
+ (localization != null ? localization : Localization.DEFAULT).getCountryCode()
13071321
+ ")";

0 commit comments

Comments
 (0)