|
22 | 22 | import org.schabi.newpipe.extractor.services.youtube.ItagItem;
|
23 | 23 | import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
|
24 | 24 | 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.*; |
35 | 26 | import org.schabi.newpipe.extractor.utils.Parser;
|
36 | 27 | import org.schabi.newpipe.extractor.utils.Utils;
|
37 | 28 |
|
@@ -101,6 +92,8 @@ public class DeobfuscateException extends ParsingException {
|
101 | 92 | private JsonObject videoSecondaryInfoRenderer;
|
102 | 93 | private int ageLimit;
|
103 | 94 |
|
| 95 | + private boolean newJsonScheme; |
| 96 | + |
104 | 97 | @Nonnull
|
105 | 98 | private List<SubtitlesInfo> subtitlesInfos = new ArrayList<>();
|
106 | 99 |
|
@@ -405,19 +398,19 @@ public String getUploaderAvatarUrl() throws ParsingException {
|
405 | 398 |
|
406 | 399 | @Nonnull
|
407 | 400 | @Override
|
408 |
| - public String getSubChannelUrl() throws ParsingException { |
| 401 | + public String getSubChannelUrl() { |
409 | 402 | return "";
|
410 | 403 | }
|
411 | 404 |
|
412 | 405 | @Nonnull
|
413 | 406 | @Override
|
414 |
| - public String getSubChannelName() throws ParsingException { |
| 407 | + public String getSubChannelName() { |
415 | 408 | return "";
|
416 | 409 | }
|
417 | 410 |
|
418 | 411 | @Nonnull
|
419 | 412 | @Override
|
420 |
| - public String getSubChannelAvatarUrl() throws ParsingException { |
| 413 | + public String getSubChannelAvatarUrl() { |
421 | 414 | return "";
|
422 | 415 | }
|
423 | 416 |
|
@@ -666,25 +659,22 @@ public void onFetchPage(@Nonnull Downloader downloader) throws IOException, Extr
|
666 | 659 | JsonObject playerConfig;
|
667 | 660 |
|
668 | 661 | // 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"); |
676 | 674 |
|
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); |
683 | 677 | }
|
684 |
| - initialData = initialAjaxJson.getObject(3).getObject("response"); |
685 |
| - |
686 |
| - playerArgs = getPlayerArgs(playerConfig); |
687 |
| - playerUrl = getPlayerUrl(playerConfig); |
688 | 678 | }
|
689 | 679 |
|
690 | 680 | playerResponse = getPlayerResponse();
|
@@ -732,6 +722,10 @@ private String getPlayerUrl(final JsonObject playerConfig) throws ParsingExcepti
|
732 | 722 | private JsonObject getPlayerResponse() throws ParsingException {
|
733 | 723 | try {
|
734 | 724 | String playerResponseStr;
|
| 725 | + if (newJsonScheme) { |
| 726 | + return initialAjaxJson.getObject(2).getObject("playerResponse"); |
| 727 | + } |
| 728 | + |
735 | 729 | if (playerArgs != null) {
|
736 | 730 | playerResponseStr = playerArgs.getString("player_response");
|
737 | 731 | } else {
|
|
0 commit comments