Skip to content

Commit c66d388

Browse files
authored
Merge pull request #11 from madeyoga/add-language
Add language parameter to YoutubeClient.search
2 parents 86fc299 + 8285e9d commit c66d388

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/main/java/YouTubeSearchApi/YoutubeClient.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ public YoutubeClient() {
2525
this.YOUTUBE_BASE_URL = "https://www.youtube.com/";
2626
}
2727

28-
public List<YoutubeVideo> search(String keywords, int maxResults) throws IOException, NoResultFoundException {
28+
public List<YoutubeVideo> search(String keywords, int maxResults, String language) throws IOException, NoResultFoundException {
2929
String startFeature = "ytInitialData";
3030
String encodedKeywords = URLEncoder.encode(keywords, StandardCharsets.UTF_8.toString());
31-
String searchUrl = this.YOUTUBE_BASE_URL + "results?search_query=" + encodedKeywords;
31+
String searchUrl = this.YOUTUBE_BASE_URL + "results?gl=AU&hl=" + language
32+
+ "&persist_gl=1&persist_hl=1&search_query=" + encodedKeywords;
3233

3334
// try get feature 3 times
3435
String pageContent = "";

src/test/java/YouTubeSearchApi/TestYoutubeClientSearch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static void main(String[] args) {
1717
List<YoutubeVideo> videos;
1818

1919
try {
20-
videos = client.search("CHiCO Love Letter", 5);
20+
videos = client.search("yoasobi", 5, "en");
2121
System.out.println(videos.size());
2222
System.out.println(videos.toString());
2323
} catch (IOException | NoResultFoundException e) {

0 commit comments

Comments
 (0)