Merge pull request #313 from Royosef/DisplayParentChannelDetails

Display parent channel details
This commit is contained in:
wb9688 2020-05-08 15:52:32 +02:00 committed by GitHub
commit 44d382b4bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 339 additions and 18 deletions

View File

@ -37,4 +37,7 @@ public abstract class ChannelExtractor extends ListExtractor<StreamInfoItem> {
public abstract String getFeedUrl() throws ParsingException; public abstract String getFeedUrl() throws ParsingException;
public abstract long getSubscriberCount() throws ParsingException; public abstract long getSubscriberCount() throws ParsingException;
public abstract String getDescription() throws ParsingException; public abstract String getDescription() throws ParsingException;
public abstract String getSubChannelName() throws ParsingException;
public abstract String getSubChannelUrl() throws ParsingException;
public abstract String getSubChannelAvatarUrl() throws ParsingException;
} }

View File

@ -94,16 +94,61 @@ public class ChannelInfo extends ListInfo<StreamInfoItem> {
info.addError(e); info.addError(e);
} }
try {
info.setSubChannelName(extractor.getSubChannelName());
} catch (Exception e) {
info.addError(e);
}
try {
info.setSubChannelUrl(extractor.getSubChannelUrl());
} catch (Exception e) {
info.addError(e);
}
try {
info.setSubChannelAvatarUrl(extractor.getSubChannelAvatarUrl());
} catch (Exception e) {
info.addError(e);
}
return info; return info;
} }
private String avatarUrl; private String avatarUrl;
private String subChannelName;
private String subChannelUrl;
private String subChannelAvatarUrl;
private String bannerUrl; private String bannerUrl;
private String feedUrl; private String feedUrl;
private long subscriberCount = -1; private long subscriberCount = -1;
private String description; private String description;
private String[] donationLinks; private String[] donationLinks;
public String getSubChannelName() {
return subChannelName;
}
public void setSubChannelName(String subChannelName) {
this.subChannelName = subChannelName;
}
public String getSubChannelUrl() {
return subChannelUrl;
}
public void setSubChannelUrl(String subChannelUrl) {
this.subChannelUrl = subChannelUrl;
}
public String getSubChannelAvatarUrl() {
return subChannelAvatarUrl;
}
public void setSubChannelAvatarUrl(String subChannelAvatarUrl) {
this.subChannelAvatarUrl = subChannelAvatarUrl;
}
public String getAvatarUrl() { public String getAvatarUrl() {
return avatarUrl; return avatarUrl;
} }

View File

@ -52,6 +52,21 @@ public class MediaCCCConferenceExtractor extends ChannelExtractor {
return null; return null;
} }
@Override
public String getSubChannelName() throws ParsingException {
return "";
}
@Override
public String getSubChannelUrl() throws ParsingException {
return "";
}
@Override
public String getSubChannelAvatarUrl() throws ParsingException {
return "";
}
@Nonnull @Nonnull
@Override @Override
public InfoItemsPage<StreamInfoItem> getInitialPage() { public InfoItemsPage<StreamInfoItem> getInitialPage() {

View File

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

View File

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

View File

@ -75,6 +75,27 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
} }
} }
@Override
public String getSubChannelName() throws ParsingException {
return JsonUtils.getString(json, "ownerAccount.name");
}
@Override
public String getSubChannelUrl() throws ParsingException {
return JsonUtils.getString(json, "ownerAccount.url");
}
@Override
public String getSubChannelAvatarUrl() throws ParsingException {
String value;
try {
value = JsonUtils.getString(json, "ownerAccount.avatar.path");
} catch (Exception e) {
value = "/client/assets/images/default-avatar.png";
}
return baseUrl + value;
}
@Override @Override
public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, ExtractionException { public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, ExtractionException {
super.fetchPage(); super.fetchPage();

View File

@ -147,6 +147,29 @@ public class PeertubeStreamExtractor extends StreamExtractor {
return baseUrl + value; return baseUrl + value;
} }
@Override
public String getSubChannelUrl() throws ParsingException {
return JsonUtils.getString(json, "channel.url");
}
@Nonnull
@Override
public String getSubChannelName() throws ParsingException {
return JsonUtils.getString(json, "channel.displayName");
}
@Nonnull
@Override
public String getSubChannelAvatarUrl() 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 @Override
public String getDashMpdUrl() throws ParsingException { public String getDashMpdUrl() throws ParsingException {
return ""; return "";

View File

@ -83,6 +83,21 @@ public class SoundcloudChannelExtractor extends ChannelExtractor {
return user.getString("description", EMPTY_STRING); return user.getString("description", EMPTY_STRING);
} }
@Override
public String getSubChannelName() throws ParsingException {
return "";
}
@Override
public String getSubChannelUrl() throws ParsingException {
return "";
}
@Override
public String getSubChannelAvatarUrl() throws ParsingException {
return "";
}
@Nonnull @Nonnull
@Override @Override
public InfoItemsPage<StreamInfoItem> getInitialPage() throws ExtractionException { public InfoItemsPage<StreamInfoItem> getInitialPage() throws ExtractionException {

View File

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

View File

@ -212,6 +212,21 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
} }
} }
@Override
public String getSubChannelName() throws ParsingException {
return "";
}
@Override
public String getSubChannelUrl() throws ParsingException {
return "";
}
@Override
public String getSubChannelAvatarUrl() throws ParsingException {
return "";
}
@Nonnull @Nonnull
@Override @Override
public InfoItemsPage<StreamInfoItem> getInitialPage() throws ExtractionException { public InfoItemsPage<StreamInfoItem> getInitialPage() throws ExtractionException {

View File

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

View File

@ -23,6 +23,7 @@ package org.schabi.newpipe.extractor.stream;
import org.schabi.newpipe.extractor.Extractor; import org.schabi.newpipe.extractor.Extractor;
import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.MediaFormat;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.LinkHandler; import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
@ -148,7 +149,7 @@ public abstract class StreamExtractor extends Extractor {
/** /**
* The Url to the page of the creator/uploader of the stream. This must not be a homepage, * The Url to the page of the creator/uploader 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 * 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>, * {@link ChannelExtractor},
* so be sure to implement that one before you return a value here, otherwise NewPipe will crash if one selects * so be sure to implement that one before you return a value here, otherwise NewPipe will crash if one selects
* this url. * this url.
* *
@ -178,6 +179,39 @@ public abstract class StreamExtractor extends Extractor {
@Nonnull @Nonnull
public abstract String getUploaderAvatarUrl() throws ParsingException; public abstract String getUploaderAvatarUrl() throws ParsingException;
/**
* The Url to the page of the sub-channel 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
* {@link ChannelExtractor},
* 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 sub-channel of the stream or an empty String
* @throws ParsingException
*/
@Nonnull
public abstract String getSubChannelUrl() throws ParsingException;
/**
* The name of the sub-channel of the stream.
* If the name is not available you can simply return an empty string.
*
* @return the name of the sub-channel of the stream or an empty String
* @throws ParsingException
*/
@Nonnull
public abstract String getSubChannelName() throws ParsingException;
/**
* The url to the image file/profile picture/avatar of the sub-channel of the stream.
* If the url is not available you can return an empty String.
*
* @return The url of the image file of the sub-channel or an empty String
* @throws ParsingException
*/
@Nonnull
public abstract String getSubChannelAvatarUrl() throws ParsingException;
/** /**
* Get the dash mpd url. If you don't know what a dash MPD is you can read about it * 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>. * <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) { } catch (Exception e) {
streamInfo.addError(e); streamInfo.addError(e);
} }
try {
streamInfo.setUploaderAvatarUrl(extractor.getUploaderAvatarUrl());
} catch (Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setSubChannelName(extractor.getSubChannelName());
} catch (Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setSubChannelUrl(extractor.getSubChannelUrl());
} catch (Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setSubChannelAvatarUrl(extractor.getSubChannelAvatarUrl());
} catch (Exception e) {
streamInfo.addError(e);
}
try { try {
streamInfo.setDescription(extractor.getDescription()); streamInfo.setDescription(extractor.getDescription());
} catch (Exception e) { } catch (Exception e) {
@ -243,11 +265,6 @@ public class StreamInfo extends Info {
} catch (Exception e) { } catch (Exception e) {
streamInfo.addError(e); streamInfo.addError(e);
} }
try {
streamInfo.setUploaderAvatarUrl(extractor.getUploaderAvatarUrl());
} catch (Exception e) {
streamInfo.addError(e);
}
try { try {
streamInfo.setStartPosition(extractor.getTimeStamp()); streamInfo.setStartPosition(extractor.getTimeStamp());
} catch (Exception e) { } catch (Exception e) {
@ -332,6 +349,10 @@ public class StreamInfo extends Info {
private String uploaderUrl = ""; private String uploaderUrl = "";
private String uploaderAvatarUrl = ""; private String uploaderAvatarUrl = "";
private String subChannelName = "";
private String subChannelUrl = "";
private String subChannelAvatarUrl = "";
private List<VideoStream> videoStreams = new ArrayList<>(); private List<VideoStream> videoStreams = new ArrayList<>();
private List<AudioStream> audioStreams = new ArrayList<>(); private List<AudioStream> audioStreams = new ArrayList<>();
private List<VideoStream> videoOnlyStreams = new ArrayList<>(); private List<VideoStream> videoOnlyStreams = new ArrayList<>();
@ -486,6 +507,30 @@ public class StreamInfo extends Info {
this.uploaderAvatarUrl = uploaderAvatarUrl; this.uploaderAvatarUrl = uploaderAvatarUrl;
} }
public String getSubChannelName() {
return subChannelName;
}
public void setSubChannelName(String subChannelName) {
this.subChannelName = subChannelName;
}
public String getSubChannelUrl() {
return subChannelUrl;
}
public void setSubChannelUrl(String subChannelUrl) {
this.subChannelUrl = subChannelUrl;
}
public String getSubChannelAvatarUrl() {
return subChannelAvatarUrl;
}
public void setSubChannelAvatarUrl(String subChannelAvatarUrl) {
this.subChannelAvatarUrl = subChannelAvatarUrl;
}
public List<VideoStream> getVideoStreams() { public List<VideoStream> getVideoStreams() {
return videoStreams; return videoStreams;
} }

View File

@ -84,6 +84,16 @@ public class PeertubeChannelExtractorTest {
assertNotNull(extractor.getDescription()); assertNotNull(extractor.getDescription());
} }
@Test
public void testSubChannelName() throws ParsingException {
assertEquals("libux", extractor.getSubChannelName());
}
@Test
public void testSubChannelUrl() throws ParsingException {
assertEquals("https://peertube.mastodon.host/accounts/libux", extractor.getSubChannelUrl());
}
@Test @Test
public void testAvatarUrl() throws ParsingException { public void testAvatarUrl() throws ParsingException {
assertIsSecureUrl(extractor.getAvatarUrl()); assertIsSecureUrl(extractor.getAvatarUrl());
@ -181,6 +191,16 @@ public class PeertubeChannelExtractorTest {
assertNotNull(extractor.getDescription()); assertNotNull(extractor.getDescription());
} }
@Test
public void testSubChannelName() throws ParsingException {
assertEquals("booteille", extractor.getSubChannelName());
}
@Test
public void testSubChannelUrl() throws ParsingException {
assertEquals("https://peertube.mastodon.host/accounts/booteille", extractor.getSubChannelUrl());
}
@Test @Test
public void testAvatarUrl() throws ParsingException { public void testAvatarUrl() throws ParsingException {
assertIsSecureUrl(extractor.getAvatarUrl()); assertIsSecureUrl(extractor.getAvatarUrl());

View File

@ -87,6 +87,33 @@ public class PeertubeStreamExtractorDefaultTest {
assertEquals("Framasoft", extractor.getUploaderName()); assertEquals("Framasoft", extractor.getUploaderName());
} }
@Test
public void testGetUploaderUrl() throws ParsingException {
assertIsSecureUrl(extractor.getUploaderUrl());
assertEquals("https://framatube.org/api/v1/accounts/framasoft@framatube.org", extractor.getUploaderUrl());
}
@Test
public void testGetUploaderAvatarUrl() throws ParsingException {
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
}
@Test
public void testGetSubChannelName() throws ParsingException {
assertEquals("Les vidéos de Framasoft", extractor.getSubChannelName());
}
@Test
public void testGetSubChannelUrl() throws ParsingException {
assertIsSecureUrl(extractor.getSubChannelUrl());
assertEquals("https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8", extractor.getSubChannelUrl());
}
@Test
public void testGetSubChannelAvatarUrl() throws ParsingException {
assertIsSecureUrl(extractor.getSubChannelAvatarUrl());
}
@Test @Test
public void testGetLength() throws ParsingException { public void testGetLength() throws ParsingException {
assertEquals(113, extractor.getLength()); assertEquals(113, extractor.getLength());
@ -98,22 +125,11 @@ public class PeertubeStreamExtractorDefaultTest {
extractor.getViewCount() > 10); extractor.getViewCount() > 10);
} }
@Test
public void testGetUploaderUrl() throws ParsingException {
assertIsSecureUrl(extractor.getUploaderUrl());
assertEquals("https://framatube.org/api/v1/accounts/framasoft@framatube.org", extractor.getUploaderUrl());
}
@Test @Test
public void testGetThumbnailUrl() throws ParsingException { public void testGetThumbnailUrl() throws ParsingException {
assertIsSecureUrl(extractor.getThumbnailUrl()); assertIsSecureUrl(extractor.getThumbnailUrl());
} }
@Test
public void testGetUploaderAvatarUrl() throws ParsingException {
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
}
@Test @Test
public void testGetVideoStreams() throws IOException, ExtractionException { public void testGetVideoStreams() throws IOException, ExtractionException {
assertFalse(extractor.getVideoStreams().isEmpty()); assertFalse(extractor.getVideoStreams().isEmpty());