agelimit now returns 18 if the video is marked as nsfw, 0 otherwise

+ created getBoolean method in JsonUtils.java
This commit is contained in:
B0pol 2020-01-23 04:42:54 +01:00
parent bcfe7be4e6
commit 1a15c0e750
3 changed files with 24 additions and 2 deletions

View File

@ -92,7 +92,12 @@ public class PeertubeStreamExtractor extends StreamExtractor {
@Override @Override
public int getAgeLimit() throws ParsingException { public int getAgeLimit() throws ParsingException {
return NO_AGE_LIMIT; boolean isNSFW = JsonUtils.getBoolean(json, "nsfw");
if (isNSFW) {
return 18;
} else {
return NO_AGE_LIMIT;
}
} }
@Override @Override
@ -352,7 +357,6 @@ public class PeertubeStreamExtractor extends StreamExtractor {
return baseUrl + "/videos/watch/" + getId(); return baseUrl + "/videos/watch/" + getId();
} }
//TODO: change privacy, category, licence by getting ID, therefore we will be able to translate it
@Override @Override
public String getHost() throws ParsingException { public String getHost() throws ParsingException {
return JsonUtils.getString(json, "account.host"); return JsonUtils.getString(json, "account.host");

View File

@ -37,6 +37,16 @@ public class JsonUtils {
throw new ParsingException("Unable to get " + path); throw new ParsingException("Unable to get " + path);
} }
} }
@Nonnull
public static Boolean getBoolean(@Nonnull JsonObject object, @Nonnull String path) throws ParsingException{
Object value = getValue(object, path);
if(value instanceof Boolean) {
return (Boolean) value;
}else {
throw new ParsingException("Unable to get " + path);
}
}
@Nonnull @Nonnull
public static Number getNumber(@Nonnull JsonObject object, @Nonnull String path) throws ParsingException{ public static Number getNumber(@Nonnull JsonObject object, @Nonnull String path) throws ParsingException{

View File

@ -139,4 +139,12 @@ public class PeertubeStreamExtractorDefaultTest {
public void testGetSubtitlesList() throws IOException, ExtractionException { public void testGetSubtitlesList() throws IOException, ExtractionException {
assertFalse(extractor.getSubtitlesDefault().isEmpty()); assertFalse(extractor.getSubtitlesDefault().isEmpty());
} }
@Test
public void testGetAgeLimit() throws ExtractionException, IOException {
assertEquals(0, extractor.getAgeLimit());
PeertubeStreamExtractor ageLimit = (PeertubeStreamExtractor) PeerTube.getStreamExtractor("https://peertube.co.uk/videos/watch/6762bb04-cad5-407b-81ee-c18eac4715a7");
ageLimit.fetchPage();
assertEquals(18, ageLimit.getAgeLimit());
}
} }