mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-01-11 18:00:32 +00:00
Added country language param to the suggestionList method in search engine
This commit is contained in:
parent
c7679bec87
commit
8fc113cc52
@ -40,7 +40,7 @@ public class YoutubeSearchEngineTest extends AndroidTestCase {
|
|||||||
|
|
||||||
result = engine.search("https://www.youtube.com/results?search_query=bla",
|
result = engine.search("https://www.youtube.com/results?search_query=bla",
|
||||||
0, "de", new Downloader());
|
0, "de", new Downloader());
|
||||||
suggestionReply = engine.suggestionList("hello", new Downloader());
|
suggestionReply = engine.suggestionList("hello","de",new Downloader());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIfNoErrorOccur() {
|
public void testIfNoErrorOccur() {
|
||||||
|
@ -16,20 +16,10 @@ import java.util.ArrayList;
|
|||||||
*/
|
*/
|
||||||
public class SuggestionListAdapter extends CursorAdapter {
|
public class SuggestionListAdapter extends CursorAdapter {
|
||||||
|
|
||||||
private ArrayList<String> suggestions;
|
|
||||||
private String[] columns = new String[]{"_id", "title"};
|
private String[] columns = new String[]{"_id", "title"};
|
||||||
|
|
||||||
public SuggestionListAdapter(Context context) {
|
public SuggestionListAdapter(Context context) {
|
||||||
super(context, null, false);
|
super(context, null, false);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getSuggestions() {
|
|
||||||
return suggestions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSuggestions(ArrayList<String> suggestions) {
|
|
||||||
this.suggestions = suggestions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,6 +2,7 @@ package org.schabi.newpipe;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
@ -150,16 +151,21 @@ public class VideoItemListActivity extends AppCompatActivity
|
|||||||
private final SearchEngine engine;
|
private final SearchEngine engine;
|
||||||
private final String query;
|
private final String query;
|
||||||
final Handler h = new Handler();
|
final Handler h = new Handler();
|
||||||
|
private Context context;
|
||||||
private SuggestionSearchRunnable(SearchEngine engine, String query) {
|
private SuggestionSearchRunnable(SearchEngine engine, String query) {
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
|
context = VideoItemListActivity.this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
ArrayList<String>suggestions = engine.suggestionList(query,new Downloader());
|
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
String searchLanguageKey = context.getString(R.string.search_language_key);
|
||||||
|
String searchLanguage = sp.getString(searchLanguageKey,
|
||||||
|
getString(R.string.default_language_value));
|
||||||
|
ArrayList<String>suggestions = engine.suggestionList(query,searchLanguage,new Downloader());
|
||||||
h.post(new SuggestionResultRunnable(suggestions));
|
h.post(new SuggestionResultRunnable(suggestions));
|
||||||
} catch (ExtractionException e) {
|
} catch (ExtractionException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -33,7 +33,7 @@ public interface SearchEngine {
|
|||||||
public final List<VideoPreviewInfo> resultList = new Vector<>();
|
public final List<VideoPreviewInfo> resultList = new Vector<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<String> suggestionList(String query, Downloader dl)
|
ArrayList<String> suggestionList(String query,String contentCountry, Downloader dl)
|
||||||
throws ExtractionException, IOException;
|
throws ExtractionException, IOException;
|
||||||
|
|
||||||
//Result search(String query, int page);
|
//Result search(String query, int page);
|
||||||
|
@ -147,7 +147,7 @@ public class YoutubeSearchEngine implements SearchEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<String> suggestionList(String query, Downloader dl)
|
public ArrayList<String> suggestionList(String query,String contentCountry, Downloader dl)
|
||||||
throws IOException, ParsingException {
|
throws IOException, ParsingException {
|
||||||
|
|
||||||
ArrayList<String> suggestions = new ArrayList<>();
|
ArrayList<String> suggestions = new ArrayList<>();
|
||||||
@ -160,6 +160,7 @@ public class YoutubeSearchEngine implements SearchEngine {
|
|||||||
.appendQueryParameter("client", "")
|
.appendQueryParameter("client", "")
|
||||||
.appendQueryParameter("output", "toolbar")
|
.appendQueryParameter("output", "toolbar")
|
||||||
.appendQueryParameter("ds", "yt")
|
.appendQueryParameter("ds", "yt")
|
||||||
|
.appendQueryParameter("hl",contentCountry)
|
||||||
.appendQueryParameter("q", query);
|
.appendQueryParameter("q", query);
|
||||||
String url = builder.build().toString();
|
String url = builder.build().toString();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user