From 7186f58374d557c6a89dce91fdc8f15c6d0f334f Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 12 Feb 2017 14:21:59 +0100 Subject: [PATCH] remove StreamInfoItemSearchCollector --- .../youtube/YoutubeSearchResultTest.java | 4 +--- .../newpipe/extractor/InfoItemCollector.java | 2 +- .../newpipe/extractor/StreamingService.java | 1 - .../{search => }/SuggestionExtractor.java | 2 +- .../extractor/search/InfoItemSearchCollector.java | 15 ++++++++++++++- .../newpipe/extractor/search/SearchEngine.java | 7 ------- .../services/youtube/YoutubeSearchEngine.java | 9 ++------- .../services/youtube/YoutubeService.java | 2 +- .../youtube/YoutubeSuggestionExtractor.java | 3 +-- .../search_fragment/SuggestionSearchRunnable.java | 2 +- 10 files changed, 22 insertions(+), 25 deletions(-) rename app/src/main/java/org/schabi/newpipe/extractor/{search => }/SuggestionExtractor.java (96%) diff --git a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeSearchResultTest.java b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeSearchResultTest.java index 8f4a18b37..106e16779 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeSearchResultTest.java +++ b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeSearchResultTest.java @@ -4,11 +4,9 @@ import android.test.AndroidTestCase; import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.exceptions.ExtractionException; -import org.schabi.newpipe.extractor.search.SuggestionExtractor; +import org.schabi.newpipe.extractor.SuggestionExtractor; import org.schabi.newpipe.extractor.services.youtube.YoutubeSuggestionExtractor; -import java.io.IOException; import java.util.List; /** diff --git a/app/src/main/java/org/schabi/newpipe/extractor/InfoItemCollector.java b/app/src/main/java/org/schabi/newpipe/extractor/InfoItemCollector.java index 1bc27171c..1667e55dd 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/InfoItemCollector.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/InfoItemCollector.java @@ -42,7 +42,7 @@ public class InfoItemCollector { public List getErrors() { return errors; } - public void addFromCollector(InfoItemCollector otherC) throws ExtractionException { + protected void addFromCollector(InfoItemCollector otherC) throws ExtractionException { if(serviceId != otherC.serviceId) { throw new ExtractionException("Service Id does not equal: " + NewPipe.getNameOfService(serviceId) diff --git a/app/src/main/java/org/schabi/newpipe/extractor/StreamingService.java b/app/src/main/java/org/schabi/newpipe/extractor/StreamingService.java index 8ed6f9234..7252cea49 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/StreamingService.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/StreamingService.java @@ -3,7 +3,6 @@ package org.schabi.newpipe.extractor; import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.search.SearchEngine; -import org.schabi.newpipe.extractor.search.SuggestionExtractor; import org.schabi.newpipe.extractor.stream_info.StreamExtractor; import java.io.IOException; diff --git a/app/src/main/java/org/schabi/newpipe/extractor/search/SuggestionExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/SuggestionExtractor.java similarity index 96% rename from app/src/main/java/org/schabi/newpipe/extractor/search/SuggestionExtractor.java rename to app/src/main/java/org/schabi/newpipe/extractor/SuggestionExtractor.java index f77b1912d..f198bc5e0 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/search/SuggestionExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/SuggestionExtractor.java @@ -1,4 +1,4 @@ -package org.schabi.newpipe.extractor.search; +package org.schabi.newpipe.extractor; import org.schabi.newpipe.extractor.exceptions.ExtractionException; diff --git a/app/src/main/java/org/schabi/newpipe/extractor/search/InfoItemSearchCollector.java b/app/src/main/java/org/schabi/newpipe/extractor/search/InfoItemSearchCollector.java index 3040452ed..533331719 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/search/InfoItemSearchCollector.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/search/InfoItemSearchCollector.java @@ -2,6 +2,10 @@ package org.schabi.newpipe.extractor.search; import org.schabi.newpipe.extractor.InfoItemCollector; import org.schabi.newpipe.extractor.UrlIdHandler; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.stream_info.StreamInfoItemCollector; +import org.schabi.newpipe.extractor.stream_info.StreamInfoItemExtractor; /** * Created by Christian Schabesberger on 12.02.17. @@ -25,20 +29,29 @@ import org.schabi.newpipe.extractor.UrlIdHandler; public class InfoItemSearchCollector extends InfoItemCollector { private String suggestion = ""; + private StreamInfoItemCollector streamCollector; InfoItemSearchCollector(UrlIdHandler handler, int serviceId) { super(handler, serviceId); + streamCollector = new StreamInfoItemCollector(handler, serviceId); } public void setSuggestion(String suggestion) { this.suggestion = suggestion; } - public SearchResult getSearchResult() { + public SearchResult getSearchResult() throws ExtractionException { SearchResult result = new SearchResult(); + + addFromCollector(streamCollector); + result.suggestion = suggestion; result.errors = getErrors(); result.resultList = getItemList(); return result; } + + public void commit(StreamInfoItemExtractor extractor) throws ParsingException { + streamCollector.commit(extractor); + } } diff --git a/app/src/main/java/org/schabi/newpipe/extractor/search/SearchEngine.java b/app/src/main/java/org/schabi/newpipe/extractor/search/SearchEngine.java index 03474d80c..ce7e6e061 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/search/SearchEngine.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/search/SearchEngine.java @@ -32,19 +32,12 @@ public abstract class SearchEngine { super(message); } } - - private StreamInfoItemCollector streamCollector; private InfoItemSearchCollector collector; public SearchEngine(UrlIdHandler urlIdHandler, int serviceId) { - streamCollector = new StreamInfoItemCollector(urlIdHandler, serviceId); collector = new InfoItemSearchCollector(urlIdHandler, serviceId); } - protected StreamInfoItemCollector getStreamPreviewInfoCollector() { - return streamCollector; - } - protected InfoItemSearchCollector getInfoItemSearchCollector() { return collector; } diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngine.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngine.java index db5dbd32f..2b738204c 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngine.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngine.java @@ -48,7 +48,6 @@ public class YoutubeSearchEngine extends SearchEngine { @Override public InfoItemSearchCollector search(String query, int page, String languageCode) throws IOException, ExtractionException { - StreamInfoItemCollector streamCollector = getStreamPreviewInfoCollector(); InfoItemSearchCollector collector = getInfoItemSearchCollector(); @@ -100,17 +99,13 @@ public class YoutubeSearchEngine extends SearchEngine { // video item type } else if ((el = item.select("div[class*=\"yt-lockup-video\"").first()) != null) { - streamCollector.commit(extractPreviewInfo(el)); + collector.commit(new YoutubeStreamInfoItemExtractor(el)); } else { //noinspection ConstantConditions throw new ExtractionException("unexpected element found:\"" + el + "\""); } } - collector.addFromCollector(streamCollector); + return collector; } - - private StreamInfoItemExtractor extractPreviewInfo(final Element item) { - return new YoutubeStreamInfoItemExtractor(item); - } } diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java index 030878b03..595513ace 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java @@ -5,7 +5,7 @@ import org.schabi.newpipe.extractor.UrlIdHandler; import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.search.SearchEngine; -import org.schabi.newpipe.extractor.search.SuggestionExtractor; +import org.schabi.newpipe.extractor.SuggestionExtractor; import org.schabi.newpipe.extractor.stream_info.StreamExtractor; import java.io.IOException; diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSuggestionExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSuggestionExtractor.java index 8cd1651b8..0535961e8 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSuggestionExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSuggestionExtractor.java @@ -4,7 +4,7 @@ import org.schabi.newpipe.extractor.Downloader; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.search.SuggestionExtractor; +import org.schabi.newpipe.extractor.SuggestionExtractor; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; @@ -15,7 +15,6 @@ import java.io.IOException; import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; -import java.util.Vector; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; diff --git a/app/src/main/java/org/schabi/newpipe/search_fragment/SuggestionSearchRunnable.java b/app/src/main/java/org/schabi/newpipe/search_fragment/SuggestionSearchRunnable.java index 0110052ec..8b8f75e7e 100644 --- a/app/src/main/java/org/schabi/newpipe/search_fragment/SuggestionSearchRunnable.java +++ b/app/src/main/java/org/schabi/newpipe/search_fragment/SuggestionSearchRunnable.java @@ -8,7 +8,7 @@ import android.widget.Toast; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ExtractionException; -import org.schabi.newpipe.extractor.search.SuggestionExtractor; +import org.schabi.newpipe.extractor.SuggestionExtractor; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.R;