remove StreamInfoItemSearchCollector

This commit is contained in:
Christian Schabesberger 2017-02-12 14:21:59 +01:00
parent 5c8bcf15ba
commit 7186f58374
10 changed files with 22 additions and 25 deletions

View file

@ -4,11 +4,9 @@ import android.test.AndroidTestCase;
import org.schabi.newpipe.Downloader; import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.SuggestionExtractor;
import org.schabi.newpipe.extractor.search.SuggestionExtractor;
import org.schabi.newpipe.extractor.services.youtube.YoutubeSuggestionExtractor; import org.schabi.newpipe.extractor.services.youtube.YoutubeSuggestionExtractor;
import java.io.IOException;
import java.util.List; import java.util.List;
/** /**

View file

@ -42,7 +42,7 @@ public class InfoItemCollector {
public List<Throwable> getErrors() { public List<Throwable> getErrors() {
return errors; return errors;
} }
public void addFromCollector(InfoItemCollector otherC) throws ExtractionException { protected void addFromCollector(InfoItemCollector otherC) throws ExtractionException {
if(serviceId != otherC.serviceId) { if(serviceId != otherC.serviceId) {
throw new ExtractionException("Service Id does not equal: " throw new ExtractionException("Service Id does not equal: "
+ NewPipe.getNameOfService(serviceId) + NewPipe.getNameOfService(serviceId)

View file

@ -3,7 +3,6 @@ package org.schabi.newpipe.extractor;
import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.search.SearchEngine; import org.schabi.newpipe.extractor.search.SearchEngine;
import org.schabi.newpipe.extractor.search.SuggestionExtractor;
import org.schabi.newpipe.extractor.stream_info.StreamExtractor; import org.schabi.newpipe.extractor.stream_info.StreamExtractor;
import java.io.IOException; import java.io.IOException;

View file

@ -1,4 +1,4 @@
package org.schabi.newpipe.extractor.search; package org.schabi.newpipe.extractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;

View file

@ -2,6 +2,10 @@ package org.schabi.newpipe.extractor.search;
import org.schabi.newpipe.extractor.InfoItemCollector; import org.schabi.newpipe.extractor.InfoItemCollector;
import org.schabi.newpipe.extractor.UrlIdHandler; 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. * Created by Christian Schabesberger on 12.02.17.
@ -25,20 +29,29 @@ import org.schabi.newpipe.extractor.UrlIdHandler;
public class InfoItemSearchCollector extends InfoItemCollector { public class InfoItemSearchCollector extends InfoItemCollector {
private String suggestion = ""; private String suggestion = "";
private StreamInfoItemCollector streamCollector;
InfoItemSearchCollector(UrlIdHandler handler, int serviceId) { InfoItemSearchCollector(UrlIdHandler handler, int serviceId) {
super(handler, serviceId); super(handler, serviceId);
streamCollector = new StreamInfoItemCollector(handler, serviceId);
} }
public void setSuggestion(String suggestion) { public void setSuggestion(String suggestion) {
this.suggestion = suggestion; this.suggestion = suggestion;
} }
public SearchResult getSearchResult() { public SearchResult getSearchResult() throws ExtractionException {
SearchResult result = new SearchResult(); SearchResult result = new SearchResult();
addFromCollector(streamCollector);
result.suggestion = suggestion; result.suggestion = suggestion;
result.errors = getErrors(); result.errors = getErrors();
result.resultList = getItemList(); result.resultList = getItemList();
return result; return result;
} }
public void commit(StreamInfoItemExtractor extractor) throws ParsingException {
streamCollector.commit(extractor);
}
} }

View file

@ -32,19 +32,12 @@ public abstract class SearchEngine {
super(message); super(message);
} }
} }
private StreamInfoItemCollector streamCollector;
private InfoItemSearchCollector collector; private InfoItemSearchCollector collector;
public SearchEngine(UrlIdHandler urlIdHandler, int serviceId) { public SearchEngine(UrlIdHandler urlIdHandler, int serviceId) {
streamCollector = new StreamInfoItemCollector(urlIdHandler, serviceId);
collector = new InfoItemSearchCollector(urlIdHandler, serviceId); collector = new InfoItemSearchCollector(urlIdHandler, serviceId);
} }
protected StreamInfoItemCollector getStreamPreviewInfoCollector() {
return streamCollector;
}
protected InfoItemSearchCollector getInfoItemSearchCollector() { protected InfoItemSearchCollector getInfoItemSearchCollector() {
return collector; return collector;
} }

View file

@ -48,7 +48,6 @@ public class YoutubeSearchEngine extends SearchEngine {
@Override @Override
public InfoItemSearchCollector search(String query, int page, String languageCode) public InfoItemSearchCollector search(String query, int page, String languageCode)
throws IOException, ExtractionException { throws IOException, ExtractionException {
StreamInfoItemCollector streamCollector = getStreamPreviewInfoCollector();
InfoItemSearchCollector collector = getInfoItemSearchCollector(); InfoItemSearchCollector collector = getInfoItemSearchCollector();
@ -100,17 +99,13 @@ public class YoutubeSearchEngine extends SearchEngine {
// video item type // video item type
} else if ((el = item.select("div[class*=\"yt-lockup-video\"").first()) != null) { } else if ((el = item.select("div[class*=\"yt-lockup-video\"").first()) != null) {
streamCollector.commit(extractPreviewInfo(el)); collector.commit(new YoutubeStreamInfoItemExtractor(el));
} else { } else {
//noinspection ConstantConditions //noinspection ConstantConditions
throw new ExtractionException("unexpected element found:\"" + el + "\""); throw new ExtractionException("unexpected element found:\"" + el + "\"");
} }
} }
collector.addFromCollector(streamCollector);
return collector; return collector;
} }
private StreamInfoItemExtractor extractPreviewInfo(final Element item) {
return new YoutubeStreamInfoItemExtractor(item);
}
} }

View file

@ -5,7 +5,7 @@ import org.schabi.newpipe.extractor.UrlIdHandler;
import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.search.SearchEngine; 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 org.schabi.newpipe.extractor.stream_info.StreamExtractor;
import java.io.IOException; import java.io.IOException;

View file

@ -4,7 +4,7 @@ import org.schabi.newpipe.extractor.Downloader;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; 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.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
@ -15,7 +15,6 @@ import java.io.IOException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Vector;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;

View file

@ -8,7 +8,7 @@ import android.widget.Toast;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; 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.report.ErrorActivity;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;