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

This commit is contained in:
Roy Yosef 2020-04-13 23:33:44 +03:00 committed by wb9688
parent 665c69b530
commit 4234740baa
7 changed files with 134 additions and 0 deletions

View File

@ -37,4 +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;
}

View File

@ -94,16 +94,61 @@ public class ChannelInfo extends ListInfo<StreamInfoItem> {
info.addError(e);
}
try {
info.setParentChannelName(extractor.getParentChannelName());
} catch (Exception e) {
info.addError(e);
}
try {
info.setParentChannelUrl(extractor.getParentChannelUrl());
} catch (Exception e) {
info.addError(e);
}
try {
info.setParentChannelAvatarUrl(extractor.getParentChannelAvatarUrl());
} catch (Exception e) {
info.addError(e);
}
return info;
}
private String avatarUrl;
private String parentChannelName;
private String parentChannelUrl;
private String parentChannelAvatarUrl;
private String bannerUrl;
private String feedUrl;
private long subscriberCount = -1;
private String description;
private String[] donationLinks;
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 String getAvatarUrl() {
return avatarUrl;
}

View File

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

View File

@ -75,6 +75,27 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
}
}
@Override
public String getParentChannelName() throws ParsingException {
return JsonUtils.getString(json, "ownerAccount.name");
}
@Override
public String getParentChannelUrl() throws ParsingException {
return JsonUtils.getString(json, "ownerAccount.url");
}
@Override
public String getParentChannelAvatarUrl() 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
public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, ExtractionException {
super.fetchPage();

View File

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

View File

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

View File

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