diff --git a/src/main/java/YouTubeSearchApi/YoutubeClient.java b/src/main/java/YouTubeSearchApi/YoutubeClient.java index 335119d..ff5a2c2 100644 --- a/src/main/java/YouTubeSearchApi/YoutubeClient.java +++ b/src/main/java/YouTubeSearchApi/YoutubeClient.java @@ -25,10 +25,11 @@ public YoutubeClient() { this.YOUTUBE_BASE_URL = "https://www.youtube.com/"; } - public List search(String keywords, int maxResults) throws IOException, NoResultFoundException { + public List 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 = ""; diff --git a/src/test/java/YouTubeSearchApi/TestYoutubeClientSearch.java b/src/test/java/YouTubeSearchApi/TestYoutubeClientSearch.java index 0fb2058..45d03b0 100644 --- a/src/test/java/YouTubeSearchApi/TestYoutubeClientSearch.java +++ b/src/test/java/YouTubeSearchApi/TestYoutubeClientSearch.java @@ -17,7 +17,7 @@ public static void main(String[] args) { List 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) {