From 2edfcb78fef49259d022eecf4c0ae33ec10f362b Mon Sep 17 00:00:00 2001 From: rrooij Date: Sun, 21 Feb 2016 18:45:28 +0100 Subject: [PATCH] YTStreamExtractor: implement getAgeRestriction --- .../YoutubeStreamExtractorRestrictedTest.java | 4 ++++ .../services/youtube/YoutubeStreamExtractor.java | 14 ++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorRestrictedTest.java b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorRestrictedTest.java index ccdf59fcf..5e0a83c19 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorRestrictedTest.java +++ b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorRestrictedTest.java @@ -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()); } diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java index 1f9e65df3..f245fec4d 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java @@ -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