Commit 4a91e29d authored by Mauricio Colli's avatar Mauricio Colli Committed by GitHub
Browse files

Merge pull request #31 from dosvald/yt-search-suggestions

Change search suggestions to match what is seen at youtube.com
parents 841955a8 24a8df7c
......@@ -48,15 +48,23 @@ public class YoutubeSuggestionExtractor extends SuggestionExtractor {
List<String> suggestions = new ArrayList<>();
String url = "https://suggestqueries.google.com/complete/search"
+ "?client=" + "firefox" // 'toolbar' for xml
+ "?client=" + "youtube" //"firefox" for JSON, 'toolbar' for xml
+ "&jsonp=" + "JP"
+ "&ds=" + "yt"
+ "&hl=" + URLEncoder.encode(contentCountry, CHARSET_UTF_8)
+ "&q=" + URLEncoder.encode(query, CHARSET_UTF_8);
String response = dl.download(url);
// trim JSONP part "JP(...)"
response = response.substring(3, response.length()-1);
try {
JsonArray collection = JsonParser.array().from(response).getArray(1);
for (Object suggestion : collection) suggestions.add(suggestion.toString());
JsonArray collection = JsonParser.array().from(response).getArray(1, new JsonArray());
for (Object suggestion : collection) {
if (!(suggestion instanceof JsonArray)) continue;
String suggestionStr = ((JsonArray)suggestion).getString(0);
if (suggestionStr == null) continue;
suggestions.add(suggestionStr);
}
return suggestions;
} catch (JsonParserException e) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment