From e0f1b5cd7935fa1a7151a15d73316ca09ff29b02 Mon Sep 17 00:00:00 2001 From: John Zhen M Date: Mon, 7 Aug 2017 10:00:36 -0700 Subject: [PATCH] Added description parsing for channel info. --- .../services/soundcloud/SoundcloudUserExtractor.java | 5 +++++ .../extractor/services/youtube/YoutubeUserExtractor.java | 9 +++++++++ .../org/schabi/newpipe/extractor/user/UserExtractor.java | 1 + .../java/org/schabi/newpipe/extractor/user/UserInfo.java | 6 ++++++ .../services/youtube/YoutubeUserExtractorTest.java | 5 +++++ 5 files changed, 26 insertions(+) diff --git a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudUserExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudUserExtractor.java index 2d602b96f..f2f2c99fb 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudUserExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudUserExtractor.java @@ -99,4 +99,9 @@ public class SoundcloudUserExtractor extends UserExtractor { return new NextItemsResult(collector.getItemList(), nextStreamsUrl); } + + @Override + public String getDescription() throws ParsingException { + return user.getString("description"); + } } diff --git a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeUserExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeUserExtractor.java index 6d6d05aa5..28af77420 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeUserExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeUserExtractor.java @@ -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 public String getFeedUrl() throws ParsingException { try { diff --git a/src/main/java/org/schabi/newpipe/extractor/user/UserExtractor.java b/src/main/java/org/schabi/newpipe/extractor/user/UserExtractor.java index 703ff97ee..1b6e55ff3 100644 --- a/src/main/java/org/schabi/newpipe/extractor/user/UserExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/user/UserExtractor.java @@ -45,5 +45,6 @@ public abstract class UserExtractor extends ListExtractor { public abstract String getBannerUrl() throws ParsingException; public abstract String getFeedUrl() throws ParsingException; public abstract long getSubscriberCount() throws ParsingException; + public abstract String getDescription() throws ParsingException; } diff --git a/src/main/java/org/schabi/newpipe/extractor/user/UserInfo.java b/src/main/java/org/schabi/newpipe/extractor/user/UserInfo.java index 1b0fffa67..18d3ebac7 100644 --- a/src/main/java/org/schabi/newpipe/extractor/user/UserInfo.java +++ b/src/main/java/org/schabi/newpipe/extractor/user/UserInfo.java @@ -90,6 +90,11 @@ public class UserInfo extends ListInfo { } catch (Exception 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 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 feed_url; public long subscriber_count = -1; + public String description = ""; } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeUserExtractorTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeUserExtractorTest.java index 8051922cf..0868334a7 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeUserExtractorTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeUserExtractorTest.java @@ -56,6 +56,11 @@ public class YoutubeUserExtractorTest { 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 public void testGetAvatarUrl() throws Exception { assertTrue(extractor.getAvatarUrl(), extractor.getAvatarUrl().contains("yt3"));