Skip to content

Commit 0c3dc86

Browse files
committed
add support for yt content country
1 parent 3a86574 commit 0c3dc86

4 files changed

Lines changed: 7 additions & 31 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import javax.annotation.Nonnull;
3131

3232
public abstract class KioskExtractor extends ListExtractor<StreamInfoItem> {
33-
private String contentCountry = null;
3433
private final String id;
3534

3635
public KioskExtractor(StreamingService streamingService,
@@ -41,17 +40,6 @@ public KioskExtractor(StreamingService streamingService,
4140
this.id = kioskId;
4241
}
4342

44-
/**
45-
* For certain Websites the content of a kiosk will be different depending
46-
* on the country you want to poen the website in. Therefore you should
47-
* set the contentCountry.
48-
* @param contentCountry Set the country decoded as Country Code: http://www.1728.org/countries.htm
49-
*/
50-
public void setContentCountry(String contentCountry) {
51-
this.contentCountry = contentCountry;
52-
}
53-
54-
5543
@Nonnull
5644
@Override
5745
public String getId() {
@@ -69,9 +57,4 @@ public String getId() {
6957
@Nonnull
7058
@Override
7159
public abstract String getName() throws ParsingException;
72-
73-
74-
public String getContentCountry() {
75-
return contentCountry;
76-
}
7760
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,16 @@ public YoutubeSearchExtractor(StreamingService service,
5353
@Override
5454
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
5555
final String site;
56-
final String url = getUrl();
57-
final String contentCountry = getLocalization().getCountry();
56+
final String url = getUrl() + "?gl="+ getLocalization().getCountry();
5857
//String url = builder.build().toString();
5958
//if we've been passed a valid language code, append it to the URL
60-
if (!contentCountry.isEmpty()) {
61-
//assert Pattern.matches("[a-z]{2}(-([A-Z]{2}|[0-9]{1,3}))?", languageCode);
62-
site = downloader.download(url, getLocalization());
63-
} else {
64-
site = downloader.download(url);
65-
}
59+
site = downloader.download(url, getLocalization());
6660

6761
doc = Jsoup.parse(site, url);
6862
}
6963

7064
@Override
71-
public String getSearchSuggestion() throws ParsingException {
65+
public String getSearchSuggestion() {
7266
final Element el = doc.select("div[class*=\"spell-correction\"]").first();
7367
if (el != null) {
7468
return el.select("a").first().text();
@@ -79,13 +73,13 @@ public String getSearchSuggestion() throws ParsingException {
7973

8074
@Nonnull
8175
@Override
82-
public InfoItemsPage<InfoItem> getInitialPage() throws IOException, ExtractionException {
76+
public InfoItemsPage<InfoItem> getInitialPage() throws ExtractionException {
8377
return new InfoItemsPage<>(collectItems(doc), getNextPageUrl());
8478
}
8579

8680
@Override
8781
public String getNextPageUrl() throws ExtractionException {
88-
return getUrl() + "&page=" + Integer.toString( 2);
82+
return getUrl() + "&page=" + 2;
8983
}
9084

9185
@Override
@@ -104,7 +98,7 @@ private String getNextPageUrlFromCurrentUrl(String currentUrl)
10498
.getQuery())
10599
.get("page"));
106100

107-
return currentUrl.replace("&page=" + Integer.toString( pageNr),
101+
return currentUrl.replace("&page=" + pageNr,
108102
"&page=" + Integer.toString(pageNr + 1));
109103
}
110104

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeTrendingExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public YoutubeTrendingExtractor(StreamingService service,
5050

5151
@Override
5252
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
53-
final String contentCountry = getContentCountry();
53+
final String contentCountry = getLocalization().getCountry();
5454
String url = getUrl();
5555
if(contentCountry != null && !contentCountry.isEmpty()) {
5656
url += "?gl=" + contentCountry;

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public static void setUp() throws Exception {
5151
.getKioskList()
5252
.getExtractorById("Trending", null);
5353
extractor.fetchPage();
54-
extractor.setContentCountry("de");
5554
}
5655

5756
@Test

0 commit comments

Comments
 (0)