Skip to content

Commit a7d64eb

Browse files
committed
fix youtube decryption and three attempt bug
fixes TeamNewPipe/NewPipe#4752 fixes #439
1 parent 943334b commit a7d64eb

File tree

1 file changed

+24
-30
lines changed

1 file changed

+24
-30
lines changed

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

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,7 @@
2222
import org.schabi.newpipe.extractor.services.youtube.ItagItem;
2323
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
2424
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory;
25-
import org.schabi.newpipe.extractor.stream.AudioStream;
26-
import org.schabi.newpipe.extractor.stream.Description;
27-
import org.schabi.newpipe.extractor.stream.Frameset;
28-
import org.schabi.newpipe.extractor.stream.Stream;
29-
import org.schabi.newpipe.extractor.stream.StreamExtractor;
30-
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
31-
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
32-
import org.schabi.newpipe.extractor.stream.StreamType;
33-
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
34-
import org.schabi.newpipe.extractor.stream.VideoStream;
25+
import org.schabi.newpipe.extractor.stream.*;
3526
import org.schabi.newpipe.extractor.utils.Parser;
3627
import org.schabi.newpipe.extractor.utils.Utils;
3728

@@ -101,6 +92,8 @@ public class DeobfuscateException extends ParsingException {
10192
private JsonObject videoSecondaryInfoRenderer;
10293
private int ageLimit;
10394

95+
private boolean newJsonScheme;
96+
10497
@Nonnull
10598
private List<SubtitlesInfo> subtitlesInfos = new ArrayList<>();
10699

@@ -405,19 +398,19 @@ public String getUploaderAvatarUrl() throws ParsingException {
405398

406399
@Nonnull
407400
@Override
408-
public String getSubChannelUrl() throws ParsingException {
401+
public String getSubChannelUrl() {
409402
return "";
410403
}
411404

412405
@Nonnull
413406
@Override
414-
public String getSubChannelName() throws ParsingException {
407+
public String getSubChannelName() {
415408
return "";
416409
}
417410

418411
@Nonnull
419412
@Override
420-
public String getSubChannelAvatarUrl() throws ParsingException {
413+
public String getSubChannelAvatarUrl() {
421414
return "";
422415
}
423416

@@ -666,25 +659,22 @@ public void onFetchPage(@Nonnull Downloader downloader) throws IOException, Extr
666659
JsonObject playerConfig;
667660

668661
// sometimes at random YouTube does not provide the player config,
669-
// so just retry the same request three times
670-
int attempts = 2;
671-
while (true) {
672-
playerConfig = initialAjaxJson.getObject(2).getObject("player", null);
673-
if (playerConfig != null) {
674-
break;
675-
}
662+
playerConfig = initialAjaxJson.getObject(2).getObject("player", null);
663+
if (playerConfig == null) {
664+
newJsonScheme = true;
665+
666+
initialData = initialAjaxJson.getObject(3).getObject("response");
667+
final EmbeddedInfo info = getEmbeddedInfo();
668+
final String videoInfoUrl = getVideoInfoUrl(getId(), info.sts);
669+
final String infoPageResponse = downloader.get(videoInfoUrl, getExtractorLocalization()).responseBody();
670+
videoInfoPage.putAll(Parser.compatParseMap(infoPageResponse));
671+
playerUrl = info.url;
672+
} else {
673+
initialData = initialAjaxJson.getObject(3).getObject("response");
676674

677-
if (attempts <= 0) {
678-
throw new ParsingException(
679-
"YouTube did not provide player config even after three attempts");
680-
}
681-
initialAjaxJson = getJsonResponse(url, getExtractorLocalization());
682-
--attempts;
675+
playerArgs = getPlayerArgs(playerConfig);
676+
playerUrl = getPlayerUrl(playerConfig);
683677
}
684-
initialData = initialAjaxJson.getObject(3).getObject("response");
685-
686-
playerArgs = getPlayerArgs(playerConfig);
687-
playerUrl = getPlayerUrl(playerConfig);
688678
}
689679

690680
playerResponse = getPlayerResponse();
@@ -732,6 +722,10 @@ private String getPlayerUrl(final JsonObject playerConfig) throws ParsingExcepti
732722
private JsonObject getPlayerResponse() throws ParsingException {
733723
try {
734724
String playerResponseStr;
725+
if (newJsonScheme) {
726+
return initialAjaxJson.getObject(2).getObject("playerResponse");
727+
}
728+
735729
if (playerArgs != null) {
736730
playerResponseStr = playerArgs.getString("player_response");
737731
} else {

0 commit comments

Comments
 (0)