Cleanup + bug fix with ALL search
This commit is contained in:
parent
26938ff22b
commit
488e41d24e
|
@ -64,7 +64,8 @@ import javax.annotation.Nullable;
|
|||
public class YoutubeSearchExtractor extends SearchExtractor {
|
||||
|
||||
@Nullable
|
||||
private String searchType;
|
||||
private final String searchType;
|
||||
public final boolean isExactSearch;
|
||||
private final boolean extractVideoResults;
|
||||
private final boolean extractChannelResults;
|
||||
private final boolean extractPlaylistResults;
|
||||
|
@ -76,11 +77,11 @@ public class YoutubeSearchExtractor extends SearchExtractor {
|
|||
super(service, linkHandler);
|
||||
final List<String> contentFilters = linkHandler.getContentFilters();
|
||||
searchType = isNullOrEmpty(contentFilters) ? null : contentFilters.get(0);
|
||||
|
||||
// Save whether we should extract video, channel and playlist results depending on the
|
||||
// requested search type, as YouTube returns sometimes videos inside channel search results
|
||||
// If no search type is provided or ALL/EXACT (without another search type) filter
|
||||
// is requested, extract everything
|
||||
|
||||
extractVideoResults = searchType == null || ALL.equals(searchType)
|
||||
|| VIDEOS.equals(searchType) || EXACT.equals(searchType);
|
||||
extractChannelResults = searchType == null || ALL.equals(searchType)
|
||||
|
@ -88,11 +89,8 @@ public class YoutubeSearchExtractor extends SearchExtractor {
|
|||
extractPlaylistResults = searchType == null || ALL.equals(searchType)
|
||||
|| PLAYLISTS.equals(searchType) || EXACT.equals(searchType);
|
||||
|
||||
// if EXACT is a content filter, it replaces the current search type
|
||||
// this needs to happen AFTER the extract... params are set
|
||||
if (!isNullOrEmpty(contentFilters) && contentFilters.contains(EXACT)) {
|
||||
searchType = EXACT;
|
||||
}
|
||||
// If EXACT is NOT the search type this is needed to filter for a content filter + EXACT
|
||||
isExactSearch = !isNullOrEmpty(contentFilters) && contentFilters.contains(EXACT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -100,7 +98,7 @@ public class YoutubeSearchExtractor extends SearchExtractor {
|
|||
ExtractionException {
|
||||
final String query = super.getSearchString();
|
||||
final Localization localization = getExtractorLocalization();
|
||||
final String params = getSearchParameter(searchType);
|
||||
final String params = getSearchParameter(searchType, isExactSearch);
|
||||
final JsonBuilder<JsonObject> jsonBody = prepareDesktopJsonBuilder(localization,
|
||||
getExtractorContentCountry())
|
||||
.value("query", query);
|
||||
|
|
|
@ -39,24 +39,18 @@ public final class YoutubeSearchQueryHandlerFactory extends SearchQueryHandlerFa
|
|||
@Nonnull final List<String> contentFilters,
|
||||
final String sortFilter)
|
||||
throws ParsingException, UnsupportedOperationException {
|
||||
final String contentFilter;
|
||||
|
||||
// EXACT takes precedence over other filters
|
||||
if (contentFilters.contains(EXACT)) {
|
||||
contentFilter = EXACT;
|
||||
} else {
|
||||
contentFilter = !contentFilters.isEmpty() ? contentFilters.get(0) : "";
|
||||
}
|
||||
final String contentFilter = !contentFilters.isEmpty() ? contentFilters.get(0) : "";
|
||||
final boolean isExactSearch = !contentFilters.isEmpty() && contentFilter.contains(EXACT);
|
||||
|
||||
switch (contentFilter) {
|
||||
case EXACT:
|
||||
return SEARCH_URL + encodeUrlUtf8(searchString) + "&sp=QgIIAQ%253D%253D";
|
||||
case VIDEOS:
|
||||
return SEARCH_URL + encodeUrlUtf8(searchString) + "&sp=EgIQAfABAQ%253D%253D";
|
||||
return SEARCH_URL + encodeUrlUtf8(searchString) + (isExactSearch ? "&sp=EgIQAUICCAE%253D" : "&sp=EgIQAfABAQ%253D%253D");
|
||||
case CHANNELS:
|
||||
return SEARCH_URL + encodeUrlUtf8(searchString) + "&sp=EgIQAvABAQ%253D%253D";
|
||||
return SEARCH_URL + encodeUrlUtf8(searchString) + (isExactSearch ? "&sp=EgIQAkICCAE%253D" : "&sp=EgIQAvABAQ%253D%253D");
|
||||
case PLAYLISTS:
|
||||
return SEARCH_URL + encodeUrlUtf8(searchString) + "&sp=EgIQA_ABAQ%253D%253D";
|
||||
return SEARCH_URL + encodeUrlUtf8(searchString) + (isExactSearch ? "&sp=EgIQA0ICCAE%253D" : "&sp=EgIQA_ABAQ%253D%253D");
|
||||
case MUSIC_SONGS:
|
||||
case MUSIC_VIDEOS:
|
||||
case MUSIC_ALBUMS:
|
||||
|
@ -86,7 +80,7 @@ public final class YoutubeSearchQueryHandlerFactory extends SearchQueryHandlerFa
|
|||
}
|
||||
|
||||
@Nonnull
|
||||
public static String getSearchParameter(final String contentFilter) {
|
||||
public static String getSearchParameter(final String contentFilter, final boolean isExactSearch) {
|
||||
if (isNullOrEmpty(contentFilter)) {
|
||||
return "8AEB";
|
||||
}
|
||||
|
@ -95,11 +89,11 @@ public final class YoutubeSearchQueryHandlerFactory extends SearchQueryHandlerFa
|
|||
case EXACT:
|
||||
return "QgIIAQ%3D%3D";
|
||||
case VIDEOS:
|
||||
return "EgIQAfABAQ%3D%3D";
|
||||
return isExactSearch ? "EgIQAUICCAE%3D" : "EgIQAfABAQ%3D%3D";
|
||||
case CHANNELS:
|
||||
return "EgIQAvABAQ%3D%3D";
|
||||
return isExactSearch ? "EgIQAkICCAE%3D" : "EgIQAvABAQ%3D%3D";
|
||||
case PLAYLISTS:
|
||||
return "EgIQA_ABAQ%3D%3D";
|
||||
return isExactSearch ? "EgIQA0ICCAE%3D" : "EgIQA_ABAQ%3D%3D";
|
||||
case MUSIC_SONGS:
|
||||
case MUSIC_VIDEOS:
|
||||
case MUSIC_ALBUMS:
|
||||
|
|
Loading…
Reference in New Issue