Skip to content

Commit 6921e80

Browse files
committed
Try again to don't fetch at each time the JavaScript player
1 parent 70927dd commit 6921e80

26 files changed

Lines changed: 164 additions & 66 deletions

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public String getName() throws ParsingException {
131131
try {
132132
title = getTextFromObject(getVideoPrimaryInfoRenderer().getObject("title"));
133133
} catch (final ParsingException ignored) {
134-
// age-restricted videos cause a ParsingException here
134+
// Age-restricted videos cause a ParsingException here
135135
}
136136

137137
if (isNullOrEmpty(title)) {
@@ -605,7 +605,7 @@ public List<SubtitlesStream> getSubtitlesDefault() throws ParsingException {
605605
@Nonnull
606606
public List<SubtitlesStream> getSubtitles(final MediaFormat format) throws ParsingException {
607607
assertPageFetched();
608-
// If the video is age restricted getSubtitles will fail
608+
// If the video is age-restricted getSubtitles will fail
609609
if (getAgeLimit() != NO_AGE_LIMIT) {
610610
return Collections.emptyList();
611611
}
@@ -846,7 +846,7 @@ private void fetchAndroidMobileJsonPlayer(final ContentCountry contentCountry,
846846
// download it again only if we didn't have a signatureTimestamp before fetching the
847847
// data of this video (the sts string).
848848
if (!stsKnown && isCipherProtectedContent()) {
849-
sts = getStsFromPlayerJs();
849+
getStsFromPlayerJs();
850850
final JsonObject playerResponseWithSignatureTimestamp = getJsonPostResponse(
851851
"player", createPlayerBodyWithSts(localization, contentCountry, videoId),
852852
localization);
@@ -860,7 +860,7 @@ private void fetchAndroidMobileJsonPlayer(final ContentCountry contentCountry,
860860

861861
private void fetchVideoInfoPage() throws ParsingException, ReCaptchaException, IOException {
862862
if (sts == null) {
863-
sts = getStsFromPlayerJs();
863+
getStsFromPlayerJs();
864864
}
865865
final String videoInfoUrl = getVideoInfoUrl(getId(), sts);
866866
final String infoPageResponse = NewPipe.getDownloader()
@@ -1024,26 +1024,20 @@ private String loadDeobfuscationCode() throws DeobfuscateException {
10241024
@Nonnull
10251025
private String getDeobfuscationCode() throws ParsingException {
10261026
if (cachedDeobfuscationCode == null) {
1027-
if (playerCode == null) {
1028-
storePlayerJs();
1029-
if (playerCode == null) {
1030-
throw new ParsingException("Could not get YouTube's JavaScript player");
1031-
}
1032-
}
1027+
if (isNullOrEmpty(playerCode)) throw new ParsingException("playerCode is null");
10331028

10341029
cachedDeobfuscationCode = loadDeobfuscationCode();
10351030
}
10361031
return cachedDeobfuscationCode;
10371032
}
10381033

1039-
private String getStsFromPlayerJs() throws ParsingException {
1040-
if (!isNullOrEmpty(sts)) return sts;
1034+
private void getStsFromPlayerJs() throws ParsingException {
1035+
if (!isNullOrEmpty(sts)) return;
10411036
if (playerCode == null) {
10421037
storePlayerJs();
10431038
if (playerCode == null) throw new ParsingException("playerCode is null");
10441039
}
10451040
sts = Parser.matchGroup1(STS_REGEX, playerCode);
1046-
return sts;
10471041
}
10481042

10491043
private String deobfuscateSignature(final String obfuscatedSig) throws ParsingException {

extractor/src/test/resources/org/schabi/newpipe/extractor/services/youtube/extractor/stream/notAvailable/generated_mock_0.json

Lines changed: 13 additions & 1 deletion
Large diffs are not rendered by default.

extractor/src/test/resources/org/schabi/newpipe/extractor/services/youtube/extractor/stream/notAvailable/generated_mock_1.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@
169169
<<<<<<< HEAD
170170
<<<<<<< HEAD
171171
<<<<<<< HEAD
172+
<<<<<<< HEAD
172173
<<<<<<< HEAD
173174
"Wed, 23 Jun 2021 10:12:06 GMT"
174175
=======
@@ -194,9 +195,12 @@
194195
=======
195196
"Wed, 02 Jun 2021 17:18:37 GMT"
196197
>>>>>>> c1d526e7 (Update client version and mocks)
198+
=======
199+
"Wed, 02 Jun 2021 18:19:18 GMT"
200+
>>>>>>> 70fc468f (Try again to don't fetch at each time the JavaScript player)
197201
],
198202
"expires": [
199-
"Wed, 02 Jun 2021 17:18:37 GMT"
203+
"Wed, 02 Jun 2021 18:19:18 GMT"
200204
],
201205
"p3p": [
202206
"CP\u003d\"This is not a P3P policy! See g.co/p3phelp for more info.\""
@@ -209,6 +213,7 @@
209213
<<<<<<< HEAD
210214
<<<<<<< HEAD
211215
<<<<<<< HEAD
216+
<<<<<<< HEAD
212217
<<<<<<< HEAD
213218
"YSC\u003d-LT8a9maoCU; Domain\u003d.youtube.com; Path\u003d/; Secure; HttpOnly; SameSite\u003dnone",
214219
"CONSENT\u003dPENDING+142; expires\u003dFri, 01-Jan-2038 00:00:00 GMT; path\u003d/; domain\u003d.youtube.com; Secure"
@@ -241,6 +246,9 @@
241246
=======
242247
"CONSENT\u003dPENDING+791; expires\u003dFri, 01-Jan-2038 00:00:00 GMT; path\u003d/; domain\u003d.youtube.com; Secure"
243248
>>>>>>> c1d526e7 (Update client version and mocks)
249+
=======
250+
"CONSENT\u003dPENDING+773; expires\u003dFri, 01-Jan-2038 00:00:00 GMT; path\u003d/; domain\u003d.youtube.com; Secure"
251+
>>>>>>> 70fc468f (Try again to don't fetch at each time the JavaScript player)
244252
],
245253
"vary": [
246254
"Origin",
@@ -261,6 +269,7 @@
261269
<<<<<<< HEAD
262270
<<<<<<< HEAD
263271
<<<<<<< HEAD
272+
<<<<<<< HEAD
264273
<<<<<<< HEAD
265274
"responseBody": "[\r\n{\"page\": \"watch\",\"rootVe\": \"3832\"},\r\n{\"page\": \"watch\",\"preconnect\": [\"https:\\/\\/r5---sn-hgn7yn7z.googlevideo.com\\/generate_204\",\"https:\\/\\/r5---sn-hgn7yn7z.googlevideo.com\\/generate_204?conn2\"]},\r\n{\"page\": \"watch\",\"playerResponse\": {\"responseContext\":{\"serviceTrackingParams\":[{\"service\":\"GFEEDBACK\",\"params\":[{\"key\":\"is_viewed_live\",\"value\":\"False\"},{\"key\":\"logged_in\",\"value\":\"0\"},{\"key\":\"e\",\"value\":\"24001373,23946420,23970529,24049577,24042868,23966208,23804281,24027649,23998056,24049575,24036947,24004644,24017848,23891344,24007246,24037794,24052246,23963745,23934970,23996830,24030040,23983296,23891346,23884386,24037806,24042870,24012513,24058813,23857948,24053867,24049569,23968386,24049820,1714249,23973490,24049567,23918597,24003105,24049573,23744176,23974595,24058380,24003103,23882685,23944779,24038425,23890959,23999405\"}]},{\"service\":\"CSI\",\"params\":[{\"key\":\"c\",\"value\":\"WEB\"},{\"key\":\"cver\",\"value\":\"2.20200214.04.00\"},{\"key\":\"yt_li\",\"value\":\"0\"},{\"key\":\"GetPlayer_rid\",\"value\":\"0x58da0be5a82f9e65\"}]},{\"service\":\"GUIDED_HELP\",\"params\":[{\"key\":\"logged_in\",\"value\":\"0\"}]},{\"service\":\"ECATCHER\",\"params\":[{\"key\":\"client.version\",\"value\":\"2.20210526\"},{\"key\":\"client.name\",\"value\":\"WEB\"}]}],\"mainAppWebResponseContext\":{\"loggedOut\":true},\"webResponseContextExtensionData\":{\"hasDecorated\":true}},\"playabilityStatus\":{\"status\":\"ERROR\",\"reason\":\"Video unavailable\",\"errorScreen\":{\"playerErrorMessageRenderer\":{\"reason\":{\"simpleText\":\"Video unavailable\"},\"thumbnail\":{\"thumbnails\":[{\"url\":\"//s.ytimg.com/yts/img/meh7-vflGevej7.png\",\"width\":140,\"height\":100}]},\"icon\":{\"iconType\":\"ERROR_OUTLINE\"}}},\"contextParams\":\"Q0FBU0FnZ0E\u003d\"},\"trackingParams\":\"CAAQu2kiEwiG75Ocwq3xAhU_NPEFHUM9A70\u003d\",\"frameworkUpdates\":{\"entityBatchUpdate\":{\"mutations\":[{\"entityKey\":\"Eg0KC0lOVkFMSURfSURfIPYBKAE%3D\",\"type\":\"ENTITY_MUTATION_TYPE_REPLACE\",\"payload\":{\"offlineabilityEntity\":{\"key\":\"Eg0KC0lOVkFMSURfSURfIPYBKAE%3D\",\"accessState\":\"OFFLINEABILITY_FEATURE_ACCESS_STATE_UNKNOWN\"}}}],\"timestamp\":{\"seconds\":\"1624443126\",\"nanos\":616071922}}}}},\r\n{\"page\": \"watch\",\"response\": {\"responseContext\":{\"webResponseContextExtensionData\":{\"ytConfigData\":{\"visitorData\":\"Cgs1SUlhQUVDenVSUSj2kcyGBg%3D%3D\",\"rootVisualElementType\":3832}}}},\"xsrf_token\": \"QUFFLUhqbkdDQldjVWFhaHN4ZUQzTjMtY01fU1FpVElFd3xBQ3Jtc0tseTZPT0J2ZzA2eDNuYXRMREtXaGN0RWJsUWJ5eW1vWDQ4aGg5TDJHTjZvX3lSM2tRamh2M3lDdDNXc3haZE00TUJveWNZa2JBbWdYX21URUI2dTM2MTlfX0pIcWU1RVNXRHpreExHeHNfaW5LQjdvQQ\\u003d\\u003d\",\"url\": \"/watch?v\\u003dINVALID_ID_\",\"endpoint\": {\"clickTrackingParams\":\"IhMIpImTnMKt8QIV9TvxBR0TrgLLMghleHRlcm5hbA\u003d\u003d\",\"commandMetadata\":{\"webCommandMetadata\":{\"url\":\"/watch?v\u003dINVALID_ID_\",\"webPageType\":\"WEB_PAGE_TYPE_WATCH\",\"rootVe\":3832}},\"watchEndpoint\":{\"videoId\":\"INVALID_ID_\"}}},\r\n{\"page\": \"watch\",\"timing\": {\"info\": {\"st\": 0.0 }}}]\r\n",
266275
=======
@@ -287,6 +296,9 @@
287296
>>>>>>> 43ce1dc4 (Update mocks)
288297
=======
289298
"responseBody": "{\n \"responseContext\": {\n \"visitorData\": \"CgtZOUFzWlYyQzVKZyjt-t6FBg%3D%3D\",\n \"serviceTrackingParams\": [\n {\n \"service\": \"GFEEDBACK\",\n \"params\": [\n {\n \"key\": \"is_viewed_live\",\n \"value\": \"False\"\n },\n {\n \"key\": \"logged_in\",\n \"value\": \"0\"\n },\n {\n \"key\": \"e\",\n \"value\": \"24005646,23858057,23918597,24037794,23970529,24051749,24005602,24042868,23966208,23968099,24043242,24044575,23804281,24044136,23934970,23996830,24030040,23983296,23857950,24037806,23884386,23891346,24042870,24027133,9405963,24040786,23940237,23968386,24027649,24024873,24005802,23890959,23882503,23986024,23744176,23974595,24022728,23944779,24010465,24024949,24035275,24050414,23891344,24036085,24007246,24001373,23748146,23946420,23993672,1714248,24049122,24030993,24004644\"\n }\n ]\n },\n {\n \"service\": \"CSI\",\n \"params\": [\n {\n \"key\": \"c\",\n \"value\": \"WEB\"\n },\n {\n \"key\": \"cver\",\n \"value\": \"2.20210601.07.00\"\n },\n {\n \"key\": \"yt_li\",\n \"value\": \"0\"\n },\n {\n \"key\": \"GetPlayer_rid\",\n \"value\": \"0x9563640b7d533d1b\"\n }\n ]\n },\n {\n \"service\": \"GUIDED_HELP\",\n \"params\": [\n {\n \"key\": \"logged_in\",\n \"value\": \"0\"\n }\n ]\n },\n {\n \"service\": \"ECATCHER\",\n \"params\": [\n {\n \"key\": \"client.version\",\n \"value\": \"2.20210601\"\n },\n {\n \"key\": \"client.name\",\n \"value\": \"WEB\"\n }\n ]\n }\n ],\n \"mainAppWebResponseContext\": {\n \"loggedOut\": true\n },\n \"webResponseContextExtensionData\": {\n \"hasDecorated\": true\n }\n },\n \"trackingParams\": \"CAAQu2kiEwjI07SxuvnwAhWEp9UKHTLgA0g\u003d\",\n \"playabilityStatus\": {\n \"status\": \"ERROR\",\n \"reason\": \"Video unavailable\",\n \"errorScreen\": {\n \"playerErrorMessageRenderer\": {\n \"reason\": {\n \"simpleText\": \"Video unavailable\"\n },\n \"thumbnail\": {\n \"thumbnails\": [\n {\n \"url\": \"//s.ytimg.com/yts/img/meh7-vflGevej7.png\",\n \"width\": 140,\n \"height\": 100\n }\n ]\n },\n \"icon\": {\n \"iconType\": \"ERROR_OUTLINE\"\n }\n }\n },\n \"contextParams\": \"Q0FBU0FnZ0E\u003d\"\n }\n}\n",
299+
=======
300+
"responseBody": "{\n \"responseContext\": {\n \"visitorData\": \"CgtQaXp3Vl9la3RDMCiml9-FBg%3D%3D\",\n \"serviceTrackingParams\": [\n {\n \"service\": \"GFEEDBACK\",\n \"params\": [\n {\n \"key\": \"is_viewed_live\",\n \"value\": \"False\"\n },\n {\n \"key\": \"logged_in\",\n \"value\": \"0\"\n },\n {\n \"key\": \"e\",\n \"value\": \"24037806,23891344,24005802,24036085,24040343,23983296,23986028,24010466,23890959,23974595,23996830,24051485,24030148,23934970,23744176,24047687,24026152,23918597,24005646,24035275,24004644,23882685,23940238,24032653,24001373,24027649,23968386,24050517,24040786,23748147,23944779,24027133,24007246,24044575,23999405,24042870,24042654,23884386,24030040,24044136,23804281,23946420,24037794,1714259,24024590,23970529,23966208,23968099,24042868,23857949,23891346\"\n }\n ]\n },\n {\n \"service\": \"CSI\",\n \"params\": [\n {\n \"key\": \"c\",\n \"value\": \"WEB\"\n },\n {\n \"key\": \"cver\",\n \"value\": \"2.20210601.07.00\"\n },\n {\n \"key\": \"yt_li\",\n \"value\": \"0\"\n },\n {\n \"key\": \"GetPlayer_rid\",\n \"value\": \"0x63da5aceeaf2a6ca\"\n }\n ]\n },\n {\n \"service\": \"GUIDED_HELP\",\n \"params\": [\n {\n \"key\": \"logged_in\",\n \"value\": \"0\"\n }\n ]\n },\n {\n \"service\": \"ECATCHER\",\n \"params\": [\n {\n \"key\": \"client.version\",\n \"value\": \"2.20210601\"\n },\n {\n \"key\": \"client.name\",\n \"value\": \"WEB\"\n }\n ]\n }\n ],\n \"mainAppWebResponseContext\": {\n \"loggedOut\": true\n },\n \"webResponseContextExtensionData\": {\n \"hasDecorated\": true\n }\n },\n \"trackingParams\": \"CAAQu2kiEwjK3rr5x_nwAhWcFPEFHXpbBms\u003d\",\n \"playabilityStatus\": {\n \"status\": \"ERROR\",\n \"reason\": \"Video unavailable\",\n \"errorScreen\": {\n \"playerErrorMessageRenderer\": {\n \"reason\": {\n \"simpleText\": \"Video unavailable\"\n },\n \"thumbnail\": {\n \"thumbnails\": [\n {\n \"url\": \"//s.ytimg.com/yts/img/meh7-vflGevej7.png\",\n \"width\": 140,\n \"height\": 100\n }\n ]\n },\n \"icon\": {\n \"iconType\": \"ERROR_OUTLINE\"\n }\n }\n },\n \"contextParams\": \"Q0FBU0FnZ0E\u003d\"\n }\n}\n",
301+
>>>>>>> 70fc468f (Try again to don't fetch at each time the JavaScript player)
290302
"latestUrl": "https://www.youtube.com/youtubei/v1/player?key\u003dAIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8"
291303
>>>>>>> c1d526e7 (Update client version and mocks)
292304
}

extractor/src/test/resources/org/schabi/newpipe/extractor/services/youtube/extractor/stream/notAvailable/generated_mock_10.json

Lines changed: 8 additions & 4 deletions
Large diffs are not rendered by default.

extractor/src/test/resources/org/schabi/newpipe/extractor/services/youtube/extractor/stream/notAvailable/generated_mock_11.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"bytes"
4242
],
4343
"age": [
44-
"127213"
44+
"130852"
4545
],
4646
"alt-svc": [
4747
"h3\u003d\":443\"; ma\u003d2592000,h3-29\u003d\":443\"; ma\u003d2592000,h3-T051\u003d\":443\"; ma\u003d2592000,h3-Q050\u003d\":443\"; ma\u003d2592000,h3-Q046\u003d\":443\"; ma\u003d2592000,h3-Q043\u003d\":443\"; ma\u003d2592000,quic\u003d\":443\"; ma\u003d2592000; v\u003d\"46,43\""

extractor/src/test/resources/org/schabi/newpipe/extractor/services/youtube/extractor/stream/notAvailable/generated_mock_12.json

Lines changed: 12 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)