Skip to content

Commit

Permalink
Merge pull request #11 from madeyoga/add-language
Browse files Browse the repository at this point in the history
Add language parameter to YoutubeClient.search
  • Loading branch information
Shiroechi authored Nov 17, 2020
2 parents 86fc299 + 8285e9d commit c66d388
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/main/java/YouTubeSearchApi/YoutubeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ public YoutubeClient() {
this.YOUTUBE_BASE_URL = "https://www.youtube.com/";
}

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

// try get feature 3 times
String pageContent = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void main(String[] args) {
List<YoutubeVideo> videos;

try {
videos = client.search("CHiCO Love Letter", 5);
videos = client.search("yoasobi", 5, "en");
System.out.println(videos.size());
System.out.println(videos.toString());
} catch (IOException | NoResultFoundException e) {
Expand Down

0 comments on commit c66d388

Please sign in to comment.