YTStreamExtractor: implement getAgeRestriction

This commit is contained in:
rrooij 2016-02-21 18:45:28 +01:00
parent 3f0947fa5b
commit 2edfcb78fe
2 changed files with 14 additions and 4 deletions

View file

@ -30,6 +30,10 @@ public class YoutubeStreamExtractorRestrictedTest extends AndroidTestCase {
extractor.getTimeStamp() == 174);
}
public void testGetAgeLimit() throws ParsingException {
assertTrue(extractor.getAgeLimit() == 18);
}
public void testGetTitle() throws ParsingException {
assertTrue(!extractor.getTitle().isEmpty());
}

View file

@ -529,10 +529,16 @@ public class YoutubeStreamExtractor implements StreamExtractor {
@Override
public int getAgeLimit() throws ParsingException {
// Not yet implemented.
// Also you need to be logged in to see age restricted videos on youtube,
// therefore NP is not able to receive such videos.
return 0;
if (!isAgeRestricted) {
return 0;
}
try {
return Integer.valueOf(doc.head()
.getElementsByAttributeValue("property", "og:restrictions:age")
.attr("content").replace("+", ""));
} catch (Exception e) {
throw new ParsingException("Could not get age restriction");
}
}
@Override