This commit is contained in:
Koitharu 2018-09-15 20:13:06 +00:00 committed by GitHub
commit 700e36957d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 58 additions and 8 deletions

View File

@ -20,6 +20,8 @@ public abstract class Extractor {
@Nullable
private boolean pageFetched = false;
private final Downloader downloader;
@Nullable
private String language = null;
public Extractor(final StreamingService service, final LinkHandler uIHandler) {
if(service == null) throw new NullPointerException("service is null");
@ -100,4 +102,13 @@ public abstract class Extractor {
public Downloader getDownloader() {
return downloader;
}
public void setLanguage(@Nullable String language) {
this.language = language;
}
@Nonnull
public String getLanguage() {
return language == null ? "en" : language;
}
}

View File

@ -6,8 +6,8 @@ import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
import java.io.IOException;
@ -38,12 +38,23 @@ public class ChannelInfo extends ListInfo<StreamInfoItem> {
super(serviceId, urlIdHandler, name);
}
@Deprecated
public static ChannelInfo getInfo(String url) throws IOException, ExtractionException {
return getInfo(NewPipe.getServiceByUrl(url), url);
return getInfo(NewPipe.getServiceByUrl(url), url, null);
}
public static ChannelInfo getInfo(String url, String language) throws IOException, ExtractionException {
return getInfo(NewPipe.getServiceByUrl(url), url, language);
}
@Deprecated
public static ChannelInfo getInfo(StreamingService service, String url) throws IOException, ExtractionException {
return getInfo(service, url, null);
}
public static ChannelInfo getInfo(StreamingService service, String url, String language) throws IOException, ExtractionException {
ChannelExtractor extractor = service.getChannelExtractor(url);
extractor.setLanguage(language);
extractor.fetchPage();
return getInfo(extractor);
}

View File

@ -35,27 +35,53 @@ public class KioskInfo extends ListInfo<StreamInfoItem> {
super(serviceId, urlIdHandler, name);
}
@Deprecated
public static ListExtractor.InfoItemsPage<StreamInfoItem> getMoreItems(StreamingService service,
String url,
String pageUrl,
String contentCountry) throws IOException, ExtractionException {
return getMoreItems(service, url, pageUrl, contentCountry, null);
}
public static ListExtractor.InfoItemsPage<StreamInfoItem> getMoreItems(StreamingService service,
String url,
String pageUrl,
String contentCountry,
String language) throws IOException, ExtractionException {
KioskList kl = service.getKioskList();
KioskExtractor extractor = kl.getExtractorByUrl(url, pageUrl);
extractor.setContentCountry(contentCountry);
extractor.setLanguage(language);
return extractor.getPage(pageUrl);
}
@Deprecated
public static KioskInfo getInfo(String url,
String contentCountry) throws IOException, ExtractionException {
return getInfo(NewPipe.getServiceByUrl(url), url, contentCountry);
return getInfo(url, contentCountry, null);
}
public static KioskInfo getInfo(String url,
String contentCountry,
String language) throws IOException, ExtractionException {
return getInfo(NewPipe.getServiceByUrl(url), url, contentCountry, language);
}
@Deprecated
public static KioskInfo getInfo(StreamingService service,
String url,
String contentCountry) throws IOException, ExtractionException {
return getInfo(service, url, contentCountry, null);
}
public static KioskInfo getInfo(StreamingService service,
String url,
String contentCountry) throws IOException, ExtractionException {
String contentCountry,
String language) throws IOException, ExtractionException {
KioskList kl = service.getKioskList();
KioskExtractor extractor = kl.getExtractorByUrl(url, null);
extractor.setContentCountry(contentCountry);
extractor.setLanguage(language);
extractor.fetchPage();
return getInfo(extractor);
}

View File

@ -57,7 +57,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
@Override
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
String channelUrl = super.getUrl() + CHANNEL_URL_PARAMETERS;
String channelUrl = super.getUrl() + CHANNEL_URL_PARAMETERS + "&hl=" + getLanguage();
String pageContent = downloader.download(channelUrl);
doc = Jsoup.parse(pageContent, channelUrl);
}

View File

@ -50,8 +50,9 @@ public class YoutubeTrendingExtractor extends KioskExtractor {
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
final String contentCountry = getContentCountry();
String url = getUrl();
url += "?hl=" + getLanguage();
if(contentCountry != null && !contentCountry.isEmpty()) {
url += "?gl=" + contentCountry;
url += "&gl=" + contentCountry;
}
String pageContent = downloader.download(url);

View File

@ -49,8 +49,9 @@ public class YoutubeTrendingExtractorTest {
extractor = (YoutubeTrendingExtractor) YouTube
.getKioskList()
.getExtractorById("Trending", null);
extractor.fetchPage();
extractor.setLanguage("ru");
extractor.setContentCountry("de");
extractor.fetchPage();
}
@Test

View File

@ -45,7 +45,7 @@ public class YoutubeTrendingKioskInfoTest {
StreamingService service = YouTube;
LinkHandlerFactory LinkHandlerFactory = service.getKioskList().getListLinkHandlerFactoryByType("Trending");
kioskInfo = KioskInfo.getInfo(YouTube, LinkHandlerFactory.fromId("Trending").getUrl(), null);
kioskInfo = KioskInfo.getInfo(YouTube, LinkHandlerFactory.fromId("Trending").getUrl(), null, null);
}
@Test