NewPipeExtractor/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchInfo.java

74 lines
2.5 KiB
Java
Raw Normal View History

2018-05-13 21:28:51 +02:00
package org.schabi.newpipe.extractor.search;
import org.schabi.newpipe.extractor.InfoItem;
2018-07-08 14:32:31 +02:00
import org.schabi.newpipe.extractor.ListExtractor;
2018-05-13 21:28:51 +02:00
import org.schabi.newpipe.extractor.ListInfo;
2018-07-08 14:32:31 +02:00
import org.schabi.newpipe.extractor.StreamingService;
2018-05-13 21:28:51 +02:00
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
2018-07-08 20:49:13 +02:00
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
2018-05-13 21:28:51 +02:00
2018-07-08 14:32:31 +02:00
import java.io.IOException;
2018-05-13 21:28:51 +02:00
public class SearchInfo extends ListInfo<InfoItem> {
2018-07-02 13:47:39 +02:00
private String searchString;
private String searchSuggestion;
2018-05-13 21:28:51 +02:00
public SearchInfo(int serviceId,
SearchQueryHandler qIHandler,
2018-07-08 14:32:31 +02:00
String searchString) {
2018-07-02 13:47:39 +02:00
super(serviceId, qIHandler, "Search");
this.searchString = searchString;
2018-05-13 21:28:51 +02:00
}
2018-09-15 21:47:53 +02:00
public static SearchInfo getInfo(StreamingService service, SearchQueryHandler searchQuery) throws ExtractionException, IOException {
SearchExtractor extractor = service.getSearchExtractor(searchQuery);
extractor.fetchPage();
return getInfo(extractor);
}
public static SearchInfo getInfo(SearchExtractor extractor) throws ExtractionException, IOException {
2018-05-13 21:28:51 +02:00
final SearchInfo info = new SearchInfo(
extractor.getServiceId(),
extractor.getLinkHandler(),
extractor.getSearchString());
2018-05-13 21:28:51 +02:00
2018-12-23 21:52:40 +01:00
try {
info.setOriginalUrl(extractor.getOriginalUrl());
} catch (Exception e) {
info.addError(e);
}
2018-05-13 21:28:51 +02:00
try {
info.searchSuggestion = extractor.getSearchSuggestion();
} catch (Exception e) {
info.addError(e);
}
2018-07-08 20:49:13 +02:00
ListExtractor.InfoItemsPage<InfoItem> page = ExtractorHelper.getItemsPageOrLogError(info, extractor);
info.setRelatedItems(page.getItems());
info.setNextPageUrl(page.getNextPageUrl());
2018-05-13 21:28:51 +02:00
return info;
}
2018-07-08 14:32:31 +02:00
public static ListExtractor.InfoItemsPage<InfoItem> getMoreItems(StreamingService service,
SearchQueryHandler query,
2018-07-08 14:32:31 +02:00
String pageUrl)
throws IOException, ExtractionException {
2018-09-15 21:47:53 +02:00
return service.getSearchExtractor(query).getPage(pageUrl);
2018-07-08 14:32:31 +02:00
}
2018-05-13 21:28:51 +02:00
// Getter
public String getSearchString() {
return searchString;
2018-05-13 21:28:51 +02:00
}
public String getSearchSuggestion() {
return searchSuggestion;
}
}