Add parent channel info to StreamExtractor: name, url & avatar url

This commit is contained in:
Roy Yosef 2020-04-13 23:34:20 +03:00 committed by wb9688
parent 4234740baa
commit 1de1f97cf1
7 changed files with 176 additions and 6 deletions

View File

@ -112,7 +112,25 @@ public class MediaCCCStreamExtractor extends StreamExtractor {
@Nonnull
@Override
public String getDashMpdUrl() {
public String getParentChannelUrl() throws ParsingException {
return "";
}
@Nonnull
@Override
public String getParentChannelName() throws ParsingException {
return "";
}
@Nonnull
@Override
public String getParentChannelAvatarUrl() throws ParsingException {
return "";
}
@Nonnull
@Override
public String getDashMpdUrl() throws ParsingException {
return "";
}

View File

@ -75,6 +75,21 @@ public class PeertubeAccountExtractor extends ChannelExtractor {
}
}
@Override
public String getParentChannelName() throws ParsingException {
return "";
}
@Override
public String getParentChannelUrl() throws ParsingException {
return "";
}
@Override
public String getParentChannelAvatarUrl() throws ParsingException {
return "";
}
@Override
public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, ExtractionException {
super.fetchPage();

View File

@ -147,6 +147,29 @@ public class PeertubeStreamExtractor extends StreamExtractor {
return baseUrl + value;
}
@Override
public String getParentChannelUrl() throws ParsingException {
return JsonUtils.getString(json, "channel.url");
}
@Nonnull
@Override
public String getParentChannelName() throws ParsingException {
return JsonUtils.getString(json, "channel.displayName");
}
@Nonnull
@Override
public String getParentChannelAvatarUrl() throws ParsingException {
String value;
try {
value = JsonUtils.getString(json, "channel.avatar.path");
} catch (Exception e) {
value = "/client/assets/images/default-avatar.png";
}
return baseUrl + value;
}
@Override
public String getDashMpdUrl() throws ParsingException {
return "";

View File

@ -142,6 +142,24 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
return SoundcloudParsingHelper.getAvatarUrl(track);
}
@Nonnull
@Override
public String getParentChannelUrl() throws ParsingException {
return "";
}
@Nonnull
@Override
public String getParentChannelName() throws ParsingException {
return "";
}
@Nonnull
@Override
public String getParentChannelAvatarUrl() throws ParsingException {
return "";
}
@Nonnull
@Override
public String getDashMpdUrl() {

View File

@ -352,6 +352,24 @@ public class YoutubeStreamExtractor extends StreamExtractor {
}
}
@Nonnull
@Override
public String getParentChannelUrl() throws ParsingException {
return "";
}
@Nonnull
@Override
public String getParentChannelName() throws ParsingException {
return "";
}
@Nonnull
@Override
public String getParentChannelAvatarUrl() throws ParsingException {
return "";
}
@Nonnull
@Override
public String getDashMpdUrl() throws ParsingException {

View File

@ -178,6 +178,39 @@ public abstract class StreamExtractor extends Extractor {
@Nonnull
public abstract String getUploaderAvatarUrl() throws ParsingException;
/**
* The Url to the page of the parent chanel of the stream. This must not be a homepage,
* but the page offered by the service the extractor handles. This url will be handled by the
* <a href="https://teamnewpipe.github.io/documentation/03_Implement_a_service/#channel">ChannelExtractor</a>,
* so be sure to implement that one before you return a value here, otherwise NewPipe will crash if one selects
* this url.
*
* @return the url to the page of the parent chanel of the stream or an empty String
* @throws ParsingException
*/
@Nonnull
public abstract String getParentChannelUrl() throws ParsingException;
/**
* The name of the parent chanel of the stream.
* If the name is not available you can simply return an empty string.
*
* @return the name of the parent chanel of the stream or an empty String
* @throws ParsingException
*/
@Nonnull
public abstract String getParentChannelName() throws ParsingException;
/**
* The url to the image file/profile picture/avatar of the parent chanel of the stream.
* If the url is not available you can return an empty String.
*
* @return The url of the image file of the parent chanel or an empty String
* @throws ParsingException
*/
@Nonnull
public abstract String getParentChannelAvatarUrl() throws ParsingException;
/**
* Get the dash mpd url. If you don't know what a dash MPD is you can read about it
* <a href="https://www.brendanlong.com/the-structure-of-an-mpeg-dash-mpd.html">here</a>.

View File

@ -223,6 +223,28 @@ public class StreamInfo extends Info {
} catch (Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setUploaderAvatarUrl(extractor.getUploaderAvatarUrl());
} catch (Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setParentChannelName(extractor.getParentChannelName());
} catch (Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setParentChannelUrl(extractor.getParentChannelUrl());
} catch (Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setParentChannelAvatarUrl(extractor.getParentChannelAvatarUrl());
} catch (Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setDescription(extractor.getDescription());
} catch (Exception e) {
@ -243,11 +265,6 @@ public class StreamInfo extends Info {
} catch (Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setUploaderAvatarUrl(extractor.getUploaderAvatarUrl());
} catch (Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setStartPosition(extractor.getTimeStamp());
} catch (Exception e) {
@ -332,6 +349,10 @@ public class StreamInfo extends Info {
private String uploaderUrl = "";
private String uploaderAvatarUrl = "";
private String parentChannelName = "";
private String parentChannelUrl = "";
private String parentChannelAvatarUrl = "";
private List<VideoStream> videoStreams = new ArrayList<>();
private List<AudioStream> audioStreams = new ArrayList<>();
private List<VideoStream> videoOnlyStreams = new ArrayList<>();
@ -486,6 +507,30 @@ public class StreamInfo extends Info {
this.uploaderAvatarUrl = uploaderAvatarUrl;
}
public String getParentChannelName() {
return parentChannelName;
}
public void setParentChannelName(String parentChannelName) {
this.parentChannelName = parentChannelName;
}
public String getParentChannelUrl() {
return parentChannelUrl;
}
public void setParentChannelUrl(String parentChannelUrl) {
this.parentChannelUrl = parentChannelUrl;
}
public String getParentChannelAvatarUrl() {
return parentChannelAvatarUrl;
}
public void setParentChannelAvatarUrl(String parentChannelAvatarUrl) {
this.parentChannelAvatarUrl = parentChannelAvatarUrl;
}
public List<VideoStream> getVideoStreams() {
return videoStreams;
}