From 3a865749e89b213538f5073b2161d154173f67e1 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Fri, 5 Oct 2018 16:01:10 +0200 Subject: [PATCH] fix issues Kiosk issue about localization, nad rename to preferred localization --- .../org/schabi/newpipe/extractor/NewPipe.java | 2 +- .../newpipe/extractor/StreamingService.java | 24 ++++++++---------- .../extractor/channel/ChannelInfo.java | 3 +-- .../newpipe/extractor/kiosk/KioskInfo.java | 13 +++------- .../newpipe/extractor/kiosk/KioskList.java | 25 ++++++++++++++----- .../soundcloud/SoundcloudService.java | 4 +-- .../services/youtube/YoutubeService.java | 4 +-- .../YoutubeStreamExtractorDefaultTest.java | 2 +- .../youtube/YoutubeTrendingKioskInfoTest.java | 2 +- 9 files changed, 41 insertions(+), 38 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/NewPipe.java b/extractor/src/main/java/org/schabi/newpipe/extractor/NewPipe.java index fcbde0f9..cf4a2643 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/NewPipe.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/NewPipe.java @@ -103,7 +103,7 @@ public class NewPipe { NewPipe.localization = localization; } - public static Localization getLocalization() { + public static Localization getPreferredLocalization() { return localization; } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java b/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java index 55efd1f5..a85d8f3a 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java @@ -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()); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java b/extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java index 0aed6e11..20abdfe4 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java @@ -51,8 +51,7 @@ public class ChannelInfo extends ListInfo { public static InfoItemsPage getMoreItems(StreamingService service, String url, - String pageUrl, - Localization localization) throws IOException, ExtractionException { + String pageUrl) throws IOException, ExtractionException { return service.getChannelExtractor(url).getPage(pageUrl); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskInfo.java b/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskInfo.java index 141b480c..9ebb0cd9 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskInfo.java @@ -37,25 +37,20 @@ public class KioskInfo extends ListInfo { public static ListExtractor.InfoItemsPage 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); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java b/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java index b37b7c04..22a9f2ca 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java @@ -23,7 +23,6 @@ public class KioskList { private final int service_id; private final HashMap 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 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); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudService.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudService.java index c43d34ce..0202bba5 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudService.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudService.java @@ -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(); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java index d9187ca4..57cd3f85 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java @@ -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 { diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java index ea88e350..2c026f36 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java @@ -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(); } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingKioskInfoTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingKioskInfoTest.java index 85480eaf..68a5bae0 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingKioskInfoTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingKioskInfoTest.java @@ -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