fix issues Kiosk issue about localization, nad rename to preferred localization

This commit is contained in:
Christian Schabesberger 2018-10-05 16:01:10 +02:00
parent 5223aece7b
commit 3a865749e8
9 changed files with 41 additions and 38 deletions

View File

@ -103,7 +103,7 @@ public class NewPipe {
NewPipe.localization = localization;
}
public static Localization getLocalization() {
public static Localization getPreferredLocalization() {
return localization;
}
}

View File

@ -80,7 +80,7 @@ public abstract class StreamingService {
public abstract SearchExtractor getSearchExtractor(SearchQueryHandler queryHandler, Localization localization);
public abstract SuggestionExtractor getSuggestionExtractor(Localization localization);
public abstract SubscriptionExtractor getSubscriptionExtractor();
public abstract KioskList getKioskList(Localization localization) throws ExtractionException;
public abstract KioskList getKioskList() throws ExtractionException;
public abstract ChannelExtractor getChannelExtractor(ListLinkHandler linkHandler,
Localization localization) throws ExtractionException;
@ -93,27 +93,23 @@ public abstract class StreamingService {
////////////////////////////////////////////
public SearchExtractor getSearchExtractor(SearchQueryHandler queryHandler) {
return getSearchExtractor(queryHandler, NewPipe.getLocalization());
return getSearchExtractor(queryHandler, NewPipe.getPreferredLocalization());
}
public SuggestionExtractor getSuggestionExtractor() {
return getSuggestionExtractor(NewPipe.getLocalization());
}
public KioskList getKioskList() throws ExtractionException {
return getKioskList(NewPipe.getLocalization());
return getSuggestionExtractor(NewPipe.getPreferredLocalization());
}
public ChannelExtractor getChannelExtractor(ListLinkHandler linkHandler) throws ExtractionException {
return getChannelExtractor(linkHandler, NewPipe.getLocalization());
return getChannelExtractor(linkHandler, NewPipe.getPreferredLocalization());
}
public PlaylistExtractor getPlaylistExtractor(ListLinkHandler linkHandler) throws ExtractionException {
return getPlaylistExtractor(linkHandler, NewPipe.getLocalization());
return getPlaylistExtractor(linkHandler, NewPipe.getPreferredLocalization());
}
public StreamExtractor getStreamExtractor(LinkHandler linkHandler) throws ExtractionException {
return getStreamExtractor(linkHandler, NewPipe.getLocalization());
return getStreamExtractor(linkHandler, NewPipe.getPreferredLocalization());
}
////////////////////////////////////////////
@ -154,19 +150,19 @@ public abstract class StreamingService {
////////////////////////////////////////////
public SearchExtractor getSearchExtractor(String query) throws ExtractionException {
return getSearchExtractor(getSearchQHFactory().fromQuery(query), NewPipe.getLocalization());
return getSearchExtractor(getSearchQHFactory().fromQuery(query), NewPipe.getPreferredLocalization());
}
public ChannelExtractor getChannelExtractor(String url) throws ExtractionException {
return getChannelExtractor(getChannelLHFactory().fromUrl(url), NewPipe.getLocalization());
return getChannelExtractor(getChannelLHFactory().fromUrl(url), NewPipe.getPreferredLocalization());
}
public PlaylistExtractor getPlaylistExtractor(String url) throws ExtractionException {
return getPlaylistExtractor(getPlaylistLHFactory().fromUrl(url), NewPipe.getLocalization());
return getPlaylistExtractor(getPlaylistLHFactory().fromUrl(url), NewPipe.getPreferredLocalization());
}
public StreamExtractor getStreamExtractor(String url) throws ExtractionException {
return getStreamExtractor(getStreamLHFactory().fromUrl(url), NewPipe.getLocalization());
return getStreamExtractor(getStreamLHFactory().fromUrl(url), NewPipe.getPreferredLocalization());
}

View File

@ -51,8 +51,7 @@ public class ChannelInfo extends ListInfo<StreamInfoItem> {
public static InfoItemsPage<StreamInfoItem> getMoreItems(StreamingService service,
String url,
String pageUrl,
Localization localization) throws IOException, ExtractionException {
String pageUrl) throws IOException, ExtractionException {
return service.getChannelExtractor(url).getPage(pageUrl);
}

View File

@ -37,25 +37,20 @@ public class KioskInfo extends ListInfo<StreamInfoItem> {
public static ListExtractor.InfoItemsPage<StreamInfoItem> getMoreItems(StreamingService service,
String url,
String pageUrl,
String contentCountry) throws IOException, ExtractionException {
String pageUrl) throws IOException, ExtractionException {
KioskList kl = service.getKioskList();
KioskExtractor extractor = kl.getExtractorByUrl(url, pageUrl);
extractor.setContentCountry(contentCountry);
return extractor.getPage(pageUrl);
}
public static KioskInfo getInfo(String url,
String contentCountry) throws IOException, ExtractionException {
return getInfo(NewPipe.getServiceByUrl(url), url, contentCountry);
public static KioskInfo getInfo(String url) throws IOException, ExtractionException {
return getInfo(NewPipe.getServiceByUrl(url), url);
}
public static KioskInfo getInfo(StreamingService service,
String url,
String contentCountry) throws IOException, ExtractionException {
String url) throws IOException, ExtractionException {
KioskList kl = service.getKioskList();
KioskExtractor extractor = kl.getExtractorByUrl(url, null);
extractor.setContentCountry(contentCountry);
extractor.fetchPage();
return getInfo(extractor);
}

View File

@ -23,7 +23,6 @@ public class KioskList {
private final int service_id;
private final HashMap<String, KioskEntry> kioskList = new HashMap<>();
private String defaultKiosk = null;
private final Localization localization;
private class KioskEntry {
public KioskEntry(KioskExtractorFactory ef, ListLinkHandlerFactory h) {
@ -34,9 +33,8 @@ public class KioskList {
final ListLinkHandlerFactory handlerFactory;
}
public KioskList(int service_id, Localization localization) {
public KioskList(int service_id) {
this.service_id = service_id;
this.localization = localization;
}
public void addKioskEntry(KioskExtractorFactory extractorFactory, ListLinkHandlerFactory handlerFactory, String id)
@ -53,13 +51,18 @@ public class KioskList {
public KioskExtractor getDefaultKioskExtractor(String nextPageUrl)
throws ExtractionException, IOException {
return getDefaultKioskExtractor(nextPageUrl, NewPipe.getPreferredLocalization());
}
public KioskExtractor getDefaultKioskExtractor(String nextPageUrl, Localization localization)
throws ExtractionException, IOException {
if(defaultKiosk != null && !defaultKiosk.equals("")) {
return getExtractorById(defaultKiosk, nextPageUrl);
return getExtractorById(defaultKiosk, nextPageUrl, localization);
} else {
if(!kioskList.isEmpty()) {
// if not set get any entry
Object[] keySet = kioskList.keySet().toArray();
return getExtractorById(keySet[0].toString(), nextPageUrl);
return getExtractorById(keySet[0].toString(), nextPageUrl, localization);
} else {
return null;
}
@ -72,6 +75,11 @@ public class KioskList {
public KioskExtractor getExtractorById(String kioskId, String nextPageUrl)
throws ExtractionException, IOException {
return getExtractorById(kioskId, nextPageUrl, NewPipe.getPreferredLocalization());
}
public KioskExtractor getExtractorById(String kioskId, String nextPageUrl, Localization localization)
throws ExtractionException, IOException {
KioskEntry ke = kioskList.get(kioskId);
if(ke == null) {
throw new ExtractionException("No kiosk found with the type: " + kioskId);
@ -86,11 +94,16 @@ public class KioskList {
}
public KioskExtractor getExtractorByUrl(String url, String nextPageUrl)
throws ExtractionException, IOException{
return getExtractorByUrl(url, nextPageUrl, NewPipe.getPreferredLocalization());
}
public KioskExtractor getExtractorByUrl(String url, String nextPageUrl, Localization localization)
throws ExtractionException, IOException {
for(Map.Entry<String, KioskEntry> e : kioskList.entrySet()) {
KioskEntry ke = e.getValue();
if(ke.handlerFactory.acceptUrl(url)) {
return getExtractorById(e.getKey(), nextPageUrl);
return getExtractorById(e.getKey(), nextPageUrl, localization);
}
}
throw new ExtractionException("Could not find a kiosk that fits to the url: " + url);

View File

@ -68,7 +68,7 @@ public class SoundcloudService extends StreamingService {
}
@Override
public KioskList getKioskList(Localization localization) throws ExtractionException {
public KioskList getKioskList() throws ExtractionException {
KioskList.KioskExtractorFactory chartsFactory = new KioskList.KioskExtractorFactory() {
@Override
public KioskExtractor createNewKiosk(StreamingService streamingService,
@ -81,7 +81,7 @@ public class SoundcloudService extends StreamingService {
}
};
KioskList list = new KioskList(getServiceId(), localization);
KioskList list = new KioskList(getServiceId());
// add kiosks here e.g.:
final SoundcloudChartsLinkHandlerFactory h = new SoundcloudChartsLinkHandlerFactory();

View File

@ -90,8 +90,8 @@ public class YoutubeService extends StreamingService {
}
@Override
public KioskList getKioskList(final Localization localization) throws ExtractionException {
KioskList list = new KioskList(getServiceId(), localization);
public KioskList getKioskList() throws ExtractionException {
KioskList list = new KioskList(getServiceId());
// add kiosks here e.g.:
try {

View File

@ -177,7 +177,7 @@ public class YoutubeStreamExtractorDefaultTest {
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance(), new Localization("GB", "en"));
extractor = (YoutubeStreamExtractor) YouTube
.getStreamExtractor("https://www.youtube.com/watch?v=LzR8Sf5PK2Q");
.getStreamExtractor("https://www.youtube.com/watch?v=fBc4Q_htqPg");
extractor.fetchPage();
}

View File

@ -46,7 +46,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());
}
@Test