Check if there are no related streams in getAgeLimit()
This commit is contained in:
parent
985c3ec877
commit
1c3a4e710b
|
@ -100,8 +100,6 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private List<SubtitlesInfo> subtitlesInfos = new ArrayList<>();
|
private List<SubtitlesInfo> subtitlesInfos = new ArrayList<>();
|
||||||
|
|
||||||
private boolean isAgeRestricted;
|
|
||||||
|
|
||||||
public YoutubeStreamExtractor(StreamingService service, LinkHandler linkHandler) {
|
public YoutubeStreamExtractor(StreamingService service, LinkHandler linkHandler) {
|
||||||
super(service, linkHandler);
|
super(service, linkHandler);
|
||||||
}
|
}
|
||||||
|
@ -261,17 +259,14 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAgeLimit() throws ParsingException {
|
public int getAgeLimit() {
|
||||||
assertPageFetched();
|
assertPageFetched();
|
||||||
if (!isAgeRestricted) {
|
if (initialData.getObject("contents").getObject("twoColumnWatchNextResults")
|
||||||
|
.getObject("secondaryResults") == null) {
|
||||||
|
return 18;
|
||||||
|
} else {
|
||||||
return NO_AGE_LIMIT;
|
return NO_AGE_LIMIT;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
return Integer.valueOf(doc.select("meta[property=\"og:restrictions:age\"]")
|
|
||||||
.attr(CONTENT).replace("+", ""));
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new ParsingException("Could not get age restriction");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -578,7 +573,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
@Override
|
@Override
|
||||||
public StreamInfoItem getNextStream() throws ExtractionException {
|
public StreamInfoItem getNextStream() throws ExtractionException {
|
||||||
assertPageFetched();
|
assertPageFetched();
|
||||||
if (isAgeRestricted) {
|
if (getAgeLimit() == 18) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -599,7 +594,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
@Override
|
@Override
|
||||||
public StreamInfoItemsCollector getRelatedStreams() throws ExtractionException {
|
public StreamInfoItemsCollector getRelatedStreams() throws ExtractionException {
|
||||||
assertPageFetched();
|
assertPageFetched();
|
||||||
if (isAgeRestricted) {
|
if (getAgeLimit() == 18) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -678,18 +673,16 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
|
|
||||||
final String playerUrl;
|
final String playerUrl;
|
||||||
// Check if the video is age restricted
|
// Check if the video is age restricted
|
||||||
if (!doc.select("meta[property=\"og:restrictions:age\"]").isEmpty()) {
|
if (getAgeLimit() == 18) {
|
||||||
final EmbeddedInfo info = getEmbeddedInfo();
|
final EmbeddedInfo info = getEmbeddedInfo();
|
||||||
final String videoInfoUrl = getVideoInfoUrl(getId(), info.sts);
|
final String videoInfoUrl = getVideoInfoUrl(getId(), info.sts);
|
||||||
final String infoPageResponse = downloader.get(videoInfoUrl, getExtractorLocalization()).responseBody();
|
final String infoPageResponse = downloader.get(videoInfoUrl, getExtractorLocalization()).responseBody();
|
||||||
videoInfoPage.putAll(Parser.compatParseMap(infoPageResponse));
|
videoInfoPage.putAll(Parser.compatParseMap(infoPageResponse));
|
||||||
playerUrl = info.url;
|
playerUrl = info.url;
|
||||||
isAgeRestricted = true;
|
|
||||||
} else {
|
} else {
|
||||||
final JsonObject ytPlayerConfig = getPlayerConfig();
|
final JsonObject ytPlayerConfig = getPlayerConfig();
|
||||||
playerArgs = getPlayerArgs(ytPlayerConfig);
|
playerArgs = getPlayerArgs(ytPlayerConfig);
|
||||||
playerUrl = getPlayerUrl(ytPlayerConfig);
|
playerUrl = getPlayerUrl(ytPlayerConfig);
|
||||||
isAgeRestricted = false;
|
|
||||||
}
|
}
|
||||||
playerResponse = getPlayerResponse();
|
playerResponse = getPlayerResponse();
|
||||||
initialData = YoutubeParsingHelper.getInitialData(pageHtml);
|
initialData = YoutubeParsingHelper.getInitialData(pageHtml);
|
||||||
|
@ -869,7 +862,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private List<SubtitlesInfo> getAvailableSubtitlesInfo() {
|
private List<SubtitlesInfo> getAvailableSubtitlesInfo() {
|
||||||
// If the video is age restricted getPlayerConfig will fail
|
// If the video is age restricted getPlayerConfig will fail
|
||||||
if (isAgeRestricted) return Collections.emptyList();
|
if (getAgeLimit() == 18) return Collections.emptyList();
|
||||||
|
|
||||||
final JsonObject captions;
|
final JsonObject captions;
|
||||||
if (!playerResponse.has("captions")) {
|
if (!playerResponse.has("captions")) {
|
||||||
|
|
Loading…
Reference in New Issue