add extraction for support info and rename getLanguageInfo function

This commit is contained in:
bopol 2020-01-23 14:19:22 +01:00
parent 1a15c0e750
commit 74439f692a
7 changed files with 66 additions and 9 deletions

View File

@ -248,7 +248,7 @@ public class MediaCCCStreamExtractor extends StreamExtractor {
} }
@Override @Override
public String getStreamInfoLanguage() throws ParsingException { public String getLanguageInfo() throws ParsingException {
return ""; return "";
} }
@ -257,4 +257,10 @@ public class MediaCCCStreamExtractor extends StreamExtractor {
public List<String> getTags() throws ParsingException { public List<String> getTags() throws ParsingException {
return new ArrayList<>(); return new ArrayList<>();
} }
@Nonnull
@Override
public String getSupportInfo() throws ParsingException {
return "";
}
} }

View File

@ -35,6 +35,8 @@ import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser; import com.grack.nanojson.JsonParser;
import com.grack.nanojson.JsonParserException; import com.grack.nanojson.JsonParserException;
import javax.annotation.Nonnull;
public class PeertubeStreamExtractor extends StreamExtractor { public class PeertubeStreamExtractor extends StreamExtractor {
@ -251,6 +253,12 @@ public class PeertubeStreamExtractor extends StreamExtractor {
} }
} }
@Nonnull
@Override
public String getSupportInfo() throws ParsingException {
return JsonUtils.getString(json, "support");
}
private String getRelatedStreamsUrl(List<String> tags) throws UnsupportedEncodingException { private String getRelatedStreamsUrl(List<String> tags) throws UnsupportedEncodingException {
String url = baseUrl + PeertubeSearchQueryHandlerFactory.SEARCH_ENDPOINT; String url = baseUrl + PeertubeSearchQueryHandlerFactory.SEARCH_ENDPOINT;
StringBuilder params = new StringBuilder(); StringBuilder params = new StringBuilder();
@ -378,7 +386,7 @@ public class PeertubeStreamExtractor extends StreamExtractor {
} }
@Override @Override
public String getStreamInfoLanguage() throws ParsingException { public String getLanguageInfo() throws ParsingException {
return JsonUtils.getString(json, "language.label"); return JsonUtils.getString(json, "language.label");
} }
} }

View File

@ -276,7 +276,7 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
} }
@Override @Override
public String getStreamInfoLanguage() throws ParsingException { public String getLanguageInfo() throws ParsingException {
return ""; return "";
} }
@ -285,4 +285,10 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
public List<String> getTags() throws ParsingException { public List<String> getTags() throws ParsingException {
return new ArrayList<>(); return new ArrayList<>();
} }
@Nonnull
@Override
public String getSupportInfo() throws ParsingException {
return "";
}
} }

View File

@ -1156,7 +1156,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
} }
@Override @Override
public String getStreamInfoLanguage() throws ParsingException { public String getLanguageInfo() throws ParsingException {
return ""; return "";
} }
@ -1165,4 +1165,10 @@ public class YoutubeStreamExtractor extends StreamExtractor {
public List<String> getTags() throws ParsingException { public List<String> getTags() throws ParsingException {
return new ArrayList<>(); return new ArrayList<>();
} }
@Nonnull
@Override
public String getSupportInfo() throws ParsingException {
return "";
}
} }

View File

@ -396,7 +396,7 @@ public abstract class StreamExtractor extends Extractor {
* @throws ParsingException * @throws ParsingException
*/ */
@Nonnull @Nonnull
public abstract String getStreamInfoLanguage() throws ParsingException; public abstract String getLanguageInfo() throws ParsingException;
/** /**
* The list of tags of the stream. * The list of tags of the stream.
@ -406,4 +406,16 @@ public abstract class StreamExtractor extends Extractor {
*/ */
@Nonnull @Nonnull
public abstract List<String> getTags() throws ParsingException; public abstract List<String> getTags() throws ParsingException;
/**
* The support information of the stream.
* see: https://framatube.org/videos/watch/ee408ec8-07cd-4e35-b884-fb681a4b9d37
* (support button).
* If the support information are not available,
* you can simply return an empty String.
* @return the support information of the stream or an empty String.
* @throws ParsingException
*/
@Nonnull
public abstract String getSupportInfo() throws ParsingException;
} }

View File

@ -292,7 +292,7 @@ public class StreamInfo extends Info {
streamInfo.addError(e); streamInfo.addError(e);
} }
try { try {
streamInfo.setLanguage(extractor.getStreamInfoLanguage()); streamInfo.setLanguageInfo(extractor.getLanguageInfo());
} catch (Exception e) { } catch (Exception e) {
streamInfo.addError(e); streamInfo.addError(e);
} }
@ -301,6 +301,11 @@ public class StreamInfo extends Info {
} catch (Exception e) { } catch (Exception e) {
streamInfo.addError(e); streamInfo.addError(e);
} }
try {
streamInfo.setSupportInfo(extractor.getSupportInfo());
} catch (Exception e) {
streamInfo.addError(e);
}
streamInfo.setRelatedStreams(ExtractorHelper.getRelatedVideosOrLogError(streamInfo, extractor)); streamInfo.setRelatedStreams(ExtractorHelper.getRelatedVideosOrLogError(streamInfo, extractor));
@ -345,6 +350,7 @@ public class StreamInfo extends Info {
private String category = ""; private String category = "";
private String licence = ""; private String licence = "";
private String language = ""; private String language = "";
private String support = "";
private List<String> tags = new ArrayList<>(); private List<String> tags = new ArrayList<>();
/** /**
@ -604,11 +610,11 @@ public class StreamInfo extends Info {
this.licence = str; this.licence = str;
} }
public String getLanguage() { public String getLanguageInfo() {
return this.language; return this.language;
} }
public void setLanguage(String lang) { public void setLanguageInfo(String lang) {
this.language = lang; this.language = lang;
} }
@ -620,5 +626,11 @@ public class StreamInfo extends Info {
this.tags = tags; this.tags = tags;
} }
public void setSupportInfo(String support) {
this.support = support;
}
public String getSupportInfo() {
return this.support;
}
} }

View File

@ -147,4 +147,11 @@ public class PeertubeStreamExtractorDefaultTest {
ageLimit.fetchPage(); ageLimit.fetchPage();
assertEquals(18, ageLimit.getAgeLimit()); assertEquals(18, ageLimit.getAgeLimit());
} }
@Test
public void testGetSupportInformation() throws ExtractionException, IOException {
PeertubeStreamExtractor supportInfoExtractor = (PeertubeStreamExtractor) PeerTube.getStreamExtractor("https://framatube.org/videos/watch/ee408ec8-07cd-4e35-b884-fb681a4b9d37");
supportInfoExtractor.fetchPage();
assertEquals("https://utip.io/chatsceptique", supportInfoExtractor.getSupportInfo());
}
} }