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 long getSubscriberCount() throws ParsingException;
public abstract String getDescription() throws ParsingException;
public abstract String getParentChannelName() throws ParsingException;
public abstract String getParentChannelUrl() throws ParsingException;
public abstract String getParentChannelAvatarUrl() throws ParsingException;
public abstract String getSubChannelName() throws ParsingException;
public abstract String getSubChannelUrl() throws ParsingException;
public abstract String getSubChannelAvatarUrl() throws ParsingException;
}

View File

@ -95,19 +95,19 @@ public class ChannelInfo extends ListInfo<StreamInfoItem> {
}
try {
info.setParentChannelName(extractor.getParentChannelName());
info.setSubChannelName(extractor.getSubChannelName());
} catch (Exception e) {
info.addError(e);
}
try {
info.setParentChannelUrl(extractor.getParentChannelUrl());
info.setSubChannelUrl(extractor.getSubChannelUrl());
} catch (Exception e) {
info.addError(e);
}
try {
info.setParentChannelAvatarUrl(extractor.getParentChannelAvatarUrl());
info.setSubChannelAvatarUrl(extractor.getSubChannelAvatarUrl());
} catch (Exception e) {
info.addError(e);
}
@ -116,37 +116,37 @@ public class ChannelInfo extends ListInfo<StreamInfoItem> {
}
private String avatarUrl;
private String parentChannelName;
private String parentChannelUrl;
private String parentChannelAvatarUrl;
private String subChannelName;
private String subChannelUrl;
private String subChannelAvatarUrl;
private String bannerUrl;
private String feedUrl;
private long subscriberCount = -1;
private String description;
private String[] donationLinks;
public String getParentChannelName() {
return parentChannelName;
public String getSubChannelName() {
return subChannelName;
}
public void setParentChannelName(String parentChannelName) {
this.parentChannelName = parentChannelName;
public void setSubChannelName(String subChannelName) {
this.subChannelName = subChannelName;
}
public String getParentChannelUrl() {
return parentChannelUrl;
public String getSubChannelUrl() {
return subChannelUrl;
}
public void setParentChannelUrl(String parentChannelUrl) {
this.parentChannelUrl = parentChannelUrl;
public void setSubChannelUrl(String subChannelUrl) {
this.subChannelUrl = subChannelUrl;
}
public String getParentChannelAvatarUrl() {
return parentChannelAvatarUrl;
public String getSubChannelAvatarUrl() {
return subChannelAvatarUrl;
}
public void setParentChannelAvatarUrl(String parentChannelAvatarUrl) {
this.parentChannelAvatarUrl = parentChannelAvatarUrl;
public void setSubChannelAvatarUrl(String subChannelAvatarUrl) {
this.subChannelAvatarUrl = subChannelAvatarUrl;
}
public String getAvatarUrl() {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -23,6 +23,7 @@ package org.schabi.newpipe.extractor.stream;
import org.schabi.newpipe.extractor.Extractor;
import org.schabi.newpipe.extractor.MediaFormat;
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.ParsingException;
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,
* 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
* this url.
*
@ -179,37 +180,37 @@ public abstract class StreamExtractor extends Extractor {
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
* <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
* 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
*/
@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.
*
* @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
*/
@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.
*
* @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
*/
@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

View File

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

View File

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

View File

@ -87,6 +87,33 @@ public class PeertubeStreamExtractorDefaultTest {
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
public void testGetLength() throws ParsingException {
assertEquals(113, extractor.getLength());
@ -98,22 +125,11 @@ public class PeertubeStreamExtractorDefaultTest {
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
public void testGetThumbnailUrl() throws ParsingException {
assertIsSecureUrl(extractor.getThumbnailUrl());
}
@Test
public void testGetUploaderAvatarUrl() throws ParsingException {
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
}
@Test
public void testGetVideoStreams() throws IOException, ExtractionException {
assertFalse(extractor.getVideoStreams().isEmpty());