-Fixed youtube stream type to no longer return none.

-Fixed search result errors on empty.
This commit is contained in:
John Zhen Mo 2018-02-27 18:16:29 -08:00
parent 837dbd6b86
commit 4cf4ee394f
2 changed files with 5 additions and 20 deletions

View File

@ -44,23 +44,10 @@ public class SearchResult {
this.errors = Collections.unmodifiableList(new ArrayList<>(errors)); this.errors = Collections.unmodifiableList(new ArrayList<>(errors));
} }
public static SearchResult getSearchResult(SearchEngine engine, String query, int page, String languageCode, SearchEngine.Filter filter) public static SearchResult getSearchResult(@Nonnull final SearchEngine engine, final String query, final int page,
final String languageCode, final SearchEngine.Filter filter)
throws IOException, ExtractionException { throws IOException, ExtractionException {
return engine.search(query, page, languageCode, filter).getSearchResult();
SearchResult result = engine
.search(query, page, languageCode, filter)
.getSearchResult();
if (result.resultList.isEmpty()) {
if (result.suggestion.isEmpty()) {
if (result.errors.isEmpty()) {
throw new ExtractionException("Empty result despite no error");
}
} else {
// This is used as a fallback. Do not relay on it !!!
throw new SearchEngine.NothingFoundException(result.suggestion);
}
}
return result;
} }
public String getSuggestion() { public String getSuggestion() {

View File

@ -458,11 +458,9 @@ public class YoutubeStreamExtractor extends StreamExtractor {
@Override @Override
public StreamType getStreamType() throws ParsingException { public StreamType getStreamType() throws ParsingException {
assertPageFetched(); assertPageFetched();
if (playerArgs == null) return StreamType.NONE;
try { try {
if (playerArgs.has("ps") && playerArgs.get("ps").toString().equals("live") || if (playerArgs != null && (playerArgs.has("ps") && playerArgs.get("ps").toString().equals("live") ||
playerArgs.get(URL_ENCODED_FMT_STREAM_MAP).toString().isEmpty()) { playerArgs.get(URL_ENCODED_FMT_STREAM_MAP).toString().isEmpty())) {
return StreamType.LIVE_STREAM; return StreamType.LIVE_STREAM;
} }
} catch (Exception e) { } catch (Exception e) {