From 14cd1dbcbb112faeeba78c775f4a0dd985fb7339 Mon Sep 17 00:00:00 2001 From: Ritvik Saraf <13ritvik@gmail.com> Date: Wed, 26 Dec 2018 12:50:43 +0530 Subject: [PATCH] fixed kiosk by url --- .../newpipe/extractor/kiosk/KioskList.java | 2 +- .../PeertubeTrendingLinkHandlerFactory.java | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) 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 22a9f2ca8..1896a6a7d 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 @@ -103,7 +103,7 @@ public class KioskList { for(Map.Entry e : kioskList.entrySet()) { KioskEntry ke = e.getValue(); if(ke.handlerFactory.acceptUrl(url)) { - return getExtractorById(e.getKey(), nextPageUrl, localization); + return getExtractorById(ke.handlerFactory.getId(url), 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/peertube/linkHandler/PeertubeTrendingLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeTrendingLinkHandlerFactory.java index b3763ccb8..bda842985 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeTrendingLinkHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeTrendingLinkHandlerFactory.java @@ -13,6 +13,7 @@ public class PeertubeTrendingLinkHandlerFactory extends ListLinkHandlerFactory { public static final Map KIOSK_MAP; + public static final Map REVERSE_KIOSK_MAP; public static final String KIOSK_TRENDING = "Trending"; public static final String KIOSK_RECENT = "Recently added"; public static final String KIOSK_LOCAL = "Local"; @@ -23,6 +24,12 @@ public class PeertubeTrendingLinkHandlerFactory extends ListLinkHandlerFactory { map.put(KIOSK_RECENT, "%s/api/v1/videos?sort=-publishedAt"); map.put(KIOSK_LOCAL, "%s/api/v1/videos?filter=local"); KIOSK_MAP = Collections.unmodifiableMap(map); + + Map reverseMap = new HashMap<>(); + for(Map.Entry entry : KIOSK_MAP.entrySet()){ + reverseMap.put(entry.getValue(), entry.getKey()); + } + REVERSE_KIOSK_MAP = Collections.unmodifiableMap(reverseMap); } public String getUrl(String id, List contentFilters, String sortFilter) { @@ -33,13 +40,15 @@ public class PeertubeTrendingLinkHandlerFactory extends ListLinkHandlerFactory { @Override public String getId(String url) throws ParsingException { - if(url.contains("/videos/trending")) { + if (url.contains("/videos/trending")) { return KIOSK_TRENDING; - }else if(url.contains("/videos/recently-added")) { + } else if (url.contains("/videos/recently-added")) { return KIOSK_RECENT; - }else if(url.contains("/videos/local")){ + } else if (url.contains("/videos/local")) { return KIOSK_LOCAL; - }else { + } else if (REVERSE_KIOSK_MAP.containsKey(url)) { + return REVERSE_KIOSK_MAP.get(url); + } else { throw new ParsingException("no id found for this url"); } }