Fix PR review

Rename "ParentChannel" to "SubChannel"
Add Tests for sub-channel info fetching
This commit is contained in:
Roy Yosef 2020-04-16 15:19:36 +03:00 committed by wb9688
parent 1de1f97cf1
commit a408661771
15 changed files with 113 additions and 96 deletions

View File

@ -37,7 +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 getParentChannelName() throws ParsingException; public abstract String getSubChannelName() throws ParsingException;
public abstract String getParentChannelUrl() throws ParsingException; public abstract String getSubChannelUrl() throws ParsingException;
public abstract String getParentChannelAvatarUrl() throws ParsingException; public abstract String getSubChannelAvatarUrl() throws ParsingException;
} }

View File

@ -95,19 +95,19 @@ public class ChannelInfo extends ListInfo<StreamInfoItem> {
} }
try { try {
info.setParentChannelName(extractor.getParentChannelName()); info.setSubChannelName(extractor.getSubChannelName());
} catch (Exception e) { } catch (Exception e) {
info.addError(e); info.addError(e);
} }
try { try {
info.setParentChannelUrl(extractor.getParentChannelUrl()); info.setSubChannelUrl(extractor.getSubChannelUrl());
} catch (Exception e) { } catch (Exception e) {
info.addError(e); info.addError(e);
} }
try { try {
info.setParentChannelAvatarUrl(extractor.getParentChannelAvatarUrl()); info.setSubChannelAvatarUrl(extractor.getSubChannelAvatarUrl());
} catch (Exception e) { } catch (Exception e) {
info.addError(e); info.addError(e);
} }
@ -116,37 +116,37 @@ public class ChannelInfo extends ListInfo<StreamInfoItem> {
} }
private String avatarUrl; private String avatarUrl;
private String parentChannelName; private String subChannelName;
private String parentChannelUrl; private String subChannelUrl;
private String parentChannelAvatarUrl; 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 getParentChannelName() { public String getSubChannelName() {
return parentChannelName; return subChannelName;
} }
public void setParentChannelName(String parentChannelName) { public void setSubChannelName(String subChannelName) {
this.parentChannelName = parentChannelName; this.subChannelName = subChannelName;
} }
public String getParentChannelUrl() { public String getSubChannelUrl() {
return parentChannelUrl; return subChannelUrl;
} }
public void setParentChannelUrl(String parentChannelUrl) { public void setSubChannelUrl(String subChannelUrl) {
this.parentChannelUrl = parentChannelUrl; this.subChannelUrl = subChannelUrl;
} }
public String getParentChannelAvatarUrl() { public String getSubChannelAvatarUrl() {
return parentChannelAvatarUrl; return subChannelAvatarUrl;
} }
public void setParentChannelAvatarUrl(String parentChannelAvatarUrl) { public void setSubChannelAvatarUrl(String subChannelAvatarUrl) {
this.parentChannelAvatarUrl = parentChannelAvatarUrl; this.subChannelAvatarUrl = subChannelAvatarUrl;
} }
public String getAvatarUrl() { public String getAvatarUrl() {

View File

@ -53,17 +53,17 @@ public class MediaCCCConferenceExtractor extends ChannelExtractor {
} }
@Override @Override
public String getParentChannelName() throws ParsingException { public String getSubChannelName() throws ParsingException {
return ""; return "";
} }
@Override @Override
public String getParentChannelUrl() throws ParsingException { public String getSubChannelUrl() throws ParsingException {
return ""; return "";
} }
@Override @Override
public String getParentChannelAvatarUrl() throws ParsingException { public String getSubChannelAvatarUrl() throws ParsingException {
return ""; return "";
} }

View File

@ -112,19 +112,19 @@ public class MediaCCCStreamExtractor extends StreamExtractor {
@Nonnull @Nonnull
@Override @Override
public String getParentChannelUrl() throws ParsingException { public String getSubChannelUrl() throws ParsingException {
return ""; return "";
} }
@Nonnull @Nonnull
@Override @Override
public String getParentChannelName() throws ParsingException { public String getSubChannelName() throws ParsingException {
return ""; return "";
} }
@Nonnull @Nonnull
@Override @Override
public String getParentChannelAvatarUrl() throws ParsingException { public String getSubChannelAvatarUrl() throws ParsingException {
return ""; return "";
} }

View File

@ -76,17 +76,17 @@ public class PeertubeAccountExtractor extends ChannelExtractor {
} }
@Override @Override
public String getParentChannelName() throws ParsingException { public String getSubChannelName() throws ParsingException {
return ""; return "";
} }
@Override @Override
public String getParentChannelUrl() throws ParsingException { public String getSubChannelUrl() throws ParsingException {
return ""; return "";
} }
@Override @Override
public String getParentChannelAvatarUrl() throws ParsingException { public String getSubChannelAvatarUrl() throws ParsingException {
return ""; return "";
} }

View File

@ -76,17 +76,17 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
} }
@Override @Override
public String getParentChannelName() throws ParsingException { public String getSubChannelName() throws ParsingException {
return JsonUtils.getString(json, "ownerAccount.name"); return JsonUtils.getString(json, "ownerAccount.name");
} }
@Override @Override
public String getParentChannelUrl() throws ParsingException { public String getSubChannelUrl() throws ParsingException {
return JsonUtils.getString(json, "ownerAccount.url"); return JsonUtils.getString(json, "ownerAccount.url");
} }
@Override @Override
public String getParentChannelAvatarUrl() throws ParsingException { public String getSubChannelAvatarUrl() throws ParsingException {
String value; String value;
try { try {
value = JsonUtils.getString(json, "ownerAccount.avatar.path"); value = JsonUtils.getString(json, "ownerAccount.avatar.path");

View File

@ -148,19 +148,19 @@ public class PeertubeStreamExtractor extends StreamExtractor {
} }
@Override @Override
public String getParentChannelUrl() throws ParsingException { public String getSubChannelUrl() throws ParsingException {
return JsonUtils.getString(json, "channel.url"); return JsonUtils.getString(json, "channel.url");
} }
@Nonnull @Nonnull
@Override @Override
public String getParentChannelName() throws ParsingException { public String getSubChannelName() throws ParsingException {
return JsonUtils.getString(json, "channel.displayName"); return JsonUtils.getString(json, "channel.displayName");
} }
@Nonnull @Nonnull
@Override @Override
public String getParentChannelAvatarUrl() throws ParsingException { public String getSubChannelAvatarUrl() throws ParsingException {
String value; String value;
try { try {
value = JsonUtils.getString(json, "channel.avatar.path"); value = JsonUtils.getString(json, "channel.avatar.path");

View File

@ -84,17 +84,17 @@ public class SoundcloudChannelExtractor extends ChannelExtractor {
} }
@Override @Override
public String getParentChannelName() throws ParsingException { public String getSubChannelName() throws ParsingException {
return ""; return "";
} }
@Override @Override
public String getParentChannelUrl() throws ParsingException { public String getSubChannelUrl() throws ParsingException {
return ""; return "";
} }
@Override @Override
public String getParentChannelAvatarUrl() throws ParsingException { public String getSubChannelAvatarUrl() throws ParsingException {
return ""; return "";
} }

View File

@ -144,19 +144,19 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
@Nonnull @Nonnull
@Override @Override
public String getParentChannelUrl() throws ParsingException { public String getSubChannelUrl() throws ParsingException {
return ""; return "";
} }
@Nonnull @Nonnull
@Override @Override
public String getParentChannelName() throws ParsingException { public String getSubChannelName() throws ParsingException {
return ""; return "";
} }
@Nonnull @Nonnull
@Override @Override
public String getParentChannelAvatarUrl() throws ParsingException { public String getSubChannelAvatarUrl() throws ParsingException {
return ""; return "";
} }

View File

@ -213,17 +213,17 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
} }
@Override @Override
public String getParentChannelName() throws ParsingException { public String getSubChannelName() throws ParsingException {
return ""; return "";
} }
@Override @Override
public String getParentChannelUrl() throws ParsingException { public String getSubChannelUrl() throws ParsingException {
return ""; return "";
} }
@Override @Override
public String getParentChannelAvatarUrl() throws ParsingException { public String getSubChannelAvatarUrl() throws ParsingException {
return ""; return "";
} }

View File

@ -354,19 +354,19 @@ public class YoutubeStreamExtractor extends StreamExtractor {
@Nonnull @Nonnull
@Override @Override
public String getParentChannelUrl() throws ParsingException { public String getSubChannelUrl() throws ParsingException {
return ""; return "";
} }
@Nonnull @Nonnull
@Override @Override
public String getParentChannelName() throws ParsingException { public String getSubChannelName() throws ParsingException {
return ""; return "";
} }
@Nonnull @Nonnull
@Override @Override
public String getParentChannelAvatarUrl() throws ParsingException { public String getSubChannelAvatarUrl() throws ParsingException {
return ""; return "";
} }

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.
* *
@ -179,37 +180,37 @@ public abstract class StreamExtractor extends Extractor {
public abstract String getUploaderAvatarUrl() throws ParsingException; public abstract String getUploaderAvatarUrl() throws ParsingException;
/** /**
* The Url to the page of the parent chanel of the stream. This must not be a homepage, * 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 * 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.
* *
* @return the url to the page of the parent chanel of the stream or an empty String * @return the url to the page of the sub-channel of the stream or an empty String
* @throws ParsingException * @throws ParsingException
*/ */
@Nonnull @Nonnull
public abstract String getParentChannelUrl() throws ParsingException; public abstract String getSubChannelUrl() throws ParsingException;
/** /**
* The name of the parent chanel of the stream. * The name of the sub-channel of the stream.
* If the name is not available you can simply return an empty string. * 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 * @return the name of the sub-channel of the stream or an empty String
* @throws ParsingException * @throws ParsingException
*/ */
@Nonnull @Nonnull
public abstract String getParentChannelName() throws ParsingException; public abstract String getSubChannelName() throws ParsingException;
/** /**
* The url to the image file/profile picture/avatar of the parent chanel of the stream. * 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. * 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 * @return The url of the image file of the sub-channel or an empty String
* @throws ParsingException * @throws ParsingException
*/ */
@Nonnull @Nonnull
public abstract String getParentChannelAvatarUrl() throws ParsingException; 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

View File

@ -230,17 +230,17 @@ public class StreamInfo extends Info {
} }
try { try {
streamInfo.setParentChannelName(extractor.getParentChannelName()); streamInfo.setSubChannelName(extractor.getSubChannelName());
} catch (Exception e) { } catch (Exception e) {
streamInfo.addError(e); streamInfo.addError(e);
} }
try { try {
streamInfo.setParentChannelUrl(extractor.getParentChannelUrl()); streamInfo.setSubChannelUrl(extractor.getSubChannelUrl());
} catch (Exception e) { } catch (Exception e) {
streamInfo.addError(e); streamInfo.addError(e);
} }
try { try {
streamInfo.setParentChannelAvatarUrl(extractor.getParentChannelAvatarUrl()); streamInfo.setSubChannelAvatarUrl(extractor.getSubChannelAvatarUrl());
} catch (Exception e) { } catch (Exception e) {
streamInfo.addError(e); streamInfo.addError(e);
} }
@ -349,9 +349,9 @@ public class StreamInfo extends Info {
private String uploaderUrl = ""; private String uploaderUrl = "";
private String uploaderAvatarUrl = ""; private String uploaderAvatarUrl = "";
private String parentChannelName = ""; private String subChannelName = "";
private String parentChannelUrl = ""; private String subChannelUrl = "";
private String parentChannelAvatarUrl = ""; 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<>();
@ -507,28 +507,28 @@ public class StreamInfo extends Info {
this.uploaderAvatarUrl = uploaderAvatarUrl; this.uploaderAvatarUrl = uploaderAvatarUrl;
} }
public String getParentChannelName() { public String getSubChannelName() {
return parentChannelName; return subChannelName;
} }
public void setParentChannelName(String parentChannelName) { public void setSubChannelName(String subChannelName) {
this.parentChannelName = parentChannelName; this.subChannelName = subChannelName;
} }
public String getParentChannelUrl() { public String getSubChannelUrl() {
return parentChannelUrl; return subChannelUrl;
} }
public void setParentChannelUrl(String parentChannelUrl) { public void setSubChannelUrl(String subChannelUrl) {
this.parentChannelUrl = parentChannelUrl; this.subChannelUrl = subChannelUrl;
} }
public String getParentChannelAvatarUrl() { public String getSubChannelAvatarUrl() {
return parentChannelAvatarUrl; return subChannelAvatarUrl;
} }
public void setParentChannelAvatarUrl(String parentChannelAvatarUrl) { public void setSubChannelAvatarUrl(String subChannelAvatarUrl) {
this.parentChannelAvatarUrl = parentChannelAvatarUrl; this.subChannelAvatarUrl = subChannelAvatarUrl;
} }
public List<VideoStream> getVideoStreams() { public List<VideoStream> getVideoStreams() {

View File

@ -85,13 +85,13 @@ public class PeertubeChannelExtractorTest {
} }
@Test @Test
public void testParentChannelName() throws ParsingException { public void testSubChannelName() throws ParsingException {
assertEquals("libux", extractor.getParentChannelName()); assertEquals("libux", extractor.getSubChannelName());
} }
@Test @Test
public void testParentChannelUrl() throws ParsingException { public void testSubChannelUrl() throws ParsingException {
assertEquals("https://peertube.mastodon.host/accounts/libux", extractor.getParentChannelUrl()); assertEquals("https://peertube.mastodon.host/accounts/libux", extractor.getSubChannelUrl());
} }
@Test @Test
@ -192,13 +192,13 @@ public class PeertubeChannelExtractorTest {
} }
@Test @Test
public void testParentChannelName() throws ParsingException { public void testSubChannelName() throws ParsingException {
assertEquals("booteille", extractor.getParentChannelName()); assertEquals("booteille", extractor.getSubChannelName());
} }
@Test @Test
public void testParentChannelUrl() throws ParsingException { public void testSubChannelUrl() throws ParsingException {
assertEquals("https://peertube.mastodon.host/accounts/booteille", extractor.getParentChannelUrl()); assertEquals("https://peertube.mastodon.host/accounts/booteille", extractor.getSubChannelUrl());
} }
@Test @Test

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());