From 0c3dc86b07e5d57970cd7e994af0ee62b49b8484 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sat, 6 Oct 2018 12:22:37 +0200 Subject: [PATCH] add support for yt content country --- .../extractor/kiosk/KioskExtractor.java | 17 ----------------- .../extractors/YoutubeSearchExtractor.java | 18 ++++++------------ .../extractors/YoutubeTrendingExtractor.java | 2 +- .../youtube/YoutubeTrendingExtractorTest.java | 1 - 4 files changed, 7 insertions(+), 31 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java index 8c003b015..481bb63ca 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java @@ -30,7 +30,6 @@ import org.schabi.newpipe.extractor.utils.Localization; import javax.annotation.Nonnull; public abstract class KioskExtractor extends ListExtractor { - private String contentCountry = null; private final String id; public KioskExtractor(StreamingService streamingService, @@ -41,17 +40,6 @@ public abstract class KioskExtractor extends ListExtractor { this.id = kioskId; } - /** - * For certain Websites the content of a kiosk will be different depending - * on the country you want to poen the website in. Therefore you should - * set the contentCountry. - * @param contentCountry Set the country decoded as Country Code: http://www.1728.org/countries.htm - */ - public void setContentCountry(String contentCountry) { - this.contentCountry = contentCountry; - } - - @Nonnull @Override public String getId() { @@ -69,9 +57,4 @@ public abstract class KioskExtractor extends ListExtractor { @Nonnull @Override public abstract String getName() throws ParsingException; - - - public String getContentCountry() { - return contentCountry; - } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java index 1c1bad6b2..2d411fa78 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java @@ -53,22 +53,16 @@ public class YoutubeSearchExtractor extends SearchExtractor { @Override public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { final String site; - final String url = getUrl(); - final String contentCountry = getLocalization().getCountry(); + final String url = getUrl() + "?gl="+ getLocalization().getCountry(); //String url = builder.build().toString(); //if we've been passed a valid language code, append it to the URL - if (!contentCountry.isEmpty()) { - //assert Pattern.matches("[a-z]{2}(-([A-Z]{2}|[0-9]{1,3}))?", languageCode); - site = downloader.download(url, getLocalization()); - } else { - site = downloader.download(url); - } + site = downloader.download(url, getLocalization()); doc = Jsoup.parse(site, url); } @Override - public String getSearchSuggestion() throws ParsingException { + public String getSearchSuggestion() { final Element el = doc.select("div[class*=\"spell-correction\"]").first(); if (el != null) { return el.select("a").first().text(); @@ -79,13 +73,13 @@ public class YoutubeSearchExtractor extends SearchExtractor { @Nonnull @Override - public InfoItemsPage getInitialPage() throws IOException, ExtractionException { + public InfoItemsPage getInitialPage() throws ExtractionException { return new InfoItemsPage<>(collectItems(doc), getNextPageUrl()); } @Override public String getNextPageUrl() throws ExtractionException { - return getUrl() + "&page=" + Integer.toString( 2); + return getUrl() + "&page=" + 2; } @Override @@ -104,7 +98,7 @@ public class YoutubeSearchExtractor extends SearchExtractor { .getQuery()) .get("page")); - return currentUrl.replace("&page=" + Integer.toString( pageNr), + return currentUrl.replace("&page=" + pageNr, "&page=" + Integer.toString(pageNr + 1)); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeTrendingExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeTrendingExtractor.java index 9dd0a6371..f33f7b8a5 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeTrendingExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeTrendingExtractor.java @@ -50,7 +50,7 @@ public class YoutubeTrendingExtractor extends KioskExtractor { @Override public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { - final String contentCountry = getContentCountry(); + final String contentCountry = getLocalization().getCountry(); String url = getUrl(); if(contentCountry != null && !contentCountry.isEmpty()) { url += "?gl=" + contentCountry; diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java index fb61797bf..8dee92e09 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java @@ -51,7 +51,6 @@ public class YoutubeTrendingExtractorTest { .getKioskList() .getExtractorById("Trending", null); extractor.fetchPage(); - extractor.setContentCountry("de"); } @Test