Skip to content

Commit c82317e

Browse files
committed
[YouTube] Spoof more mobile clients
Additional parameters have been added to the player requests of ANDROID and IOS clients: - for both clients: osName and osVersion: their respective values are: - for the ANDROID one: Android and 12; - for the IOS one: iOS and 15.6.0.19G71. - for the ANDROID client: androidTargetSdkVersion, with the Android SDK version corresponding to the Android version used in the player requests of this client. This parameter is now required with this client to be sure to get a correct player response, otherwise, the one of a video saying that this content is not available in this app and to watch it with the latest version of YouTube can be returned instead; - for the IOS client: deviceMake, with Apple as its value. The iOS version sent in the IOS client player requests has been also updated to the version 15.6 of the OS. Finally, a comment about the requirement to use the signature timestamp from the player JavaScript base file for HTML5 player requests on videos with obfuscated URLs has been added and replaces a previous one which may be not true.
1 parent d0549a5 commit c82317e

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,20 @@ public static JsonBuilder<JsonObject> prepareAndroidMobileJsonBuilder(
11831183
.value("clientName", "ANDROID")
11841184
.value("clientVersion", ANDROID_YOUTUBE_CLIENT_VERSION)
11851185
.value("platform", "MOBILE")
1186+
.value("osName", "Android")
1187+
.value("osVersion", "12")
1188+
/*
1189+
A valid Android SDK version is required to be sure to get a valid player
1190+
response
1191+
If this parameter is not provided, the player response may be replaced by
1192+
the one of a 5-minute video saying the message "The following content is
1193+
not available on this app. Watch this content on the latest version on
1194+
YouTube"
1195+
See https://github.com/TeamNewPipe/NewPipe/issues/8713
1196+
The Android SDK version corresponding to the Android version used in
1197+
requests is sent
1198+
*/
1199+
.value("androidSdkVersion", 31)
11861200
.value("hl", localization.getLocalizationCode())
11871201
.value("gl", contentCountry.getCountryCode())
11881202
.end()
@@ -1205,9 +1219,16 @@ public static JsonBuilder<JsonObject> prepareIosMobileJsonBuilder(
12051219
.object("client")
12061220
.value("clientName", "IOS")
12071221
.value("clientVersion", IOS_YOUTUBE_CLIENT_VERSION)
1222+
.value("deviceMake", "Apple")
12081223
// Device model is required to get 60fps streams
12091224
.value("deviceModel", IOS_DEVICE_MODEL)
12101225
.value("platform", "MOBILE")
1226+
.value("osName", "iOS")
1227+
// The value of this field seems to use the following structure:
1228+
// "iOS version.0.build version"
1229+
// The build version corresponding to the iOS version used can be found on
1230+
// https://www.theiphonewiki.com/wiki/Firmware/iPhone/15.x#iPhone_13
1231+
.value("osVersion", "15.6.0.19G71")
12111232
.value("hl", localization.getLocalizationCode())
12121233
.value("gl", contentCountry.getCountryCode())
12131234
.end()
@@ -1262,8 +1283,8 @@ public static byte[] createDesktopPlayerBody(
12621283
: prepareDesktopJsonBuilder(localization, contentCountry))
12631284
.object("playbackContext")
12641285
.object("contentPlaybackContext")
1265-
// Some parameters which are sent by the official WEB client in player
1266-
// requests, which seems to avoid throttling on streams from it
1286+
// Signature timestamp from the JavaScript base player is needed to get
1287+
// working obfuscated URLs
12671288
.value("signatureTimestamp", sts)
12681289
.value("referer", "https://www.youtube.com/watch?v=" + videoId)
12691290
.end()
@@ -1314,9 +1335,9 @@ public static String getAndroidUserAgent(@Nullable final Localization localizati
13141335
*/
13151336
@Nonnull
13161337
public static String getIosUserAgent(@Nullable final Localization localization) {
1317-
// Spoofing an iPhone running iOS 15.4 with the hardcoded mobile client version
1338+
// Spoofing an iPhone 13 running iOS 15.6 with the hardcoded version of the iOS app
13181339
return "com.google.ios.youtube/" + IOS_YOUTUBE_CLIENT_VERSION
1319-
+ "(" + IOS_DEVICE_MODEL + "; U; CPU iOS 15_4 like Mac OS X; "
1340+
+ "(" + IOS_DEVICE_MODEL + "; U; CPU iOS 15_6 like Mac OS X; "
13201341
+ (localization != null ? localization : Localization.DEFAULT).getCountryCode()
13211342
+ ")";
13221343
}

0 commit comments

Comments
 (0)