From 7ae274b2998548d39d798cc673bdbb1875b0dcc6 Mon Sep 17 00:00:00 2001 From: Mauricio Colli Date: Mon, 11 Sep 2017 10:19:16 -0300 Subject: [PATCH] Fix uploader name when requesting next streams --- .../extractor/channel/ChannelInfo.java | 8 +++---- .../extractor/playlist/PlaylistInfo.java | 8 +++---- .../youtube/YoutubeChannelExtractor.java | 22 +++++++++---------- .../youtube/YoutubeChannelExtractorTest.java | 1 - 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java b/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java index 62d0255f..d48e6658 100644 --- a/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java +++ b/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java @@ -34,12 +34,12 @@ import java.util.ArrayList; public class ChannelInfo extends ListInfo { - public static NextItemsResult getMoreItems(ServiceList serviceItem, String nextStreamsUrl) throws IOException, ExtractionException { - return getMoreItems(serviceItem.getService(), nextStreamsUrl); + public static NextItemsResult getMoreItems(ServiceList serviceItem, String url, String nextStreamsUrl) throws IOException, ExtractionException { + return getMoreItems(serviceItem.getService(), url, nextStreamsUrl); } - public static NextItemsResult getMoreItems(StreamingService service, String nextStreamsUrl) throws IOException, ExtractionException { - return service.getChannelExtractor(null, nextStreamsUrl).getNextStreams(); + public static NextItemsResult getMoreItems(StreamingService service, String url, String nextStreamsUrl) throws IOException, ExtractionException { + return service.getChannelExtractor(url, nextStreamsUrl).getNextStreams(); } public static ChannelInfo getInfo(String url) throws IOException, ExtractionException { diff --git a/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java b/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java index e892d820..ab6ddc5a 100644 --- a/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java +++ b/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java @@ -14,12 +14,12 @@ import java.util.ArrayList; public class PlaylistInfo extends ListInfo { - public static NextItemsResult getMoreItems(ServiceList serviceItem, String nextStreamsUrl) throws IOException, ExtractionException { - return getMoreItems(serviceItem.getService(), nextStreamsUrl); + public static NextItemsResult getMoreItems(ServiceList serviceItem, String url, String nextStreamsUrl) throws IOException, ExtractionException { + return getMoreItems(serviceItem.getService(), url, nextStreamsUrl); } - public static NextItemsResult getMoreItems(StreamingService service, String nextStreamsUrl) throws IOException, ExtractionException { - return service.getPlaylistExtractor(null, nextStreamsUrl).getNextStreams(); + public static NextItemsResult getMoreItems(StreamingService service, String url, String nextStreamsUrl) throws IOException, ExtractionException { + return service.getPlaylistExtractor(url, nextStreamsUrl).getNextStreams(); } public static PlaylistInfo getInfo(String url) throws IOException, ExtractionException { diff --git a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java index 8d2914f5..94e2d29c 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java @@ -45,8 +45,6 @@ public class YoutubeChannelExtractor extends ChannelExtractor { private static final String CHANNEL_FEED_BASE = "https://www.youtube.com/feeds/videos.xml?channel_id="; private static final String CHANNEL_URL_PARAMETERS = "/videos?view=0&flow=list&sort=dd&live_view=10000"; - private String channelName = ""; //Small hack used to make the channelName available to NextStreams - private Document doc; /** * It's lazily initialized (when getNextStreams is called) @@ -69,6 +67,13 @@ public class YoutubeChannelExtractor extends ChannelExtractor { nextStreamsAjax = null; } + @Override + protected boolean fetchPageUponCreation() { + // Unfortunately, we have to fetch the page even if we are getting only next streams, + // as they don't deliver enough information on their own (the channel name, for example). + return true; + } + @Override public String getCleanUrl() { try { @@ -93,8 +98,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor { @Override public String getName() throws ParsingException { try { - channelName = doc.select("span[class=\"qualified-channel-title-text\"]").first().select("a").first().text(); - return channelName; + return doc.select("meta[property=\"og:title\"]").first().attr("content"); } catch (Exception e) { throw new ParsingException("Could not get channel name", e); } @@ -204,10 +208,10 @@ public class YoutubeChannelExtractor extends ChannelExtractor { } } - private void collectStreamsFrom(StreamInfoItemCollector collector, - Element element) throws ParsingException { + private void collectStreamsFrom(StreamInfoItemCollector collector, Element element) throws ParsingException { collector.getItemList().clear(); + final String uploaderName = getName(); for (final Element li : element.children()) { if (li.select("div[class=\"feed-item-dismissable\"]").first() != null) { collector.commit(new YoutubeStreamInfoItemExtractor(li) { @@ -235,11 +239,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor { @Override public String getUploaderName() throws ParsingException { - if(channelName.isEmpty()) { - return ""; - } else { - return channelName; - } + return uploaderName; } @Override diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java index 84e7e622..3df3add3 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java @@ -6,7 +6,6 @@ import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.channel.ChannelExtractor; -import org.schabi.newpipe.extractor.stream.StreamInfoItem; import static org.junit.Assert.*; import static org.schabi.newpipe.extractor.ServiceList.YouTube;