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; NewPipe.localization = localization;
} }
public static Localization getLocalization() { public static Localization getPreferredLocalization() {
return localization; return localization;
} }
} }

View File

@ -80,7 +80,7 @@ public abstract class StreamingService {
public abstract SearchExtractor getSearchExtractor(SearchQueryHandler queryHandler, Localization localization); public abstract SearchExtractor getSearchExtractor(SearchQueryHandler queryHandler, Localization localization);
public abstract SuggestionExtractor getSuggestionExtractor(Localization localization); public abstract SuggestionExtractor getSuggestionExtractor(Localization localization);
public abstract SubscriptionExtractor getSubscriptionExtractor(); public abstract SubscriptionExtractor getSubscriptionExtractor();
public abstract KioskList getKioskList(Localization localization) throws ExtractionException; public abstract KioskList getKioskList() throws ExtractionException;
public abstract ChannelExtractor getChannelExtractor(ListLinkHandler linkHandler, public abstract ChannelExtractor getChannelExtractor(ListLinkHandler linkHandler,
Localization localization) throws ExtractionException; Localization localization) throws ExtractionException;
@ -93,27 +93,23 @@ public abstract class StreamingService {
//////////////////////////////////////////// ////////////////////////////////////////////
public SearchExtractor getSearchExtractor(SearchQueryHandler queryHandler) { public SearchExtractor getSearchExtractor(SearchQueryHandler queryHandler) {
return getSearchExtractor(queryHandler, NewPipe.getLocalization()); return getSearchExtractor(queryHandler, NewPipe.getPreferredLocalization());
} }
public SuggestionExtractor getSuggestionExtractor() { public SuggestionExtractor getSuggestionExtractor() {
return getSuggestionExtractor(NewPipe.getLocalization()); return getSuggestionExtractor(NewPipe.getPreferredLocalization());
}
public KioskList getKioskList() throws ExtractionException {
return getKioskList(NewPipe.getLocalization());
} }
public ChannelExtractor getChannelExtractor(ListLinkHandler linkHandler) throws ExtractionException { public ChannelExtractor getChannelExtractor(ListLinkHandler linkHandler) throws ExtractionException {
return getChannelExtractor(linkHandler, NewPipe.getLocalization()); return getChannelExtractor(linkHandler, NewPipe.getPreferredLocalization());
} }
public PlaylistExtractor getPlaylistExtractor(ListLinkHandler linkHandler) throws ExtractionException { public PlaylistExtractor getPlaylistExtractor(ListLinkHandler linkHandler) throws ExtractionException {
return getPlaylistExtractor(linkHandler, NewPipe.getLocalization()); return getPlaylistExtractor(linkHandler, NewPipe.getPreferredLocalization());
} }
public StreamExtractor getStreamExtractor(LinkHandler linkHandler) throws ExtractionException { 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 { 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 { 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 { 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 { 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, public static InfoItemsPage<StreamInfoItem> getMoreItems(StreamingService service,
String url, String url,
String pageUrl, String pageUrl) throws IOException, ExtractionException {
Localization localization) throws IOException, ExtractionException {
return service.getChannelExtractor(url).getPage(pageUrl); 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, public static ListExtractor.InfoItemsPage<StreamInfoItem> getMoreItems(StreamingService service,
String url, String url,
String pageUrl, String pageUrl) throws IOException, ExtractionException {
String contentCountry) throws IOException, ExtractionException {
KioskList kl = service.getKioskList(); KioskList kl = service.getKioskList();
KioskExtractor extractor = kl.getExtractorByUrl(url, pageUrl); KioskExtractor extractor = kl.getExtractorByUrl(url, pageUrl);
extractor.setContentCountry(contentCountry);
return extractor.getPage(pageUrl); return extractor.getPage(pageUrl);
} }
public static KioskInfo getInfo(String url, public static KioskInfo getInfo(String url) throws IOException, ExtractionException {
String contentCountry) throws IOException, ExtractionException { return getInfo(NewPipe.getServiceByUrl(url), url);
return getInfo(NewPipe.getServiceByUrl(url), url, contentCountry);
} }
public static KioskInfo getInfo(StreamingService service, public static KioskInfo getInfo(StreamingService service,
String url, String url) throws IOException, ExtractionException {
String contentCountry) throws IOException, ExtractionException {
KioskList kl = service.getKioskList(); KioskList kl = service.getKioskList();
KioskExtractor extractor = kl.getExtractorByUrl(url, null); KioskExtractor extractor = kl.getExtractorByUrl(url, null);
extractor.setContentCountry(contentCountry);
extractor.fetchPage(); extractor.fetchPage();
return getInfo(extractor); return getInfo(extractor);
} }

View File

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

View File

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

View File

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

View File

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