Skip to content

Commit 271cdf5

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 125eac8 commit 271cdf5

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
@@ -1135,6 +1135,20 @@ public static JsonBuilder<JsonObject> prepareAndroidMobileJsonBuilder(
11351135
.value("clientName", "ANDROID")
11361136
.value("clientVersion", ANDROID_YOUTUBE_CLIENT_VERSION)
11371137
.value("platform", "MOBILE")
1138+
.value("osName", "Android")
1139+
.value("osVersion", "12")
1140+
/*
1141+
A valid Android SDK version is required to be sure to get a valid player
1142+
response
1143+
If this parameter is not provided, the player response may be replaced by
1144+
the one of a 5-minute video saying the message "The following content is
1145+
not available on this app. Watch this content on the latest version on
1146+
YouTube"
1147+
See https://github.com/TeamNewPipe/NewPipe/issues/8713
1148+
The Android SDK version corresponding to the Android version used in
1149+
requests is sent
1150+
*/
1151+
.value("androidSdkVersion", 31)
11381152
.value("hl", localization.getLocalizationCode())
11391153
.value("gl", contentCountry.getCountryCode())
11401154
.end()
@@ -1157,9 +1171,16 @@ public static JsonBuilder<JsonObject> prepareIosMobileJsonBuilder(
11571171
.object("client")
11581172
.value("clientName", "IOS")
11591173
.value("clientVersion", IOS_YOUTUBE_CLIENT_VERSION)
1174+
.value("deviceMake", "Apple")
11601175
// Device model is required to get 60fps streams
11611176
.value("deviceModel", IOS_DEVICE_MODEL)
11621177
.value("platform", "MOBILE")
1178+
.value("osName", "iOS")
1179+
// The value of this field seems to use the following structure:
1180+
// "iOS version.0.build version"
1181+
// The build version corresponding to the iOS version used can be found on
1182+
// https://www.theiphonewiki.com/wiki/Firmware/iPhone/15.x#iPhone_13
1183+
.value("osVersion", "15.6.0.19G71")
11631184
.value("hl", localization.getLocalizationCode())
11641185
.value("gl", contentCountry.getCountryCode())
11651186
.end()
@@ -1214,8 +1235,8 @@ public static byte[] createDesktopPlayerBody(
12141235
: prepareDesktopJsonBuilder(localization, contentCountry))
12151236
.object("playbackContext")
12161237
.object("contentPlaybackContext")
1217-
// Some parameters which are sent by the official WEB client in player
1218-
// requests, which seems to avoid throttling on streams from it
1238+
// Signature timestamp from the JavaScript base player is needed to get
1239+
// working obfuscated URLs
12191240
.value("signatureTimestamp", sts)
12201241
.value("referer", "https://www.youtube.com/watch?v=" + videoId)
12211242
.end()
@@ -1266,9 +1287,9 @@ public static String getAndroidUserAgent(@Nullable final Localization localizati
12661287
*/
12671288
@Nonnull
12681289
public static String getIosUserAgent(@Nullable final Localization localization) {
1269-
// Spoofing an iPhone running iOS 15.4 with the hardcoded mobile client version
1290+
// Spoofing an iPhone 13 running iOS 15.6 with the hardcoded version of the iOS app
12701291
return "com.google.ios.youtube/" + IOS_YOUTUBE_CLIENT_VERSION
1271-
+ "(" + IOS_DEVICE_MODEL + "; U; CPU iOS 15_4 like Mac OS X; "
1292+
+ "(" + IOS_DEVICE_MODEL + "; U; CPU iOS 15_6 like Mac OS X; "
12721293
+ (localization != null ? localization : Localization.DEFAULT).getCountryCode()
12731294
+ ")";
12741295
}

0 commit comments

Comments
 (0)