From bd5423fe2a84c61312912266f1bba2ea64915b63 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 1 Jul 2018 16:21:40 +0200 Subject: [PATCH] make less tests fail --- .../schabi/newpipe/extractor/Extractor.java | 22 +++--- .../org/schabi/newpipe/extractor/Info.java | 12 ++-- .../newpipe/extractor/ListExtractor.java | 11 +-- .../schabi/newpipe/extractor/ListInfo.java | 13 ++-- .../newpipe/extractor/ListUIHFactory.java | 62 ---------------- .../newpipe/extractor/StreamingService.java | 24 +++---- .../extractor/channel/ChannelExtractor.java | 4 +- .../extractor/channel/ChannelInfo.java | 7 +- .../extractor/kiosk/KioskExtractor.java | 5 +- .../newpipe/extractor/kiosk/KioskInfo.java | 6 +- .../newpipe/extractor/kiosk/KioskList.java | 4 +- .../extractor/playlist/PlaylistExtractor.java | 5 +- .../extractor/playlist/PlaylistInfo.java | 7 +- .../extractor/search/SearchExtractor.java | 12 ++-- .../newpipe/extractor/search/SearchInfo.java | 7 +- .../extractor/search/SearchQIHFactory.java | 44 ------------ .../SoundcloudChannelExtractor.java | 6 +- .../SoundcloudChannelUIHFactory.java | 8 ++- .../soundcloud/SoundcloudChartsExtractor.java | 4 +- .../SoundcloudChartsUIHFactory.java | 9 ++- .../SoundcloudPlaylistExtractor.java | 6 +- .../SoundcloudPlaylistUIHFactory.java | 8 ++- .../soundcloud/SoundcloudSearchExtractor.java | 4 +- .../SoundcloudSearchQIHFactory.java | 9 +-- .../soundcloud/SoundcloudService.java | 17 ++--- .../soundcloud/SoundcloudStreamExtractor.java | 5 +- .../SoundcloudStreamUIHFactory.java | 6 +- .../SoundcloudSubscriptionExtractor.java | 2 +- .../services/youtube/YoutubeService.java | 19 +++-- .../extractors/YoutubeChannelExtractor.java | 6 +- .../extractors/YoutubePlaylistExtractor.java | 13 ++-- .../extractors/YoutubeSearchExtractor.java | 24 ++++++- .../extractors/YoutubeStreamExtractor.java | 7 +- .../extractors/YoutubeTrendingExtractor.java | 9 +-- .../YoutubeChannelUIHFactory.java | 10 +-- .../YoutubePlaylistUIHFactory.java | 8 ++- .../YoutubeSearchQIHFactory.java | 11 +-- .../YoutubeStreamUIHFactory.java | 29 ++++---- .../YoutubeTrendingUIHFactory.java | 10 +-- .../extractor/stream/StreamExtractor.java | 7 +- .../newpipe/extractor/uih/ListUIHFactory.java | 71 +++++++++++++++++++ .../newpipe/extractor/uih/ListUIHandler.java | 45 ++++++++++++ .../extractor/uih/SearchQIHFactory.java | 43 +++++++++++ .../extractor/uih/SearchQIHandler.java | 32 +++++++++ .../extractor/{ => uih}/UIHFactory.java | 51 ++++++------- .../newpipe/extractor/uih/UIHandler.java | 31 ++++++++ .../SoundcloudChartsUIHFactoryTest.java | 8 +-- .../SoundcloudStreamUIHFactoryTest.java | 24 +++---- .../SoundcloudSubscriptionExtractorTest.java | 2 +- .../SoundcloudSearchExtractorBaseTest.java | 7 +- ...ndcloudSearchExtractorChannelOnlyTest.java | 10 +-- .../SoundcloudSearchExtractorDefaultTest.java | 8 +-- .../search/SoundcloudSearchQUHTest.java | 40 +++++++---- .../youtube/YoutubeChannelUIHFactoryTest.java | 19 ++--- .../youtube/YoutubeStreamUIHFactoryTest.java | 68 +++++++++--------- .../YoutubeSubscriptionExtractorTest.java | 2 +- .../youtube/YoutubeTrendingKioskInfoTest.java | 4 +- .../YoutubeTrendingUIHFactoryTest.java | 12 ++-- .../youtube/search/YoutubeSearchQUHTest.java | 22 +++--- 59 files changed, 582 insertions(+), 399 deletions(-) delete mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/ListUIHFactory.java delete mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQIHFactory.java create mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/uih/ListUIHFactory.java create mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/uih/ListUIHandler.java create mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/uih/SearchQIHFactory.java create mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/uih/SearchQIHandler.java rename extractor/src/main/java/org/schabi/newpipe/extractor/{ => uih}/UIHFactory.java (63%) create mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/uih/UIHandler.java diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java index c3127874a..8fd9e269b 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java @@ -2,6 +2,8 @@ package org.schabi.newpipe.extractor; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.uih.UIHandler; +import org.schabi.newpipe.extractor.uih.UIHandler; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -14,27 +16,27 @@ public abstract class Extractor { */ private final StreamingService service; - private final UIHFactory UIHFactory; + private final org.schabi.newpipe.extractor.uih.UIHandler uIHandler; @Nullable private boolean pageFetched = false; private final Downloader downloader; - public Extractor(final StreamingService service, final UIHFactory UIHFactory) { + public Extractor(final StreamingService service, final UIHandler uIHandler) { if(service == null) throw new NullPointerException("service is null"); - if(UIHFactory == null) throw new NullPointerException("UIHFactory is null"); + if(uIHandler == null) throw new NullPointerException("UIHandler is null"); this.service = service; - this.UIHFactory = UIHFactory; + this.uIHandler = uIHandler; this.downloader = NewPipe.getDownloader(); if(downloader == null) throw new NullPointerException("downloader is null"); } /** - * @return The {@link UIHFactory} of the current extractor object (e.g. a ChannelExtractor should return a channel url handler). + * @return The {@link UIHandler} of the current extractor object (e.g. a ChannelExtractor should return a channel url handler). */ @Nonnull - public UIHFactory getUIHFactory() { - return UIHFactory; + public UIHandler getUIHandler() { + return uIHandler; } /** @@ -66,7 +68,7 @@ public abstract class Extractor { @Nonnull public String getId() throws ParsingException { - return UIHFactory.getId(); + return uIHandler.getId(); } /** @@ -79,12 +81,12 @@ public abstract class Extractor { @Nonnull public String getOriginalUrl() throws ParsingException { - return UIHFactory.getOriginalUrl(); + return uIHandler.getOriginalUrl(); } @Nonnull public String getUrl() throws ParsingException { - return UIHFactory.getUrl(); + return uIHandler.getUrl(); } @Nonnull diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/Info.java b/extractor/src/main/java/org/schabi/newpipe/extractor/Info.java index 5918a00a4..7eb80ad82 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/Info.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/Info.java @@ -1,6 +1,8 @@ package org.schabi.newpipe.extractor; import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.uih.UIHFactory; +import org.schabi.newpipe.extractor.uih.UIHandler; import java.io.Serializable; import java.util.ArrayList; @@ -18,7 +20,7 @@ public abstract class Info implements Serializable { /** * Different than the {@link #originalUrl} in the sense that it may be set as a cleaned url. * - * @see UIHFactory#getUrl() + * @see UIHandler#getUrl() * @see Extractor#getOriginalUrl() */ private final String url; @@ -48,11 +50,11 @@ public abstract class Info implements Serializable { this.name = name; } - public Info(int serviceId, UIHFactory UIHFactory, String name) throws ParsingException { + public Info(int serviceId, UIHandler uiHandler, String name) { this(serviceId, - UIHFactory.getId(), - UIHFactory.getUrl(), - UIHFactory.getOriginalUrl(), + uiHandler.getId(), + uiHandler.getUrl(), + uiHandler.getOriginalUrl(), name); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java index a07ecdde3..adefb8888 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java @@ -1,8 +1,11 @@ package org.schabi.newpipe.extractor; import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.uih.ListUIHFactory; +import org.schabi.newpipe.extractor.uih.ListUIHandler; import javax.annotation.Nonnull; +import javax.swing.plaf.ListUI; import java.io.IOException; import java.util.Collections; import java.util.List; @@ -12,8 +15,8 @@ import java.util.List; */ public abstract class ListExtractor extends Extractor { - public ListExtractor(StreamingService service, ListUIHFactory urlIdHandler) { - super(service, urlIdHandler); + public ListExtractor(StreamingService service, ListUIHandler uiHandler) { + super(service, uiHandler); } /** @@ -50,8 +53,8 @@ public abstract class ListExtractor extends Extractor { } @Override - public ListUIHFactory getUIHFactory() { - return (ListUIHFactory) super.getUIHFactory(); + public ListUIHandler getUIHandler() { + return (ListUIHandler) super.getUIHandler(); } /*////////////////////////////////////////////////////////////////////////// diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/ListInfo.java b/extractor/src/main/java/org/schabi/newpipe/extractor/ListInfo.java index 5d591a1ee..7a2d6e872 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/ListInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/ListInfo.java @@ -1,6 +1,7 @@ package org.schabi.newpipe.extractor; import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.uih.ListUIHandler; import java.util.ArrayList; import java.util.List; @@ -8,7 +9,7 @@ import java.util.List; public abstract class ListInfo extends Info { private List relatedItems; private String nextPageUrl = null; - private List contentFilter = new ArrayList<>(); + private List contentFilters = new ArrayList<>(); private String sortFilter = ""; public ListInfo(int serviceId, @@ -19,13 +20,13 @@ public abstract class ListInfo extends Info { List contentFilter, String sortFilter) { super(serviceId, id, url, originalUrl, name); - this.contentFilter = contentFilter; + this.contentFilters = contentFilter; this.sortFilter = sortFilter; } - public ListInfo(int serviceId, ListUIHFactory listUrlIdHandler, String name) throws ParsingException { + public ListInfo(int serviceId, ListUIHandler listUrlIdHandler, String name) throws ParsingException { super(serviceId, listUrlIdHandler, name); - this.contentFilter = listUrlIdHandler.getContentFilter(); + this.contentFilters = listUrlIdHandler.getContentFilters(); this.sortFilter = listUrlIdHandler.getSortFilter(); } @@ -49,8 +50,8 @@ public abstract class ListInfo extends Info { this.nextPageUrl = pageUrl; } - public List getContentFilter() { - return contentFilter; + public List getContentFilters() { + return contentFilters; } public String getSortFilter() { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/ListUIHFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/ListUIHFactory.java deleted file mode 100644 index 88ec0e476..000000000 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/ListUIHFactory.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.schabi.newpipe.extractor; - -import org.schabi.newpipe.extractor.exceptions.ParsingException; - -import java.util.ArrayList; -import java.util.List; - -public abstract class ListUIHFactory extends UIHFactory { - - protected List contentFilter = new ArrayList<>(0); - protected String sortFilter = ""; - - public ListUIHFactory setQuery(String id, - List contentFilter, - String sortFilter) throws ParsingException { - setId(id); - this.contentFilter = contentFilter; - this.sortFilter = sortFilter; - return this; - } - - - public ListUIHFactory setQuery(String id) throws ParsingException { - setQuery(id, new ArrayList(), ""); - return this; - } - - public ListUIHFactory setUrl(String url) throws ParsingException { - return (ListUIHFactory) super.setUrl(url); - } - - public ListUIHFactory setId(String id) throws ParsingException { - return (ListUIHFactory) super.setId(id); - } - - /** - * Will returns content filter the corresponding extractor can handle like "channels", "videos", "music", etc. - * - * @return filter that can be applied when building a query for getting a list - */ - public String[] getAvailableContentFilter() { - return new String[0]; - } - - /** - * Will returns sort filter the corresponding extractor can handle like "A-Z", "oldest first", "size", etc. - * - * @return filter that can be applied when building a query for getting a list - */ - public String[] getAvailableSortFilter() { - return new String[0]; - } - - - public List getContentFilter() { - return contentFilter; - } - - public String getSortFilter() { - return sortFilter; - } -} 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 04b5ca85d..b20f117b4 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java @@ -6,7 +6,7 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.kiosk.KioskList; import org.schabi.newpipe.extractor.playlist.PlaylistExtractor; import org.schabi.newpipe.extractor.search.SearchExtractor; -import org.schabi.newpipe.extractor.search.SearchQIHFactory; +import org.schabi.newpipe.extractor.uih.*; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; @@ -76,41 +76,41 @@ public abstract class StreamingService { //////////////////////////////////////////// // Extractor //////////////////////////////////////////// - public abstract SearchExtractor getSearchExtractor(SearchQIHFactory queryHandler, String contentCountry); + public abstract SearchExtractor getSearchExtractor(SearchQIHandler queryHandler, String contentCountry); public abstract SuggestionExtractor getSuggestionExtractor(); public abstract SubscriptionExtractor getSubscriptionExtractor(); public abstract KioskList getKioskList() throws ExtractionException; - public abstract ChannelExtractor getChannelExtractor(ListUIHFactory urlIdHandler) throws ExtractionException; - public abstract PlaylistExtractor getPlaylistExtractor(ListUIHFactory urlIdHandler) throws ExtractionException; - public abstract StreamExtractor getStreamExtractor(UIHFactory UIHFactory) throws ExtractionException; + public abstract ChannelExtractor getChannelExtractor(ListUIHandler urlIdHandler) throws ExtractionException; + public abstract PlaylistExtractor getPlaylistExtractor(ListUIHandler urlIdHandler) throws ExtractionException; + public abstract StreamExtractor getStreamExtractor(UIHandler UIHFactory) throws ExtractionException; public SearchExtractor getSearchExtractor(String query, List contentFilter, String sortFilter, String contentCountry) throws ExtractionException { - return getSearchExtractor(getSearchQIHFactory().setQuery(query, contentFilter, sortFilter), contentCountry); + return getSearchExtractor(getSearchQIHFactory().fromQuery(query, contentFilter, sortFilter), contentCountry); } public ChannelExtractor getChannelExtractor(String id, List contentFilter, String sortFilter) throws ExtractionException { - return getChannelExtractor(getChannelUIHFactory().setQuery(id, contentFilter, sortFilter)); + return getChannelExtractor(getChannelUIHFactory().fromQuery(id, contentFilter, sortFilter)); } public PlaylistExtractor getPlaylistExtractor(String id, List contentFilter, String sortFilter) throws ExtractionException { - return getPlaylistExtractor(getPlaylistUIHFactory().setQuery(id, contentFilter, sortFilter)); + return getPlaylistExtractor(getPlaylistUIHFactory().fromQuery(id, contentFilter, sortFilter)); } public SearchExtractor getSearchExtractor(String query, String contentCountry) throws ExtractionException { - return getSearchExtractor(getSearchQIHFactory().setQuery(query), contentCountry); + return getSearchExtractor(getSearchQIHFactory().fromQuery(query), contentCountry); } public ChannelExtractor getChannelExtractor(String url) throws ExtractionException { - return getChannelExtractor(getChannelUIHFactory().setUrl(url)); + return getChannelExtractor(getChannelUIHFactory().fromUrl(url)); } public PlaylistExtractor getPlaylistExtractor(String url) throws ExtractionException { - return getPlaylistExtractor(getPlaylistUIHFactory().setUrl(url)); + return getPlaylistExtractor(getPlaylistUIHFactory().fromUrl(url)); } public StreamExtractor getStreamExtractor(String url) throws ExtractionException { - return getStreamExtractor(getStreamUIHFactory().setUrl(url)); + return getStreamExtractor(getStreamUIHFactory().fromUrl(url)); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelExtractor.java index b41f041e2..79b48e9e9 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelExtractor.java @@ -1,10 +1,10 @@ package org.schabi.newpipe.extractor.channel; import org.schabi.newpipe.extractor.ListExtractor; -import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.stream.StreamInfoItem; +import org.schabi.newpipe.extractor.uih.ListUIHandler; /* * Created by Christian Schabesberger on 25.07.16. @@ -28,7 +28,7 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem; public abstract class ChannelExtractor extends ListExtractor { - public ChannelExtractor(StreamingService service, ListUIHFactory urlIdHandler) { + public ChannelExtractor(StreamingService service, ListUIHandler urlIdHandler) { super(service, urlIdHandler); } 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 372feaa9c..a16926703 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 @@ -2,12 +2,13 @@ package org.schabi.newpipe.extractor.channel; import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage; import org.schabi.newpipe.extractor.ListInfo; -import org.schabi.newpipe.extractor.ListUIHFactory; +import org.schabi.newpipe.extractor.uih.ListUIHFactory; 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.uih.ListUIHandler; import org.schabi.newpipe.extractor.utils.ExtractorHelper; import java.io.IOException; @@ -34,7 +35,7 @@ import java.io.IOException; public class ChannelInfo extends ListInfo { - public ChannelInfo(int serviceId, ListUIHFactory urlIdHandler, String name) throws ParsingException { + public ChannelInfo(int serviceId, ListUIHandler urlIdHandler, String name) throws ParsingException { super(serviceId, urlIdHandler, name); } @@ -55,7 +56,7 @@ public class ChannelInfo extends ListInfo { public static ChannelInfo getInfo(ChannelExtractor extractor) throws IOException, ExtractionException { ChannelInfo info = new ChannelInfo(extractor.getServiceId(), - extractor.getUIHFactory(), + extractor.getUIHandler(), extractor.getName()); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java index c46de368d..4c64e3908 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java @@ -21,10 +21,11 @@ package org.schabi.newpipe.extractor.kiosk; */ import org.schabi.newpipe.extractor.ListExtractor; -import org.schabi.newpipe.extractor.ListUIHFactory; +import org.schabi.newpipe.extractor.uih.ListUIHFactory; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.stream.StreamInfoItem; +import org.schabi.newpipe.extractor.uih.ListUIHandler; import javax.annotation.Nonnull; @@ -33,7 +34,7 @@ public abstract class KioskExtractor extends ListExtractor { private final String id; public KioskExtractor(StreamingService streamingService, - ListUIHFactory urlIdHandler, + ListUIHandler urlIdHandler, String kioskId) { super(streamingService, urlIdHandler); this.id = kioskId; 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 afd02727d..66a9db3c1 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 @@ -24,13 +24,15 @@ import org.schabi.newpipe.extractor.*; 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.uih.ListUIHFactory; +import org.schabi.newpipe.extractor.uih.ListUIHandler; import org.schabi.newpipe.extractor.utils.ExtractorHelper; import java.io.IOException; public class KioskInfo extends ListInfo { - private KioskInfo(int serviceId, ListUIHFactory urlIdHandler, String name) throws ParsingException { + private KioskInfo(int serviceId, ListUIHandler urlIdHandler, String name) throws ParsingException { super(serviceId, urlIdHandler, name); } @@ -67,7 +69,7 @@ public class KioskInfo extends ListInfo { public static KioskInfo getInfo(KioskExtractor extractor) throws ExtractionException { final KioskInfo info = new KioskInfo(extractor.getServiceId(), - extractor.getUIHFactory(), + extractor.getUIHandler(), extractor.getName()); final ListExtractor.InfoItemsPage itemsPage = ExtractorHelper.getItemsPageOrLogError(info, 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 a4739e630..04d8d7bed 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 @@ -2,7 +2,7 @@ package org.schabi.newpipe.extractor.kiosk; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; -import org.schabi.newpipe.extractor.UIHFactory; +import org.schabi.newpipe.extractor.uih.UIHFactory; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import java.io.IOException; @@ -73,7 +73,7 @@ public class KioskList { throw new ExtractionException("No kiosk found with the type: " + kioskId); } else { return ke.extractorFactory.createNewKiosk(NewPipe.getService(service_id), - ke.handler.setId(kioskId).getUrl(), kioskId); + ke.handler.fromId(kioskId).getUrl(), kioskId); } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistExtractor.java index 924ff8cbe..d5008a504 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistExtractor.java @@ -1,14 +1,15 @@ package org.schabi.newpipe.extractor.playlist; import org.schabi.newpipe.extractor.ListExtractor; -import org.schabi.newpipe.extractor.ListUIHFactory; +import org.schabi.newpipe.extractor.uih.ListUIHFactory; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.stream.StreamInfoItem; +import org.schabi.newpipe.extractor.uih.ListUIHandler; public abstract class PlaylistExtractor extends ListExtractor { - public PlaylistExtractor(StreamingService service, ListUIHFactory urlIdHandler) { + public PlaylistExtractor(StreamingService service, ListUIHandler urlIdHandler) { super(service, urlIdHandler); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java index edcfe34e9..5e3f94ddf 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java @@ -2,19 +2,20 @@ package org.schabi.newpipe.extractor.playlist; import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage; import org.schabi.newpipe.extractor.ListInfo; -import org.schabi.newpipe.extractor.ListUIHFactory; +import org.schabi.newpipe.extractor.uih.ListUIHFactory; 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.uih.ListUIHandler; import org.schabi.newpipe.extractor.utils.ExtractorHelper; import java.io.IOException; public class PlaylistInfo extends ListInfo { - public PlaylistInfo(int serviceId, ListUIHFactory urlIdHandler, String name) throws ParsingException { + public PlaylistInfo(int serviceId, ListUIHandler urlIdHandler, String name) throws ParsingException { super(serviceId, urlIdHandler, name); } @@ -41,7 +42,7 @@ public class PlaylistInfo extends ListInfo { final PlaylistInfo info = new PlaylistInfo( extractor.getServiceId(), - extractor.getUIHFactory(), + extractor.getUIHandler(), extractor.getName()); try { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchExtractor.java index 68a10ded0..751152ca5 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchExtractor.java @@ -5,6 +5,8 @@ import org.schabi.newpipe.extractor.ListExtractor; 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.uih.SearchQIHFactory; +import org.schabi.newpipe.extractor.uih.SearchQIHandler; public abstract class SearchExtractor extends ListExtractor { @@ -17,14 +19,14 @@ public abstract class SearchExtractor extends ListExtractor { private final InfoItemsSearchCollector collector; private final String contentCountry; - public SearchExtractor(StreamingService service, SearchQIHFactory urlIdHandler, String contentCountry) { + public SearchExtractor(StreamingService service, SearchQIHandler urlIdHandler, String contentCountry) { super(service, urlIdHandler); collector = new InfoItemsSearchCollector(service.getServiceId()); this.contentCountry = contentCountry; } public String getSearchString() { - return getUIHFactory().getSearchString(); + return getUIHandler().getSearchString(); } public abstract String getSearchSuggestion() throws ParsingException; @@ -34,13 +36,13 @@ public abstract class SearchExtractor extends ListExtractor { } @Override - public SearchQIHFactory getUIHFactory() { - return (SearchQIHFactory) super.getUIHFactory(); + public SearchQIHandler getUIHandler() { + return (SearchQIHandler) super.getUIHandler(); } @Override public String getName() { - return getUIHFactory().getSearchString(); + return getUIHandler().getSearchString(); } protected String getContentCountry() { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchInfo.java b/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchInfo.java index 4d9ad12d6..5c1583c7a 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchInfo.java @@ -2,9 +2,10 @@ package org.schabi.newpipe.extractor.search; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.ListInfo; -import org.schabi.newpipe.extractor.ListUIHFactory; +import org.schabi.newpipe.extractor.uih.ListUIHFactory; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.uih.ListUIHandler; public class SearchInfo extends ListInfo { @@ -13,7 +14,7 @@ public class SearchInfo extends ListInfo { public SearchInfo(int serviceId, - ListUIHFactory urlIdHandler, + ListUIHandler urlIdHandler, String searchString) throws ParsingException { super(serviceId, urlIdHandler, "Search"); this.searchString = searchString; @@ -23,7 +24,7 @@ public class SearchInfo extends ListInfo { public static SearchInfo getInfo(SearchExtractor extractor) throws ExtractionException { final SearchInfo info = new SearchInfo( extractor.getServiceId(), - extractor.getUIHFactory(), + extractor.getUIHandler(), extractor.getSearchString()); try { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQIHFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQIHFactory.java deleted file mode 100644 index 2e96f434d..000000000 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQIHFactory.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.schabi.newpipe.extractor.search; - -import org.schabi.newpipe.extractor.ListUIHFactory; -import org.schabi.newpipe.extractor.exceptions.ParsingException; - -import java.util.List; - -public abstract class SearchQIHFactory extends ListUIHFactory { - - @Override - public String onGetIdFromUrl(String url) { - return "Search"; - } - - public String getSearchString() { - return getId(); - } - - @Override - public SearchQIHFactory setQuery(String querry, - List contentFilter, - String sortFilter) throws ParsingException { - return (SearchQIHFactory) super.setQuery(querry, contentFilter, sortFilter); - } - - - @Override - public SearchQIHFactory setQuery(String querry) throws ParsingException { - return (SearchQIHFactory) super.setQuery(querry); - } - - - @Override - public boolean onAcceptUrl(String url) { - return false; - } - - public SearchQIHFactory setId(String query) throws ParsingException { - if(query == null) throw new IllegalArgumentException("id can not be null"); - this.id = query; - return this; - } - -} diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractor.java index 9eaeef46b..ea2195e38 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractor.java @@ -5,7 +5,7 @@ import com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonParser; import com.grack.nanojson.JsonParserException; import org.schabi.newpipe.extractor.Downloader; -import org.schabi.newpipe.extractor.ListUIHFactory; +import org.schabi.newpipe.extractor.uih.ListUIHandler; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.exceptions.ExtractionException; @@ -24,14 +24,14 @@ public class SoundcloudChannelExtractor extends ChannelExtractor { private StreamInfoItemsCollector streamInfoItemsCollector = null; private String nextPageUrl = null; - public SoundcloudChannelExtractor(StreamingService service, ListUIHFactory urlIdHandler) { + public SoundcloudChannelExtractor(StreamingService service, ListUIHandler urlIdHandler) { super(service, urlIdHandler); } @Override public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { - userId = getUIHFactory().getId(); + userId = getUIHandler().getId(); String apiUrl = "https://api-v2.soundcloud.com/users/" + userId + "?client_id=" + SoundcloudParsingHelper.clientId(); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelUIHFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelUIHFactory.java index 142d8da37..5a8b10112 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelUIHFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelUIHFactory.java @@ -1,10 +1,12 @@ package org.schabi.newpipe.extractor.services.soundcloud; -import org.schabi.newpipe.extractor.ListUIHFactory; +import org.schabi.newpipe.extractor.uih.ListUIHFactory; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Utils; +import java.util.List; + public class SoundcloudChannelUIHFactory extends ListUIHFactory { private static final SoundcloudChannelUIHFactory instance = new SoundcloudChannelUIHFactory(); private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" + @@ -16,7 +18,7 @@ public class SoundcloudChannelUIHFactory extends ListUIHFactory { @Override - public String onGetIdFromUrl(String url) throws ParsingException { + public String getId(String url) throws ParsingException { Utils.checkUrl(URL_PATTERN, url); try { @@ -27,7 +29,7 @@ public class SoundcloudChannelUIHFactory extends ListUIHFactory { } @Override - public String getUrl() throws ParsingException { + public String getUrl(String id, List contentFilter, String sortFilter) throws ParsingException { try { return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/users/" + id); } catch (Exception e) { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractor.java index 24542dce6..ab9e92c3f 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractor.java @@ -1,7 +1,7 @@ package org.schabi.newpipe.extractor.services.soundcloud; import org.schabi.newpipe.extractor.Downloader; -import org.schabi.newpipe.extractor.ListUIHFactory; +import org.schabi.newpipe.extractor.uih.ListUIHandler; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.kiosk.KioskExtractor; @@ -17,7 +17,7 @@ public class SoundcloudChartsExtractor extends KioskExtractor { private StreamInfoItemsCollector collector = null; private String nextPageUrl = null; - public SoundcloudChartsExtractor(StreamingService service, ListUIHFactory urlIdHandler, String kioskId) { + public SoundcloudChartsExtractor(StreamingService service, ListUIHandler urlIdHandler, String kioskId) { super(service, urlIdHandler, kioskId); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUIHFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUIHFactory.java index f4b9109e4..8fdb8f5ec 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUIHFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUIHFactory.java @@ -1,15 +1,17 @@ package org.schabi.newpipe.extractor.services.soundcloud; -import org.schabi.newpipe.extractor.ListUIHFactory; +import org.schabi.newpipe.extractor.uih.ListUIHFactory; import org.schabi.newpipe.extractor.utils.Parser; +import java.util.List; + public class SoundcloudChartsUIHFactory extends ListUIHFactory { private final String TOP_URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/charts(/top)?/?([#?].*)?$"; private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/charts(/top|/new)?/?([#?].*)?$"; @Override - public String onGetIdFromUrl(String url) { + public String getId(String url) { if (Parser.isMatch(TOP_URL_PATTERN, url.toLowerCase())) { return "Top 50"; } else { @@ -17,7 +19,8 @@ public class SoundcloudChartsUIHFactory extends ListUIHFactory { } } - public String getUrl() { + @Override + public String getUrl(String id, List contentFilter, String sortFilter) { if (id.equals("Top 50")) { return "https://soundcloud.com/charts/top"; } else { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractor.java index 00c619491..727486ddb 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractor.java @@ -4,7 +4,7 @@ import com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonParser; import com.grack.nanojson.JsonParserException; import org.schabi.newpipe.extractor.Downloader; -import org.schabi.newpipe.extractor.ListUIHFactory; +import org.schabi.newpipe.extractor.uih.ListUIHandler; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; @@ -23,14 +23,14 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor { private StreamInfoItemsCollector streamInfoItemsCollector = null; private String nextPageUrl = null; - public SoundcloudPlaylistExtractor(StreamingService service, ListUIHFactory urlIdHandler) { + public SoundcloudPlaylistExtractor(StreamingService service, ListUIHandler urlIdHandler) { super(service, urlIdHandler); } @Override public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { - playlistId = getUIHFactory().getId(); + playlistId = getUIHandler().getId(); String apiUrl = "https://api.soundcloud.com/playlists/" + playlistId + "?client_id=" + SoundcloudParsingHelper.clientId() + "&representation=compact"; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistUIHFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistUIHFactory.java index 18bd4f612..e4dc0cb2f 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistUIHFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistUIHFactory.java @@ -1,10 +1,12 @@ package org.schabi.newpipe.extractor.services.soundcloud; -import org.schabi.newpipe.extractor.ListUIHFactory; +import org.schabi.newpipe.extractor.uih.ListUIHFactory; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Utils; +import java.util.List; + public class SoundcloudPlaylistUIHFactory extends ListUIHFactory { private static final SoundcloudPlaylistUIHFactory instance = new SoundcloudPlaylistUIHFactory(); private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" + @@ -15,7 +17,7 @@ public class SoundcloudPlaylistUIHFactory extends ListUIHFactory { } @Override - public String onGetIdFromUrl(String url) throws ParsingException { + public String getId(String url) throws ParsingException { Utils.checkUrl(URL_PATTERN, url); try { @@ -26,7 +28,7 @@ public class SoundcloudPlaylistUIHFactory extends ListUIHFactory { } @Override - public String getUrl() throws ParsingException { + public String getUrl(String id, List contentFilter, String sortFilter) throws ParsingException { try { return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/playlists/" + id); } catch (Exception e) { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchExtractor.java index 0ef3c86a7..8c5476398 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchExtractor.java @@ -10,7 +10,7 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.search.InfoItemsSearchCollector; import org.schabi.newpipe.extractor.search.SearchEngine; import org.schabi.newpipe.extractor.search.SearchExtractor; -import org.schabi.newpipe.extractor.search.SearchQIHFactory; +import org.schabi.newpipe.extractor.uih.SearchQIHandler; import org.schabi.newpipe.extractor.utils.Parser; import javax.annotation.Nonnull; @@ -26,7 +26,7 @@ public class SoundcloudSearchExtractor extends SearchExtractor { private JsonArray searchCollection; public SoundcloudSearchExtractor(StreamingService service, - SearchQIHFactory urlIdHandler, + SearchQIHandler urlIdHandler, String contentCountry) { super(service, urlIdHandler, contentCountry); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQIHFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQIHFactory.java index 349fd8bfc..9f053c181 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQIHFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQIHFactory.java @@ -2,11 +2,12 @@ package org.schabi.newpipe.extractor.services.soundcloud; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; -import org.schabi.newpipe.extractor.search.SearchQIHFactory; +import org.schabi.newpipe.extractor.uih.SearchQIHFactory; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.util.List; public class SoundcloudSearchQIHFactory extends SearchQIHFactory { public static final String CHARSET_UTF_8 = "UTF-8"; @@ -19,12 +20,12 @@ public class SoundcloudSearchQIHFactory extends SearchQIHFactory { public static final int ITEMS_PER_PAGE = 10; @Override - public String getUrl() throws ParsingException { + public String getUrl(String id, List contentFilter, String sortFilter) throws ParsingException { try { String url = "https://api-v2.soundcloud.com/search"; - if(getContentFilter().size() > 0) { - switch (getContentFilter().get(0)) { + if(contentFilter.size() > 0) { + switch (contentFilter.get(0)) { case TRACKS: url += "/tracks"; break; 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 b55c215e0..901d1ef2c 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 @@ -1,16 +1,13 @@ package org.schabi.newpipe.extractor.services.soundcloud; import org.schabi.newpipe.extractor.*; -import org.schabi.newpipe.extractor.ListUIHFactory; -import org.schabi.newpipe.extractor.UIHFactory; +import org.schabi.newpipe.extractor.uih.*; import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.kiosk.KioskExtractor; import org.schabi.newpipe.extractor.kiosk.KioskList; import org.schabi.newpipe.extractor.playlist.PlaylistExtractor; -import org.schabi.newpipe.extractor.search.SearchEngine; import org.schabi.newpipe.extractor.search.SearchExtractor; -import org.schabi.newpipe.extractor.search.SearchQIHFactory; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; @@ -24,7 +21,7 @@ public class SoundcloudService extends StreamingService { } @Override - public SearchExtractor getSearchExtractor(SearchQIHFactory queryHandler, String contentCountry) { + public SearchExtractor getSearchExtractor(SearchQIHandler queryHandler, String contentCountry) { return new SoundcloudSearchExtractor(this, queryHandler, contentCountry); } @@ -50,17 +47,17 @@ public class SoundcloudService extends StreamingService { @Override - public StreamExtractor getStreamExtractor(UIHFactory UIHFactory) { - return new SoundcloudStreamExtractor(this, UIHFactory); + public StreamExtractor getStreamExtractor(UIHandler UIHandler) { + return new SoundcloudStreamExtractor(this, UIHandler); } @Override - public ChannelExtractor getChannelExtractor(ListUIHFactory urlIdHandler) { + public ChannelExtractor getChannelExtractor(ListUIHandler urlIdHandler) { return new SoundcloudChannelExtractor(this, urlIdHandler); } @Override - public PlaylistExtractor getPlaylistExtractor(ListUIHFactory urlIdHandler) { + public PlaylistExtractor getPlaylistExtractor(ListUIHandler urlIdHandler) { return new SoundcloudPlaylistExtractor(this, urlIdHandler); } @@ -78,7 +75,7 @@ public class SoundcloudService extends StreamingService { String id) throws ExtractionException { return new SoundcloudChartsExtractor(SoundcloudService.this, - new SoundcloudChartsUIHFactory().setUrl(url), id); + new SoundcloudChartsUIHFactory().fromUrl(url), id); } }; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java index 285743fe4..853d17bc3 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java @@ -8,6 +8,7 @@ import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.stream.*; +import org.schabi.newpipe.extractor.uih.UIHandler; import javax.annotation.Nonnull; import java.io.IOException; @@ -20,8 +21,8 @@ import java.util.List; public class SoundcloudStreamExtractor extends StreamExtractor { private JsonObject track; - public SoundcloudStreamExtractor(StreamingService service, UIHFactory UIHFactory) { - super(service, UIHFactory); + public SoundcloudStreamExtractor(StreamingService service, UIHandler uIHandler) { + super(service, uIHandler); } @Override diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUIHFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUIHFactory.java index 3aec24ece..a4e5e6043 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUIHFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUIHFactory.java @@ -1,6 +1,6 @@ package org.schabi.newpipe.extractor.services.soundcloud; -import org.schabi.newpipe.extractor.UIHFactory; +import org.schabi.newpipe.extractor.uih.UIHFactory; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Utils; @@ -18,7 +18,7 @@ public class SoundcloudStreamUIHFactory extends UIHFactory { } @Override - public String getUrl() throws ParsingException { + public String getUrl(String id) throws ParsingException { try { return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/tracks/" + id); } catch (Exception e) { @@ -27,7 +27,7 @@ public class SoundcloudStreamUIHFactory extends UIHFactory { } @Override - public String onGetIdFromUrl(String url) throws ParsingException { + public String getId(String url) throws ParsingException { Utils.checkUrl(URL_PATTERN, url); try { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSubscriptionExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSubscriptionExtractor.java index 5b5db292c..b5bdcb535 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSubscriptionExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSubscriptionExtractor.java @@ -31,7 +31,7 @@ public class SoundcloudSubscriptionExtractor extends SubscriptionExtractor { String id; try { - id = service.getChannelUIHFactory().setUrl(getUrlFrom(channelUrl)).getId(); + id = service.getChannelUIHFactory().fromUrl(getUrlFrom(channelUrl)).getId(); } catch (ExtractionException e) { throw new InvalidSourceException(e); } 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 e425f1f5e..4490f1386 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 @@ -1,16 +1,13 @@ package org.schabi.newpipe.extractor.services.youtube; import org.schabi.newpipe.extractor.*; -import org.schabi.newpipe.extractor.ListUIHFactory; -import org.schabi.newpipe.extractor.UIHFactory; +import org.schabi.newpipe.extractor.uih.*; import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.kiosk.KioskExtractor; import org.schabi.newpipe.extractor.kiosk.KioskList; import org.schabi.newpipe.extractor.playlist.PlaylistExtractor; -import org.schabi.newpipe.extractor.search.SearchEngine; import org.schabi.newpipe.extractor.search.SearchExtractor; -import org.schabi.newpipe.extractor.search.SearchQIHFactory; import org.schabi.newpipe.extractor.services.youtube.extractors.*; import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.*; import org.schabi.newpipe.extractor.stream.StreamExtractor; @@ -23,7 +20,7 @@ import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCap /* * Created by Christian Schabesberger on 23.08.15. * - * Copyright (C) Christian Schabesberger 2015 + * Copyright (C) Christian Schabesberger 2018 * YoutubeService.java is part of NewPipe. * * NewPipe is free software: you can redistribute it and/or modify @@ -47,7 +44,7 @@ public class YoutubeService extends StreamingService { } @Override - public SearchExtractor getSearchExtractor(SearchQIHFactory query, String contentCountry) { + public SearchExtractor getSearchExtractor(SearchQIHandler query, String contentCountry) { return new YoutubeSearchExtractor(this, query, contentCountry); } @@ -72,17 +69,17 @@ public class YoutubeService extends StreamingService { } @Override - public StreamExtractor getStreamExtractor(UIHFactory UIHFactory) throws ExtractionException { - return new YoutubeStreamExtractor(this, UIHFactory); + public StreamExtractor getStreamExtractor(UIHandler uiHandler) throws ExtractionException { + return new YoutubeStreamExtractor(this, uiHandler); } @Override - public ChannelExtractor getChannelExtractor(ListUIHFactory urlIdHandler) throws ExtractionException { + public ChannelExtractor getChannelExtractor(ListUIHandler urlIdHandler) throws ExtractionException { return new YoutubeChannelExtractor(this, urlIdHandler); } @Override - public PlaylistExtractor getPlaylistExtractor(ListUIHFactory urlIdHandler) throws ExtractionException { + public PlaylistExtractor getPlaylistExtractor(ListUIHandler urlIdHandler) throws ExtractionException { return new YoutubePlaylistExtractor(this, urlIdHandler); } @@ -102,7 +99,7 @@ public class YoutubeService extends StreamingService { public KioskExtractor createNewKiosk(StreamingService streamingService, String url, String id) throws ExtractionException { return new YoutubeTrendingExtractor(YoutubeService.this, - new YoutubeTrendingUIHFactory().setUrl(url), id); + new YoutubeTrendingUIHFactory().fromUrl(url), id); } }, new YoutubeTrendingUIHFactory(), "Trending"); list.setDefaultKiosk("Trending"); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java index 7abd70391..72176d69a 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java @@ -13,6 +13,8 @@ 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.stream.StreamInfoItemsCollector; +import org.schabi.newpipe.extractor.uih.ListUIHFactory; +import org.schabi.newpipe.extractor.uih.ListUIHandler; import org.schabi.newpipe.extractor.utils.DonationLinkHelper; import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Utils; @@ -24,7 +26,7 @@ import java.util.ArrayList; /* * Created by Christian Schabesberger on 25.07.16. * - * Copyright (C) Christian Schabesberger 2016 + * Copyright (C) Christian Schabesberger 2018 * YoutubeChannelExtractor.java is part of NewPipe. * * NewPipe is free software: you can redistribute it and/or modify @@ -48,7 +50,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor { private Document doc; - public YoutubeChannelExtractor(StreamingService service, ListUIHFactory urlIdHandler) { + public YoutubeChannelExtractor(StreamingService service, ListUIHandler urlIdHandler) { super(service, urlIdHandler); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistExtractor.java index 7654ce98c..cc116ebbb 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistExtractor.java @@ -14,6 +14,7 @@ import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeParsin import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; import org.schabi.newpipe.extractor.stream.StreamType; +import org.schabi.newpipe.extractor.uih.ListUIHandler; import org.schabi.newpipe.extractor.utils.Utils; import javax.annotation.Nonnull; @@ -24,7 +25,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { private Document doc; - public YoutubePlaylistExtractor(StreamingService service, ListUIHFactory urlIdHandler) throws ExtractionException { + public YoutubePlaylistExtractor(StreamingService service, ListUIHandler urlIdHandler) throws ExtractionException { super(service, urlIdHandler); } @@ -170,10 +171,10 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { } } - private void collectStreamsFrom(StreamInfoItemsCollector collector, Element element) throws ParsingException { + private void collectStreamsFrom(StreamInfoItemsCollector collector, Element element) { collector.reset(); - final UIHFactory streamUIHFactory = getService().getStreamUIHFactory(); + final org.schabi.newpipe.extractor.uih.UIHFactory streamUIHFactory = getService().getStreamUIHFactory(); for (final Element li : element.children()) { if(isDeletedItem(li)) { continue; @@ -183,14 +184,14 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { public Element uploaderLink; @Override - public boolean isAd() throws ParsingException { + public boolean isAd() { return false; } @Override public String getUrl() throws ParsingException { try { - return streamUIHFactory.setId(li.attr("data-video-id")).getUrl(); + return streamUIHFactory.fromId(li.attr("data-video-id")).getUrl(); } catch (Exception e) { throw new ParsingException("Could not get web page url for the video", e); } @@ -255,7 +256,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { @Override public String getThumbnailUrl() throws ParsingException { try { - return "https://i.ytimg.com/vi/" + streamUIHFactory.setUrl(getUrl()).getId() + "/hqdefault.jpg"; + return "https://i.ytimg.com/vi/" + streamUIHFactory.fromUrl(getUrl()).getId() + "/hqdefault.jpg"; } catch (Exception e) { throw new ParsingException("Could not get thumbnail url", e); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java index af63be038..bdf55ac45 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java @@ -10,7 +10,7 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.search.InfoItemsSearchCollector; import org.schabi.newpipe.extractor.search.SearchExtractor; -import org.schabi.newpipe.extractor.search.SearchQIHFactory; +import org.schabi.newpipe.extractor.uih.SearchQIHandler; import org.schabi.newpipe.extractor.utils.Parser; import javax.annotation.Nonnull; @@ -19,12 +19,32 @@ import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; +/* + * Created by Christian Schabesberger on 22.07.2018 + * + * Copyright (C) Christian Schabesberger 2018 + * YoutubeSearchExtractor.java is part of NewPipe. + * + * NewPipe is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NewPipe is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NewPipe. If not, see . + */ + public class YoutubeSearchExtractor extends SearchExtractor { private Document doc; public YoutubeSearchExtractor(StreamingService service, - SearchQIHFactory urlIdHandler, + SearchQIHandler urlIdHandler, String contentCountry) { super(service, urlIdHandler, contentCountry); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index b1e1552f2..133906a24 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -17,6 +17,7 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; import org.schabi.newpipe.extractor.services.youtube.ItagItem; import org.schabi.newpipe.extractor.stream.*; +import org.schabi.newpipe.extractor.uih.UIHandler; import org.schabi.newpipe.extractor.utils.DonationLinkHelper; import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Utils; @@ -29,7 +30,7 @@ import java.util.*; /* * Created by Christian Schabesberger on 06.08.15. * - * Copyright (C) Christian Schabesberger 2015 + * Copyright (C) Christian Schabesberger 2018 * YoutubeStreamExtractor.java is part of NewPipe. * * NewPipe is free software: you can redistribute it and/or modify @@ -84,8 +85,8 @@ public class YoutubeStreamExtractor extends StreamExtractor { private boolean isAgeRestricted; - public YoutubeStreamExtractor(StreamingService service, UIHFactory UIHFactory) throws ExtractionException { - super(service, UIHFactory); + public YoutubeStreamExtractor(StreamingService service, UIHandler uiHandler) throws ExtractionException { + super(service, uiHandler); } /*////////////////////////////////////////////////////////////////////////// diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeTrendingExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeTrendingExtractor.java index d32125ca7..7feb0090b 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeTrendingExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeTrendingExtractor.java @@ -3,7 +3,7 @@ package org.schabi.newpipe.extractor.services.youtube.extractors; /* * Created by Christian Schabesberger on 12.08.17. * - * Copyright (C) Christian Schabesberger 2017 + * Copyright (C) Christian Schabesberger 2018 * YoutubeTrendingExtractor.java is part of NewPipe. * * NewPipe is free software: you can redistribute it and/or modify @@ -25,7 +25,7 @@ import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; import org.schabi.newpipe.extractor.Downloader; -import org.schabi.newpipe.extractor.ListUIHFactory; +import org.schabi.newpipe.extractor.uih.ListUIHandler; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; @@ -40,8 +40,9 @@ public class YoutubeTrendingExtractor extends KioskExtractor { private Document doc; - public YoutubeTrendingExtractor(StreamingService service, ListUIHFactory urlIdHandler, String kioskId) - throws ExtractionException { + public YoutubeTrendingExtractor(StreamingService service, + ListUIHandler urlIdHandler, + String kioskId) { super(service, urlIdHandler, kioskId); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeChannelUIHFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeChannelUIHFactory.java index c95413cdb..187933e98 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeChannelUIHFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeChannelUIHFactory.java @@ -1,13 +1,15 @@ package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers; -import org.schabi.newpipe.extractor.ListUIHFactory; +import org.schabi.newpipe.extractor.uih.ListUIHFactory; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.utils.Parser; +import java.util.List; + /* * Created by Christian Schabesberger on 25.07.16. * - * Copyright (C) Christian Schabesberger 2016 + * Copyright (C) Christian Schabesberger 2018 * YoutubeChannelUIHFactory.java is part of NewPipe. * * NewPipe is free software: you can redistribute it and/or modify @@ -34,12 +36,12 @@ public class YoutubeChannelUIHFactory extends ListUIHFactory { } @Override - public String onGetIdFromUrl(String url) throws ParsingException { + public String getId(String url) throws ParsingException { return Parser.matchGroup1(ID_PATTERN, url); } @Override - public String getUrl() { + public String getUrl(String id, List contentFilters, String searchFilter) { return "https://www.youtube.com/" + id; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubePlaylistUIHFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubePlaylistUIHFactory.java index d3daa3eaa..c55057af3 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubePlaylistUIHFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubePlaylistUIHFactory.java @@ -1,10 +1,12 @@ package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers; -import org.schabi.newpipe.extractor.ListUIHFactory; +import org.schabi.newpipe.extractor.uih.ListUIHFactory; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.utils.Parser; +import java.util.List; + public class YoutubePlaylistUIHFactory extends ListUIHFactory { private static final YoutubePlaylistUIHFactory instance = new YoutubePlaylistUIHFactory(); @@ -15,12 +17,12 @@ public class YoutubePlaylistUIHFactory extends ListUIHFactory { } @Override - public String getUrl() { + public String getUrl(String id, List contentFilters, String sortFilter) { return "https://www.youtube.com/playlist?list=" + id; } @Override - public String onGetIdFromUrl(String url) throws ParsingException { + public String getId(String url) throws ParsingException { try { return Parser.matchGroup1("list=" + ID_PATTERN, url); } catch (final Exception exception) { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeSearchQIHFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeSearchQIHFactory.java index 1dbb9e15e..db688f32d 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeSearchQIHFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeSearchQIHFactory.java @@ -1,10 +1,11 @@ package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers; import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.search.SearchQIHFactory; +import org.schabi.newpipe.extractor.uih.SearchQIHFactory; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.util.List; public class YoutubeSearchQIHFactory extends SearchQIHFactory { @@ -20,13 +21,13 @@ public class YoutubeSearchQIHFactory extends SearchQIHFactory { } @Override - public String getUrl() throws ParsingException { + public String getUrl(String searchString, List contentFilters, String sortFilter) throws ParsingException { try { final String url = "https://www.youtube.com/results" - + "?q=" + URLEncoder.encode(id, CHARSET_UTF_8); + + "?q=" + URLEncoder.encode(searchString, CHARSET_UTF_8); - if(getContentFilter().size() > 0) { - switch (getContentFilter().get(0)) { + if(contentFilters.size() > 0) { + switch (contentFilters.get(0)) { case STREAM: return url + "&sp=EgIQAVAU"; case CHANNEL: return url + "&sp=EgIQAlAU"; case PLAYLIST: return url + "&sp=EgIQA1AU"; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeStreamUIHFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeStreamUIHFactory.java index 10efba8b2..95f9da499 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeStreamUIHFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeStreamUIHFactory.java @@ -5,7 +5,7 @@ import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.schabi.newpipe.extractor.Downloader; import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.UIHFactory; +import org.schabi.newpipe.extractor.uih.UIHFactory; import org.schabi.newpipe.extractor.exceptions.FoundAdException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; @@ -20,7 +20,7 @@ import java.net.URLDecoder; /* * Created by Christian Schabesberger on 02.02.16. * - * Copyright (C) Christian Schabesberger 2016 + * Copyright (C) Christian Schabesberger 2018 * YoutubeStreamUIHFactory.java is part of NewPipe. * * NewPipe is free software: you can redistribute it and/or modify @@ -50,12 +50,12 @@ public class YoutubeStreamUIHFactory extends UIHFactory { } @Override - public String getUrl() { + public String getUrl(String id) { return "https://www.youtube.com/watch?v=" + id; } @Override - public String onGetIdFromUrl(String url) throws ParsingException, IllegalArgumentException { + public String getId(String url) throws ParsingException, IllegalArgumentException { if (url.isEmpty()) { throw new IllegalArgumentException("The url parameter should not be empty"); } @@ -141,16 +141,13 @@ public class YoutubeStreamUIHFactory extends UIHFactory { } catch (IOException | ReCaptchaException e) { throw new ParsingException("Unable to resolve shared link", e); } - Document document = Jsoup.parse(content); - String urlWithRealId; + final Document document = Jsoup.parse(content); - Element element = document.select("link[rel=\"canonical\"]").first(); - if (element != null) { - urlWithRealId = element.attr("abs:href"); - } else { - urlWithRealId = document.select("meta[property=\"og:url\"]").first() + final Element element = document.select("link[rel=\"canonical\"]").first(); + final String urlWithRealId = (element != null) + ? element.attr("abs:href") + : document.select("meta[property=\"og:url\"]").first() .attr("abs:content"); - } String realId = Parser.matchGroup1(ID_PATTERN, urlWithRealId); if (sharedId.equals(realId)) { @@ -167,16 +164,18 @@ public class YoutubeStreamUIHFactory extends UIHFactory { } @Override - public boolean onAcceptUrl(final String url) { + public boolean onAcceptUrl(final String url) throws FoundAdException { final String lowercaseUrl = url.toLowerCase(); if (lowercaseUrl.contains("youtube") || lowercaseUrl.contains("youtu.be") || lowercaseUrl.contains("hooktube")) { // bad programming I know try { - onGetIdFromUrl(url); + getId(url); return true; - } catch (Exception e) { + } catch (FoundAdException fe) { + throw fe; + } catch (ParsingException e) { return false; } } else { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeTrendingUIHFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeTrendingUIHFactory.java index 9ee9a4e46..823516197 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeTrendingUIHFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeTrendingUIHFactory.java @@ -3,7 +3,7 @@ package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers; /* * Created by Christian Schabesberger on 12.08.17. * - * Copyright (C) Christian Schabesberger 2017 + * Copyright (C) Christian Schabesberger 2018 * YoutubeTrendingUIHFactory.java is part of NewPipe. * * NewPipe is free software: you can redistribute it and/or modify @@ -20,17 +20,19 @@ package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers; * along with NewPipe. If not, see . */ -import org.schabi.newpipe.extractor.ListUIHFactory; +import org.schabi.newpipe.extractor.uih.ListUIHFactory; import org.schabi.newpipe.extractor.utils.Parser; +import java.util.List; + public class YoutubeTrendingUIHFactory extends ListUIHFactory { - public String getUrl() { + public String getUrl(String id, List contentFilters, String sortFilter) { return "https://www.youtube.com/feed/trending"; } @Override - public String onGetIdFromUrl(String url) { + public String getId(String url) { return "Trending"; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java index 1bfa56258..a4409c7a2 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java @@ -23,9 +23,10 @@ package org.schabi.newpipe.extractor.stream; import org.schabi.newpipe.extractor.Extractor; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.Subtitles; -import org.schabi.newpipe.extractor.UIHFactory; +import org.schabi.newpipe.extractor.uih.UIHFactory; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.uih.UIHandler; import org.schabi.newpipe.extractor.utils.Parser; import javax.annotation.Nonnull; @@ -39,8 +40,8 @@ public abstract class StreamExtractor extends Extractor { public static final int NO_AGE_LIMIT = 0; - public StreamExtractor(StreamingService service, UIHFactory UIHFactory) { - super(service, UIHFactory); + public StreamExtractor(StreamingService service, UIHandler uiHandler) { + super(service, uiHandler); } @Nonnull diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/uih/ListUIHFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/uih/ListUIHFactory.java new file mode 100644 index 000000000..111ee0456 --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/uih/ListUIHFactory.java @@ -0,0 +1,71 @@ +package org.schabi.newpipe.extractor.uih; + +import org.schabi.newpipe.extractor.exceptions.ParsingException; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public abstract class ListUIHFactory extends UIHFactory { + + /////////////////////////////////// + // To Override + /////////////////////////////////// + + public List getContentFilter(String url) throws ParsingException { return new ArrayList<>(0);} + public String getSortFilter(String url) throws ParsingException {return ""; } + public abstract String getUrl(String id, List contentFilter, String sortFilter) throws ParsingException; + + /////////////////////////////////// + // Logic + /////////////////////////////////// + + + @Override + public ListUIHandler fromUrl(String url) throws ParsingException { + if(url == null) throw new IllegalArgumentException("url may not be null"); + + return new ListUIHandler(super.fromUrl(url), getContentFilter(url), getSortFilter(url)); + } + + @Override + public ListUIHandler fromId(String id) throws ParsingException { + return new ListUIHandler(super.fromId(id), new ArrayList(0), ""); + } + + public ListUIHandler fromQuery(String id, + List contentFilters, + String sortFilter) throws ParsingException { + final String url = getUrl(id, contentFilters, sortFilter); + return new ListUIHandler(url, url, id, contentFilters, sortFilter); + } + + + /** + * For makeing ListUIHFactory compatible with UIHFactory we need to override this, + * however it should not be overridden by the actual implementation. + * @param id + * @return the url coresponding to id without any filters applied + */ + public String getUrl(String id) throws ParsingException { + return getUrl(id, new ArrayList(0), ""); + } + + /** + * Will returns content filter the corresponding extractor can handle like "channels", "videos", "music", etc. + * + * @return filter that can be applied when building a query for getting a list + */ + public String[] getAvailableContentFilter() { + return new String[0]; + } + + /** + * Will returns sort filter the corresponding extractor can handle like "A-Z", "oldest first", "size", etc. + * + * @return filter that can be applied when building a query for getting a list + */ + public String[] getAvailableSortFilter() { + return new String[0]; + } +} diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/uih/ListUIHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/uih/ListUIHandler.java new file mode 100644 index 000000000..b9151fa7b --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/uih/ListUIHandler.java @@ -0,0 +1,45 @@ +package org.schabi.newpipe.extractor.uih; + +import java.util.Collections; +import java.util.List; + +public class ListUIHandler extends UIHandler { + protected final List contentFilters; + protected final String sortFilter; + + public ListUIHandler(String originalUrl, + String url, + String id, + List contentFilters, + String sortFilter) { + super(originalUrl, url, id); + this.contentFilters = Collections.unmodifiableList(contentFilters); + this.sortFilter = sortFilter; + } + + public ListUIHandler(ListUIHandler handler) { + this(handler.originalUrl, + handler.url, + handler.id, + handler.contentFilters, + handler.sortFilter); + } + + public ListUIHandler(UIHandler handler, + List contentFilters, + String sortFilter) { + this(handler.originalUrl, + handler.url, + handler.id, + contentFilters, + sortFilter); + } + + public List getContentFilters() { + return contentFilters; + } + + public String getSortFilter() { + return sortFilter; + } +} diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/uih/SearchQIHFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/uih/SearchQIHFactory.java new file mode 100644 index 000000000..648dbd141 --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/uih/SearchQIHFactory.java @@ -0,0 +1,43 @@ +package org.schabi.newpipe.extractor.uih; + +import org.schabi.newpipe.extractor.exceptions.ParsingException; + +import java.util.ArrayList; +import java.util.List; + +public abstract class SearchQIHFactory extends ListUIHFactory { + + /////////////////////////////////// + // To Override + /////////////////////////////////// + + @Override + public abstract String getUrl(String querry, List contentFilter, String sortFilter) throws ParsingException; + public String getSearchString(String url) { return "";} + + /////////////////////////////////// + // Logic + /////////////////////////////////// + + @Override + public String getId(String url) { return getSearchString(url); } + + @Override + public SearchQIHandler fromQuery(String querry, + List contentFilter, + String sortFilter) throws ParsingException { + return new SearchQIHandler(super.fromQuery(querry, contentFilter, sortFilter)); + } + + public SearchQIHandler fromQuery(String querry) throws ParsingException { + return fromQuery(querry, new ArrayList(0), ""); + } + + /** + * It's not mandatorry for NewPipe to handle the Url + * @param url + * @return + */ + @Override + public boolean onAcceptUrl(String url) { return false; } +} diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/uih/SearchQIHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/uih/SearchQIHandler.java new file mode 100644 index 000000000..891a38f6c --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/uih/SearchQIHandler.java @@ -0,0 +1,32 @@ +package org.schabi.newpipe.extractor.uih; + +import java.util.List; + +public class SearchQIHandler extends ListUIHandler { + + public SearchQIHandler(String originalUrl, + String url, + String searchString, + List contentFilters, + String sortFilter) { + super(originalUrl, url, searchString, contentFilters, sortFilter); + } + + public SearchQIHandler(ListUIHandler handler) { + this(handler.originalUrl, + handler.url, + handler.id, + handler.contentFilters, + handler.sortFilter); + } + + + /** + * Returns the search string. Since ListQIHandler is based on ListUIHandler + * getSearchString() is equivalent to calling getId(). + * @return the search string + */ + public String getSearchString() { + return getId(); + } +} diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/UIHFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/uih/UIHFactory.java similarity index 63% rename from extractor/src/main/java/org/schabi/newpipe/extractor/UIHFactory.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/uih/UIHFactory.java index fbf4e7efd..08aebcae5 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/UIHFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/uih/UIHFactory.java @@ -1,5 +1,6 @@ -package org.schabi.newpipe.extractor; +package org.schabi.newpipe.extractor.uih; +import org.schabi.newpipe.extractor.exceptions.FoundAdException; import org.schabi.newpipe.extractor.exceptions.ParsingException; /* @@ -24,38 +25,32 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; public abstract class UIHFactory { - protected String id = ""; - protected String originalUrl = ""; + /////////////////////////////////// + // To Override + /////////////////////////////////// - public abstract String onGetIdFromUrl(String url) throws ParsingException; - public abstract String getUrl() throws ParsingException; + public abstract String getId(String url) throws ParsingException; + public abstract String getUrl(String id) throws ParsingException; public abstract boolean onAcceptUrl(final String url) throws ParsingException; + /////////////////////////////////// + // Logic + /////////////////////////////////// - public UIHFactory setUrl(String url) throws ParsingException { + public UIHandler fromUrl(String url) throws ParsingException { if(url == null) throw new IllegalArgumentException("url can not be null"); - originalUrl = url; - id = onGetIdFromUrl(url); - return this; - } - - public UIHFactory setId(String id) throws ParsingException { - if(id == null) throw new IllegalArgumentException("id can not be null"); - this.id = id; - if(!acceptUrl(getUrl())) { - throw new ParsingException("Malformed unacceptable url: " + getUrl()); + if(!acceptUrl(url)) { + throw new ParsingException("Malformed unacceptable url: " + url); } - return this; + + final String id = getId(url); + return new UIHandler(url, getUrl(id), id); } - public String getId() { - return id; - } - - public String getOriginalUrl() throws ParsingException { - return (originalUrl == null || originalUrl.isEmpty()) - ? getUrl() - : originalUrl; + public UIHandler fromId(String id) throws ParsingException { + if(id == null) throw new IllegalArgumentException("id can not be null"); + final String url = getUrl(id); + return new UIHandler(url, url, id); } /** @@ -63,11 +58,11 @@ public abstract class UIHFactory { * Intent was meant to be watched with this Service. * Return false if this service shall not allow to be called through ACTIONs. */ - public boolean acceptUrl(final String url) { + public boolean acceptUrl(final String url) throws ParsingException { try { return onAcceptUrl(url); - } catch (Exception e) { - return false; + } catch (FoundAdException fe) { + throw fe; } } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/uih/UIHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/uih/UIHandler.java new file mode 100644 index 000000000..5b0d3383e --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/uih/UIHandler.java @@ -0,0 +1,31 @@ +package org.schabi.newpipe.extractor.uih; + +import java.io.Serializable; + +public class UIHandler implements Serializable { + protected final String originalUrl; + protected final String url; + protected final String id; + + public UIHandler(String originalUrl, String url, String id) { + this.originalUrl = originalUrl; + this.url = url; + this.id = id; + } + + public UIHandler(UIHandler handler) { + this(handler.originalUrl, handler.url, handler.id); + } + + public String getOriginalUrl() { + return originalUrl; + } + + public String getUrl() { + return url; + } + + public String getId() { + return id; + } +} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUIHFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUIHFactoryTest.java index 70920368f..e5d8ca2bd 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUIHFactoryTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUIHFactoryTest.java @@ -24,14 +24,14 @@ public class SoundcloudChartsUIHFactoryTest { @Test public void getUrl() throws Exception { - assertEquals(urlIdHandler.setId("Top 50").getUrl(), "https://soundcloud.com/charts/top"); - assertEquals(urlIdHandler.setId("New & hot").getUrl(), "https://soundcloud.com/charts/new"); + assertEquals(urlIdHandler.fromId("Top 50").getUrl(), "https://soundcloud.com/charts/top"); + assertEquals(urlIdHandler.fromId("New & hot").getUrl(), "https://soundcloud.com/charts/new"); } @Test public void getId() throws ParsingException { - assertEquals(urlIdHandler.setUrl("http://soundcloud.com/charts/top?genre=all-music").getId(), "Top 50"); - assertEquals(urlIdHandler.setUrl("HTTP://www.soundcloud.com/charts/new/?genre=all-music&country=all-countries").getId(), "New & hot"); + assertEquals(urlIdHandler.fromUrl("http://soundcloud.com/charts/top?genre=all-music").getId(), "Top 50"); + assertEquals(urlIdHandler.fromUrl("HTTP://www.soundcloud.com/charts/new/?genre=all-music&country=all-countries").getId(), "New & hot"); } @Test diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUIHFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUIHFactoryTest.java index 5fb597d53..4084ac3bb 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUIHFactoryTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUIHFactoryTest.java @@ -25,7 +25,7 @@ public class SoundcloudStreamUIHFactoryTest { @Test(expected = IllegalArgumentException.class) public void getIdWithNullAsUrl() throws ParsingException { - urlIdHandler.setUrl(null).getId(); + urlIdHandler.fromUrl(null).getId(); } @Test @@ -37,7 +37,7 @@ public class SoundcloudStreamUIHFactoryTest { for (String invalidUrl : invalidUrls) { Throwable exception = null; try { - urlIdHandler.setUrl(invalidUrl).getId(); + urlIdHandler.fromUrl(invalidUrl).getId(); } catch (ParsingException e) { exception = e; } @@ -49,16 +49,16 @@ public class SoundcloudStreamUIHFactoryTest { @Test public void getId() throws Exception { - assertEquals("309689103", urlIdHandler.setUrl("https://soundcloud.com/liluzivert/15-ysl").getId()); - assertEquals("309689082", urlIdHandler.setUrl("https://www.soundcloud.com/liluzivert/15-luv-scars-ko").getId()); - assertEquals("309689035", urlIdHandler.setUrl("http://soundcloud.com/liluzivert/15-boring-shit").getId()); - assertEquals("294488599", urlIdHandler.setUrl("http://www.soundcloud.com/liluzivert/secure-the-bag-produced-by-glohan-beats").getId()); - assertEquals("294488438", urlIdHandler.setUrl("HtTpS://sOuNdClOuD.cOm/LiLuZiVeRt/In-O4-pRoDuCeD-bY-dP-bEaTz").getId()); - assertEquals("294488147", urlIdHandler.setUrl("https://soundcloud.com/liluzivert/fresh-produced-by-zaytoven#t=69").getId()); - assertEquals("294487876", urlIdHandler.setUrl("https://soundcloud.com/liluzivert/threesome-produced-by-zaytoven#t=1:09").getId()); - assertEquals("294487684", urlIdHandler.setUrl("https://soundcloud.com/liluzivert/blonde-brigitte-produced-manny-fresh#t=1:9").getId()); - assertEquals("294487428", urlIdHandler.setUrl("https://soundcloud.com/liluzivert/today-produced-by-c-note#t=1m9s").getId()); - assertEquals("294487157", urlIdHandler.setUrl("https://soundcloud.com/liluzivert/changed-my-phone-produced-by-c-note#t=1m09s").getId()); + assertEquals("309689103", urlIdHandler.fromUrl("https://soundcloud.com/liluzivert/15-ysl").getId()); + assertEquals("309689082", urlIdHandler.fromUrl("https://www.soundcloud.com/liluzivert/15-luv-scars-ko").getId()); + assertEquals("309689035", urlIdHandler.fromUrl("http://soundcloud.com/liluzivert/15-boring-shit").getId()); + assertEquals("294488599", urlIdHandler.fromUrl("http://www.soundcloud.com/liluzivert/secure-the-bag-produced-by-glohan-beats").getId()); + assertEquals("294488438", urlIdHandler.fromUrl("HtTpS://sOuNdClOuD.cOm/LiLuZiVeRt/In-O4-pRoDuCeD-bY-dP-bEaTz").getId()); + assertEquals("294488147", urlIdHandler.fromUrl("https://soundcloud.com/liluzivert/fresh-produced-by-zaytoven#t=69").getId()); + assertEquals("294487876", urlIdHandler.fromUrl("https://soundcloud.com/liluzivert/threesome-produced-by-zaytoven#t=1:09").getId()); + assertEquals("294487684", urlIdHandler.fromUrl("https://soundcloud.com/liluzivert/blonde-brigitte-produced-manny-fresh#t=1:9").getId()); + assertEquals("294487428", urlIdHandler.fromUrl("https://soundcloud.com/liluzivert/today-produced-by-c-note#t=1m9s").getId()); + assertEquals("294487157", urlIdHandler.fromUrl("https://soundcloud.com/liluzivert/changed-my-phone-produced-by-c-note#t=1m09s").getId()); } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSubscriptionExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSubscriptionExtractorTest.java index c27569a95..ebb5c3512 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSubscriptionExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSubscriptionExtractorTest.java @@ -5,7 +5,7 @@ import org.junit.Test; import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.ServiceList; -import org.schabi.newpipe.extractor.UIHFactory; +import org.schabi.newpipe.extractor.uih.UIHFactory; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionItem; diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorBaseTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorBaseTest.java index 9c164dcd2..db38c8d4a 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorBaseTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorBaseTest.java @@ -37,10 +37,15 @@ public abstract class SoundcloudSearchExtractorBaseTest { protected static ListExtractor.InfoItemsPage itemsPage; + protected static String removeClientId(String url) { + String[] splitUrl = url.split("client_id=[a-zA-Z0-9]*&"); + return splitUrl[0] + splitUrl[1]; + } + @Test public void testResultListElementsLength() { assertTrue(Integer.toString(itemsPage.getItems().size()), - itemsPage.getItems().size() >= 10); + itemsPage.getItems().size() >= 3); } @Test diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorChannelOnlyTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorChannelOnlyTest.java index c1816cb3a..e1ca59b01 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorChannelOnlyTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorChannelOnlyTest.java @@ -30,7 +30,7 @@ public class SoundcloudSearchExtractorChannelOnlyTest extends SoundcloudSearchEx asList(new String[]{"users"}), null, "de"); ListExtractor.InfoItemsPage secondPage = secondExtractor.getPage(itemsPage.getNextPageUrl()); assertTrue(Integer.toString(secondPage.getItems().size()), - secondPage.getItems().size() >= 7); + secondPage.getItems().size() >= 3); // check if its the same result boolean equals = true; @@ -43,14 +43,14 @@ public class SoundcloudSearchExtractorChannelOnlyTest extends SoundcloudSearchEx } assertFalse("First and second page are equal", equals); - assertEquals("https://api-v2.soundcloud.com/search/users?q=lill+uzi+vert&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=20", - secondPage.getNextPageUrl()); + assertEquals("https://api-v2.soundcloud.com/search/users?q=lill+uzi+vert&limit=10&offset=20", + removeClientId(secondPage.getNextPageUrl())); } @Test public void testGetSecondPageUrl() throws Exception { - assertEquals("https://api-v2.soundcloud.com/search/users?q=lill+uzi+vert&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=10", - extractor.getNextPageUrl()); + assertEquals("https://api-v2.soundcloud.com/search/users?q=lill+uzi+vert&limit=10&offset=10", + removeClientId(extractor.getNextPageUrl())); } @Test diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorDefaultTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorDefaultTest.java index 5dc5f63c8..81329bd0a 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorDefaultTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorDefaultTest.java @@ -50,8 +50,8 @@ public class SoundcloudSearchExtractorDefaultTest extends SoundcloudSearchExtrac @Test public void testGetSecondPageUrl() throws Exception { - assertEquals("https://api-v2.soundcloud.com/search?q=lill+uzi+vert&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=10", - extractor.getNextPageUrl()); + assertEquals("https://api-v2.soundcloud.com/search?q=lill+uzi+vert&limit=10&offset=10", + removeClientId(extractor.getNextPageUrl())); } @Test @@ -92,8 +92,8 @@ public class SoundcloudSearchExtractorDefaultTest extends SoundcloudSearchExtrac } assertFalse("First and second page are equal", equals); - assertEquals("https://api-v2.soundcloud.com/search?q=lill+uzi+vert&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=20", - secondPage.getNextPageUrl()); + assertEquals("https://api-v2.soundcloud.com/search?q=lill+uzi+vert&limit=10&offset=20", + removeClientId(secondPage.getNextPageUrl())); } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchQUHTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchQUHTest.java index 109af2023..a21db1138 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchQUHTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchQUHTest.java @@ -16,33 +16,43 @@ public class SoundcloudSearchQUHTest { NewPipe.init(Downloader.getInstance()); } + private static String removeClientId(String url) { + String[] splitUrl = url.split("client_id=[a-zA-Z0-9]*&"); + return splitUrl[0] + splitUrl[1]; + } + @Test public void testRegularValues() throws Exception { - assertEquals("https://api-v2.soundcloud.com/search?q=asdf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQIHFactory().setQuery("asdf").getUrl()); - assertEquals("https://api-v2.soundcloud.com/search?q=hans&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0",SoundCloud.getSearchQIHFactory().setQuery("hans").getUrl()); - assertEquals("https://api-v2.soundcloud.com/search?q=Poifj%26jaijf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQIHFactory().setQuery("Poifj&jaijf").getUrl()); - assertEquals("https://api-v2.soundcloud.com/search?q=G%C3%BCl%C3%BCm&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQIHFactory().setQuery("Gülüm").getUrl()); - assertEquals("https://api-v2.soundcloud.com/search?q=%3Fj%24%29H%C2%A7B&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQIHFactory().setQuery("?j$)H§B").getUrl()); + assertEquals("https://api-v2.soundcloud.com/search?q=asdf&limit=10&offset=0", + removeClientId(SoundCloud.getSearchQIHFactory().fromQuery("asdf").getUrl())); + assertEquals("https://api-v2.soundcloud.com/search?q=hans&limit=10&offset=0", + removeClientId(SoundCloud.getSearchQIHFactory().fromQuery("hans").getUrl())); + assertEquals("https://api-v2.soundcloud.com/search?q=Poifj%26jaijf&limit=10&offset=0", + removeClientId(SoundCloud.getSearchQIHFactory().fromQuery("Poifj&jaijf").getUrl())); + assertEquals("https://api-v2.soundcloud.com/search?q=G%C3%BCl%C3%BCm&limit=10&offset=0", + removeClientId(SoundCloud.getSearchQIHFactory().fromQuery("Gülüm").getUrl())); + assertEquals("https://api-v2.soundcloud.com/search?q=%3Fj%24%29H%C2%A7B&limit=10&offset=0", + removeClientId(SoundCloud.getSearchQIHFactory().fromQuery("?j$)H§B").getUrl())); } @Test public void testGetContentFilter() throws Exception { assertEquals("tracks", SoundCloud.getSearchQIHFactory() - .setQuery("", asList(new String[]{"tracks"}), "").getContentFilter().get(0)); + .fromQuery("", asList(new String[]{"tracks"}), "").getContentFilters().get(0)); assertEquals("users", SoundCloud.getSearchQIHFactory() - .setQuery("asdf", asList(new String[]{"users"}), "").getContentFilter().get(0)); + .fromQuery("asdf", asList(new String[]{"users"}), "").getContentFilters().get(0)); } @Test public void testWithContentfilter() throws Exception { - assertEquals("https://api-v2.soundcloud.com/search/tracks?q=asdf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQIHFactory() - .setQuery("asdf", asList(new String[]{"tracks"}), "").getUrl()); - assertEquals("https://api-v2.soundcloud.com/search/users?q=asdf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQIHFactory() - .setQuery("asdf", asList(new String[]{"users"}), "").getUrl()); - assertEquals("https://api-v2.soundcloud.com/search/playlists?q=asdf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQIHFactory() - .setQuery("asdf", asList(new String[]{"playlist"}), "").getUrl()); - assertEquals("https://api-v2.soundcloud.com/search?q=asdf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQIHFactory() - .setQuery("asdf", asList(new String[]{"fjiijie"}), "").getUrl()); + assertEquals("https://api-v2.soundcloud.com/search/tracks?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQIHFactory() + .fromQuery("asdf", asList(new String[]{"tracks"}), "").getUrl())); + assertEquals("https://api-v2.soundcloud.com/search/users?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQIHFactory() + .fromQuery("asdf", asList(new String[]{"users"}), "").getUrl())); + assertEquals("https://api-v2.soundcloud.com/search/playlists?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQIHFactory() + .fromQuery("asdf", asList(new String[]{"playlist"}), "").getUrl())); + assertEquals("https://api-v2.soundcloud.com/search?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQIHFactory() + .fromQuery("asdf", asList(new String[]{"fjiijie"}), "").getUrl())); } @Test diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelUIHFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelUIHFactoryTest.java index aff6aa35b..1be835aa8 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelUIHFactoryTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelUIHFactoryTest.java @@ -4,6 +4,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.exceptions.FoundAdException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeChannelUIHFactory; @@ -24,7 +25,7 @@ public class YoutubeChannelUIHFactoryTest { } @Test - public void acceptrUrlTest() { + public void acceptrUrlTest() throws ParsingException { assertTrue(urlIdHandler.acceptUrl("https://www.youtube.com/user/Gronkh")); assertTrue(urlIdHandler.acceptUrl("https://www.youtube.com/user/Netzkino/videos")); @@ -40,17 +41,17 @@ public class YoutubeChannelUIHFactoryTest { @Test public void getIdFromUrl() throws ParsingException { - assertEquals("user/Gronkh", urlIdHandler.setUrl("https://www.youtube.com/user/Gronkh").getId()); - assertEquals("user/Netzkino", urlIdHandler.setUrl("https://www.youtube.com/user/Netzkino/videos").getId()); + assertEquals("user/Gronkh", urlIdHandler.fromUrl("https://www.youtube.com/user/Gronkh").getId()); + assertEquals("user/Netzkino", urlIdHandler.fromUrl("https://www.youtube.com/user/Netzkino/videos").getId()); - assertEquals("channel/UClq42foiSgl7sSpLupnugGA", urlIdHandler.setUrl("https://www.youtube.com/channel/UClq42foiSgl7sSpLupnugGA").getId()); - assertEquals("channel/UClq42foiSgl7sSpLupnugGA", urlIdHandler.setUrl("https://www.youtube.com/channel/UClq42foiSgl7sSpLupnugGA/videos?disable_polymer=1").getId()); + assertEquals("channel/UClq42foiSgl7sSpLupnugGA", urlIdHandler.fromUrl("https://www.youtube.com/channel/UClq42foiSgl7sSpLupnugGA").getId()); + assertEquals("channel/UClq42foiSgl7sSpLupnugGA", urlIdHandler.fromUrl("https://www.youtube.com/channel/UClq42foiSgl7sSpLupnugGA/videos?disable_polymer=1").getId()); - assertEquals("user/Gronkh", urlIdHandler.setUrl("https://hooktube.com/user/Gronkh").getId()); - assertEquals("user/Netzkino", urlIdHandler.setUrl("https://hooktube.com/user/Netzkino/videos").getId()); + assertEquals("user/Gronkh", urlIdHandler.fromUrl("https://hooktube.com/user/Gronkh").getId()); + assertEquals("user/Netzkino", urlIdHandler.fromUrl("https://hooktube.com/user/Netzkino/videos").getId()); - assertEquals("channel/UClq42foiSgl7sSpLupnugGA", urlIdHandler.setUrl("https://hooktube.com/channel/UClq42foiSgl7sSpLupnugGA").getId()); - assertEquals("channel/UClq42foiSgl7sSpLupnugGA", urlIdHandler.setUrl("https://hooktube.com/channel/UClq42foiSgl7sSpLupnugGA/videos?disable_polymer=1").getId()); + assertEquals("channel/UClq42foiSgl7sSpLupnugGA", urlIdHandler.fromUrl("https://hooktube.com/channel/UClq42foiSgl7sSpLupnugGA").getId()); + assertEquals("channel/UClq42foiSgl7sSpLupnugGA", urlIdHandler.fromUrl("https://hooktube.com/channel/UClq42foiSgl7sSpLupnugGA/videos?disable_polymer=1").getId()); } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUIHFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUIHFactoryTest.java index 57210b707..e2e6f401f 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUIHFactoryTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUIHFactoryTest.java @@ -28,12 +28,12 @@ public class YoutubeStreamUIHFactoryTest { @Test(expected = IllegalArgumentException.class) public void getIdWithNullAsUrl() throws ParsingException { - urlIdHandler.setId(null); + urlIdHandler.fromId(null); } @Test(expected = FoundAdException.class) public void getIdForAd() throws ParsingException { - urlIdHandler.setUrl(AD_URL).getId(); + urlIdHandler.fromUrl(AD_URL).getId(); } @Test @@ -45,7 +45,7 @@ public class YoutubeStreamUIHFactoryTest { for (String invalidUrl : invalidUrls) { Throwable exception = null; try { - urlIdHandler.setUrl(invalidUrl).getId(); + urlIdHandler.fromUrl(invalidUrl).getId(); } catch (ParsingException e) { exception = e; } @@ -57,37 +57,37 @@ public class YoutubeStreamUIHFactoryTest { @Test public void getIdfromYt() throws Exception { - assertEquals("jZViOEv90dI", urlIdHandler.setUrl("https://www.youtube.com/watch?v=jZViOEv90dI").getId()); - assertEquals("W-fFHeTX70Q", urlIdHandler.setUrl("https://www.youtube.com/watch?v=W-fFHeTX70Q").getId()); - assertEquals("jZViOEv90dI", urlIdHandler.setUrl("https://www.youtube.com/watch?v=jZViOEv90dI?t=100").getId()); - assertEquals("jZViOEv90dI", urlIdHandler.setUrl("https://WWW.YouTube.com/watch?v=jZViOEv90dI?t=100").getId()); - assertEquals("jZViOEv90dI", urlIdHandler.setUrl("HTTPS://www.youtube.com/watch?v=jZViOEv90dI?t=100").getId()); - assertEquals("jZViOEv90dI", urlIdHandler.setUrl("https://youtu.be/jZViOEv90dI?t=9s").getId()); - assertEquals("jZViOEv90dI", urlIdHandler.setUrl("HTTPS://Youtu.be/jZViOEv90dI?t=9s").getId()); - assertEquals("uEJuoEs1UxY", urlIdHandler.setUrl("http://www.youtube.com/watch_popup?v=uEJuoEs1UxY").getId()); - assertEquals("uEJuoEs1UxY", urlIdHandler.setUrl("http://www.Youtube.com/watch_popup?v=uEJuoEs1UxY").getId()); - assertEquals("jZViOEv90dI", urlIdHandler.setUrl("https://www.youtube.com/embed/jZViOEv90dI").getId()); - assertEquals("jZViOEv90dI", urlIdHandler.setUrl("https://www.youtube-nocookie.com/embed/jZViOEv90dI").getId()); - assertEquals("jZViOEv90dI", urlIdHandler.setUrl("http://www.youtube.com/watch?v=jZViOEv90dI").getId()); - assertEquals("jZViOEv90dI", urlIdHandler.setUrl("http://youtube.com/watch?v=jZViOEv90dI").getId()); - assertEquals("jZViOEv90dI", urlIdHandler.setUrl("http://youtu.be/jZViOEv90dI?t=9s").getId()); - assertEquals("7_WWz2DSnT8", urlIdHandler.setUrl("https://youtu.be/7_WWz2DSnT8").getId()); - assertEquals("oy6NvWeVruY", urlIdHandler.setUrl("https://m.youtube.com/watch?v=oy6NvWeVruY").getId()); - assertEquals("jZViOEv90dI", urlIdHandler.setUrl("http://www.youtube.com/embed/jZViOEv90dI").getId()); - assertEquals("jZViOEv90dI", urlIdHandler.setUrl("http://www.Youtube.com/embed/jZViOEv90dI").getId()); - assertEquals("jZViOEv90dI", urlIdHandler.setUrl("http://www.youtube-nocookie.com/embed/jZViOEv90dI").getId()); - assertEquals("EhxJLojIE_o", urlIdHandler.setUrl("http://www.youtube.com/attribution_link?a=JdfC0C9V6ZI&u=%2Fwatch%3Fv%3DEhxJLojIE_o%26feature%3Dshare").getId()); - assertEquals("jZViOEv90dI", urlIdHandler.setUrl("vnd.youtube://www.youtube.com/watch?v=jZViOEv90dI").getId()); - assertEquals("jZViOEv90dI", urlIdHandler.setUrl("vnd.youtube:jZViOEv90dI").getId()); + assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("https://www.youtube.com/watch?v=jZViOEv90dI").getId()); + assertEquals("W-fFHeTX70Q", urlIdHandler.fromUrl("https://www.youtube.com/watch?v=W-fFHeTX70Q").getId()); + assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("https://www.youtube.com/watch?v=jZViOEv90dI?t=100").getId()); + assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("https://WWW.YouTube.com/watch?v=jZViOEv90dI?t=100").getId()); + assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("HTTPS://www.youtube.com/watch?v=jZViOEv90dI?t=100").getId()); + assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("https://youtu.be/jZViOEv90dI?t=9s").getId()); + assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("HTTPS://Youtu.be/jZViOEv90dI?t=9s").getId()); + assertEquals("uEJuoEs1UxY", urlIdHandler.fromUrl("http://www.youtube.com/watch_popup?v=uEJuoEs1UxY").getId()); + assertEquals("uEJuoEs1UxY", urlIdHandler.fromUrl("http://www.Youtube.com/watch_popup?v=uEJuoEs1UxY").getId()); + assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("https://www.youtube.com/embed/jZViOEv90dI").getId()); + assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("https://www.youtube-nocookie.com/embed/jZViOEv90dI").getId()); + assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("http://www.youtube.com/watch?v=jZViOEv90dI").getId()); + assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("http://youtube.com/watch?v=jZViOEv90dI").getId()); + assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("http://youtu.be/jZViOEv90dI?t=9s").getId()); + assertEquals("7_WWz2DSnT8", urlIdHandler.fromUrl("https://youtu.be/7_WWz2DSnT8").getId()); + assertEquals("oy6NvWeVruY", urlIdHandler.fromUrl("https://m.youtube.com/watch?v=oy6NvWeVruY").getId()); + assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("http://www.youtube.com/embed/jZViOEv90dI").getId()); + assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("http://www.Youtube.com/embed/jZViOEv90dI").getId()); + assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("http://www.youtube-nocookie.com/embed/jZViOEv90dI").getId()); + assertEquals("EhxJLojIE_o", urlIdHandler.fromUrl("http://www.youtube.com/attribution_link?a=JdfC0C9V6ZI&u=%2Fwatch%3Fv%3DEhxJLojIE_o%26feature%3Dshare").getId()); + assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("vnd.youtube://www.youtube.com/watch?v=jZViOEv90dI").getId()); + assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("vnd.youtube:jZViOEv90dI").getId()); } @Test public void getIdfromSharedLinksYt() throws Exception { String sharedId = "7JIArTByb3E"; String realId = "Q7JsK50NGaA"; - assertEquals(realId, urlIdHandler.setUrl("vnd.youtube://www.YouTube.com/shared?ci=" + sharedId + "&feature=twitter-deep-link").getId()); - assertEquals(realId, urlIdHandler.setUrl("vnd.youtube://www.youtube.com/shared?ci=" + sharedId).getId()); - assertEquals(realId, urlIdHandler.setUrl("https://www.youtube.com/shared?ci=" + sharedId).getId()); + assertEquals(realId, urlIdHandler.fromUrl("vnd.youtube://www.YouTube.com/shared?ci=" + sharedId + "&feature=twitter-deep-link").getId()); + assertEquals(realId, urlIdHandler.fromUrl("vnd.youtube://www.youtube.com/shared?ci=" + sharedId).getId()); + assertEquals(realId, urlIdHandler.fromUrl("https://www.youtube.com/shared?ci=" + sharedId).getId()); } @@ -131,11 +131,11 @@ public class YoutubeStreamUIHFactoryTest { @Test public void testGetHookIdfromUrl() throws ParsingException { - assertEquals("TglNG-yjabU", urlIdHandler.setUrl("https://hooktube.com/watch?v=TglNG-yjabU").getId()); - assertEquals("3msbfr6pBNE", urlIdHandler.setUrl("hooktube.com/watch?v=3msbfr6pBNE").getId()); - assertEquals("ocH3oSnZG3c", urlIdHandler.setUrl("https://hooktube.com/watch?v=ocH3oSnZG3c&list=PLS2VU1j4vzuZwooPjV26XM9UEBY2CPNn2").getId()); - assertEquals("3msbfr6pBNE", urlIdHandler.setUrl("hooktube.com/watch/3msbfr6pBNE").getId()); - assertEquals("3msbfr6pBNE", urlIdHandler.setUrl("hooktube.com/v/3msbfr6pBNE").getId()); - assertEquals("3msbfr6pBNE", urlIdHandler.setUrl("hooktube.com/embed/3msbfr6pBNE").getId()); + assertEquals("TglNG-yjabU", urlIdHandler.fromUrl("https://hooktube.com/watch?v=TglNG-yjabU").getId()); + assertEquals("3msbfr6pBNE", urlIdHandler.fromUrl("hooktube.com/watch?v=3msbfr6pBNE").getId()); + assertEquals("ocH3oSnZG3c", urlIdHandler.fromUrl("https://hooktube.com/watch?v=ocH3oSnZG3c&list=PLS2VU1j4vzuZwooPjV26XM9UEBY2CPNn2").getId()); + assertEquals("3msbfr6pBNE", urlIdHandler.fromUrl("hooktube.com/watch/3msbfr6pBNE").getId()); + assertEquals("3msbfr6pBNE", urlIdHandler.fromUrl("hooktube.com/v/3msbfr6pBNE").getId()); + assertEquals("3msbfr6pBNE", urlIdHandler.fromUrl("hooktube.com/embed/3msbfr6pBNE").getId()); } } \ No newline at end of file diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSubscriptionExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSubscriptionExtractorTest.java index 0e7adfbbd..cd921ae5b 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSubscriptionExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSubscriptionExtractorTest.java @@ -5,7 +5,7 @@ import org.junit.Test; import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.ServiceList; -import org.schabi.newpipe.extractor.UIHFactory; +import org.schabi.newpipe.extractor.uih.UIHFactory; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSubscriptionExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionItem; 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 5265fe1fe..b7f0a50bd 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 @@ -25,7 +25,7 @@ import org.junit.Test; import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; -import org.schabi.newpipe.extractor.UIHFactory; +import org.schabi.newpipe.extractor.uih.UIHFactory; import org.schabi.newpipe.extractor.kiosk.KioskInfo; import static org.junit.Assert.assertFalse; @@ -45,7 +45,7 @@ public class YoutubeTrendingKioskInfoTest { StreamingService service = YouTube; UIHFactory UIHFactory = service.getKioskList().getUrlIdHandlerByType("Trending"); - kioskInfo = KioskInfo.getInfo(YouTube, UIHFactory.setId("Trending").getUrl(), null); + kioskInfo = KioskInfo.getInfo(YouTube, UIHFactory.fromId("Trending").getUrl(), null); } @Test diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUIHFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUIHFactoryTest.java index fb9375e0f..3bbf7e949 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUIHFactoryTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUIHFactoryTest.java @@ -24,9 +24,13 @@ import org.junit.BeforeClass; import org.junit.Test; import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.UIHFactory; +import org.schabi.newpipe.extractor.exceptions.FoundAdException; +import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.uih.UIHFactory; import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeTrendingUIHFactory; +import java.text.ParseException; + import static junit.framework.TestCase.assertFalse; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -47,17 +51,17 @@ public class YoutubeTrendingUIHFactoryTest { @Test public void getUrl() throws Exception { - assertEquals(UIHFactory.setId("").getUrl(), "https://www.youtube.com/feed/trending"); + assertEquals(UIHFactory.fromId("").getUrl(), "https://www.youtube.com/feed/trending"); } @Test public void getId() throws Exception { - assertEquals(UIHFactory.setUrl("").getId(), "Trending"); + assertEquals(UIHFactory.fromUrl("https://www.youtube.com/feed/trending").getId(), "Trending"); } @Test - public void acceptUrl() { + public void acceptUrl() throws ParsingException { assertTrue(UIHFactory.acceptUrl("https://www.youtube.com/feed/trending")); assertTrue(UIHFactory.acceptUrl("https://www.youtube.com/feed/trending?adsf=fjaj#fhe")); assertTrue(UIHFactory.acceptUrl("http://www.youtube.com/feed/trending")); diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchQUHTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchQUHTest.java index 09d95f310..eddf4310b 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchQUHTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchQUHTest.java @@ -10,31 +10,31 @@ public class YoutubeSearchQUHTest { @Test public void testRegularValues() throws Exception { - assertEquals("https://www.youtube.com/results?q=asdf", YouTube.getSearchQIHFactory().setQuery("asdf").getUrl()); - assertEquals("https://www.youtube.com/results?q=hans",YouTube.getSearchQIHFactory().setQuery("hans").getUrl()); - assertEquals("https://www.youtube.com/results?q=Poifj%26jaijf", YouTube.getSearchQIHFactory().setQuery("Poifj&jaijf").getUrl()); - assertEquals("https://www.youtube.com/results?q=G%C3%BCl%C3%BCm", YouTube.getSearchQIHFactory().setQuery("Gülüm").getUrl()); - assertEquals("https://www.youtube.com/results?q=%3Fj%24%29H%C2%A7B", YouTube.getSearchQIHFactory().setQuery("?j$)H§B").getUrl()); + assertEquals("https://www.youtube.com/results?q=asdf", YouTube.getSearchQIHFactory().fromQuery("asdf").getUrl()); + assertEquals("https://www.youtube.com/results?q=hans",YouTube.getSearchQIHFactory().fromQuery("hans").getUrl()); + assertEquals("https://www.youtube.com/results?q=Poifj%26jaijf", YouTube.getSearchQIHFactory().fromQuery("Poifj&jaijf").getUrl()); + assertEquals("https://www.youtube.com/results?q=G%C3%BCl%C3%BCm", YouTube.getSearchQIHFactory().fromQuery("Gülüm").getUrl()); + assertEquals("https://www.youtube.com/results?q=%3Fj%24%29H%C2%A7B", YouTube.getSearchQIHFactory().fromQuery("?j$)H§B").getUrl()); } @Test public void testGetContentFilter() throws Exception { assertEquals("stream", YouTube.getSearchQIHFactory() - .setQuery("", asList(new String[]{"stream"}), "").getContentFilter().get(0)); + .fromQuery("", asList(new String[]{"stream"}), "").getContentFilters().get(0)); assertEquals("channel", YouTube.getSearchQIHFactory() - .setQuery("asdf", asList(new String[]{"channel"}), "").getContentFilter().get(0)); + .fromQuery("asdf", asList(new String[]{"channel"}), "").getContentFilters().get(0)); } @Test public void testWithContentfilter() throws Exception { assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQAVAU", YouTube.getSearchQIHFactory() - .setQuery("asdf", asList(new String[]{"stream"}), "").getUrl()); + .fromQuery("asdf", asList(new String[]{"stream"}), "").getUrl()); assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQAlAU", YouTube.getSearchQIHFactory() - .setQuery("asdf", asList(new String[]{"channel"}), "").getUrl()); + .fromQuery("asdf", asList(new String[]{"channel"}), "").getUrl()); assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQA1AU", YouTube.getSearchQIHFactory() - .setQuery("asdf", asList(new String[]{"playlist"}), "").getUrl()); + .fromQuery("asdf", asList(new String[]{"playlist"}), "").getUrl()); assertEquals("https://www.youtube.com/results?q=asdf", YouTube.getSearchQIHFactory() - .setQuery("asdf", asList(new String[]{"fjiijie"}), "").getUrl()); + .fromQuery("asdf", asList(new String[]{"fjiijie"}), "").getUrl()); } @Test