Added description parsing for channel info.

This commit is contained in:
John Zhen M 2017-08-07 10:00:36 -07:00
parent 28d12cd90c
commit e0f1b5cd79
5 changed files with 26 additions and 0 deletions

View file

@ -99,4 +99,9 @@ public class SoundcloudUserExtractor extends UserExtractor {
return new NextItemsResult(collector.getItemList(), nextStreamsUrl); return new NextItemsResult(collector.getItemList(), nextStreamsUrl);
} }
@Override
public String getDescription() throws ParsingException {
return user.getString("description");
}
} }

View file

@ -119,6 +119,15 @@ public class YoutubeUserExtractor extends UserExtractor {
} }
} }
@Override
public String getDescription() throws ParsingException {
try {
return doc.select("meta[name=\"description\"]").first().attr("content");
} catch(Exception e) {
throw new ParsingException("Could not get channel name", e);
}
}
@Override @Override
public String getFeedUrl() throws ParsingException { public String getFeedUrl() throws ParsingException {
try { try {

View file

@ -45,5 +45,6 @@ public abstract class UserExtractor extends ListExtractor {
public abstract String getBannerUrl() throws ParsingException; public abstract String getBannerUrl() throws ParsingException;
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;
} }

View file

@ -90,6 +90,11 @@ public class UserInfo extends ListInfo {
} catch (Exception e) { } catch (Exception e) {
info.errors.add(e); info.errors.add(e);
} }
try {
info.description = extractor.getDescription();
} catch (Exception e) {
info.errors.add(e);
}
// Lists can be null if a exception was thrown during extraction // Lists can be null if a exception was thrown during extraction
if (info.related_streams == null) info.related_streams = new ArrayList<>(); if (info.related_streams == null) info.related_streams = new ArrayList<>();
@ -103,4 +108,5 @@ public class UserInfo extends ListInfo {
public String banner_url; public String banner_url;
public String feed_url; public String feed_url;
public long subscriber_count = -1; public long subscriber_count = -1;
public String description = "";
} }

View file

@ -56,6 +56,11 @@ public class YoutubeUserExtractorTest {
assertEquals(extractor.getUserName(), "Gronkh"); assertEquals(extractor.getUserName(), "Gronkh");
} }
@Test
public void testGetDescription() throws Exception {
assertEquals(extractor.getDescription(), "★ ★ ★ KLICK MICH HART, DU SAU! :D ★ ★ ★ Zart im Schmelz und süffig im Abgang. Ungebremster Spieltrieb seit 1896. Tägliche Folgen nonstop seit dem 01.04.2010!...");
}
@Test @Test
public void testGetAvatarUrl() throws Exception { public void testGetAvatarUrl() throws Exception {
assertTrue(extractor.getAvatarUrl(), extractor.getAvatarUrl().contains("yt3")); assertTrue(extractor.getAvatarUrl(), extractor.getAvatarUrl().contains("yt3"));