Skip to content

Commit

Permalink
[youtube] Fix extraction of age restricted videos
Browse files Browse the repository at this point in the history
  • Loading branch information
B0pol committed Jun 23, 2021
1 parent 65fd874 commit 08278a2
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,8 @@
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.exceptions.AgeRestrictedContentException;
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException;
import org.schabi.newpipe.extractor.exceptions.PaidContentException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.exceptions.PrivateContentException;
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
import org.schabi.newpipe.extractor.exceptions.YoutubeMusicPremiumContentException;
import org.schabi.newpipe.extractor.downloader.Response;
import org.schabi.newpipe.extractor.exceptions.*;
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
import org.schabi.newpipe.extractor.localization.DateWrapper;
import org.schabi.newpipe.extractor.localization.Localization;
Expand Down Expand Up @@ -792,11 +785,9 @@ public void onFetchPage(@Nonnull final Downloader downloader)
}

private void fetchVideoInfoPage() throws ParsingException, ReCaptchaException, IOException {
final String sts = getEmbeddedInfoStsAndStorePlayerJsUrl();
final String videoInfoUrl = getVideoInfoUrl(getId(), sts);
final String infoPageResponse = NewPipe.getDownloader()
.get(videoInfoUrl, getExtractorLocalization()).responseBody();
videoInfoPage.putAll(Parser.compatParseMap(infoPageResponse));
final String videoInfoUrl = getVideoInfoUrl(getId());
final Response videoInfoResponse = NewPipe.getDownloader().get(videoInfoUrl, getExtractorLocalization());
videoInfoPage.putAll(Parser.compatParseMap(videoInfoResponse.responseBody()));

try {
playerResponse = JsonParser.object().from(videoInfoPage.get("player_response"));
Expand Down Expand Up @@ -975,11 +966,11 @@ private JsonObject getVideoSecondaryInfoRenderer() throws ParsingException {
}

@Nonnull
private static String getVideoInfoUrl(final String id, final String sts) {
private static String getVideoInfoUrl(final String id) {
// TODO: Try parsing embedded_player_response first
return "https://www.youtube.com/get_video_info?" + "video_id=" + id +
"&html5=1&eurl=https://youtube.googleapis.com/v/" + id +
"&sts=" + sts + "&ps=default&gl=US&hl=en";
"&eurl=https://youtube.googleapis.com/v/" + id +
"&html5=1&c=TVHTML5&cver=6.20180913&gl=US&hl=en";
}

private Map<String, ItagItem> getItags(final String streamingDataKey,
Expand Down Expand Up @@ -1121,7 +1112,7 @@ public Privacy getPrivacy() {
public String getCategory() {
return playerResponse.getObject("microformat")
.getObject("playerMicroformatRenderer")
.getString("category");
.getString("category", EMPTY_STRING);
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void setUp() throws Exception {
@Nullable @Override public String expectedErrorMessage() { return "Sign in to confirm your age"; }
@Override public boolean expectedHasSubtitles() { return false; }

@Override public String expectedCategory() {return "Entertainment"; }
@Override public String expectedCategory() { return ""; } // Unavailable on age restricted videos
@Override public String expectedLicence() { return "YouTube licence"; }
@Override
public List<String> expectedTags() {
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

This file was deleted.

0 comments on commit 08278a2

Please sign in to comment.