From b4544a67e85e32616d6025defb288d1f804c2cbe Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 13 May 2018 21:28:51 +0200 Subject: [PATCH 01/20] add SearchExtractor --- .../schabi/newpipe/extractor/Extractor.java | 3 +- .../org/schabi/newpipe/extractor/Info.java | 14 +++++- .../newpipe/extractor/ListExtractor.java | 5 ++ .../schabi/newpipe/extractor/ListInfo.java | 28 ++++++++++- .../newpipe/extractor/ListUrlIdHandler.java | 9 ++++ .../newpipe/extractor/StreamingService.java | 2 + .../extractor/channel/ChannelExtractor.java | 6 --- .../extractor/channel/ChannelInfo.java | 17 +++---- .../newpipe/extractor/kiosk/KioskInfo.java | 20 +++----- .../extractor/playlist/PlaylistExtractor.java | 6 --- .../extractor/playlist/PlaylistInfo.java | 18 ++++---- .../search/InfoItemsSearchCollector.java | 2 +- .../extractor/search/SearchExtractor.java | 38 +++++++++++++++ .../newpipe/extractor/search/SearchInfo.java | 46 +++++++++++++++++++ .../search/SearchQuerryUrlHandler.java | 11 +++++ .../soundcloud/SoundcloudChartsExtractor.java | 6 --- .../soundcloud/SoundcloudService.java | 7 +++ .../services/youtube/YoutubeService.java | 6 +++ .../extractors/YoutubeTrendingExtractor.java | 6 --- .../extractor/stream/StreamExtractor.java | 6 --- .../youtube/YoutubePlaylistExtractorTest.java | 2 +- 21 files changed, 189 insertions(+), 69 deletions(-) create mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchExtractor.java create mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchInfo.java create mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQuerryUrlHandler.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 832ec562..26625989 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java @@ -1,6 +1,5 @@ package org.schabi.newpipe.extractor; -import edu.umd.cs.findbugs.annotations.NonNull; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; @@ -34,7 +33,7 @@ public abstract class Extractor { * @return The {@link UrlIdHandler} of the current extractor object (e.g. a ChannelExtractor should return a channel url handler). */ @Nonnull - protected UrlIdHandler getUrlIdHandler() { + public UrlIdHandler getUrlIdHandler() { return urlIdHandler; } 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 974c4555..99b4d555 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/Info.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/Info.java @@ -1,5 +1,7 @@ package org.schabi.newpipe.extractor; +import org.schabi.newpipe.extractor.exceptions.ParsingException; + import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; @@ -16,8 +18,8 @@ public abstract class Info implements Serializable { /** * Different than the {@link #originalUrl} in the sense that it may be set as a cleaned url. * - * @see UrlIdHandler#cleanUrl(String) - * @see Extractor#getCleanUrl() + * @see UrlIdHandler#getUrl() + * @see Extractor#getOriginalUrl() */ private final String url; /** @@ -46,6 +48,14 @@ public abstract class Info implements Serializable { this.name = name; } + public Info(int serviceId, UrlIdHandler urlIdHandler, String name) throws ParsingException { + this(serviceId, + urlIdHandler.getId(), + urlIdHandler.getUrl(), + urlIdHandler.getOriginalUrl(), + name); + } + @Override public String toString() { final String ifDifferentString = !url.equals(originalUrl) ? " (originalUrl=\"" + originalUrl + "\")" : ""; 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 e1a79011..0f68707b 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java @@ -49,6 +49,11 @@ public abstract class ListExtractor extends Extractor { return nextPageUrl != null && !nextPageUrl.isEmpty(); } + @Override + public ListUrlIdHandler getUrlIdHandler() { + return (ListUrlIdHandler) super.getUrlIdHandler(); + } + /*////////////////////////////////////////////////////////////////////////// // Inner //////////////////////////////////////////////////////////////////////////*/ 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 1b8ce1d9..c676956c 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/ListInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/ListInfo.java @@ -1,13 +1,31 @@ package org.schabi.newpipe.extractor; +import org.schabi.newpipe.extractor.exceptions.ParsingException; + import java.util.List; public abstract class ListInfo extends Info { private List relatedItems; private String nextPageUrl = null; + private String[] contentFilter = {}; + private String sortFilter = ""; - public ListInfo(int serviceId, String id, String url, String originalUrl, String name) { + public ListInfo(int serviceId, + String id, + String url, + String originalUrl, + String name, + String[] contentFilter, + String sortFilter) { super(serviceId, id, url, originalUrl, name); + this.contentFilter = contentFilter; + this.sortFilter = sortFilter; + } + + public ListInfo(int serviceId, ListUrlIdHandler listUrlIdHandler, String name) throws ParsingException { + super(serviceId, listUrlIdHandler, name); + this.contentFilter = listUrlIdHandler.getContentFilter(); + this.sortFilter = listUrlIdHandler.getSortFilter(); } public List getRelatedItems() { @@ -29,4 +47,12 @@ public abstract class ListInfo extends Info { public void setNextPageUrl(String pageUrl) { this.nextPageUrl = pageUrl; } + + public String[] getContentFilter() { + return contentFilter; + } + + public String getSortFilter() { + return sortFilter; + } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/ListUrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/ListUrlIdHandler.java index 43ff19c8..aca3e50d 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/ListUrlIdHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/ListUrlIdHandler.java @@ -39,4 +39,13 @@ public abstract class ListUrlIdHandler extends UrlIdHandler { public String[] getAvailableSortFilter() { return new String[0]; } + + + public String[] 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 fc68dd30..8349b10d 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java @@ -6,6 +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.SearchEngine; +import org.schabi.newpipe.extractor.search.SearchExtractor; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; @@ -75,6 +76,7 @@ public abstract class StreamingService { // Extractor //////////////////////////////////////////// public abstract SearchEngine getSearchEngine(); + public abstract SearchExtractor getSearchExtractor(); public abstract SuggestionExtractor getSuggestionExtractor(); public abstract SubscriptionExtractor getSubscriptionExtractor(); public abstract KioskList getKioskList() throws ExtractionException; 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 625f6381..9d6bef52 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 @@ -36,12 +36,6 @@ public abstract class ChannelExtractor extends ListExtractor { super(service, urlIdHandler); } - @Nonnull - @Override - protected UrlIdHandler getUrlIdHandler() { - return getService().getChannelUrlIdHandler(); - } - public abstract String getAvatarUrl() throws ParsingException; public abstract String getBannerUrl() throws ParsingException; public abstract String getFeedUrl() throws ParsingException; 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 fd5868b2..38f2b6e4 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,9 +2,11 @@ package org.schabi.newpipe.extractor.channel; import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage; import org.schabi.newpipe.extractor.ListInfo; +import org.schabi.newpipe.extractor.ListUrlIdHandler; 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.utils.ExtractorHelper; @@ -32,8 +34,8 @@ import java.io.IOException; public class ChannelInfo extends ListInfo { - public ChannelInfo(int serviceId, String id, String url, String originalUrl, String name) { - super(serviceId, id, url, originalUrl, name); + public ChannelInfo(int serviceId, ListUrlIdHandler urlIdHandler, String name) throws ParsingException { + super(serviceId, urlIdHandler, name); } public static ChannelInfo getInfo(String url) throws IOException, ExtractionException { @@ -52,14 +54,9 @@ public class ChannelInfo extends ListInfo { public static ChannelInfo getInfo(ChannelExtractor extractor) throws IOException, ExtractionException { - // important data - int serviceId = extractor.getServiceId(); - String url = extractor.getUrl(); - String originalUrl = extractor.getOriginalUrl(); - String id = extractor.getId(); - String name = extractor.getName(); - - ChannelInfo info = new ChannelInfo(serviceId, id, url, originalUrl, name); + ChannelInfo info = new ChannelInfo(extractor.getServiceId(), + extractor.getUrlIdHandler(), + extractor.getName()); try { 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 f11ebb9f..56feb40e 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 @@ -20,11 +20,9 @@ package org.schabi.newpipe.extractor.kiosk; * along with NewPipe. If not, see . */ -import org.schabi.newpipe.extractor.ListExtractor; -import org.schabi.newpipe.extractor.ListInfo; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.StreamingService; +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.utils.ExtractorHelper; @@ -32,8 +30,8 @@ import java.io.IOException; public class KioskInfo extends ListInfo { - private KioskInfo(int serviceId, String id, String url, String originalUrl, String name) { - super(serviceId, id, url, originalUrl, name); + private KioskInfo(int serviceId, ListUrlIdHandler urlIdHandler, String name) throws ParsingException { + super(serviceId, urlIdHandler, name); } public static ListExtractor.InfoItemsPage getMoreItems(StreamingService service, @@ -68,13 +66,9 @@ public class KioskInfo extends ListInfo { */ public static KioskInfo getInfo(KioskExtractor extractor) throws ExtractionException { - int serviceId = extractor.getServiceId(); - String name = extractor.getName(); - String id = extractor.getId(); - String url = extractor.getUrl(); - String originalUrl = extractor.getOriginalUrl(); - - KioskInfo info = new KioskInfo(serviceId, id, url, originalUrl, name); + final KioskInfo info = new KioskInfo(extractor.getServiceId(), + extractor.getUrlIdHandler(), + extractor.getName()); final ListExtractor.InfoItemsPage itemsPage = ExtractorHelper.getItemsPageOrLogError(info, extractor); info.setRelatedItems(itemsPage.getItems()); 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 cc7107f7..490367fe 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 @@ -16,12 +16,6 @@ public abstract class PlaylistExtractor extends ListExtractor { super(service, urlIdHandler); } - @Nonnull - @Override - protected UrlIdHandler getUrlIdHandler() { - return getService().getPlaylistUrlIdHandler(); - } - public abstract String getThumbnailUrl() throws ParsingException; public abstract String getBannerUrl() throws ParsingException; 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 29f7b144..cdc6c5fe 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,9 +2,11 @@ package org.schabi.newpipe.extractor.playlist; import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage; import org.schabi.newpipe.extractor.ListInfo; +import org.schabi.newpipe.extractor.ListUrlIdHandler; 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.utils.ExtractorHelper; @@ -12,8 +14,8 @@ import java.io.IOException; public class PlaylistInfo extends ListInfo { - public PlaylistInfo(int serviceId, String id, String url, String originalUrl, String name) { - super(serviceId, id, url, originalUrl, name); + public PlaylistInfo(int serviceId, ListUrlIdHandler urlIdHandler, String name) throws ParsingException { + super(serviceId, urlIdHandler, name); } public static PlaylistInfo getInfo(String url) throws IOException, ExtractionException { @@ -35,14 +37,12 @@ public class PlaylistInfo extends ListInfo { * * @param extractor an extractor where fetchPage() was already got called on. */ - public static PlaylistInfo getInfo(PlaylistExtractor extractor) throws IOException, ExtractionException { + public static PlaylistInfo getInfo(PlaylistExtractor extractor) throws ExtractionException { - int serviceId = extractor.getServiceId(); - String url = extractor.getUrl(); - String originalUrl = extractor.getOriginalUrl(); - String id = extractor.getId(); - String name = extractor.getName(); - PlaylistInfo info = new PlaylistInfo(serviceId, id, url, originalUrl, name); + final PlaylistInfo info = new PlaylistInfo( + extractor.getServiceId(), + extractor.getUrlIdHandler(), + extractor.getName()); try { info.setStreamCount(extractor.getStreamCount()); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/search/InfoItemsSearchCollector.java b/extractor/src/main/java/org/schabi/newpipe/extractor/search/InfoItemsSearchCollector.java index d8f4ca0f..87735cd5 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/search/InfoItemsSearchCollector.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/search/InfoItemsSearchCollector.java @@ -61,7 +61,7 @@ public class InfoItemsSearchCollector extends InfoItemsCollector { + + public static class NothingFoundException extends ExtractionException { + public NothingFoundException(String message) { + super(message); + } + } + + private final InfoItemsSearchCollector collector; + + public SearchExtractor(StreamingService service, SearchQuerryUrlHandler urlIdHandler) { + super(service, urlIdHandler); + collector = new InfoItemsSearchCollector(service.getServiceId()); + } + + public String getSearchQuerry() { + return getUrlIdHandler().getSearchQuerry(); + } + + public abstract String getSearchSuggestion() throws ParsingException; + protected InfoItemsSearchCollector getInfoItemSearchCollector() { + return collector; + } + + @Override + public SearchQuerryUrlHandler getUrlIdHandler() { + return (SearchQuerryUrlHandler) super.getUrlIdHandler(); + } + +} 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 new file mode 100644 index 00000000..963890d1 --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchInfo.java @@ -0,0 +1,46 @@ +package org.schabi.newpipe.extractor.search; + +import org.schabi.newpipe.extractor.InfoItem; +import org.schabi.newpipe.extractor.ListInfo; +import org.schabi.newpipe.extractor.ListUrlIdHandler; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.exceptions.ParsingException; + +public class SearchInfo extends ListInfo { + + private String searchQuerry = ""; + private String searchSuggestion = ""; + + + public SearchInfo(int serviceId, + ListUrlIdHandler urlIdHandler, + String searchQuerry) throws ParsingException { + super(serviceId, urlIdHandler, "Search"); + this.searchQuerry = searchQuerry; + } + + + public static SearchInfo getInfo(SearchExtractor extractor) throws ExtractionException { + final SearchInfo info = new SearchInfo( + extractor.getServiceId(), + extractor.getUrlIdHandler(), + extractor.getSearchQuerry()); + + try { + info.searchSuggestion = extractor.getSearchSuggestion(); + } catch (Exception e) { + info.addError(e); + } + + return info; + } + + // Getter + public String getSearchQuerry() { + return searchQuerry; + } + + public String getSearchSuggestion() { + return searchSuggestion; + } +} diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQuerryUrlHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQuerryUrlHandler.java new file mode 100644 index 00000000..dfaa6406 --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQuerryUrlHandler.java @@ -0,0 +1,11 @@ +package org.schabi.newpipe.extractor.search; + +import org.schabi.newpipe.extractor.ListUrlIdHandler; + +public abstract class SearchQuerryUrlHandler extends ListUrlIdHandler { + String searchQuerry; + + public String getSearchQuerry() { + return searchQuerry; + } +} 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 655d4c06..d2423fcb 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 @@ -32,12 +32,6 @@ public class SoundcloudChartsExtractor extends KioskExtractor { return getId(); } - @Nonnull - @Override - public UrlIdHandler getUrlIdHandler() { - return new SoundcloudChartsUrlIdHandler(); - } - @Override public InfoItemsPage getPage(String pageUrl) throws IOException, ExtractionException { if (pageUrl == null || pageUrl.isEmpty()) { 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 b3e90e72..38cf7fb2 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 @@ -10,6 +10,7 @@ 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.stream.StreamExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; @@ -27,6 +28,12 @@ public class SoundcloudService extends StreamingService { return new SoundcloudSearchEngine(getServiceId()); } + @Override + public SearchExtractor getSearchExtractor() { + return null; + } + + @Override public UrlIdHandler getStreamUrlIdHandler() { return SoundcloudStreamUrlIdHandler.getInstance(); 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 77929139..7b400d50 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 @@ -10,6 +10,7 @@ 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.services.youtube.extractors.*; import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeChannelUrlIdHandler; import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubePlaylistUrlIdHandler; @@ -53,6 +54,11 @@ public class YoutubeService extends StreamingService { return new YoutubeSearchEngine(getServiceId()); } + @Override + public SearchExtractor getSearchExtractor() { + return null; + } + @Override public UrlIdHandler getStreamUrlIdHandler() { return YoutubeStreamUrlIdHandler.getInstance(); 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 9c4cb080..94b9cc6c 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 @@ -59,12 +59,6 @@ public class YoutubeTrendingExtractor extends KioskExtractor { doc = Jsoup.parse(pageContent, url); } - @Nonnull - @Override - public UrlIdHandler getUrlIdHandler() { - return new YoutubeTrendingUrlIdHandler(); - } - @Override public String getNextPageUrl() { return ""; 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 a03bb613..ff8c9f41 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 @@ -43,12 +43,6 @@ public abstract class StreamExtractor extends Extractor { super(service, urlIdHandler); } - @Nonnull - @Override - protected UrlIdHandler getUrlIdHandler() { - return getService().getStreamUrlIdHandler(); - } - @Nonnull public abstract String getUploadDate() throws ParsingException; @Nonnull diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java index 957ceacc..2bfccbd0 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java @@ -46,7 +46,7 @@ public class YoutubePlaylistExtractorTest { @Test public void testName() throws Exception { String name = extractor.getName(); - assertTrue(name, name.startsWith("Pop Music Playlist: Timeless Pop Hits")); + assertTrue(name, name.startsWith("Pop Music Playlist")); } @Test From 06c67763d22ae1d53da9ecd77ddfc1e044969766 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sat, 26 May 2018 19:15:45 +0200 Subject: [PATCH 02/20] remove soundcloud and make first search test work --- .../schabi/newpipe/extractor/Extractor.java | 4 + .../newpipe/extractor/ListExtractor.java | 4 +- .../schabi/newpipe/extractor/ListInfo.java | 8 +- .../newpipe/extractor/ListUrlIdHandler.java | 19 +- .../schabi/newpipe/extractor/ServiceList.java | 11 +- .../newpipe/extractor/StreamingService.java | 17 +- .../search/InfoItemsSearchCollector.java | 9 - .../extractor/search/SearchExtractor.java | 21 +- .../newpipe/extractor/search/SearchInfo.java | 12 +- .../search/SearchQuerryUrlHandler.java | 11 - .../search/SearchQueryUrlHandler.java | 45 +++ .../extractor/search/SearchResult.java | 2 +- .../soundcloud/SoundcloudQueryUrlHandler.java | 62 ++++ .../soundcloud/SoundcloudService.java | 7 +- .../services/youtube/YoutubeService.java | 15 +- .../extractors/YoutubePlaylistExtractor.java | 4 +- .../extractors/YoutubeSearchEngine.java | 1 - .../extractors/YoutubeSearchExtractor.java | 128 +++++++ .../YoutubeSearchQueryUrlHandler.java | 52 +++ .../schabi/newpipe/extractor/NewPipeTest.java | 17 - .../soundcloud/BaseSoundcloudSearchTest.java | 57 ---- .../SoundcloudChannelExtractorTest.java | 198 ----------- .../SoundcloudChartsExtractorTest.java | 93 ----- .../SoundcloudChartsUrlIdHandlerTest.java | 50 --- .../SoundcloudParsingHelperTest.java | 28 -- .../SoundcloudPlaylistExtractorTest.java | 319 ------------------ .../SoundcloudSearchEngineAllTest.java | 35 -- .../SoundcloudSearchEngineChannelTest.java | 44 --- .../SoundcloudSearchEnginePlaylistTest.java | 64 ---- .../SoundcloudSearchEngineStreamTest.java | 44 --- .../SoundcloudStreamExtractorDefaultTest.java | 119 ------- .../SoundcloudStreamUrlIdHandlerTest.java | 78 ----- .../SoundcloudSubscriptionExtractorTest.java | 76 ----- .../SoundcloudSuggestionExtractorTest.java | 31 -- .../youtube/BaseYoutubeSearchTest.java | 54 --- .../YoutubeSearchEngineChannelTest.java | 65 ---- .../YoutubeSearchEnginePlaylistTest.java | 67 ---- .../YoutubeSearchEngineStreamTest.java | 65 ---- .../services/youtube/YoutubeServiceTest.java | 2 +- .../YoutubeSearchExtractorAllTest.java} | 26 +- 40 files changed, 387 insertions(+), 1577 deletions(-) delete mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQuerryUrlHandler.java create mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQueryUrlHandler.java create mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudQueryUrlHandler.java create mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java create mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeSearchQueryUrlHandler.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/BaseSoundcloudSearchTest.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractorTest.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandlerTest.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelperTest.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractorTest.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineAllTest.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineChannelTest.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEnginePlaylistTest.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineStreamTest.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUrlIdHandlerTest.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSubscriptionExtractorTest.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSuggestionExtractorTest.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/BaseYoutubeSearchTest.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineChannelTest.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEnginePlaylistTest.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineStreamTest.java rename extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/{YoutubeSearchEngineAllTest.java => search/YoutubeSearchExtractorAllTest.java} (69%) 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 26625989..1e9b5dac 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java @@ -95,4 +95,8 @@ public abstract class Extractor { public int getServiceId() { return service.getServiceId(); } + + public Downloader getDownloader() { + return downloader; + } } 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 0f68707b..e22ecc04 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java @@ -37,12 +37,12 @@ public abstract class ListExtractor extends Extractor { /** * Get a list of items corresponding to the specific requested page. * - * @param nextPageUrl any next page url got from the exclusive implementation of the list extractor + * @param pageUrl any page url got from the exclusive implementation of the list extractor * @return a {@link InfoItemsPage} corresponding to the requested page * @see #getNextPageUrl() * @see InfoItemsPage#getNextPageUrl() */ - public abstract InfoItemsPage getPage(final String nextPageUrl) throws IOException, ExtractionException; + public abstract InfoItemsPage getPage(final String pageUrl) throws IOException, ExtractionException; public boolean hasNextPage() throws IOException, ExtractionException { final String nextPageUrl = getNextPageUrl(); 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 c676956c..7a1b9fac 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/ListInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/ListInfo.java @@ -1,13 +1,15 @@ package org.schabi.newpipe.extractor; +import com.sun.org.apache.xerces.internal.xs.StringList; import org.schabi.newpipe.extractor.exceptions.ParsingException; +import java.util.ArrayList; import java.util.List; public abstract class ListInfo extends Info { private List relatedItems; private String nextPageUrl = null; - private String[] contentFilter = {}; + private List contentFilter = new ArrayList<>(); private String sortFilter = ""; public ListInfo(int serviceId, @@ -15,7 +17,7 @@ public abstract class ListInfo extends Info { String url, String originalUrl, String name, - String[] contentFilter, + List contentFilter, String sortFilter) { super(serviceId, id, url, originalUrl, name); this.contentFilter = contentFilter; @@ -48,7 +50,7 @@ public abstract class ListInfo extends Info { this.nextPageUrl = pageUrl; } - public String[] getContentFilter() { + public List getContentFilter() { return contentFilter; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/ListUrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/ListUrlIdHandler.java index aca3e50d..494b714a 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/ListUrlIdHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/ListUrlIdHandler.java @@ -2,18 +2,29 @@ package org.schabi.newpipe.extractor; import org.schabi.newpipe.extractor.exceptions.ParsingException; +import java.util.ArrayList; +import java.util.List; + public abstract class ListUrlIdHandler extends UrlIdHandler { - protected String[] contentFilter; - protected String sortFilter; + protected List contentFilter = new ArrayList<>(0); + protected String sortFilter = ""; - public ListUrlIdHandler setQuery(String id, String[] contentFilter, String softFilter) throws ParsingException { + public ListUrlIdHandler setQuery(String id, + List contentFilter, + String softFilter) throws ParsingException { setId(id); this.contentFilter = contentFilter; this.sortFilter = softFilter; return this; } + + public ListUrlIdHandler setQuery(String id) throws ParsingException { + setQuery(id, new ArrayList(), ""); + return this; + } + public ListUrlIdHandler setUrl(String url) throws ParsingException { return (ListUrlIdHandler) super.setUrl(url); } @@ -41,7 +52,7 @@ public abstract class ListUrlIdHandler extends UrlIdHandler { } - public String[] getContentFilter() { + public List getContentFilter() { return contentFilter; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/ServiceList.java b/extractor/src/main/java/org/schabi/newpipe/extractor/ServiceList.java index a49905e0..f61e204d 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/ServiceList.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/ServiceList.java @@ -1,6 +1,5 @@ package org.schabi.newpipe.extractor; -import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudService; import org.schabi.newpipe.extractor.services.youtube.YoutubeService; import java.util.List; @@ -16,14 +15,10 @@ public final class ServiceList { //no instance } - public static final YoutubeService YouTube; - public static final SoundcloudService SoundCloud; + public static final YoutubeService YouTube = new YoutubeService(0); - private static final List SERVICES = unmodifiableList(asList( - YouTube = new YoutubeService(0), - SoundCloud = new SoundcloudService(1) - // DailyMotion = new DailyMotionService(2); - )); + private static final List SERVICES = unmodifiableList( + asList((StreamingService) YouTube)); /** * Get all the supported services. 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 8349b10d..e0ef1978 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java @@ -1,5 +1,6 @@ package org.schabi.newpipe.extractor; +import com.sun.org.apache.xerces.internal.xs.StringList; import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; @@ -7,6 +8,7 @@ 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.SearchQueryUrlHandler; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; @@ -70,13 +72,14 @@ public abstract class StreamingService { public abstract UrlIdHandler getStreamUrlIdHandler(); public abstract ListUrlIdHandler getChannelUrlIdHandler(); public abstract ListUrlIdHandler getPlaylistUrlIdHandler(); + public abstract SearchQueryUrlHandler getSearchQueryHandler(); //////////////////////////////////////////// // Extractor //////////////////////////////////////////// public abstract SearchEngine getSearchEngine(); - public abstract SearchExtractor getSearchExtractor(); + public abstract SearchExtractor getSearchExtractor(SearchQueryUrlHandler queryHandler, String contentCountry); public abstract SuggestionExtractor getSuggestionExtractor(); public abstract SubscriptionExtractor getSubscriptionExtractor(); public abstract KioskList getKioskList() throws ExtractionException; @@ -85,14 +88,22 @@ public abstract class StreamingService { public abstract PlaylistExtractor getPlaylistExtractor(ListUrlIdHandler urlIdHandler) throws ExtractionException; public abstract StreamExtractor getStreamExtractor(UrlIdHandler urlIdHandler) throws ExtractionException; - public ChannelExtractor getChannelExtractor(String id, String[] contentFilter, String sortFilter) throws ExtractionException { + public SearchExtractor getSearchExtractor(String query, List contentFilter, String softFilter, String contentCountry) throws ExtractionException { + return getSearchExtractor(getSearchQueryHandler().setQuery(query, contentFilter, softFilter), contentCountry); + } + + public ChannelExtractor getChannelExtractor(String id, List contentFilter, String sortFilter) throws ExtractionException { return getChannelExtractor(getChannelUrlIdHandler().setQuery(id, contentFilter, sortFilter)); } - public PlaylistExtractor getPlaylistExtractor(String id, String[] contentFilter, String sortFilter) throws ExtractionException { + public PlaylistExtractor getPlaylistExtractor(String id, List contentFilter, String sortFilter) throws ExtractionException { return getPlaylistExtractor(getPlaylistUrlIdHandler().setQuery(id, contentFilter, sortFilter)); } + public SearchExtractor getSearchExtractor(String query, String contentCountry) throws ExtractionException { + return getSearchExtractor(getSearchQueryHandler().setQuery(query), contentCountry); + } + public ChannelExtractor getChannelExtractor(String url) throws ExtractionException { return getChannelExtractor(getChannelUrlIdHandler().setUrl(url)); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/search/InfoItemsSearchCollector.java b/extractor/src/main/java/org/schabi/newpipe/extractor/search/InfoItemsSearchCollector.java index 87735cd5..bad31ea2 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/search/InfoItemsSearchCollector.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/search/InfoItemsSearchCollector.java @@ -45,7 +45,6 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; * other extractor type will raise an exception. */ public class InfoItemsSearchCollector extends InfoItemsCollector { - private String suggestion = ""; private final StreamInfoItemsCollector streamCollector; private final ChannelInfoItemsCollector userCollector; private final PlaylistInfoItemsCollector playlistCollector; @@ -57,14 +56,6 @@ public class InfoItemsSearchCollector extends InfoItemsCollector { } private final InfoItemsSearchCollector collector; + private final String contentCountry; - public SearchExtractor(StreamingService service, SearchQuerryUrlHandler urlIdHandler) { + public SearchExtractor(StreamingService service, SearchQueryUrlHandler urlIdHandler, String contentCountry) { super(service, urlIdHandler); collector = new InfoItemsSearchCollector(service.getServiceId()); + this.contentCountry = contentCountry; } - public String getSearchQuerry() { - return getUrlIdHandler().getSearchQuerry(); + public String getSearchString() { + return getUrlIdHandler().getSearchString(); } public abstract String getSearchSuggestion() throws ParsingException; + protected InfoItemsSearchCollector getInfoItemSearchCollector() { return collector; } @Override - public SearchQuerryUrlHandler getUrlIdHandler() { - return (SearchQuerryUrlHandler) super.getUrlIdHandler(); + public SearchQueryUrlHandler getUrlIdHandler() { + return (SearchQueryUrlHandler) super.getUrlIdHandler(); } + @Override + public String getName() { + return getUrlIdHandler().getSearchString(); + } + + protected String getContentCountry() { + return contentCountry; + } } 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 963890d1..6b7c8b8b 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 @@ -8,15 +8,15 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; public class SearchInfo extends ListInfo { - private String searchQuerry = ""; + private String searchString = ""; private String searchSuggestion = ""; public SearchInfo(int serviceId, ListUrlIdHandler urlIdHandler, - String searchQuerry) throws ParsingException { + String searchString) throws ParsingException { super(serviceId, urlIdHandler, "Search"); - this.searchQuerry = searchQuerry; + this.searchString = searchString; } @@ -24,7 +24,7 @@ public class SearchInfo extends ListInfo { final SearchInfo info = new SearchInfo( extractor.getServiceId(), extractor.getUrlIdHandler(), - extractor.getSearchQuerry()); + extractor.getSearchString()); try { info.searchSuggestion = extractor.getSearchSuggestion(); @@ -36,8 +36,8 @@ public class SearchInfo extends ListInfo { } // Getter - public String getSearchQuerry() { - return searchQuerry; + public String getSearchString() { + return searchString; } public String getSearchSuggestion() { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQuerryUrlHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQuerryUrlHandler.java deleted file mode 100644 index dfaa6406..00000000 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQuerryUrlHandler.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.schabi.newpipe.extractor.search; - -import org.schabi.newpipe.extractor.ListUrlIdHandler; - -public abstract class SearchQuerryUrlHandler extends ListUrlIdHandler { - String searchQuerry; - - public String getSearchQuerry() { - return searchQuerry; - } -} diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQueryUrlHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQueryUrlHandler.java new file mode 100644 index 00000000..d281376b --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQueryUrlHandler.java @@ -0,0 +1,45 @@ +package org.schabi.newpipe.extractor.search; + +import org.schabi.newpipe.extractor.ListUrlIdHandler; +import org.schabi.newpipe.extractor.UrlIdHandler; +import org.schabi.newpipe.extractor.exceptions.ParsingException; + +import java.util.List; + +public abstract class SearchQueryUrlHandler extends ListUrlIdHandler { + + @Override + public String onGetIdFromUrl(String url) { + return "Search"; + } + + public String getSearchString() { + return getId(); + } + + @Override + public SearchQueryUrlHandler setQuery(String querry, + List contentFilter, + String sortFilter) throws ParsingException { + return (SearchQueryUrlHandler) super.setQuery(querry, contentFilter, sortFilter); + } + + + @Override + public SearchQueryUrlHandler setQuery(String querry) throws ParsingException { + return (SearchQueryUrlHandler) super.setQuery(querry); + } + + + @Override + public boolean onAcceptUrl(String url) { + return false; + } + + public SearchQueryUrlHandler 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/search/SearchResult.java b/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchResult.java index 3effd29d..0d4f1ac1 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchResult.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchResult.java @@ -47,7 +47,7 @@ public class SearchResult { public static SearchResult getSearchResult(@Nonnull final SearchEngine engine, final String query, final int page, final String languageCode, final SearchEngine.Filter filter) throws IOException, ExtractionException { - return engine.search(query, page, languageCode, filter).getSearchResult(); + return null; } public String getSuggestion() { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudQueryUrlHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudQueryUrlHandler.java new file mode 100644 index 00000000..97569a39 --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudQueryUrlHandler.java @@ -0,0 +1,62 @@ +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.SearchQueryUrlHandler; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; + +public class SoundcloudQueryUrlHandler extends SearchQueryUrlHandler { + public static final String CHARSET_UTF_8 = "UTF-8"; + + public static final String TRACKS = "tracks"; + public static final String USERS = "users"; + public static final String PLAYLIST = "playlist"; + public static final String ANY = "any"; + + @Override + public String getUrl() throws ParsingException { + try { + String url = "https://api-v2.soundcloud.com/search"; + + if(getContentFilter().size() > 1) { + switch (getContentFilter().get(0)) { + case TRACKS: + url += "/tracks"; + break; + case USERS: + url += "/users"; + break; + case PLAYLIST: + url += "/playlists"; + break; + case ANY: + default: + break; + } + } + + return url + "?q=" + URLEncoder.encode(id, CHARSET_UTF_8) + + "&client_id=" + SoundcloudParsingHelper.clientId() + + "&limit=10"; + + } catch (UnsupportedEncodingException e) { + throw new ParsingException("Could not encode query", e); + } catch (IOException e) { + throw new ParsingException("Could not get client id", e); + } catch (ReCaptchaException e) { + throw new ParsingException("ReCaptcha required", e); + } + } + + @Override + public String[] getAvailableContentFilter() { + return new String[] { + TRACKS, + USERS, + PLAYLIST, + ANY}; + } +} 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 38cf7fb2..036acd1b 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 @@ -11,6 +11,7 @@ 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.SearchQueryUrlHandler; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; @@ -29,10 +30,14 @@ public class SoundcloudService extends StreamingService { } @Override - public SearchExtractor getSearchExtractor() { + public SearchExtractor getSearchExtractor(SearchQueryUrlHandler queryHandler, String contentCountry) { return null; } + @Override + public SearchQueryUrlHandler getSearchQueryHandler() { + return null; + } @Override public UrlIdHandler getStreamUrlIdHandler() { 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 7b400d50..fca63532 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 @@ -11,11 +11,9 @@ 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.SearchQueryUrlHandler; import org.schabi.newpipe.extractor.services.youtube.extractors.*; -import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeChannelUrlIdHandler; -import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubePlaylistUrlIdHandler; -import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeStreamUrlIdHandler; -import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeTrendingUrlIdHandler; +import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.*; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; @@ -55,8 +53,8 @@ public class YoutubeService extends StreamingService { } @Override - public SearchExtractor getSearchExtractor() { - return null; + public SearchExtractor getSearchExtractor(SearchQueryUrlHandler query, String contentCountry) { + return new YoutubeSearchExtractor(this, query, contentCountry); } @Override @@ -74,6 +72,11 @@ public class YoutubeService extends StreamingService { return YoutubePlaylistUrlIdHandler.getInstance(); } + @Override + public SearchQueryUrlHandler getSearchQueryHandler() { + return YoutubeSearchQueryUrlHandler.getInstance(); + } + @Override public StreamExtractor getStreamExtractor(UrlIdHandler urlIdHandler) throws ExtractionException { return new YoutubeStreamExtractor(this, 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 601f6cae..13f31a6c 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 @@ -19,6 +19,8 @@ import org.schabi.newpipe.extractor.utils.Utils; import javax.annotation.Nonnull; import java.io.IOException; +import static org.schabi.newpipe.extractor.NewPipe.getDownloader; + @SuppressWarnings("WeakerAccess") public class YoutubePlaylistExtractor extends PlaylistExtractor { @@ -132,7 +134,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); JsonObject pageJson; try { - pageJson = JsonParser.object().from(NewPipe.getDownloader().download(pageUrl)); + pageJson = JsonParser.object().from(getDownloader().download(pageUrl)); } catch (JsonParserException pe) { throw new ParsingException("Could not parse ajax json", pe); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchEngine.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchEngine.java index cecfbd18..7fda65dd 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchEngine.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchEngine.java @@ -97,7 +97,6 @@ public class YoutubeSearchEngine extends SearchEngine { // both types of spell correction item if ((el = item.select("div[class*=\"spell-correction\"]").first()) != null) { - collector.setSuggestion(el.select("a").first().text()); if (list.children().size() == 1) { throw new NothingFoundException("Did you mean: " + el.select("a").first().text()); } 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 new file mode 100644 index 00000000..1491cbae --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java @@ -0,0 +1,128 @@ +package org.schabi.newpipe.extractor.services.youtube.extractors; + +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.schabi.newpipe.extractor.Downloader; +import org.schabi.newpipe.extractor.InfoItem; +import org.schabi.newpipe.extractor.InfoItemsCollector; +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.search.InfoItemsSearchCollector; +import org.schabi.newpipe.extractor.search.SearchEngine; +import org.schabi.newpipe.extractor.search.SearchExtractor; +import org.schabi.newpipe.extractor.search.SearchQueryUrlHandler; +import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeSearchQueryUrlHandler; +import org.schabi.newpipe.extractor.utils.Parser; + +import javax.annotation.Nonnull; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URL; + +public class YoutubeSearchExtractor extends SearchExtractor { + + private Document doc; + + public YoutubeSearchExtractor(StreamingService service, + SearchQueryUrlHandler urlIdHandler, + String contentCountry) { + super(service, urlIdHandler, contentCountry); + } + + @Override + public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { + final String site; + final String url = getUrl(); + final String contentCountry = getContentCountry(); + //String url = builder.build().toString(); + //if we've been passed a valid language code, append it to the URL + if (!contentCountry.isEmpty()) { + //assert Pattern.matches("[a-z]{2}(-([A-Z]{2}|[0-9]{1,3}))?", languageCode); + site = downloader.download(url, contentCountry); + } else { + site = downloader.download(url); + } + + doc = Jsoup.parse(site, url); + } + + @Override + public String getSearchSuggestion() throws ParsingException { + final Element el = doc.select("div[class*=\"spell-correction\"]").first(); + if (el != null) { + return el.select("a").first().text(); + } else { + return ""; + } + } + + @Nonnull + @Override + public InfoItemsPage getInitialPage() throws IOException, ExtractionException { + return new InfoItemsPage<>(collectItems(doc), getNextPageUrl()); + } + + @Override + public String getNextPageUrl() throws IOException, ExtractionException { + return getUrl() + "&page=" + Integer.toString( 1); + } + + @Override + public InfoItemsPage getPage(String pageUrl) throws IOException, ExtractionException { + String site = getDownloader().download(pageUrl); + doc = Jsoup.parse(site, pageUrl); + + return new InfoItemsPage<>(collectItems(doc), getNextPageUrlFromCurrentUrl(pageUrl)); + } + + private String getNextPageUrlFromCurrentUrl(String currentUrl) + throws MalformedURLException, UnsupportedEncodingException { + int nextPageNr = Integer.parseInt( + Parser.compatParseMap( + new URL(currentUrl) + .getQuery()) + .get("page")) + 1; + + return currentUrl.replace("&page=" + Integer.toString( nextPageNr-1), + "&page=" + Integer.toString(nextPageNr)); + } + + private InfoItemsSearchCollector collectItems(Document doc) throws NothingFoundException { + InfoItemsSearchCollector collector = getInfoItemSearchCollector(); + + Element list = doc.select("ol[class=\"item-section\"]").first(); + + for (Element item : list.children()) { + /* First we need to determine which kind of item we are working with. + Youtube depicts five different kinds of items on its search result page. These are + regular videos, playlists, channels, two types of video suggestions, and a "no video + found" item. Since we only want videos, we need to filter out all the others. + An example for this can be seen here: + https://www.youtube.com/results?search_query=asdf&page=1 + + We already applied a filter to the url, so we don't need to care about channels and + playlists now. + */ + + Element el; + + if ((el = item.select("div[class*=\"search-message\"]").first()) != null) { + throw new NothingFoundException(el.text()); + + // video item type + } else if ((el = item.select("div[class*=\"yt-lockup-video\"]").first()) != null) { + collector.commit(new YoutubeStreamInfoItemExtractor(el)); + } else if ((el = item.select("div[class*=\"yt-lockup-channel\"]").first()) != null) { + collector.commit(new YoutubeChannelInfoItemExtractor(el)); + } else if ((el = item.select("div[class*=\"yt-lockup-playlist\"]").first()) != null && + item.select(".yt-pl-icon-mix").isEmpty()) { + collector.commit(new YoutubePlaylistInfoItemExtractor(el)); + } + } + + return collector; + } +} diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeSearchQueryUrlHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeSearchQueryUrlHandler.java new file mode 100644 index 00000000..8e6eaf00 --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeSearchQueryUrlHandler.java @@ -0,0 +1,52 @@ +package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers; + +import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.search.SearchQueryUrlHandler; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; + +public class YoutubeSearchQueryUrlHandler extends SearchQueryUrlHandler { + + public static final String CHARSET_UTF_8 = "UTF-8"; + + public static final String STREAM = "stream"; + public static final String CHANNEL = "channel"; + public static final String PLAYLIST = "playlist"; + public static final String ANY = "any"; + + public static YoutubeSearchQueryUrlHandler getInstance() { + return new YoutubeSearchQueryUrlHandler(); + } + + @Override + public String getUrl() throws ParsingException { + try { + final String url = "https://www.youtube.com/results" + + "?q=" + URLEncoder.encode(id, CHARSET_UTF_8); + + if(getContentFilter().size() > 1) { + switch (getContentFilter().get(0)) { + case STREAM: return url + "&sp=EgIQAVAU"; + case CHANNEL: return url + "&sp=EgIQAlAU"; + case PLAYLIST: return url + "&sp=EgIQA1AU"; + case ANY: + default: return url; + } + } + + return url; + } catch (UnsupportedEncodingException e) { + throw new ParsingException("Could not encode query", e); + } + } + + @Override + public String[] getAvailableContentFilter() { + return new String[] { + STREAM, + CHANNEL, + PLAYLIST, + ANY}; + } +} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/NewPipeTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/NewPipeTest.java index b2c50fb8..bdad6cb6 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/NewPipeTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/NewPipeTest.java @@ -6,7 +6,6 @@ import java.util.HashSet; import static org.junit.Assert.*; import static org.schabi.newpipe.extractor.NewPipe.getServiceByUrl; -import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; import static org.schabi.newpipe.extractor.ServiceList.YouTube; public class NewPipeTest { @@ -28,17 +27,11 @@ public class NewPipeTest { @Test public void getServiceWithId() throws Exception { assertEquals(NewPipe.getService(YouTube.getServiceId()), YouTube); - assertEquals(NewPipe.getService(SoundCloud.getServiceId()), SoundCloud); - - assertNotEquals(NewPipe.getService(SoundCloud.getServiceId()), YouTube); } @Test public void getServiceWithName() throws Exception { assertEquals(NewPipe.getService(YouTube.getServiceInfo().getName()), YouTube); - assertEquals(NewPipe.getService(SoundCloud.getServiceInfo().getName()), SoundCloud); - - assertNotEquals(NewPipe.getService(YouTube.getServiceInfo().getName()), SoundCloud); } @Test @@ -46,27 +39,17 @@ public class NewPipeTest { assertEquals(getServiceByUrl("https://www.youtube.com/watch?v=_r6CgaFNAGg"), YouTube); assertEquals(getServiceByUrl("https://www.youtube.com/channel/UCi2bIyFtz-JdI-ou8kaqsqg"), YouTube); assertEquals(getServiceByUrl("https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH"), YouTube); - assertEquals(getServiceByUrl("https://soundcloud.com/shupemoosic/pegboard-nerds-try-this"), SoundCloud); - assertEquals(getServiceByUrl("https://soundcloud.com/deluxe314/sets/pegboard-nerds"), SoundCloud); - assertEquals(getServiceByUrl("https://soundcloud.com/pegboardnerds"), SoundCloud); assertNotEquals(getServiceByUrl("https://soundcloud.com/pegboardnerds"), YouTube); - assertNotEquals(getServiceByUrl("https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH"), SoundCloud); } @Test public void getIdWithServiceName() throws Exception { assertEquals(NewPipe.getIdOfService(YouTube.getServiceInfo().getName()), YouTube.getServiceId()); - assertEquals(NewPipe.getIdOfService(SoundCloud.getServiceInfo().getName()), SoundCloud.getServiceId()); - - assertNotEquals(NewPipe.getIdOfService(SoundCloud.getServiceInfo().getName()), YouTube.getServiceId()); } @Test public void getServiceNameWithId() throws Exception { assertEquals(NewPipe.getNameOfService(YouTube.getServiceId()), YouTube.getServiceInfo().getName()); - assertEquals(NewPipe.getNameOfService(SoundCloud.getServiceId()), SoundCloud.getServiceInfo().getName()); - - assertNotEquals(NewPipe.getNameOfService(YouTube.getServiceId()), SoundCloud.getServiceInfo().getName()); } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/BaseSoundcloudSearchTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/BaseSoundcloudSearchTest.java deleted file mode 100644 index a7b3d3a9..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/BaseSoundcloudSearchTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.schabi.newpipe.extractor.services.soundcloud; - -import org.junit.Test; -import org.schabi.newpipe.extractor.InfoItem; -import org.schabi.newpipe.extractor.channel.ChannelInfoItem; -import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem; -import org.schabi.newpipe.extractor.search.SearchResult; -import org.schabi.newpipe.extractor.stream.StreamInfoItem; -import org.schabi.newpipe.extractor.stream.StreamType; - -import static org.junit.Assert.*; -import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; - -public abstract class BaseSoundcloudSearchTest { - - protected static SearchResult result; - - @Test - public void testResultList() { - assertFalse("Got empty result list", result.resultList.isEmpty()); - for(InfoItem infoItem: result.resultList) { - assertIsSecureUrl(infoItem.getUrl()); - assertIsSecureUrl(infoItem.getThumbnailUrl()); - assertFalse(infoItem.getName().isEmpty()); - assertFalse("Name is probably a URI: " + infoItem.getName(), - infoItem.getName().contains("://")); - if(infoItem instanceof StreamInfoItem) { - // test stream item - StreamInfoItem streamInfoItem = (StreamInfoItem) infoItem; - assertIsSecureUrl(streamInfoItem.getUploaderUrl()); - assertFalse(streamInfoItem.getUploadDate().isEmpty()); - assertFalse(streamInfoItem.getUploaderName().isEmpty()); - assertEquals(StreamType.AUDIO_STREAM, streamInfoItem.getStreamType()); - } else if(infoItem instanceof ChannelInfoItem) { - // Nothing special to check? - } else if(infoItem instanceof PlaylistInfoItem) { - // test playlist item - assertTrue(infoItem.getUrl().contains("/sets/")); - long streamCount = ((PlaylistInfoItem) infoItem).getStreamCount(); - assertTrue(streamCount > 0); - } else { - fail("Unknown infoItem type: " + infoItem); - } - } - } - - @Test - public void testResultErrors() { - assertNotNull(result.errors); - if (!result.errors.isEmpty()) { - for (Throwable error : result.errors) { - error.printStackTrace(); - } - } - assertTrue(result.errors.isEmpty()); - } -} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractorTest.java deleted file mode 100644 index 30884adc..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractorTest.java +++ /dev/null @@ -1,198 +0,0 @@ -package org.schabi.newpipe.extractor.services.soundcloud; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.schabi.newpipe.Downloader; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.channel.ChannelExtractor; -import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest; - -import static org.junit.Assert.*; -import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmpty; -import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; -import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; -import static org.schabi.newpipe.extractor.services.DefaultTests.*; - -/** - * Test for {@link SoundcloudChannelExtractor} - */ -public class SoundcloudChannelExtractorTest { - public static class LilUzi implements BaseChannelExtractorTest { - private static SoundcloudChannelExtractor extractor; - - @BeforeClass - public static void setUp() throws Exception { - NewPipe.init(Downloader.getInstance()); - extractor = (SoundcloudChannelExtractor) SoundCloud - .getChannelExtractor("http://soundcloud.com/liluzivert/sets"); - extractor.fetchPage(); - } - - /*////////////////////////////////////////////////////////////////////////// - // Extractor - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testServiceId() { - assertEquals(SoundCloud.getServiceId(), extractor.getServiceId()); - } - - @Test - public void testName() { - assertEquals("LIL UZI VERT", extractor.getName()); - } - - @Test - public void testId() { - assertEquals("10494998", extractor.getId()); - } - - @Test - public void testUrl() throws ParsingException { - assertEquals("https://soundcloud.com/liluzivert", extractor.getUrl()); - } - - @Test - public void testOriginalUrl() throws ParsingException { - assertEquals("http://soundcloud.com/liluzivert/sets", extractor.getOriginalUrl()); - } - - /*////////////////////////////////////////////////////////////////////////// - // ListExtractor - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testRelatedItems() throws Exception { - defaultTestRelatedItems(extractor, SoundCloud.getServiceId()); - } - - @Test - public void testMoreRelatedItems() throws Exception { - defaultTestMoreItems(extractor, SoundCloud.getServiceId()); - } - - /*////////////////////////////////////////////////////////////////////////// - // ChannelExtractor - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testDescription() { - assertNotNull(extractor.getDescription()); - } - - @Test - public void testAvatarUrl() { - assertIsSecureUrl(extractor.getAvatarUrl()); - } - - @Test - public void testBannerUrl() { - assertIsSecureUrl(extractor.getBannerUrl()); - } - - @Test - public void testFeedUrl() { - assertEmpty(extractor.getFeedUrl()); - } - - @Test - public void testSubscriberCount() { - assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 1e6); - } - } - - public static class DubMatix implements BaseChannelExtractorTest { - private static SoundcloudChannelExtractor extractor; - - @BeforeClass - public static void setUp() throws Exception { - NewPipe.init(Downloader.getInstance()); - extractor = (SoundcloudChannelExtractor) SoundCloud - .getChannelExtractor("https://soundcloud.com/dubmatix"); - extractor.fetchPage(); - } - - /*////////////////////////////////////////////////////////////////////////// - // Additional Testing - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testGetPageInNewExtractor() throws Exception { - final ChannelExtractor newExtractor = SoundCloud.getChannelExtractor(extractor.getUrl()); - defaultTestGetPageInNewExtractor(extractor, newExtractor, SoundCloud.getServiceId()); - } - - /*////////////////////////////////////////////////////////////////////////// - // Extractor - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testServiceId() { - assertEquals(SoundCloud.getServiceId(), extractor.getServiceId()); - } - - @Test - public void testName() { - assertEquals("dubmatix", extractor.getName()); - } - - @Test - public void testId() { - assertEquals("542134", extractor.getId()); - } - - @Test - public void testUrl() throws ParsingException { - assertEquals("https://soundcloud.com/dubmatix", extractor.getUrl()); - } - - @Test - public void testOriginalUrl() throws ParsingException { - assertEquals("https://soundcloud.com/dubmatix", extractor.getOriginalUrl()); - } - - /*////////////////////////////////////////////////////////////////////////// - // ListExtractor - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testRelatedItems() throws Exception { - defaultTestRelatedItems(extractor, SoundCloud.getServiceId()); - } - - @Test - public void testMoreRelatedItems() throws Exception { - defaultTestMoreItems(extractor, SoundCloud.getServiceId()); - } - - /*////////////////////////////////////////////////////////////////////////// - // ChannelExtractor - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testDescription() { - assertNotNull(extractor.getDescription()); - } - - @Test - public void testAvatarUrl() { - assertIsSecureUrl(extractor.getAvatarUrl()); - } - - @Test - public void testBannerUrl() { - assertIsSecureUrl(extractor.getBannerUrl()); - } - - @Test - public void testFeedUrl() { - assertEmpty(extractor.getFeedUrl()); - } - - @Test - public void testSubscriberCount() { - assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 2e6); - } - } -} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java deleted file mode 100644 index a7723024..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java +++ /dev/null @@ -1,93 +0,0 @@ -package org.schabi.newpipe.extractor.services.soundcloud; - -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.schabi.newpipe.Downloader; -import org.schabi.newpipe.extractor.ListExtractor; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.kiosk.KioskExtractor; -import org.schabi.newpipe.extractor.stream.StreamInfoItem; - -import java.util.List; - -import static org.junit.Assert.*; -import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; - -/** - * Test for {@link SoundcloudChartsUrlIdHandler} - */ -public class SoundcloudChartsExtractorTest { - - static KioskExtractor extractor; - - @BeforeClass - public static void setUp() throws Exception { - NewPipe.init(Downloader.getInstance()); - extractor = SoundCloud - .getKioskList() - .getExtractorById("Top 50", null); - extractor.fetchPage(); - } - - @Test - public void testGetDownloader() throws Exception { - assertNotNull(NewPipe.getDownloader()); - } - - @Ignore - @Test - public void testGetName() throws Exception { - assertEquals(extractor.getName(), "Top 50"); - } - - @Test - public void testId() { - assertEquals(extractor.getId(), "Top 50"); - } - - @Test - public void testGetStreams() throws Exception { - ListExtractor.InfoItemsPage page = extractor.getInitialPage(); - if(!page.getErrors().isEmpty()) { - System.err.println("----------"); - List errors = page.getErrors(); - for(Throwable e: errors) { - e.printStackTrace(); - System.err.println("----------"); - } - } - assertTrue("no streams are received", - !page.getItems().isEmpty() - && page.getErrors().isEmpty()); - } - - @Test - public void testGetStreamsErrors() throws Exception { - assertTrue("errors during stream list extraction", extractor.getInitialPage().getErrors().isEmpty()); - } - - @Test - public void testHasMoreStreams() throws Exception { - // Setup the streams - extractor.getInitialPage(); - assertTrue("has more streams", extractor.hasNextPage()); - } - - @Test - public void testGetNextPageUrl() throws Exception { - assertTrue(extractor.hasNextPage()); - } - - @Test - public void testGetNextPage() throws Exception { - extractor.getInitialPage().getItems(); - assertFalse("extractor has next streams", extractor.getPage(extractor.getNextPageUrl()) == null - || extractor.getPage(extractor.getNextPageUrl()).getItems().isEmpty()); - } - - @Test - public void testGetCleanUrl() throws Exception { - assertEquals(extractor.getUrl(), "https://soundcloud.com/charts/top"); - } -} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandlerTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandlerTest.java deleted file mode 100644 index 4fa09ffa..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandlerTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.schabi.newpipe.extractor.services.soundcloud; - -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.ParsingException; - -import static junit.framework.TestCase.assertFalse; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -/** - * Test for {@link SoundcloudChartsUrlIdHandler} - */ -public class SoundcloudChartsUrlIdHandlerTest { - private static SoundcloudChartsUrlIdHandler urlIdHandler; - - @BeforeClass - public static void setUp() throws Exception { - urlIdHandler = new SoundcloudChartsUrlIdHandler(); - NewPipe.init(Downloader.getInstance()); - } - - @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"); - } - - @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"); - } - - @Test - public void acceptUrl() throws ParsingException { - assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/charts")); - assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/charts/")); - assertTrue(urlIdHandler.acceptUrl("https://www.soundcloud.com/charts/new")); - assertTrue(urlIdHandler.acceptUrl("http://soundcloud.com/charts/top?genre=all-music")); - assertTrue(urlIdHandler.acceptUrl("HTTP://www.soundcloud.com/charts/new/?genre=all-music&country=all-countries")); - - assertFalse(urlIdHandler.acceptUrl("kdskjfiiejfia")); - assertFalse(urlIdHandler.acceptUrl("soundcloud.com/charts askjkf")); - assertFalse(urlIdHandler.acceptUrl(" soundcloud.com/charts")); - assertFalse(urlIdHandler.acceptUrl("")); - } -} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelperTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelperTest.java deleted file mode 100644 index 1e38d2ac..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelperTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.schabi.newpipe.extractor.services.soundcloud; - -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.schabi.newpipe.Downloader; -import org.schabi.newpipe.extractor.NewPipe; - -public class SoundcloudParsingHelperTest { - @BeforeClass - public static void setUp() { - NewPipe.init(Downloader.getInstance()); - } - - @Test - public void resolveUrlWithEmbedPlayerTest() throws Exception { - Assert.assertEquals("https://soundcloud.com/trapcity", SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/users/26057743")); - Assert.assertEquals("https://soundcloud.com/nocopyrightsounds", SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/users/16069159")); - } - - @Test - public void resolveIdWithEmbedPlayerTest() throws Exception { - Assert.assertEquals("26057743", SoundcloudParsingHelper.resolveIdWithEmbedPlayer("https://soundcloud.com/trapcity")); - Assert.assertEquals("16069159", SoundcloudParsingHelper.resolveIdWithEmbedPlayer("https://soundcloud.com/nocopyrightsounds")); - - } - -} \ No newline at end of file diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractorTest.java deleted file mode 100644 index 29bf4d17..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractorTest.java +++ /dev/null @@ -1,319 +0,0 @@ -package org.schabi.newpipe.extractor.services.soundcloud; - -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.schabi.newpipe.Downloader; -import org.schabi.newpipe.extractor.ListExtractor; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.ServiceList; -import org.schabi.newpipe.extractor.playlist.PlaylistExtractor; -import org.schabi.newpipe.extractor.services.BasePlaylistExtractorTest; -import org.schabi.newpipe.extractor.stream.StreamInfoItem; - -import static org.junit.Assert.*; -import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; -import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; -import static org.schabi.newpipe.extractor.services.DefaultTests.*; - -/** - * Test for {@link PlaylistExtractor} - */ -public class SoundcloudPlaylistExtractorTest { - public static class LuvTape implements BasePlaylistExtractorTest { - private static SoundcloudPlaylistExtractor extractor; - - @BeforeClass - public static void setUp() throws Exception { - NewPipe.init(Downloader.getInstance()); - extractor = (SoundcloudPlaylistExtractor) SoundCloud - .getPlaylistExtractor("https://soundcloud.com/liluzivert/sets/the-perfect-luv-tape-r?test=123"); - extractor.fetchPage(); - } - - /*////////////////////////////////////////////////////////////////////////// - // Extractor - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testServiceId() { - assertEquals(SoundCloud.getServiceId(), extractor.getServiceId()); - } - - @Test - public void testName() { - assertEquals("THE PERFECT LUV TAPE®", extractor.getName()); - } - - @Test - public void testId() { - assertEquals("246349810", extractor.getId()); - } - - @Test - public void testUrl() throws Exception { - assertEquals("https://soundcloud.com/liluzivert/sets/the-perfect-luv-tape-r", extractor.getUrl()); - } - - @Test - public void testOriginalUrl() throws Exception { - assertEquals("https://soundcloud.com/liluzivert/sets/the-perfect-luv-tape-r?test=123", extractor.getOriginalUrl()); - } - - /*////////////////////////////////////////////////////////////////////////// - // ListExtractor - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testRelatedItems() throws Exception { - defaultTestRelatedItems(extractor, SoundCloud.getServiceId()); - } - - @Test - public void testMoreRelatedItems() { - try { - defaultTestMoreItems(extractor, SoundCloud.getServiceId()); - } catch (Throwable ignored) { - return; - } - - fail("This playlist doesn't have more items, it should throw an error"); - } - - /*////////////////////////////////////////////////////////////////////////// - // PlaylistExtractor - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testThumbnailUrl() { - assertIsSecureUrl(extractor.getThumbnailUrl()); - } - - @Ignore - @Test - public void testBannerUrl() { - assertIsSecureUrl(extractor.getBannerUrl()); - } - - @Test - public void testUploaderUrl() { - final String uploaderUrl = extractor.getUploaderUrl(); - assertIsSecureUrl(uploaderUrl); - assertTrue(uploaderUrl, uploaderUrl.contains("liluzivert")); - } - - @Test - public void testUploaderName() { - assertTrue(extractor.getUploaderName().contains("LIL UZI VERT")); - } - - @Test - public void testUploaderAvatarUrl() { - assertIsSecureUrl(extractor.getUploaderAvatarUrl()); - } - - @Test - public void testStreamCount() { - assertTrue("Error in the streams count", extractor.getStreamCount() >= 10); - } - } - - public static class RandomHouseDanceMusic implements BasePlaylistExtractorTest { - private static SoundcloudPlaylistExtractor extractor; - - @BeforeClass - public static void setUp() throws Exception { - NewPipe.init(Downloader.getInstance()); - extractor = (SoundcloudPlaylistExtractor) SoundCloud - .getPlaylistExtractor("https://soundcloud.com/hunter-leader/sets/house-electro-dance-music-2"); - extractor.fetchPage(); - } - - /*////////////////////////////////////////////////////////////////////////// - // Extractor - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testServiceId() { - assertEquals(SoundCloud.getServiceId(), extractor.getServiceId()); - } - - @Test - public void testName() { - assertEquals("House, Electro , Dance Music 2", extractor.getName()); - } - - @Test - public void testId() { - assertEquals("310980722", extractor.getId()); - } - - @Test - public void testUrl() throws Exception { - assertEquals("https://soundcloud.com/hunter-leader/sets/house-electro-dance-music-2", extractor.getUrl()); - } - - @Test - public void testOriginalUrl() throws Exception { - assertEquals("https://soundcloud.com/hunter-leader/sets/house-electro-dance-music-2", extractor.getOriginalUrl()); - } - - /*////////////////////////////////////////////////////////////////////////// - // ListExtractor - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testRelatedItems() throws Exception { - defaultTestRelatedItems(extractor, SoundCloud.getServiceId()); - } - - @Test - public void testMoreRelatedItems() throws Exception { - defaultTestMoreItems(extractor, SoundCloud.getServiceId()); - } - - /*////////////////////////////////////////////////////////////////////////// - // PlaylistExtractor - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testThumbnailUrl() { - assertIsSecureUrl(extractor.getThumbnailUrl()); - } - - @Ignore - @Test - public void testBannerUrl() { - assertIsSecureUrl(extractor.getBannerUrl()); - } - - @Test - public void testUploaderUrl() { - final String uploaderUrl = extractor.getUploaderUrl(); - assertIsSecureUrl(uploaderUrl); - assertTrue(uploaderUrl, uploaderUrl.contains("hunter-leader")); - } - - @Test - public void testUploaderName() { - assertEquals("Gosu", extractor.getUploaderName()); - } - - @Test - public void testUploaderAvatarUrl() { - assertIsSecureUrl(extractor.getUploaderAvatarUrl()); - } - - @Test - public void testStreamCount() { - assertTrue("Error in the streams count", extractor.getStreamCount() >= 10); - } - } - - public static class EDMxxx implements BasePlaylistExtractorTest { - private static SoundcloudPlaylistExtractor extractor; - - @BeforeClass - public static void setUp() throws Exception { - NewPipe.init(Downloader.getInstance()); - extractor = (SoundcloudPlaylistExtractor) SoundCloud - .getPlaylistExtractor("https://soundcloud.com/user350509423/sets/edm-xxx"); - extractor.fetchPage(); - } - - /*////////////////////////////////////////////////////////////////////////// - // Additional Testing - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testGetPageInNewExtractor() throws Exception { - final PlaylistExtractor newExtractor = SoundCloud.getPlaylistExtractor(extractor.getUrl()); - defaultTestGetPageInNewExtractor(extractor, newExtractor, SoundCloud.getServiceId()); - } - - /*////////////////////////////////////////////////////////////////////////// - // Extractor - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testServiceId() { - assertEquals(SoundCloud.getServiceId(), extractor.getServiceId()); - } - - @Test - public void testName() { - assertEquals("EDM xXx", extractor.getName()); - } - - @Test - public void testId() { - assertEquals("136000376", extractor.getId()); - } - - @Test - public void testUrl() throws Exception { - assertEquals("https://soundcloud.com/user350509423/sets/edm-xxx", extractor.getUrl()); - } - - @Test - public void testOriginalUrl() throws Exception { - assertEquals("https://soundcloud.com/user350509423/sets/edm-xxx", extractor.getOriginalUrl()); - } - - /*////////////////////////////////////////////////////////////////////////// - // ListExtractor - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testRelatedItems() throws Exception { - defaultTestRelatedItems(extractor, SoundCloud.getServiceId()); - } - - @Test - public void testMoreRelatedItems() throws Exception { - ListExtractor.InfoItemsPage currentPage = defaultTestMoreItems(extractor, ServiceList.SoundCloud.getServiceId()); - // Test for 2 more levels - for (int i = 0; i < 2; i++) { - currentPage = extractor.getPage(currentPage.getNextPageUrl()); - defaultTestListOfItems(SoundCloud.getServiceId(), currentPage.getItems(), currentPage.getErrors()); - } - } - - /*////////////////////////////////////////////////////////////////////////// - // PlaylistExtractor - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testThumbnailUrl() { - assertIsSecureUrl(extractor.getThumbnailUrl()); - } - - @Ignore - @Test - public void testBannerUrl() { - assertIsSecureUrl(extractor.getBannerUrl()); - } - - @Test - public void testUploaderUrl() { - final String uploaderUrl = extractor.getUploaderUrl(); - assertIsSecureUrl(uploaderUrl); - assertTrue(uploaderUrl, uploaderUrl.contains("user350509423")); - } - - @Test - public void testUploaderName() { - assertEquals("user350509423", extractor.getUploaderName()); - } - - @Test - public void testUploaderAvatarUrl() { - assertIsSecureUrl(extractor.getUploaderAvatarUrl()); - } - - @Test - public void testStreamCount() { - assertTrue("Error in the streams count", extractor.getStreamCount() >= 3900); - } - } -} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineAllTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineAllTest.java deleted file mode 100644 index 8e920115..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineAllTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.schabi.newpipe.extractor.services.soundcloud; - -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.schabi.newpipe.Downloader; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.search.SearchEngine; - -import static org.junit.Assert.assertTrue; -import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; - -/** - * Test for {@link SearchEngine} - */ -public class SoundcloudSearchEngineAllTest extends BaseSoundcloudSearchTest { - - @BeforeClass - public static void setUp() throws Exception { - NewPipe.init(Downloader.getInstance()); - SearchEngine engine = SoundCloud.getSearchEngine(); - - // SoundCloud will suggest "lil uzi vert" instead of "lill uzi vert" - // keep in mind that the suggestions can NOT change by country (the parameter "de") - result = engine.search("lill uzi vert", 0, "de", SearchEngine.Filter.ANY) - .getSearchResult(); - } - - @Ignore - @Test - public void testSuggestion() { - //todo write a real test - assertTrue(result.suggestion != null); - } -} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineChannelTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineChannelTest.java deleted file mode 100644 index b5b31596..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineChannelTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.schabi.newpipe.extractor.services.soundcloud; - -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.schabi.newpipe.Downloader; -import org.schabi.newpipe.extractor.InfoItem; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.search.SearchEngine; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; - -/** - * Test for {@link SearchEngine} - */ -public class SoundcloudSearchEngineChannelTest extends BaseSoundcloudSearchTest { - - @BeforeClass - public static void setUp() throws Exception { - NewPipe.init(Downloader.getInstance()); - SearchEngine engine = SoundCloud.getSearchEngine(); - - // SoundCloud will suggest "lil uzi vert" instead of "lill uzi vert" - // keep in mind that the suggestions can NOT change by country (the parameter "de") - result = engine.search("lill uzi vert", 0, "de", SearchEngine.Filter.CHANNEL) - .getSearchResult(); - } - - @Test - public void testResultsItemType() { - for (InfoItem infoItem : result.resultList) { - assertEquals(InfoItem.InfoType.CHANNEL, infoItem.getInfoType()); - } - } - - @Ignore - @Test - public void testSuggestion() { - //todo write a real test - assertTrue(result.suggestion != null); - } -} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEnginePlaylistTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEnginePlaylistTest.java deleted file mode 100644 index 9106855b..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEnginePlaylistTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.schabi.newpipe.extractor.services.soundcloud; - -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.schabi.newpipe.Downloader; -import org.schabi.newpipe.extractor.InfoItem; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.search.SearchEngine; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; - - -/* - * Created by Christian Schabesberger on 29.12.15. - * - * Copyright (C) Christian Schabesberger 2015 - * YoutubeSearchEngineStreamTest.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 . - */ - -/** - * Test for {@link SearchEngine} - */ -public class SoundcloudSearchEnginePlaylistTest extends BaseSoundcloudSearchTest { - - @BeforeClass - public static void setUp() throws Exception { - NewPipe.init(Downloader.getInstance()); - SearchEngine engine = SoundCloud.getSearchEngine(); - - // Search by country not yet implemented - result = engine.search("parkmemme", 0, "", SearchEngine.Filter.PLAYLIST) - .getSearchResult(); - } - - @Test - public void testUserItemType() { - for (InfoItem infoItem : result.resultList) { - assertEquals(InfoItem.InfoType.PLAYLIST, infoItem.getInfoType()); - } - } - - @Ignore - @Test - public void testSuggestion() { - //todo write a real test - assertTrue(result.suggestion != null); - } -} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineStreamTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineStreamTest.java deleted file mode 100644 index da222d33..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineStreamTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.schabi.newpipe.extractor.services.soundcloud; - -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.schabi.newpipe.Downloader; -import org.schabi.newpipe.extractor.InfoItem; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.search.SearchEngine; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; - -/** - * Test for {@link SearchEngine} - */ -public class SoundcloudSearchEngineStreamTest extends BaseSoundcloudSearchTest { - - @BeforeClass - public static void setUp() throws Exception { - NewPipe.init(Downloader.getInstance()); - SearchEngine engine = SoundCloud.getSearchEngine(); - - // SoundCloud will suggest "lil uzi vert" instead of "lill uzi vert", - // keep in mind that the suggestions can NOT change by country (the parameter "de") - result = engine.search("lill uzi vert", 0, "de", SearchEngine.Filter.STREAM) - .getSearchResult(); - } - - @Test - public void testResultsItemType() { - for (InfoItem infoItem : result.resultList) { - assertEquals(InfoItem.InfoType.STREAM, infoItem.getInfoType()); - } - } - - @Ignore - @Test - public void testSuggestion() { - //todo write a real test - assertTrue(result.suggestion != null); - } -} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java deleted file mode 100644 index a637d380..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java +++ /dev/null @@ -1,119 +0,0 @@ -package org.schabi.newpipe.extractor.services.soundcloud; - -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.ExtractionException; -import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.stream.StreamExtractor; -import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; -import org.schabi.newpipe.extractor.stream.StreamType; - -import java.io.IOException; - -import static org.junit.Assert.*; -import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; -import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; - -/** - * Test for {@link StreamExtractor} - */ -public class SoundcloudStreamExtractorDefaultTest { - private static SoundcloudStreamExtractor extractor; - - @BeforeClass - public static void setUp() throws Exception { - NewPipe.init(Downloader.getInstance()); - extractor = (SoundcloudStreamExtractor) SoundCloud.getStreamExtractor("https://soundcloud.com/liluzivert/do-what-i-want-produced-by-maaly-raw-don-cannon"); - extractor.fetchPage(); - } - - @Test - public void testGetInvalidTimeStamp() throws ParsingException { - assertTrue(extractor.getTimeStamp() + "", - extractor.getTimeStamp() <= 0); - } - - @Test - public void testGetValidTimeStamp() throws IOException, ExtractionException { - StreamExtractor extractor = SoundCloud.getStreamExtractor("https://soundcloud.com/liluzivert/do-what-i-want-produced-by-maaly-raw-don-cannon#t=69"); - assertEquals(extractor.getTimeStamp() + "", "69"); - } - - @Test - public void testGetTitle() throws ParsingException { - assertEquals(extractor.getName(), "Do What I Want [Produced By Maaly Raw + Don Cannon]"); - } - - @Test - public void testGetDescription() throws ParsingException { - assertEquals(extractor.getDescription(), "The Perfect LUV Tape®"); - } - - @Test - public void testGetUploaderName() throws ParsingException { - assertEquals(extractor.getUploaderName(), "LIL UZI VERT"); - } - - @Test - public void testGetLength() throws ParsingException { - assertEquals(extractor.getLength(), 175); - } - - @Test - public void testGetViewCount() throws ParsingException { - assertTrue(Long.toString(extractor.getViewCount()), - extractor.getViewCount() > 44227978); - } - - @Test - public void testGetUploadDate() throws ParsingException { - assertEquals("2016-07-31", extractor.getUploadDate()); - } - - @Test - public void testGetUploaderUrl() throws ParsingException { - assertIsSecureUrl(extractor.getUploaderUrl()); - assertEquals("https://soundcloud.com/liluzivert", extractor.getUploaderUrl()); - } - - @Test - public void testGetThumbnailUrl() throws ParsingException { - assertIsSecureUrl(extractor.getThumbnailUrl()); - } - - @Test - public void testGetUploaderAvatarUrl() throws ParsingException { - assertIsSecureUrl(extractor.getUploaderAvatarUrl()); - } - - @Test - public void testGetAudioStreams() throws IOException, ExtractionException { - assertFalse(extractor.getAudioStreams().isEmpty()); - } - - @Test - public void testStreamType() throws ParsingException { - assertTrue(extractor.getStreamType() == StreamType.AUDIO_STREAM); - } - - @Test - public void testGetRelatedVideos() throws ExtractionException, IOException { - StreamInfoItemsCollector relatedVideos = extractor.getRelatedVideos(); - assertFalse(relatedVideos.getItems().isEmpty()); - assertTrue(relatedVideos.getErrors().isEmpty()); - } - - @Test - public void testGetSubtitlesListDefault() throws IOException, ExtractionException { - // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null - assertTrue(extractor.getSubtitlesDefault().isEmpty()); - } - - @Test - public void testGetSubtitlesList() throws IOException, ExtractionException { - // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null - assertTrue(extractor.getSubtitlesDefault().isEmpty()); - } -} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUrlIdHandlerTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUrlIdHandlerTest.java deleted file mode 100644 index 5c1d35cf..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUrlIdHandlerTest.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.schabi.newpipe.extractor.services.soundcloud; - -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.ParsingException; - -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.*; - -/** - * Test for {@link SoundcloudStreamUrlIdHandler} - */ -public class SoundcloudStreamUrlIdHandlerTest { - private static SoundcloudStreamUrlIdHandler urlIdHandler; - - @BeforeClass - public static void setUp() throws Exception { - urlIdHandler = SoundcloudStreamUrlIdHandler.getInstance(); - NewPipe.init(Downloader.getInstance()); - } - - @Test(expected = IllegalArgumentException.class) - public void getIdWithNullAsUrl() throws ParsingException { - urlIdHandler.setUrl(null).getId(); - } - - @Test - public void getIdForInvalidUrls() { - List invalidUrls = new ArrayList<>(50); - invalidUrls.add("https://soundcloud.com/liluzivert/t.e.s.t"); - invalidUrls.add("https://soundcloud.com/liluzivert/tracks"); - invalidUrls.add("https://soundcloud.com/"); - for (String invalidUrl : invalidUrls) { - Throwable exception = null; - try { - urlIdHandler.setUrl(invalidUrl).getId(); - } catch (ParsingException e) { - exception = e; - } - if (exception == null) { - fail("Expected ParsingException for url: " + invalidUrl); - } - } - } - - @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()); - } - - - @Test - public void testAcceptUrl() throws ParsingException { - assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/liluzivert/15-ysl")); - assertTrue(urlIdHandler.acceptUrl("https://www.soundcloud.com/liluzivert/15-luv-scars-ko")); - assertTrue(urlIdHandler.acceptUrl("http://soundcloud.com/liluzivert/15-boring-shit")); - assertTrue(urlIdHandler.acceptUrl("http://www.soundcloud.com/liluzivert/secure-the-bag-produced-by-glohan-beats")); - assertTrue(urlIdHandler.acceptUrl("HtTpS://sOuNdClOuD.cOm/LiLuZiVeRt/In-O4-pRoDuCeD-bY-dP-bEaTz")); - assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/liluzivert/fresh-produced-by-zaytoven#t=69")); - assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/liluzivert/threesome-produced-by-zaytoven#t=1:09")); - assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/liluzivert/blonde-brigitte-produced-manny-fresh#t=1:9")); - assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/liluzivert/today-produced-by-c-note#t=1m9s")); - assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/liluzivert/changed-my-phone-produced-by-c-note#t=1m09s")); - } -} \ No newline at end of file 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 deleted file mode 100644 index e0e99803..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSubscriptionExtractorTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.schabi.newpipe.extractor.services.soundcloud; - -import org.junit.BeforeClass; -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.UrlIdHandler; -import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; -import org.schabi.newpipe.extractor.subscription.SubscriptionItem; - -import java.io.IOException; -import java.util.Arrays; -import java.util.List; - -import static org.junit.Assert.*; - -/** - * Test for {@link SoundcloudSubscriptionExtractor} - */ -public class SoundcloudSubscriptionExtractorTest { - private static SoundcloudSubscriptionExtractor subscriptionExtractor; - private static UrlIdHandler urlHandler; - - @BeforeClass - public static void setupClass() { - NewPipe.init(Downloader.getInstance()); - subscriptionExtractor = new SoundcloudSubscriptionExtractor(ServiceList.SoundCloud); - urlHandler = ServiceList.SoundCloud.getChannelUrlIdHandler(); - } - - @Test - public void testFromChannelUrl() throws Exception { - testList(subscriptionExtractor.fromChannelUrl("https://soundcloud.com/monstercat")); - testList(subscriptionExtractor.fromChannelUrl("http://soundcloud.com/monstercat")); - testList(subscriptionExtractor.fromChannelUrl("soundcloud.com/monstercat")); - testList(subscriptionExtractor.fromChannelUrl("monstercat")); - - //Empty followings user - testList(subscriptionExtractor.fromChannelUrl("some-random-user-184047028")); - } - - @Test - public void testInvalidSourceException() { - List invalidList = Arrays.asList( - "httttps://invalid.com/user", - ".com/monstercat", - "ithinkthatthisuserdontexist", - "", - null - ); - - for (String invalidUser : invalidList) { - try { - subscriptionExtractor.fromChannelUrl(invalidUser); - - fail("didn't throw exception"); - } catch (IOException e) { - // Ignore it, could be an unstable network on the CI server - } catch (Exception e) { - boolean isExpectedException = e instanceof SubscriptionExtractor.InvalidSourceException; - assertTrue(e.getClass().getSimpleName() + " is not the expected exception", isExpectedException); - } - } - } - - private void testList(List subscriptionItems) throws ParsingException { - for (SubscriptionItem item : subscriptionItems) { - assertNotNull(item.getName()); - assertNotNull(item.getUrl()); - assertTrue(urlHandler.acceptUrl(item.getUrl())); - assertFalse(item.getServiceId() == -1); - } - } -} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSuggestionExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSuggestionExtractorTest.java deleted file mode 100644 index b4ab8dbc..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSuggestionExtractorTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.schabi.newpipe.extractor.services.soundcloud; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.schabi.newpipe.Downloader; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.SuggestionExtractor; -import org.schabi.newpipe.extractor.exceptions.ExtractionException; - -import java.io.IOException; - -import static org.junit.Assert.assertFalse; -import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; - -/** - * Test for {@link SuggestionExtractor} - */ -public class SoundcloudSuggestionExtractorTest { - private static SuggestionExtractor suggestionExtractor; - - @BeforeClass - public static void setUp() throws Exception { - NewPipe.init(Downloader.getInstance()); - suggestionExtractor = SoundCloud.getSuggestionExtractor(); - } - - @Test - public void testIfSuggestions() throws IOException, ExtractionException { - assertFalse(suggestionExtractor.suggestionList("lil uzi vert", "de").isEmpty()); - } -} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/BaseYoutubeSearchTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/BaseYoutubeSearchTest.java deleted file mode 100644 index e643a986..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/BaseYoutubeSearchTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.schabi.newpipe.extractor.services.youtube; - -import org.junit.Test; -import org.schabi.newpipe.extractor.InfoItem; -import org.schabi.newpipe.extractor.channel.ChannelInfoItem; -import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem; -import org.schabi.newpipe.extractor.search.SearchResult; -import org.schabi.newpipe.extractor.stream.StreamInfoItem; - -import static org.junit.Assert.*; -import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; - -public abstract class BaseYoutubeSearchTest { - - protected static SearchResult result; - - @Test - public void testResultList() { - assertFalse("Got empty result list", result.resultList.isEmpty()); - for(InfoItem infoItem: result.resultList) { - assertIsSecureUrl(infoItem.getUrl()); - assertIsSecureUrl(infoItem.getThumbnailUrl()); - assertFalse(infoItem.getName().isEmpty()); - assertFalse("Name is probably a URI: " + infoItem.getName(), - infoItem.getName().contains("://")); - if(infoItem instanceof StreamInfoItem) { - // test stream item - StreamInfoItem streamInfoItem = (StreamInfoItem) infoItem; - assertIsSecureUrl(streamInfoItem.getUploaderUrl()); - assertFalse(streamInfoItem.getUploadDate().isEmpty()); - assertFalse(streamInfoItem.getUploaderName().isEmpty()); - } else if(infoItem instanceof ChannelInfoItem) { - // Nothing special to check? - } else if(infoItem instanceof PlaylistInfoItem) { - // test playlist item - long streamCount = ((PlaylistInfoItem) infoItem).getStreamCount(); - assertTrue(streamCount > 0); - } else { - fail("Unknown infoItem type: " + infoItem); - } - } - } - - @Test - public void testResultErrors() { - assertNotNull(result.errors); - if (!result.errors.isEmpty()) { - for (Throwable error : result.errors) { - error.printStackTrace(); - } - } - assertTrue(result.errors.isEmpty()); - } -} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineChannelTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineChannelTest.java deleted file mode 100644 index f8170a4a..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineChannelTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.schabi.newpipe.extractor.services.youtube; - -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.schabi.newpipe.Downloader; -import org.schabi.newpipe.extractor.InfoItem; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.search.SearchEngine; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; - - -/* - * Created by Christian Schabesberger on 29.12.15. - * - * Copyright (C) Christian Schabesberger 2015 - * YoutubeSearchEngineStreamTest.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 . - */ - -/** - * Test for {@link SearchEngine} - */ -public class YoutubeSearchEngineChannelTest extends BaseYoutubeSearchTest { - - @BeforeClass - public static void setUp() throws Exception { - NewPipe.init(Downloader.getInstance()); - SearchEngine engine = YouTube.getSearchEngine(); - - // Youtube will suggest "gronkh" instead of "grrunkh" - // keep in mind that the suggestions can change by country (the parameter "de") - result = engine.search("grrunkh", 0, "de", SearchEngine.Filter.CHANNEL) - .getSearchResult(); - } - - @Test - public void testResultsItemType() { - for (InfoItem infoItem : result.resultList) { - assertEquals(InfoItem.InfoType.CHANNEL, infoItem.getInfoType()); - } - } - - @Ignore - @Test - public void testSuggestion() { - //todo write a real test - assertTrue(result.suggestion != null); - } -} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEnginePlaylistTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEnginePlaylistTest.java deleted file mode 100644 index 235ba152..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEnginePlaylistTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.schabi.newpipe.extractor.services.youtube; - -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.schabi.newpipe.Downloader; -import org.schabi.newpipe.extractor.InfoItem; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem; -import org.schabi.newpipe.extractor.search.SearchEngine; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; - - -/* - * Created by Christian Schabesberger on 29.12.15. - * - * Copyright (C) Christian Schabesberger 2015 - * YoutubeSearchEngineStreamTest.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 . - */ - -/** - * Test for {@link SearchEngine} - */ -public class YoutubeSearchEnginePlaylistTest extends BaseYoutubeSearchTest { - - @BeforeClass - public static void setUp() throws Exception { - NewPipe.init(Downloader.getInstance()); - SearchEngine engine = YouTube.getSearchEngine(); - - // Youtube will suggest "gronkh" instead of "grrunkh" - // keep in mind that the suggestions can change by country (the parameter "de") - result = engine.search("grrunkh", 0, "de", SearchEngine.Filter.PLAYLIST) - .getSearchResult(); - } - - @Test - public void testInfoItemType() { - for (InfoItem infoItem : result.resultList) { - assertTrue(infoItem instanceof PlaylistInfoItem); - assertEquals(InfoItem.InfoType.PLAYLIST, infoItem.getInfoType()); - } - } - - @Ignore - @Test - public void testSuggestion() { - //todo write a real test - assertTrue(result.suggestion != null); - } -} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineStreamTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineStreamTest.java deleted file mode 100644 index 41d15a73..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineStreamTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.schabi.newpipe.extractor.services.youtube; - -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.schabi.newpipe.Downloader; -import org.schabi.newpipe.extractor.InfoItem; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.search.SearchEngine; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; - - -/* - * Created by Christian Schabesberger on 29.12.15. - * - * Copyright (C) Christian Schabesberger 2015 - * YoutubeSearchEngineStreamTest.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 . - */ - -/** - * Test for {@link SearchEngine} - */ -public class YoutubeSearchEngineStreamTest extends BaseYoutubeSearchTest { - - @BeforeClass - public static void setUp() throws Exception { - NewPipe.init(Downloader.getInstance()); - SearchEngine engine = YouTube.getSearchEngine(); - - // Youtube will suggest "results" instead of "rsults", - // keep in mind that the suggestions can change by country (the parameter "de") - result = engine.search("abc", 0, "de", SearchEngine.Filter.STREAM) - .getSearchResult(); - } - - @Test - public void testResultsItemType() { - for (InfoItem infoItem : result.resultList) { - assertEquals(InfoItem.InfoType.STREAM, infoItem.getInfoType()); - } - } - - @Ignore - @Test - public void testSuggestion() { - //todo write a real test - assertTrue(result.suggestion != null); - } -} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeServiceTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeServiceTest.java index 8d572c32..eef37f48 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeServiceTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeServiceTest.java @@ -4,7 +4,7 @@ package org.schabi.newpipe.extractor.services.youtube; * Created by Christian Schabesberger on 29.12.15. * * Copyright (C) Christian Schabesberger 2015 - * YoutubeSearchEngineStreamTest.java is part of NewPipe. + * YoutubeSearchExtractorStreamTest.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 diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineAllTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorAllTest.java similarity index 69% rename from extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineAllTest.java rename to extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorAllTest.java index 5742f96c..7f7e1c14 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineAllTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorAllTest.java @@ -1,23 +1,25 @@ -package org.schabi.newpipe.extractor.services.youtube; +package org.schabi.newpipe.extractor.services.youtube.search; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.InfoItem; +import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.channel.ChannelInfoItem; import org.schabi.newpipe.extractor.search.SearchEngine; -import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSearchEngine; +import org.schabi.newpipe.extractor.search.SearchExtractor; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; /* * Created by Christian Schabesberger on 29.12.15. * * Copyright (C) Christian Schabesberger 2015 - * YoutubeSearchEngineStreamTest.java is part of NewPipe. + * YoutubeSearchExtractorStreamTest.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 @@ -36,20 +38,22 @@ import static org.junit.Assert.assertTrue; /** * Test for {@link SearchEngine} */ -public class YoutubeSearchEngineAllTest extends BaseYoutubeSearchTest { +public class YoutubeSearchExtractorAllTest { + + private static SearchExtractor extractor; + private static ListExtractor.InfoItemsPage itemsPage; @BeforeClass public static void setUpClass() throws Exception { NewPipe.init(Downloader.getInstance()); - YoutubeSearchEngine engine = new YoutubeSearchEngine(1); - - result = engine.search("pewdiepie", 0, "de", SearchEngine.Filter.ANY) - .getSearchResult(); + extractor = YouTube.getSearchExtractor("pewdiepie", "de"); + extractor.fetchPage(); + itemsPage = extractor.getInitialPage(); } @Test public void testResultList_FirstElement() { - InfoItem firstInfoItem = result.getResults().get(0); + InfoItem firstInfoItem = itemsPage.getItems().get(0); // THe channel should be the first item assertTrue(firstInfoItem instanceof ChannelInfoItem); @@ -59,8 +63,8 @@ public class YoutubeSearchEngineAllTest extends BaseYoutubeSearchTest { @Ignore @Test - public void testSuggestion() { + public void testSuggestion() throws Exception { //todo write a real test - assertTrue(result.getSuggestion() != null); + assertTrue(extractor.getSearchSuggestion() != null); } } From 5718d5b8b406055a8c566eae1e51215c5cee5fc5 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 27 May 2018 19:57:52 +0200 Subject: [PATCH 03/20] add tests for searchextractor --- .../newpipe/extractor/ListUrlIdHandler.java | 4 +- .../newpipe/extractor/StreamingService.java | 4 +- .../search/SearchQueryUrlHandler.java | 1 - .../soundcloud/SoundcloudQueryUrlHandler.java | 2 +- .../extractors/YoutubeSearchExtractor.java | 4 +- .../YoutubeSearchQueryUrlHandler.java | 4 +- .../search/YoutubeSearchExtractorAllTest.java | 70 ----------- .../YoutubeSearchExtractorBaseTest.java | 52 ++++++++ ...YoutubeSearchExtractorChannelOnlyTest.java | 62 ++++++++++ .../YoutubeSearchExtractorDefaultTest.java | 117 ++++++++++++++++++ .../youtube/search/YoutubeSearchQUHTest.java | 57 +++++++++ 11 files changed, 297 insertions(+), 80 deletions(-) delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorAllTest.java create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorBaseTest.java create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorDefaultTest.java create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchQUHTest.java diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/ListUrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/ListUrlIdHandler.java index 494b714a..8357184a 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/ListUrlIdHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/ListUrlIdHandler.java @@ -12,10 +12,10 @@ public abstract class ListUrlIdHandler extends UrlIdHandler { public ListUrlIdHandler setQuery(String id, List contentFilter, - String softFilter) throws ParsingException { + String sortFilter) throws ParsingException { setId(id); this.contentFilter = contentFilter; - this.sortFilter = softFilter; + this.sortFilter = sortFilter; return this; } 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 e0ef1978..d642a749 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java @@ -88,8 +88,8 @@ public abstract class StreamingService { public abstract PlaylistExtractor getPlaylistExtractor(ListUrlIdHandler urlIdHandler) throws ExtractionException; public abstract StreamExtractor getStreamExtractor(UrlIdHandler urlIdHandler) throws ExtractionException; - public SearchExtractor getSearchExtractor(String query, List contentFilter, String softFilter, String contentCountry) throws ExtractionException { - return getSearchExtractor(getSearchQueryHandler().setQuery(query, contentFilter, softFilter), contentCountry); + public SearchExtractor getSearchExtractor(String query, List contentFilter, String sortFilter, String contentCountry) throws ExtractionException { + return getSearchExtractor(getSearchQueryHandler().setQuery(query, contentFilter, sortFilter), contentCountry); } public ChannelExtractor getChannelExtractor(String id, List contentFilter, String sortFilter) throws ExtractionException { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQueryUrlHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQueryUrlHandler.java index d281376b..d72dbb0a 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQueryUrlHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQueryUrlHandler.java @@ -1,7 +1,6 @@ package org.schabi.newpipe.extractor.search; import org.schabi.newpipe.extractor.ListUrlIdHandler; -import org.schabi.newpipe.extractor.UrlIdHandler; import org.schabi.newpipe.extractor.exceptions.ParsingException; import java.util.List; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudQueryUrlHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudQueryUrlHandler.java index 97569a39..6a99e865 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudQueryUrlHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudQueryUrlHandler.java @@ -21,7 +21,7 @@ public class SoundcloudQueryUrlHandler extends SearchQueryUrlHandler { try { String url = "https://api-v2.soundcloud.com/search"; - if(getContentFilter().size() > 1) { + if(getContentFilter().size() > 0) { switch (getContentFilter().get(0)) { case TRACKS: url += "/tracks"; 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 1491cbae..fa7cdf95 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 @@ -66,8 +66,8 @@ public class YoutubeSearchExtractor extends SearchExtractor { } @Override - public String getNextPageUrl() throws IOException, ExtractionException { - return getUrl() + "&page=" + Integer.toString( 1); + public String getNextPageUrl() throws ExtractionException { + return getUrl() + "&page=" + Integer.toString( 2); } @Override diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeSearchQueryUrlHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeSearchQueryUrlHandler.java index 8e6eaf00..a562f609 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeSearchQueryUrlHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeSearchQueryUrlHandler.java @@ -25,13 +25,13 @@ public class YoutubeSearchQueryUrlHandler extends SearchQueryUrlHandler { final String url = "https://www.youtube.com/results" + "?q=" + URLEncoder.encode(id, CHARSET_UTF_8); - if(getContentFilter().size() > 1) { + if(getContentFilter().size() > 0) { switch (getContentFilter().get(0)) { case STREAM: return url + "&sp=EgIQAVAU"; case CHANNEL: return url + "&sp=EgIQAlAU"; case PLAYLIST: return url + "&sp=EgIQA1AU"; case ANY: - default: return url; + default: } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorAllTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorAllTest.java deleted file mode 100644 index 7f7e1c14..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorAllTest.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.schabi.newpipe.extractor.services.youtube.search; - -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.schabi.newpipe.Downloader; -import org.schabi.newpipe.extractor.InfoItem; -import org.schabi.newpipe.extractor.ListExtractor; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.channel.ChannelInfoItem; -import org.schabi.newpipe.extractor.search.SearchEngine; -import org.schabi.newpipe.extractor.search.SearchExtractor; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; - -/* - * Created by Christian Schabesberger on 29.12.15. - * - * Copyright (C) Christian Schabesberger 2015 - * YoutubeSearchExtractorStreamTest.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 . - */ - -/** - * Test for {@link SearchEngine} - */ -public class YoutubeSearchExtractorAllTest { - - private static SearchExtractor extractor; - private static ListExtractor.InfoItemsPage itemsPage; - - @BeforeClass - public static void setUpClass() throws Exception { - NewPipe.init(Downloader.getInstance()); - extractor = YouTube.getSearchExtractor("pewdiepie", "de"); - extractor.fetchPage(); - itemsPage = extractor.getInitialPage(); - } - - @Test - public void testResultList_FirstElement() { - InfoItem firstInfoItem = itemsPage.getItems().get(0); - - // THe channel should be the first item - assertTrue(firstInfoItem instanceof ChannelInfoItem); - assertEquals("name", "PewDiePie", firstInfoItem.getName()); - assertEquals("url","https://www.youtube.com/user/PewDiePie", firstInfoItem.getUrl()); - } - - @Ignore - @Test - public void testSuggestion() throws Exception { - //todo write a real test - assertTrue(extractor.getSearchSuggestion() != null); - } -} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorBaseTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorBaseTest.java new file mode 100644 index 00000000..8b19b11e --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorBaseTest.java @@ -0,0 +1,52 @@ +package org.schabi.newpipe.extractor.services.youtube.search; + +import org.junit.Test; +import org.schabi.newpipe.extractor.InfoItem; +import org.schabi.newpipe.extractor.ListExtractor; +import org.schabi.newpipe.extractor.services.BaseListExtractorTest; +import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSearchExtractor; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + + +/* + * Created by Christian Schabesberger on 27.05.18 + * + * Copyright (C) Christian Schabesberger 2018 + * YoutubeSearchExtractorBaseTest.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 . + */ + +/** + * Test for {@link YoutubeSearchExtractor} + */ +public abstract class YoutubeSearchExtractorBaseTest { + + protected static YoutubeSearchExtractor extractor; + protected static ListExtractor.InfoItemsPage itemsPage; + + + @Test + public void testResultListElementsLength() { + assertTrue(Integer.toString(itemsPage.getItems().size()), + itemsPage.getItems().size() > 10); + } + + @Test + public void testUrl() throws Exception { + assertTrue(extractor.getUrl(), extractor.getUrl().startsWith("https://www.youtube.com")); + } +} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java new file mode 100644 index 00000000..f42ad407 --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java @@ -0,0 +1,62 @@ +package org.schabi.newpipe.extractor.services.youtube.search; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.InfoItem; +import org.schabi.newpipe.extractor.ListExtractor; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.channel.ChannelInfoItem; +import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSearchExtractor; + +import static java.util.Arrays.asList; +import static org.junit.Assert.*; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; + +public class YoutubeSearchExtractorChannelOnlyTest extends YoutubeSearchExtractorBaseTest { + + @BeforeClass + public static void setUpClass() throws Exception { + NewPipe.init(Downloader.getInstance()); + extractor = (YoutubeSearchExtractor) YouTube.getSearchExtractor("pewdiepie", + asList(new String[]{"channel"}), null, "de"); + extractor.fetchPage(); + itemsPage = extractor.getInitialPage(); + } + + @Test + public void testGetSecondPage() throws Exception { + YoutubeSearchExtractor secondExtractor = (YoutubeSearchExtractor) YouTube.getSearchExtractor("pewdiepie", + asList(new String[]{"channel"}), null, "de"); + ListExtractor.InfoItemsPage secondPage = secondExtractor.getPage(itemsPage.getNextPageUrl()); + assertTrue(Integer.toString(secondPage.getItems().size()), + secondPage.getItems().size() > 10); + + // check if its the same result + boolean equals = true; + for (int i = 0; i < secondPage.getItems().size() + && i < itemsPage.getItems().size(); i++) { + if(!secondPage.getItems().get(i).getUrl().equals( + itemsPage.getItems().get(i).getUrl())) { + equals = false; + } + } + assertFalse("First and second page are equal", equals); + + assertEquals("https://www.youtube.com/results?q=pewdiepie&sp=EgIQAlAU&page=3", secondPage.getNextPageUrl()); + } + + @Test + public void testGetSecondPageUrl() throws Exception { + assertEquals("https://www.youtube.com/results?q=pewdiepie&sp=EgIQAlAU&page=2", extractor.getNextPageUrl()); + } + + @Test + public void testOnlyContainChannels() { + for(InfoItem item : itemsPage.getItems()) { + if(!(item instanceof ChannelInfoItem)) { + fail("The following item is no channel item: " + item.toString()); + } + } + } +} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorDefaultTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorDefaultTest.java new file mode 100644 index 00000000..8b92e6d8 --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorDefaultTest.java @@ -0,0 +1,117 @@ +package org.schabi.newpipe.extractor.services.youtube.search; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.InfoItem; +import org.schabi.newpipe.extractor.ListExtractor; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.channel.ChannelInfoItem; +import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSearchExtractor; +import org.schabi.newpipe.extractor.stream.StreamInfoItem; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; + +/* + * Created by Christian Schabesberger on 27.05.18 + * + * Copyright (C) Christian Schabesberger 2018 + * YoutubeSearchExtractorStreamTest.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 . + */ + +/** + * Test for {@link YoutubeSearchExtractor} + */ +public class YoutubeSearchExtractorDefaultTest extends YoutubeSearchExtractorBaseTest { + + @BeforeClass + public static void setUpClass() throws Exception { + NewPipe.init(Downloader.getInstance()); + extractor = (YoutubeSearchExtractor) YouTube.getSearchExtractor("pewdiepie", "de"); + extractor.fetchPage(); + itemsPage = extractor.getInitialPage(); + } + + + + @Test + public void testGetSecondPageUrl() throws Exception { + assertEquals(extractor.getNextPageUrl(), "https://www.youtube.com/results?q=pewdiepie&page=2"); + } + + @Test + public void testResultList_FirstElement() { + InfoItem firstInfoItem = itemsPage.getItems().get(0); + + // THe channel should be the first item + assertTrue(firstInfoItem instanceof ChannelInfoItem); + assertEquals("name", "PewDiePie", firstInfoItem.getName()); + assertEquals("url","https://www.youtube.com/user/PewDiePie", firstInfoItem.getUrl()); + } + + @Test + public void testResultListCheckIfContainsStreamItems() { + boolean hasStreams = false; + for(InfoItem item : itemsPage.getItems()) { + if(item instanceof StreamInfoItem) { + hasStreams = true; + } + } + assertTrue("Has no InfoItemStreams", hasStreams); + } + + @Test + public void testGetSecondPage() throws Exception { + YoutubeSearchExtractor secondExtractor = + (YoutubeSearchExtractor) YouTube.getSearchExtractor("pewdiepie", "de"); + ListExtractor.InfoItemsPage secondPage = secondExtractor.getPage(itemsPage.getNextPageUrl()); + assertTrue(Integer.toString(secondPage.getItems().size()), + secondPage.getItems().size() > 10); + + // check if its the same result + boolean equals = true; + for (int i = 0; i < secondPage.getItems().size() + && i < itemsPage.getItems().size(); i++) { + if(!secondPage.getItems().get(i).getUrl().equals( + itemsPage.getItems().get(i).getUrl())) { + equals = false; + } + } + assertFalse("First and second page are equal", equals); + + assertEquals("https://www.youtube.com/results?q=pewdiepie&page=3", secondPage.getNextPageUrl()); + } + + @Test + public void testSuggestionNotNull() throws Exception { + //todo write a real test + assertTrue(extractor.getSearchSuggestion() != null); + } + + + @Test + public void testId() throws Exception { + assertEquals(extractor.getId(), "pewdiepie"); + } + + @Test + public void testName() { + assertEquals(extractor.getName(), "pewdiepie"); + } +} 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 new file mode 100644 index 00000000..322c9e75 --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchQUHTest.java @@ -0,0 +1,57 @@ +package org.schabi.newpipe.extractor.services.youtube.search; + +import org.junit.Test; + +import java.util.ArrayList; + +import static java.util.Arrays.asList; +import static org.junit.Assert.assertEquals; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; + +public class YoutubeSearchQUHTest { + + @Test + public void testRegularValues() throws Exception { + assertEquals("https://www.youtube.com/results?q=asdf", YouTube.getSearchQueryHandler().setQuery("asdf").getUrl()); + assertEquals("https://www.youtube.com/results?q=hans",YouTube.getSearchQueryHandler().setQuery("hans").getUrl()); + assertEquals("https://www.youtube.com/results?q=Poifj%26jaijf", YouTube.getSearchQueryHandler().setQuery("Poifj&jaijf").getUrl()); + assertEquals("https://www.youtube.com/results?q=G%C3%BCl%C3%BCm", YouTube.getSearchQueryHandler().setQuery("GÌlÌm").getUrl()); + assertEquals("https://www.youtube.com/results?q=%3Fj%24%29H%C2%A7B", YouTube.getSearchQueryHandler().setQuery("?j$)H§B").getUrl()); + } + + @Test + public void testGetContentFilter() throws Exception { + assertEquals("stream", YouTube.getSearchQueryHandler() + .setQuery("", asList(new String[]{"stream"}), "").getContentFilter().get(0)); + assertEquals("channel", YouTube.getSearchQueryHandler() + .setQuery("asdf", asList(new String[]{"channel"}), "").getContentFilter().get(0)); + } + + @Test + public void testWithContentfilter() throws Exception { + assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQAVAU", YouTube.getSearchQueryHandler() + .setQuery("asdf", asList(new String[]{"stream"}), "").getUrl()); + assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQAlAU", YouTube.getSearchQueryHandler() + .setQuery("asdf", asList(new String[]{"channel"}), "").getUrl()); + assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQA1AU", YouTube.getSearchQueryHandler() + .setQuery("asdf", asList(new String[]{"playlist"}), "").getUrl()); + assertEquals("https://www.youtube.com/results?q=asdf", YouTube.getSearchQueryHandler() + .setQuery("asdf", asList(new String[]{"fjiijie"}), "").getUrl()); + } + + @Test + public void testGetAvailableContentFilter() { + final String[] contentFilter = YouTube.getSearchQueryHandler().getAvailableContentFilter(); + assertEquals(4, contentFilter.length); + assertEquals("stream", contentFilter[0]); + assertEquals("channel", contentFilter[1]); + assertEquals("playlist", contentFilter[2]); + assertEquals("any", contentFilter[3]); + } + + @Test + public void testGetAvailableSortFilter() { + final String[] contentFilter = YouTube.getSearchQueryHandler().getAvailableSortFilter(); + assertEquals(0, contentFilter.length); + } +} From ef2ce6854cef6824d2b780b7817212f1d77d2a7e Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Fri, 1 Jun 2018 19:08:49 +0200 Subject: [PATCH 04/20] add soundcloud SearchExtractor --- .../soundcloud/SoundcloudSearchExtractor.java | 113 ++++++++++++++++++ ...a => SoundcloudSearchQueryUrlHandler.java} | 7 +- .../soundcloud/SoundcloudService.java | 10 +- .../extractors/YoutubeSearchExtractor.java | 8 +- 4 files changed, 127 insertions(+), 11 deletions(-) create mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchExtractor.java rename extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/{SoundcloudQueryUrlHandler.java => SoundcloudSearchQueryUrlHandler.java} (90%) 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 new file mode 100644 index 00000000..50452bc2 --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchExtractor.java @@ -0,0 +1,113 @@ +package org.schabi.newpipe.extractor.services.soundcloud; + +import com.grack.nanojson.JsonArray; +import com.grack.nanojson.JsonObject; +import com.grack.nanojson.JsonParser; +import com.grack.nanojson.JsonParserException; +import org.schabi.newpipe.extractor.*; +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.SearchEngine; +import org.schabi.newpipe.extractor.search.SearchExtractor; +import org.schabi.newpipe.extractor.search.SearchQueryUrlHandler; +import org.schabi.newpipe.extractor.utils.Parser; + +import javax.annotation.Nonnull; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URL; + +import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudSearchQueryUrlHandler.ITEMS_PER_PAGE; + +public class SoundcloudSearchExtractor extends SearchExtractor { + + private JsonArray searchCollection; + + public SoundcloudSearchExtractor(StreamingService service, + SearchQueryUrlHandler urlIdHandler, + String contentCountry) { + super(service, urlIdHandler, contentCountry); + } + + @Override + public String getSearchSuggestion() throws ParsingException { + return null; + } + + @Nonnull + @Override + public InfoItemsPage getInitialPage() throws IOException, ExtractionException { + return new InfoItemsPage<>(collectItems(searchCollection), getNextPageUrl()); + } + + @Override + public String getNextPageUrl() throws IOException, ExtractionException { + return getNextPageUrlFromCurrentUrl(getUrl()); + } + + @Override + public InfoItemsPage getPage(String pageUrl) throws IOException, ExtractionException { + final Downloader dl = getDownloader(); + try { + searchCollection = JsonParser.object().from(dl.download(pageUrl)).getArray("collection"); + } catch (JsonParserException e) { + throw new ParsingException("Could not parse json response", e); + } + + return new InfoItemsPage<>(collectItems(searchCollection), getNextPageUrlFromCurrentUrl(pageUrl)); + } + + @Override + public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { + final Downloader dl = getDownloader(); + final String url = getUrl(); + try { + searchCollection = JsonParser.object().from(dl.download(url)).getArray("collection"); + } catch (JsonParserException e) { + throw new ParsingException("Could not parse json response", e); + } + + if (searchCollection.size() == 0) { + throw new SearchEngine.NothingFoundException("Nothing found"); + } + } + + private InfoItemsCollector collectItems(JsonArray searchCollection) { + final InfoItemsSearchCollector collector = getInfoItemSearchCollector(); + + for (Object result : searchCollection) { + if (!(result instanceof JsonObject)) continue; + //noinspection ConstantConditions + JsonObject searchResult = (JsonObject) result; + String kind = searchResult.getString("kind", ""); + switch (kind) { + case "user": + collector.commit(new SoundcloudChannelInfoItemExtractor(searchResult)); + break; + case "track": + collector.commit(new SoundcloudStreamInfoItemExtractor(searchResult)); + break; + case "playlist": + collector.commit(new SoundcloudPlaylistInfoItemExtractor(searchResult)); + break; + } + } + + return collector; + } + + private String getNextPageUrlFromCurrentUrl(String currentUrl) + throws MalformedURLException, UnsupportedEncodingException { + final int pageOffset = Integer.parseInt( + Parser.compatParseMap( + new URL(currentUrl) + .getQuery()) + .get("offset")); + + return currentUrl.replace("&offset=" + + Integer.toString(pageOffset), + "&offset=" + Integer.toString(pageOffset + ITEMS_PER_PAGE)); + } +} diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudQueryUrlHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQueryUrlHandler.java similarity index 90% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudQueryUrlHandler.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQueryUrlHandler.java index 6a99e865..92d4c6bc 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudQueryUrlHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQueryUrlHandler.java @@ -8,7 +8,7 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; -public class SoundcloudQueryUrlHandler extends SearchQueryUrlHandler { +public class SoundcloudSearchQueryUrlHandler extends SearchQueryUrlHandler { public static final String CHARSET_UTF_8 = "UTF-8"; public static final String TRACKS = "tracks"; @@ -16,6 +16,8 @@ public class SoundcloudQueryUrlHandler extends SearchQueryUrlHandler { public static final String PLAYLIST = "playlist"; public static final String ANY = "any"; + public static final int ITEMS_PER_PAGE = 10; + @Override public String getUrl() throws ParsingException { try { @@ -40,7 +42,8 @@ public class SoundcloudQueryUrlHandler extends SearchQueryUrlHandler { return url + "?q=" + URLEncoder.encode(id, CHARSET_UTF_8) + "&client_id=" + SoundcloudParsingHelper.clientId() - + "&limit=10"; + + "&limit=" + ITEMS_PER_PAGE + + "&offset=0"; } catch (UnsupportedEncodingException e) { throw new ParsingException("Could not encode query", e); 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 036acd1b..73334a34 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 @@ -31,12 +31,12 @@ public class SoundcloudService extends StreamingService { @Override public SearchExtractor getSearchExtractor(SearchQueryUrlHandler queryHandler, String contentCountry) { - return null; + return new SoundcloudSearchExtractor(this, queryHandler, contentCountry); } @Override public SearchQueryUrlHandler getSearchQueryHandler() { - return null; + return new SoundcloudSearchQueryUrlHandler(); } @Override @@ -56,17 +56,17 @@ public class SoundcloudService extends StreamingService { @Override - public StreamExtractor getStreamExtractor(UrlIdHandler urlIdHandler) throws ExtractionException { + public StreamExtractor getStreamExtractor(UrlIdHandler urlIdHandler) { return new SoundcloudStreamExtractor(this, urlIdHandler); } @Override - public ChannelExtractor getChannelExtractor(ListUrlIdHandler urlIdHandler) throws ExtractionException { + public ChannelExtractor getChannelExtractor(ListUrlIdHandler urlIdHandler) { return new SoundcloudChannelExtractor(this, urlIdHandler); } @Override - public PlaylistExtractor getPlaylistExtractor(ListUrlIdHandler urlIdHandler) throws ExtractionException { + public PlaylistExtractor getPlaylistExtractor(ListUrlIdHandler urlIdHandler) { return new SoundcloudPlaylistExtractor(this, urlIdHandler); } 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 fa7cdf95..5d51ed1e 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 @@ -80,14 +80,14 @@ public class YoutubeSearchExtractor extends SearchExtractor { private String getNextPageUrlFromCurrentUrl(String currentUrl) throws MalformedURLException, UnsupportedEncodingException { - int nextPageNr = Integer.parseInt( + final int pageNr = Integer.parseInt( Parser.compatParseMap( new URL(currentUrl) .getQuery()) - .get("page")) + 1; + .get("page")); - return currentUrl.replace("&page=" + Integer.toString( nextPageNr-1), - "&page=" + Integer.toString(nextPageNr)); + return currentUrl.replace("&page=" + Integer.toString( pageNr), + "&page=" + Integer.toString(pageNr + 1)); } private InfoItemsSearchCollector collectItems(Document doc) throws NothingFoundException { From 9bda761103c63f13d4b3fa59661512552c5b7751 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 17 Jun 2018 21:23:13 +0200 Subject: [PATCH 05/20] add test for soundcloud search extractor --- .../schabi/newpipe/extractor/ServiceList.java | 9 +- .../SoundcloudChannelExtractorTest.java | 198 +++++++++++ .../SoundcloudChartsExtractorTest.java | 93 +++++ .../SoundcloudChartsUrlIdHandlerTest.java | 50 +++ .../SoundcloudParsingHelperTest.java | 28 ++ .../SoundcloudPlaylistExtractorTest.java | 319 ++++++++++++++++++ .../SoundcloudStreamExtractorDefaultTest.java | 119 +++++++ .../SoundcloudStreamUrlIdHandlerTest.java | 78 +++++ .../SoundcloudSubscriptionExtractorTest.java | 76 +++++ .../SoundcloudSuggestionExtractorTest.java | 31 ++ .../SoundcloudSearchExtractorBaseTest.java | 50 +++ ...ndcloudSearchExtractorChannelOnlyTest.java | 64 ++++ .../SoundcloudSearchExtractorDefaultTest.java | 109 ++++++ .../search/SoundcloudSearchQUHTest.java | 64 ++++ .../YoutubeSearchExtractorDefaultTest.java | 6 +- 15 files changed, 1289 insertions(+), 5 deletions(-) create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractorTest.java create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandlerTest.java create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelperTest.java create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractorTest.java create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUrlIdHandlerTest.java create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSubscriptionExtractorTest.java create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSuggestionExtractorTest.java create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorBaseTest.java create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorChannelOnlyTest.java create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorDefaultTest.java create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchQUHTest.java diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/ServiceList.java b/extractor/src/main/java/org/schabi/newpipe/extractor/ServiceList.java index f61e204d..846355ed 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/ServiceList.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/ServiceList.java @@ -1,5 +1,6 @@ package org.schabi.newpipe.extractor; +import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudService; import org.schabi.newpipe.extractor.services.youtube.YoutubeService; import java.util.List; @@ -15,10 +16,14 @@ public final class ServiceList { //no instance } - public static final YoutubeService YouTube = new YoutubeService(0); + public static final YoutubeService YouTube; + public static final SoundcloudService SoundCloud; private static final List SERVICES = unmodifiableList( - asList((StreamingService) YouTube)); + asList( + YouTube = new YoutubeService(0), + SoundCloud = new SoundcloudService(1) + )); /** * Get all the supported services. diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractorTest.java new file mode 100644 index 00000000..30884adc --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractorTest.java @@ -0,0 +1,198 @@ +package org.schabi.newpipe.extractor.services.soundcloud; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.channel.ChannelExtractor; +import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest; + +import static org.junit.Assert.*; +import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmpty; +import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; +import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; +import static org.schabi.newpipe.extractor.services.DefaultTests.*; + +/** + * Test for {@link SoundcloudChannelExtractor} + */ +public class SoundcloudChannelExtractorTest { + public static class LilUzi implements BaseChannelExtractorTest { + private static SoundcloudChannelExtractor extractor; + + @BeforeClass + public static void setUp() throws Exception { + NewPipe.init(Downloader.getInstance()); + extractor = (SoundcloudChannelExtractor) SoundCloud + .getChannelExtractor("http://soundcloud.com/liluzivert/sets"); + extractor.fetchPage(); + } + + /*////////////////////////////////////////////////////////////////////////// + // Extractor + //////////////////////////////////////////////////////////////////////////*/ + + @Test + public void testServiceId() { + assertEquals(SoundCloud.getServiceId(), extractor.getServiceId()); + } + + @Test + public void testName() { + assertEquals("LIL UZI VERT", extractor.getName()); + } + + @Test + public void testId() { + assertEquals("10494998", extractor.getId()); + } + + @Test + public void testUrl() throws ParsingException { + assertEquals("https://soundcloud.com/liluzivert", extractor.getUrl()); + } + + @Test + public void testOriginalUrl() throws ParsingException { + assertEquals("http://soundcloud.com/liluzivert/sets", extractor.getOriginalUrl()); + } + + /*////////////////////////////////////////////////////////////////////////// + // ListExtractor + //////////////////////////////////////////////////////////////////////////*/ + + @Test + public void testRelatedItems() throws Exception { + defaultTestRelatedItems(extractor, SoundCloud.getServiceId()); + } + + @Test + public void testMoreRelatedItems() throws Exception { + defaultTestMoreItems(extractor, SoundCloud.getServiceId()); + } + + /*////////////////////////////////////////////////////////////////////////// + // ChannelExtractor + //////////////////////////////////////////////////////////////////////////*/ + + @Test + public void testDescription() { + assertNotNull(extractor.getDescription()); + } + + @Test + public void testAvatarUrl() { + assertIsSecureUrl(extractor.getAvatarUrl()); + } + + @Test + public void testBannerUrl() { + assertIsSecureUrl(extractor.getBannerUrl()); + } + + @Test + public void testFeedUrl() { + assertEmpty(extractor.getFeedUrl()); + } + + @Test + public void testSubscriberCount() { + assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 1e6); + } + } + + public static class DubMatix implements BaseChannelExtractorTest { + private static SoundcloudChannelExtractor extractor; + + @BeforeClass + public static void setUp() throws Exception { + NewPipe.init(Downloader.getInstance()); + extractor = (SoundcloudChannelExtractor) SoundCloud + .getChannelExtractor("https://soundcloud.com/dubmatix"); + extractor.fetchPage(); + } + + /*////////////////////////////////////////////////////////////////////////// + // Additional Testing + //////////////////////////////////////////////////////////////////////////*/ + + @Test + public void testGetPageInNewExtractor() throws Exception { + final ChannelExtractor newExtractor = SoundCloud.getChannelExtractor(extractor.getUrl()); + defaultTestGetPageInNewExtractor(extractor, newExtractor, SoundCloud.getServiceId()); + } + + /*////////////////////////////////////////////////////////////////////////// + // Extractor + //////////////////////////////////////////////////////////////////////////*/ + + @Test + public void testServiceId() { + assertEquals(SoundCloud.getServiceId(), extractor.getServiceId()); + } + + @Test + public void testName() { + assertEquals("dubmatix", extractor.getName()); + } + + @Test + public void testId() { + assertEquals("542134", extractor.getId()); + } + + @Test + public void testUrl() throws ParsingException { + assertEquals("https://soundcloud.com/dubmatix", extractor.getUrl()); + } + + @Test + public void testOriginalUrl() throws ParsingException { + assertEquals("https://soundcloud.com/dubmatix", extractor.getOriginalUrl()); + } + + /*////////////////////////////////////////////////////////////////////////// + // ListExtractor + //////////////////////////////////////////////////////////////////////////*/ + + @Test + public void testRelatedItems() throws Exception { + defaultTestRelatedItems(extractor, SoundCloud.getServiceId()); + } + + @Test + public void testMoreRelatedItems() throws Exception { + defaultTestMoreItems(extractor, SoundCloud.getServiceId()); + } + + /*////////////////////////////////////////////////////////////////////////// + // ChannelExtractor + //////////////////////////////////////////////////////////////////////////*/ + + @Test + public void testDescription() { + assertNotNull(extractor.getDescription()); + } + + @Test + public void testAvatarUrl() { + assertIsSecureUrl(extractor.getAvatarUrl()); + } + + @Test + public void testBannerUrl() { + assertIsSecureUrl(extractor.getBannerUrl()); + } + + @Test + public void testFeedUrl() { + assertEmpty(extractor.getFeedUrl()); + } + + @Test + public void testSubscriberCount() { + assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 2e6); + } + } +} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java new file mode 100644 index 00000000..a7723024 --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java @@ -0,0 +1,93 @@ +package org.schabi.newpipe.extractor.services.soundcloud; + +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.ListExtractor; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.kiosk.KioskExtractor; +import org.schabi.newpipe.extractor.stream.StreamInfoItem; + +import java.util.List; + +import static org.junit.Assert.*; +import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; + +/** + * Test for {@link SoundcloudChartsUrlIdHandler} + */ +public class SoundcloudChartsExtractorTest { + + static KioskExtractor extractor; + + @BeforeClass + public static void setUp() throws Exception { + NewPipe.init(Downloader.getInstance()); + extractor = SoundCloud + .getKioskList() + .getExtractorById("Top 50", null); + extractor.fetchPage(); + } + + @Test + public void testGetDownloader() throws Exception { + assertNotNull(NewPipe.getDownloader()); + } + + @Ignore + @Test + public void testGetName() throws Exception { + assertEquals(extractor.getName(), "Top 50"); + } + + @Test + public void testId() { + assertEquals(extractor.getId(), "Top 50"); + } + + @Test + public void testGetStreams() throws Exception { + ListExtractor.InfoItemsPage page = extractor.getInitialPage(); + if(!page.getErrors().isEmpty()) { + System.err.println("----------"); + List errors = page.getErrors(); + for(Throwable e: errors) { + e.printStackTrace(); + System.err.println("----------"); + } + } + assertTrue("no streams are received", + !page.getItems().isEmpty() + && page.getErrors().isEmpty()); + } + + @Test + public void testGetStreamsErrors() throws Exception { + assertTrue("errors during stream list extraction", extractor.getInitialPage().getErrors().isEmpty()); + } + + @Test + public void testHasMoreStreams() throws Exception { + // Setup the streams + extractor.getInitialPage(); + assertTrue("has more streams", extractor.hasNextPage()); + } + + @Test + public void testGetNextPageUrl() throws Exception { + assertTrue(extractor.hasNextPage()); + } + + @Test + public void testGetNextPage() throws Exception { + extractor.getInitialPage().getItems(); + assertFalse("extractor has next streams", extractor.getPage(extractor.getNextPageUrl()) == null + || extractor.getPage(extractor.getNextPageUrl()).getItems().isEmpty()); + } + + @Test + public void testGetCleanUrl() throws Exception { + assertEquals(extractor.getUrl(), "https://soundcloud.com/charts/top"); + } +} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandlerTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandlerTest.java new file mode 100644 index 00000000..4fa09ffa --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandlerTest.java @@ -0,0 +1,50 @@ +package org.schabi.newpipe.extractor.services.soundcloud; + +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.ParsingException; + +import static junit.framework.TestCase.assertFalse; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Test for {@link SoundcloudChartsUrlIdHandler} + */ +public class SoundcloudChartsUrlIdHandlerTest { + private static SoundcloudChartsUrlIdHandler urlIdHandler; + + @BeforeClass + public static void setUp() throws Exception { + urlIdHandler = new SoundcloudChartsUrlIdHandler(); + NewPipe.init(Downloader.getInstance()); + } + + @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"); + } + + @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"); + } + + @Test + public void acceptUrl() throws ParsingException { + assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/charts")); + assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/charts/")); + assertTrue(urlIdHandler.acceptUrl("https://www.soundcloud.com/charts/new")); + assertTrue(urlIdHandler.acceptUrl("http://soundcloud.com/charts/top?genre=all-music")); + assertTrue(urlIdHandler.acceptUrl("HTTP://www.soundcloud.com/charts/new/?genre=all-music&country=all-countries")); + + assertFalse(urlIdHandler.acceptUrl("kdskjfiiejfia")); + assertFalse(urlIdHandler.acceptUrl("soundcloud.com/charts askjkf")); + assertFalse(urlIdHandler.acceptUrl(" soundcloud.com/charts")); + assertFalse(urlIdHandler.acceptUrl("")); + } +} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelperTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelperTest.java new file mode 100644 index 00000000..1e38d2ac --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelperTest.java @@ -0,0 +1,28 @@ +package org.schabi.newpipe.extractor.services.soundcloud; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.NewPipe; + +public class SoundcloudParsingHelperTest { + @BeforeClass + public static void setUp() { + NewPipe.init(Downloader.getInstance()); + } + + @Test + public void resolveUrlWithEmbedPlayerTest() throws Exception { + Assert.assertEquals("https://soundcloud.com/trapcity", SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/users/26057743")); + Assert.assertEquals("https://soundcloud.com/nocopyrightsounds", SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/users/16069159")); + } + + @Test + public void resolveIdWithEmbedPlayerTest() throws Exception { + Assert.assertEquals("26057743", SoundcloudParsingHelper.resolveIdWithEmbedPlayer("https://soundcloud.com/trapcity")); + Assert.assertEquals("16069159", SoundcloudParsingHelper.resolveIdWithEmbedPlayer("https://soundcloud.com/nocopyrightsounds")); + + } + +} \ No newline at end of file diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractorTest.java new file mode 100644 index 00000000..29bf4d17 --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractorTest.java @@ -0,0 +1,319 @@ +package org.schabi.newpipe.extractor.services.soundcloud; + +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.ListExtractor; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.ServiceList; +import org.schabi.newpipe.extractor.playlist.PlaylistExtractor; +import org.schabi.newpipe.extractor.services.BasePlaylistExtractorTest; +import org.schabi.newpipe.extractor.stream.StreamInfoItem; + +import static org.junit.Assert.*; +import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; +import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; +import static org.schabi.newpipe.extractor.services.DefaultTests.*; + +/** + * Test for {@link PlaylistExtractor} + */ +public class SoundcloudPlaylistExtractorTest { + public static class LuvTape implements BasePlaylistExtractorTest { + private static SoundcloudPlaylistExtractor extractor; + + @BeforeClass + public static void setUp() throws Exception { + NewPipe.init(Downloader.getInstance()); + extractor = (SoundcloudPlaylistExtractor) SoundCloud + .getPlaylistExtractor("https://soundcloud.com/liluzivert/sets/the-perfect-luv-tape-r?test=123"); + extractor.fetchPage(); + } + + /*////////////////////////////////////////////////////////////////////////// + // Extractor + //////////////////////////////////////////////////////////////////////////*/ + + @Test + public void testServiceId() { + assertEquals(SoundCloud.getServiceId(), extractor.getServiceId()); + } + + @Test + public void testName() { + assertEquals("THE PERFECT LUV TAPE®", extractor.getName()); + } + + @Test + public void testId() { + assertEquals("246349810", extractor.getId()); + } + + @Test + public void testUrl() throws Exception { + assertEquals("https://soundcloud.com/liluzivert/sets/the-perfect-luv-tape-r", extractor.getUrl()); + } + + @Test + public void testOriginalUrl() throws Exception { + assertEquals("https://soundcloud.com/liluzivert/sets/the-perfect-luv-tape-r?test=123", extractor.getOriginalUrl()); + } + + /*////////////////////////////////////////////////////////////////////////// + // ListExtractor + //////////////////////////////////////////////////////////////////////////*/ + + @Test + public void testRelatedItems() throws Exception { + defaultTestRelatedItems(extractor, SoundCloud.getServiceId()); + } + + @Test + public void testMoreRelatedItems() { + try { + defaultTestMoreItems(extractor, SoundCloud.getServiceId()); + } catch (Throwable ignored) { + return; + } + + fail("This playlist doesn't have more items, it should throw an error"); + } + + /*////////////////////////////////////////////////////////////////////////// + // PlaylistExtractor + //////////////////////////////////////////////////////////////////////////*/ + + @Test + public void testThumbnailUrl() { + assertIsSecureUrl(extractor.getThumbnailUrl()); + } + + @Ignore + @Test + public void testBannerUrl() { + assertIsSecureUrl(extractor.getBannerUrl()); + } + + @Test + public void testUploaderUrl() { + final String uploaderUrl = extractor.getUploaderUrl(); + assertIsSecureUrl(uploaderUrl); + assertTrue(uploaderUrl, uploaderUrl.contains("liluzivert")); + } + + @Test + public void testUploaderName() { + assertTrue(extractor.getUploaderName().contains("LIL UZI VERT")); + } + + @Test + public void testUploaderAvatarUrl() { + assertIsSecureUrl(extractor.getUploaderAvatarUrl()); + } + + @Test + public void testStreamCount() { + assertTrue("Error in the streams count", extractor.getStreamCount() >= 10); + } + } + + public static class RandomHouseDanceMusic implements BasePlaylistExtractorTest { + private static SoundcloudPlaylistExtractor extractor; + + @BeforeClass + public static void setUp() throws Exception { + NewPipe.init(Downloader.getInstance()); + extractor = (SoundcloudPlaylistExtractor) SoundCloud + .getPlaylistExtractor("https://soundcloud.com/hunter-leader/sets/house-electro-dance-music-2"); + extractor.fetchPage(); + } + + /*////////////////////////////////////////////////////////////////////////// + // Extractor + //////////////////////////////////////////////////////////////////////////*/ + + @Test + public void testServiceId() { + assertEquals(SoundCloud.getServiceId(), extractor.getServiceId()); + } + + @Test + public void testName() { + assertEquals("House, Electro , Dance Music 2", extractor.getName()); + } + + @Test + public void testId() { + assertEquals("310980722", extractor.getId()); + } + + @Test + public void testUrl() throws Exception { + assertEquals("https://soundcloud.com/hunter-leader/sets/house-electro-dance-music-2", extractor.getUrl()); + } + + @Test + public void testOriginalUrl() throws Exception { + assertEquals("https://soundcloud.com/hunter-leader/sets/house-electro-dance-music-2", extractor.getOriginalUrl()); + } + + /*////////////////////////////////////////////////////////////////////////// + // ListExtractor + //////////////////////////////////////////////////////////////////////////*/ + + @Test + public void testRelatedItems() throws Exception { + defaultTestRelatedItems(extractor, SoundCloud.getServiceId()); + } + + @Test + public void testMoreRelatedItems() throws Exception { + defaultTestMoreItems(extractor, SoundCloud.getServiceId()); + } + + /*////////////////////////////////////////////////////////////////////////// + // PlaylistExtractor + //////////////////////////////////////////////////////////////////////////*/ + + @Test + public void testThumbnailUrl() { + assertIsSecureUrl(extractor.getThumbnailUrl()); + } + + @Ignore + @Test + public void testBannerUrl() { + assertIsSecureUrl(extractor.getBannerUrl()); + } + + @Test + public void testUploaderUrl() { + final String uploaderUrl = extractor.getUploaderUrl(); + assertIsSecureUrl(uploaderUrl); + assertTrue(uploaderUrl, uploaderUrl.contains("hunter-leader")); + } + + @Test + public void testUploaderName() { + assertEquals("Gosu", extractor.getUploaderName()); + } + + @Test + public void testUploaderAvatarUrl() { + assertIsSecureUrl(extractor.getUploaderAvatarUrl()); + } + + @Test + public void testStreamCount() { + assertTrue("Error in the streams count", extractor.getStreamCount() >= 10); + } + } + + public static class EDMxxx implements BasePlaylistExtractorTest { + private static SoundcloudPlaylistExtractor extractor; + + @BeforeClass + public static void setUp() throws Exception { + NewPipe.init(Downloader.getInstance()); + extractor = (SoundcloudPlaylistExtractor) SoundCloud + .getPlaylistExtractor("https://soundcloud.com/user350509423/sets/edm-xxx"); + extractor.fetchPage(); + } + + /*////////////////////////////////////////////////////////////////////////// + // Additional Testing + //////////////////////////////////////////////////////////////////////////*/ + + @Test + public void testGetPageInNewExtractor() throws Exception { + final PlaylistExtractor newExtractor = SoundCloud.getPlaylistExtractor(extractor.getUrl()); + defaultTestGetPageInNewExtractor(extractor, newExtractor, SoundCloud.getServiceId()); + } + + /*////////////////////////////////////////////////////////////////////////// + // Extractor + //////////////////////////////////////////////////////////////////////////*/ + + @Test + public void testServiceId() { + assertEquals(SoundCloud.getServiceId(), extractor.getServiceId()); + } + + @Test + public void testName() { + assertEquals("EDM xXx", extractor.getName()); + } + + @Test + public void testId() { + assertEquals("136000376", extractor.getId()); + } + + @Test + public void testUrl() throws Exception { + assertEquals("https://soundcloud.com/user350509423/sets/edm-xxx", extractor.getUrl()); + } + + @Test + public void testOriginalUrl() throws Exception { + assertEquals("https://soundcloud.com/user350509423/sets/edm-xxx", extractor.getOriginalUrl()); + } + + /*////////////////////////////////////////////////////////////////////////// + // ListExtractor + //////////////////////////////////////////////////////////////////////////*/ + + @Test + public void testRelatedItems() throws Exception { + defaultTestRelatedItems(extractor, SoundCloud.getServiceId()); + } + + @Test + public void testMoreRelatedItems() throws Exception { + ListExtractor.InfoItemsPage currentPage = defaultTestMoreItems(extractor, ServiceList.SoundCloud.getServiceId()); + // Test for 2 more levels + for (int i = 0; i < 2; i++) { + currentPage = extractor.getPage(currentPage.getNextPageUrl()); + defaultTestListOfItems(SoundCloud.getServiceId(), currentPage.getItems(), currentPage.getErrors()); + } + } + + /*////////////////////////////////////////////////////////////////////////// + // PlaylistExtractor + //////////////////////////////////////////////////////////////////////////*/ + + @Test + public void testThumbnailUrl() { + assertIsSecureUrl(extractor.getThumbnailUrl()); + } + + @Ignore + @Test + public void testBannerUrl() { + assertIsSecureUrl(extractor.getBannerUrl()); + } + + @Test + public void testUploaderUrl() { + final String uploaderUrl = extractor.getUploaderUrl(); + assertIsSecureUrl(uploaderUrl); + assertTrue(uploaderUrl, uploaderUrl.contains("user350509423")); + } + + @Test + public void testUploaderName() { + assertEquals("user350509423", extractor.getUploaderName()); + } + + @Test + public void testUploaderAvatarUrl() { + assertIsSecureUrl(extractor.getUploaderAvatarUrl()); + } + + @Test + public void testStreamCount() { + assertTrue("Error in the streams count", extractor.getStreamCount() >= 3900); + } + } +} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java new file mode 100644 index 00000000..a637d380 --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java @@ -0,0 +1,119 @@ +package org.schabi.newpipe.extractor.services.soundcloud; + +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.ExtractionException; +import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.stream.StreamExtractor; +import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; +import org.schabi.newpipe.extractor.stream.StreamType; + +import java.io.IOException; + +import static org.junit.Assert.*; +import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; +import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; + +/** + * Test for {@link StreamExtractor} + */ +public class SoundcloudStreamExtractorDefaultTest { + private static SoundcloudStreamExtractor extractor; + + @BeforeClass + public static void setUp() throws Exception { + NewPipe.init(Downloader.getInstance()); + extractor = (SoundcloudStreamExtractor) SoundCloud.getStreamExtractor("https://soundcloud.com/liluzivert/do-what-i-want-produced-by-maaly-raw-don-cannon"); + extractor.fetchPage(); + } + + @Test + public void testGetInvalidTimeStamp() throws ParsingException { + assertTrue(extractor.getTimeStamp() + "", + extractor.getTimeStamp() <= 0); + } + + @Test + public void testGetValidTimeStamp() throws IOException, ExtractionException { + StreamExtractor extractor = SoundCloud.getStreamExtractor("https://soundcloud.com/liluzivert/do-what-i-want-produced-by-maaly-raw-don-cannon#t=69"); + assertEquals(extractor.getTimeStamp() + "", "69"); + } + + @Test + public void testGetTitle() throws ParsingException { + assertEquals(extractor.getName(), "Do What I Want [Produced By Maaly Raw + Don Cannon]"); + } + + @Test + public void testGetDescription() throws ParsingException { + assertEquals(extractor.getDescription(), "The Perfect LUV Tape®"); + } + + @Test + public void testGetUploaderName() throws ParsingException { + assertEquals(extractor.getUploaderName(), "LIL UZI VERT"); + } + + @Test + public void testGetLength() throws ParsingException { + assertEquals(extractor.getLength(), 175); + } + + @Test + public void testGetViewCount() throws ParsingException { + assertTrue(Long.toString(extractor.getViewCount()), + extractor.getViewCount() > 44227978); + } + + @Test + public void testGetUploadDate() throws ParsingException { + assertEquals("2016-07-31", extractor.getUploadDate()); + } + + @Test + public void testGetUploaderUrl() throws ParsingException { + assertIsSecureUrl(extractor.getUploaderUrl()); + assertEquals("https://soundcloud.com/liluzivert", extractor.getUploaderUrl()); + } + + @Test + public void testGetThumbnailUrl() throws ParsingException { + assertIsSecureUrl(extractor.getThumbnailUrl()); + } + + @Test + public void testGetUploaderAvatarUrl() throws ParsingException { + assertIsSecureUrl(extractor.getUploaderAvatarUrl()); + } + + @Test + public void testGetAudioStreams() throws IOException, ExtractionException { + assertFalse(extractor.getAudioStreams().isEmpty()); + } + + @Test + public void testStreamType() throws ParsingException { + assertTrue(extractor.getStreamType() == StreamType.AUDIO_STREAM); + } + + @Test + public void testGetRelatedVideos() throws ExtractionException, IOException { + StreamInfoItemsCollector relatedVideos = extractor.getRelatedVideos(); + assertFalse(relatedVideos.getItems().isEmpty()); + assertTrue(relatedVideos.getErrors().isEmpty()); + } + + @Test + public void testGetSubtitlesListDefault() throws IOException, ExtractionException { + // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null + assertTrue(extractor.getSubtitlesDefault().isEmpty()); + } + + @Test + public void testGetSubtitlesList() throws IOException, ExtractionException { + // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null + assertTrue(extractor.getSubtitlesDefault().isEmpty()); + } +} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUrlIdHandlerTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUrlIdHandlerTest.java new file mode 100644 index 00000000..5c1d35cf --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUrlIdHandlerTest.java @@ -0,0 +1,78 @@ +package org.schabi.newpipe.extractor.services.soundcloud; + +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.ParsingException; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; + +/** + * Test for {@link SoundcloudStreamUrlIdHandler} + */ +public class SoundcloudStreamUrlIdHandlerTest { + private static SoundcloudStreamUrlIdHandler urlIdHandler; + + @BeforeClass + public static void setUp() throws Exception { + urlIdHandler = SoundcloudStreamUrlIdHandler.getInstance(); + NewPipe.init(Downloader.getInstance()); + } + + @Test(expected = IllegalArgumentException.class) + public void getIdWithNullAsUrl() throws ParsingException { + urlIdHandler.setUrl(null).getId(); + } + + @Test + public void getIdForInvalidUrls() { + List invalidUrls = new ArrayList<>(50); + invalidUrls.add("https://soundcloud.com/liluzivert/t.e.s.t"); + invalidUrls.add("https://soundcloud.com/liluzivert/tracks"); + invalidUrls.add("https://soundcloud.com/"); + for (String invalidUrl : invalidUrls) { + Throwable exception = null; + try { + urlIdHandler.setUrl(invalidUrl).getId(); + } catch (ParsingException e) { + exception = e; + } + if (exception == null) { + fail("Expected ParsingException for url: " + invalidUrl); + } + } + } + + @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()); + } + + + @Test + public void testAcceptUrl() throws ParsingException { + assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/liluzivert/15-ysl")); + assertTrue(urlIdHandler.acceptUrl("https://www.soundcloud.com/liluzivert/15-luv-scars-ko")); + assertTrue(urlIdHandler.acceptUrl("http://soundcloud.com/liluzivert/15-boring-shit")); + assertTrue(urlIdHandler.acceptUrl("http://www.soundcloud.com/liluzivert/secure-the-bag-produced-by-glohan-beats")); + assertTrue(urlIdHandler.acceptUrl("HtTpS://sOuNdClOuD.cOm/LiLuZiVeRt/In-O4-pRoDuCeD-bY-dP-bEaTz")); + assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/liluzivert/fresh-produced-by-zaytoven#t=69")); + assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/liluzivert/threesome-produced-by-zaytoven#t=1:09")); + assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/liluzivert/blonde-brigitte-produced-manny-fresh#t=1:9")); + assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/liluzivert/today-produced-by-c-note#t=1m9s")); + assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/liluzivert/changed-my-phone-produced-by-c-note#t=1m09s")); + } +} \ No newline at end of file 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 new file mode 100644 index 00000000..e0e99803 --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSubscriptionExtractorTest.java @@ -0,0 +1,76 @@ +package org.schabi.newpipe.extractor.services.soundcloud; + +import org.junit.BeforeClass; +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.UrlIdHandler; +import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; +import org.schabi.newpipe.extractor.subscription.SubscriptionItem; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.*; + +/** + * Test for {@link SoundcloudSubscriptionExtractor} + */ +public class SoundcloudSubscriptionExtractorTest { + private static SoundcloudSubscriptionExtractor subscriptionExtractor; + private static UrlIdHandler urlHandler; + + @BeforeClass + public static void setupClass() { + NewPipe.init(Downloader.getInstance()); + subscriptionExtractor = new SoundcloudSubscriptionExtractor(ServiceList.SoundCloud); + urlHandler = ServiceList.SoundCloud.getChannelUrlIdHandler(); + } + + @Test + public void testFromChannelUrl() throws Exception { + testList(subscriptionExtractor.fromChannelUrl("https://soundcloud.com/monstercat")); + testList(subscriptionExtractor.fromChannelUrl("http://soundcloud.com/monstercat")); + testList(subscriptionExtractor.fromChannelUrl("soundcloud.com/monstercat")); + testList(subscriptionExtractor.fromChannelUrl("monstercat")); + + //Empty followings user + testList(subscriptionExtractor.fromChannelUrl("some-random-user-184047028")); + } + + @Test + public void testInvalidSourceException() { + List invalidList = Arrays.asList( + "httttps://invalid.com/user", + ".com/monstercat", + "ithinkthatthisuserdontexist", + "", + null + ); + + for (String invalidUser : invalidList) { + try { + subscriptionExtractor.fromChannelUrl(invalidUser); + + fail("didn't throw exception"); + } catch (IOException e) { + // Ignore it, could be an unstable network on the CI server + } catch (Exception e) { + boolean isExpectedException = e instanceof SubscriptionExtractor.InvalidSourceException; + assertTrue(e.getClass().getSimpleName() + " is not the expected exception", isExpectedException); + } + } + } + + private void testList(List subscriptionItems) throws ParsingException { + for (SubscriptionItem item : subscriptionItems) { + assertNotNull(item.getName()); + assertNotNull(item.getUrl()); + assertTrue(urlHandler.acceptUrl(item.getUrl())); + assertFalse(item.getServiceId() == -1); + } + } +} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSuggestionExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSuggestionExtractorTest.java new file mode 100644 index 00000000..b4ab8dbc --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSuggestionExtractorTest.java @@ -0,0 +1,31 @@ +package org.schabi.newpipe.extractor.services.soundcloud; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.SuggestionExtractor; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; + +import java.io.IOException; + +import static org.junit.Assert.assertFalse; +import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; + +/** + * Test for {@link SuggestionExtractor} + */ +public class SoundcloudSuggestionExtractorTest { + private static SuggestionExtractor suggestionExtractor; + + @BeforeClass + public static void setUp() throws Exception { + NewPipe.init(Downloader.getInstance()); + suggestionExtractor = SoundCloud.getSuggestionExtractor(); + } + + @Test + public void testIfSuggestions() throws IOException, ExtractionException { + assertFalse(suggestionExtractor.suggestionList("lil uzi vert", "de").isEmpty()); + } +} 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 new file mode 100644 index 00000000..9c164dcd --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorBaseTest.java @@ -0,0 +1,50 @@ +package org.schabi.newpipe.extractor.services.soundcloud.search; + +import org.junit.Test; +import org.schabi.newpipe.extractor.InfoItem; +import org.schabi.newpipe.extractor.ListExtractor; +import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudSearchExtractor; + +import static org.junit.Assert.assertTrue; + + +/* + * Created by Christian Schabesberger on 17.06.18 + * + * Copyright (C) Christian Schabesberger 2018 + * SoundcloudSearchExtractorBaseTest.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 . + */ + +/** + * Test for {@link SoundcloudSearchExtractor} + */ +public abstract class SoundcloudSearchExtractorBaseTest { + + protected static SoundcloudSearchExtractor extractor; + protected static ListExtractor.InfoItemsPage itemsPage; + + + @Test + public void testResultListElementsLength() { + assertTrue(Integer.toString(itemsPage.getItems().size()), + itemsPage.getItems().size() >= 10); + } + + @Test + public void testUrl() throws Exception { + assertTrue(extractor.getUrl(), extractor.getUrl().startsWith("https://api-v2.soundcloud.com/search")); + } +} 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 new file mode 100644 index 00000000..c1816cb3 --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorChannelOnlyTest.java @@ -0,0 +1,64 @@ +package org.schabi.newpipe.extractor.services.soundcloud.search; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.InfoItem; +import org.schabi.newpipe.extractor.ListExtractor; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.channel.ChannelInfoItem; +import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudSearchExtractor; + +import static java.util.Arrays.asList; +import static org.junit.Assert.*; +import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; + +public class SoundcloudSearchExtractorChannelOnlyTest extends SoundcloudSearchExtractorBaseTest { + + @BeforeClass + public static void setUpClass() throws Exception { + NewPipe.init(Downloader.getInstance()); + extractor = (SoundcloudSearchExtractor) SoundCloud.getSearchExtractor("lill uzi vert", + asList(new String[]{"users"}), null, "de"); + extractor.fetchPage(); + itemsPage = extractor.getInitialPage(); + } + + @Test + public void testGetSecondPage() throws Exception { + SoundcloudSearchExtractor secondExtractor = (SoundcloudSearchExtractor) SoundCloud.getSearchExtractor("lill uzi vert", + asList(new String[]{"users"}), null, "de"); + ListExtractor.InfoItemsPage secondPage = secondExtractor.getPage(itemsPage.getNextPageUrl()); + assertTrue(Integer.toString(secondPage.getItems().size()), + secondPage.getItems().size() >= 7); + + // check if its the same result + boolean equals = true; + for (int i = 0; i < secondPage.getItems().size() + && i < itemsPage.getItems().size(); i++) { + if(!secondPage.getItems().get(i).getUrl().equals( + itemsPage.getItems().get(i).getUrl())) { + equals = false; + } + } + 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()); + } + + @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()); + } + + @Test + public void testOnlyContainChannels() { + for(InfoItem item : itemsPage.getItems()) { + if(!(item instanceof ChannelInfoItem)) { + fail("The following item is no channel item: " + item.toString()); + } + } + } +} 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 new file mode 100644 index 00000000..5dc5f63c --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorDefaultTest.java @@ -0,0 +1,109 @@ +package org.schabi.newpipe.extractor.services.soundcloud.search; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.InfoItem; +import org.schabi.newpipe.extractor.ListExtractor; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.channel.ChannelInfoItem; +import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudSearchExtractor; +import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSearchExtractor; +import org.schabi.newpipe.extractor.stream.StreamInfoItem; + +import static org.junit.Assert.*; +import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; + +/* + * Created by Christian Schabesberger on 27.05.18 + * + * Copyright (C) Christian Schabesberger 2018 + * YoutubeSearchExtractorStreamTest.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 . + */ + +/** + * Test for {@link YoutubeSearchExtractor} + */ +public class SoundcloudSearchExtractorDefaultTest extends SoundcloudSearchExtractorBaseTest { + + @BeforeClass + public static void setUpClass() throws Exception { + NewPipe.init(Downloader.getInstance()); + extractor = (SoundcloudSearchExtractor) SoundCloud.getSearchExtractor("lill uzi vert", "de"); + extractor.fetchPage(); + itemsPage = extractor.getInitialPage(); + } + + @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()); + } + + @Test + public void testResultList_FirstElement() { + InfoItem firstInfoItem = itemsPage.getItems().get(0); + + // THe channel should be the first item + assertEquals("name", "Bad and Boujee (Feat. Lil Uzi Vert) [Prod. By Metro Boomin]", firstInfoItem.getName()); + assertEquals("url","https://soundcloud.com/migosatl/bad-and-boujee-feat-lil-uzi-vert-prod-by-metro-boomin", firstInfoItem.getUrl()); + } + + @Test + public void testResultListCheckIfContainsStreamItems() { + boolean hasStreams = false; + for(InfoItem item : itemsPage.getItems()) { + if(item instanceof StreamInfoItem) { + hasStreams = true; + } + } + assertTrue("Has no InfoItemStreams", hasStreams); + } + + @Test + public void testGetSecondPage() throws Exception { + SoundcloudSearchExtractor secondExtractor = (SoundcloudSearchExtractor) SoundCloud.getSearchExtractor("lill uzi vert", "de"); + ListExtractor.InfoItemsPage secondPage = secondExtractor.getPage(itemsPage.getNextPageUrl()); + assertTrue(Integer.toString(secondPage.getItems().size()), + secondPage.getItems().size() >= 10); + + // check if its the same result + boolean equals = true; + for (int i = 0; i < secondPage.getItems().size() + && i < itemsPage.getItems().size(); i++) { + if(!secondPage.getItems().get(i).getUrl().equals( + itemsPage.getItems().get(i).getUrl())) { + equals = false; + } + } + 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()); + } + + + @Test + public void testId() throws Exception { + assertEquals("lill uzi vert", extractor.getId()); + } + + @Test + public void testName() { + assertEquals("lill uzi vert", extractor.getName()); + } +} 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 new file mode 100644 index 00000000..ecc5cbdc --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchQUHTest.java @@ -0,0 +1,64 @@ +package org.schabi.newpipe.extractor.services.soundcloud.search; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudSearchExtractor; + +import static java.util.Arrays.asList; +import static org.junit.Assert.assertEquals; +import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; + +public class SoundcloudSearchQUHTest { + + @BeforeClass + public static void setUpClass() throws Exception { + NewPipe.init(Downloader.getInstance()); + } + + @Test + public void testRegularValues() throws Exception { + assertEquals("https://api-v2.soundcloud.com/search?q=asdf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQueryHandler().setQuery("asdf").getUrl()); + assertEquals("https://api-v2.soundcloud.com/search?q=hans&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0",SoundCloud.getSearchQueryHandler().setQuery("hans").getUrl()); + assertEquals("https://api-v2.soundcloud.com/search?q=Poifj%26jaijf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQueryHandler().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.getSearchQueryHandler().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.getSearchQueryHandler().setQuery("?j$)H§B").getUrl()); + } + + @Test + public void testGetContentFilter() throws Exception { + assertEquals("tracks", SoundCloud.getSearchQueryHandler() + .setQuery("", asList(new String[]{"tracks"}), "").getContentFilter().get(0)); + assertEquals("users", SoundCloud.getSearchQueryHandler() + .setQuery("asdf", asList(new String[]{"users"}), "").getContentFilter().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.getSearchQueryHandler() + .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.getSearchQueryHandler() + .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.getSearchQueryHandler() + .setQuery("asdf", asList(new String[]{"playlist"}), "").getUrl()); + assertEquals("https://api-v2.soundcloud.com/search?q=asdf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQueryHandler() + .setQuery("asdf", asList(new String[]{"fjiijie"}), "").getUrl()); + } + + @Test + public void testGetAvailableContentFilter() { + final String[] contentFilter = SoundCloud.getSearchQueryHandler().getAvailableContentFilter(); + assertEquals(4, contentFilter.length); + assertEquals("tracks", contentFilter[0]); + assertEquals("users", contentFilter[1]); + assertEquals("playlist", contentFilter[2]); + assertEquals("any", contentFilter[3]); + } + + @Test + public void testGetAvailableSortFilter() { + final String[] contentFilter = SoundCloud.getSearchQueryHandler().getAvailableSortFilter(); + assertEquals(0, contentFilter.length); + } +} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorDefaultTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorDefaultTest.java index 8b92e6d8..2ab7c6cd 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorDefaultTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorDefaultTest.java @@ -52,7 +52,7 @@ public class YoutubeSearchExtractorDefaultTest extends YoutubeSearchExtractorBas @Test public void testGetSecondPageUrl() throws Exception { - assertEquals(extractor.getNextPageUrl(), "https://www.youtube.com/results?q=pewdiepie&page=2"); + assertEquals("https://www.youtube.com/results?q=pewdiepie&page=2", extractor.getNextPageUrl()); } @Test @@ -107,11 +107,11 @@ public class YoutubeSearchExtractorDefaultTest extends YoutubeSearchExtractorBas @Test public void testId() throws Exception { - assertEquals(extractor.getId(), "pewdiepie"); + assertEquals("pewdiepie", extractor.getId()); } @Test public void testName() { - assertEquals(extractor.getName(), "pewdiepie"); + assertEquals("pewdiepie", extractor.getName()); } } From 17f46b8b12489b4928578c21cf084673f44cb826 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Thu, 21 Jun 2018 17:18:26 +0200 Subject: [PATCH 06/20] rename UrlIdHandler to UIHFactory --- .../schabi/newpipe/extractor/Extractor.java | 20 ++--- .../org/schabi/newpipe/extractor/Info.java | 10 +-- .../newpipe/extractor/ListExtractor.java | 6 +- .../schabi/newpipe/extractor/ListInfo.java | 3 +- ...tUrlIdHandler.java => ListUIHFactory.java} | 18 ++-- .../newpipe/extractor/StreamingService.java | 41 +++++----- .../{UrlIdHandler.java => UIHFactory.java} | 9 +- .../extractor/channel/ChannelExtractor.java | 8 +- .../extractor/channel/ChannelInfo.java | 6 +- .../extractor/kiosk/KioskExtractor.java | 5 +- .../newpipe/extractor/kiosk/KioskInfo.java | 4 +- .../newpipe/extractor/kiosk/KioskList.java | 10 +-- .../extractor/playlist/PlaylistExtractor.java | 8 +- .../extractor/playlist/PlaylistInfo.java | 6 +- .../extractor/search/SearchExtractor.java | 10 +-- .../newpipe/extractor/search/SearchInfo.java | 6 +- .../extractor/search/SearchQIHFactory.java | 44 ++++++++++ .../search/SearchQueryUrlHandler.java | 44 ---------- .../SoundcloudChannelExtractor.java | 8 +- ....java => SoundcloudChannelUIHFactory.java} | 14 +--- .../soundcloud/SoundcloudChartsExtractor.java | 5 +- ...r.java => SoundcloudChartsUIHFactory.java} | 6 +- .../SoundcloudPlaylistExtractor.java | 8 +- ...java => SoundcloudPlaylistUIHFactory.java} | 8 +- .../soundcloud/SoundcloudSearchExtractor.java | 6 +- ...r.java => SoundcloudSearchQIHFactory.java} | 4 +- .../soundcloud/SoundcloudService.java | 44 +++++----- .../soundcloud/SoundcloudStreamExtractor.java | 6 +- ...r.java => SoundcloudStreamUIHFactory.java} | 15 ++-- .../SoundcloudSubscriptionExtractor.java | 2 +- .../services/youtube/YoutubeService.java | 44 +++++----- .../extractors/YoutubeChannelExtractor.java | 2 +- .../extractors/YoutubePlaylistExtractor.java | 10 +-- .../extractors/YoutubeSearchExtractor.java | 7 +- .../extractors/YoutubeStreamExtractor.java | 4 +- .../extractors/YoutubeTrendingExtractor.java | 6 +- ...ler.java => YoutubeChannelUIHFactory.java} | 10 +-- ...er.java => YoutubePlaylistUIHFactory.java} | 8 +- ...dler.java => YoutubeSearchQIHFactory.java} | 8 +- ...dler.java => YoutubeStreamUIHFactory.java} | 12 +-- ...er.java => YoutubeTrendingUIHFactory.java} | 8 +- .../extractor/stream/StreamExtractor.java | 6 +- .../SoundcloudChartsExtractorTest.java | 2 +- ...va => SoundcloudChartsUIHFactoryTest.java} | 8 +- ...va => SoundcloudStreamUIHFactoryTest.java} | 8 +- .../SoundcloudSubscriptionExtractorTest.java | 6 +- .../search/SoundcloudSearchQUHTest.java | 27 +++--- ...java => YoutubeChannelUIHFactoryTest.java} | 10 +-- ...utubeStreamExtractorControversialTest.java | 4 +- .../YoutubeStreamExtractorRestrictedTest.java | 4 +- ....java => YoutubeStreamUIHFactoryTest.java} | 10 +-- .../YoutubeSubscriptionExtractorTest.java | 6 +- .../youtube/YoutubeTrendingExtractorTest.java | 4 +- .../youtube/YoutubeTrendingKioskInfoTest.java | 6 +- .../YoutubeTrendingUIHFactoryTest.java | 82 +++++++++++++++++++ .../YoutubeTrendingUrlIdHandlerTest.java | 82 ------------------- .../youtube/search/YoutubeSearchQUHTest.java | 28 +++---- 57 files changed, 369 insertions(+), 427 deletions(-) rename extractor/src/main/java/org/schabi/newpipe/extractor/{ListUrlIdHandler.java => ListUIHFactory.java} (68%) rename extractor/src/main/java/org/schabi/newpipe/extractor/{UrlIdHandler.java => UIHFactory.java} (89%) create mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQIHFactory.java delete mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQueryUrlHandler.java rename extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/{SoundcloudChannelUrlIdHandler.java => SoundcloudChannelUIHFactory.java} (69%) rename extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/{SoundcloudChartsUrlIdHandler.java => SoundcloudChartsUIHFactory.java} (79%) rename extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/{SoundcloudPlaylistUrlIdHandler.java => SoundcloudPlaylistUIHFactory.java} (80%) rename extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/{SoundcloudSearchQueryUrlHandler.java => SoundcloudSearchQIHFactory.java} (93%) rename extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/{SoundcloudStreamUrlIdHandler.java => SoundcloudStreamUIHFactory.java} (71%) rename extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/{YoutubeChannelUrlIdHandler.java => YoutubeChannelUIHFactory.java} (82%) rename extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/{YoutubePlaylistUrlIdHandler.java => YoutubePlaylistUIHFactory.java} (78%) rename extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/{YoutubeSearchQueryUrlHandler.java => YoutubeSearchQIHFactory.java} (84%) rename extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/{YoutubeStreamUrlIdHandler.java => YoutubeStreamUIHFactory.java} (94%) rename extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/{YoutubeTrendingUrlIdHandler.java => YoutubeTrendingUIHFactory.java} (81%) rename extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/{SoundcloudChartsUrlIdHandlerTest.java => SoundcloudChartsUIHFactoryTest.java} (89%) rename extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/{SoundcloudStreamUrlIdHandlerTest.java => SoundcloudStreamUIHFactoryTest.java} (94%) rename extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/{YoutubeChannelUrlIdHandlerTest.java => YoutubeChannelUIHFactoryTest.java} (91%) rename extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/{YoutubeStreamUrlIdHandlerTest.java => YoutubeStreamUIHFactoryTest.java} (97%) create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUIHFactoryTest.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUrlIdHandlerTest.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 1e9b5dac..c3127874 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java @@ -14,27 +14,27 @@ public abstract class Extractor { */ private final StreamingService service; - private final UrlIdHandler urlIdHandler; + private final UIHFactory UIHFactory; @Nullable private boolean pageFetched = false; private final Downloader downloader; - public Extractor(final StreamingService service, final UrlIdHandler urlIdHandler) { + public Extractor(final StreamingService service, final UIHFactory UIHFactory) { if(service == null) throw new NullPointerException("service is null"); - if(urlIdHandler == null) throw new NullPointerException("UrlIdHandler is null"); + if(UIHFactory == null) throw new NullPointerException("UIHFactory is null"); this.service = service; - this.urlIdHandler = urlIdHandler; + this.UIHFactory = UIHFactory; this.downloader = NewPipe.getDownloader(); if(downloader == null) throw new NullPointerException("downloader is null"); } /** - * @return The {@link UrlIdHandler} of the current extractor object (e.g. a ChannelExtractor should return a channel url handler). + * @return The {@link UIHFactory} of the current extractor object (e.g. a ChannelExtractor should return a channel url handler). */ @Nonnull - public UrlIdHandler getUrlIdHandler() { - return urlIdHandler; + public UIHFactory getUIHFactory() { + return UIHFactory; } /** @@ -66,7 +66,7 @@ public abstract class Extractor { @Nonnull public String getId() throws ParsingException { - return urlIdHandler.getId(); + return UIHFactory.getId(); } /** @@ -79,12 +79,12 @@ public abstract class Extractor { @Nonnull public String getOriginalUrl() throws ParsingException { - return urlIdHandler.getOriginalUrl(); + return UIHFactory.getOriginalUrl(); } @Nonnull public String getUrl() throws ParsingException { - return urlIdHandler.getUrl(); + return UIHFactory.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 99b4d555..5918a00a 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/Info.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/Info.java @@ -18,7 +18,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 UrlIdHandler#getUrl() + * @see UIHFactory#getUrl() * @see Extractor#getOriginalUrl() */ private final String url; @@ -48,11 +48,11 @@ public abstract class Info implements Serializable { this.name = name; } - public Info(int serviceId, UrlIdHandler urlIdHandler, String name) throws ParsingException { + public Info(int serviceId, UIHFactory UIHFactory, String name) throws ParsingException { this(serviceId, - urlIdHandler.getId(), - urlIdHandler.getUrl(), - urlIdHandler.getOriginalUrl(), + UIHFactory.getId(), + UIHFactory.getUrl(), + UIHFactory.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 e22ecc04..a07ecdde 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java @@ -12,7 +12,7 @@ import java.util.List; */ public abstract class ListExtractor extends Extractor { - public ListExtractor(StreamingService service, ListUrlIdHandler urlIdHandler) { + public ListExtractor(StreamingService service, ListUIHFactory urlIdHandler) { super(service, urlIdHandler); } @@ -50,8 +50,8 @@ public abstract class ListExtractor extends Extractor { } @Override - public ListUrlIdHandler getUrlIdHandler() { - return (ListUrlIdHandler) super.getUrlIdHandler(); + public ListUIHFactory getUIHFactory() { + return (ListUIHFactory) super.getUIHFactory(); } /*////////////////////////////////////////////////////////////////////////// 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 7a1b9fac..5d591a1e 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,5 @@ package org.schabi.newpipe.extractor; -import com.sun.org.apache.xerces.internal.xs.StringList; import org.schabi.newpipe.extractor.exceptions.ParsingException; import java.util.ArrayList; @@ -24,7 +23,7 @@ public abstract class ListInfo extends Info { this.sortFilter = sortFilter; } - public ListInfo(int serviceId, ListUrlIdHandler listUrlIdHandler, String name) throws ParsingException { + public ListInfo(int serviceId, ListUIHFactory listUrlIdHandler, String name) throws ParsingException { super(serviceId, listUrlIdHandler, name); this.contentFilter = listUrlIdHandler.getContentFilter(); this.sortFilter = listUrlIdHandler.getSortFilter(); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/ListUrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/ListUIHFactory.java similarity index 68% rename from extractor/src/main/java/org/schabi/newpipe/extractor/ListUrlIdHandler.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/ListUIHFactory.java index 8357184a..88ec0e47 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/ListUrlIdHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/ListUIHFactory.java @@ -5,14 +5,14 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; import java.util.ArrayList; import java.util.List; -public abstract class ListUrlIdHandler extends UrlIdHandler { +public abstract class ListUIHFactory extends UIHFactory { protected List contentFilter = new ArrayList<>(0); protected String sortFilter = ""; - public ListUrlIdHandler setQuery(String id, - List contentFilter, - String sortFilter) throws ParsingException { + public ListUIHFactory setQuery(String id, + List contentFilter, + String sortFilter) throws ParsingException { setId(id); this.contentFilter = contentFilter; this.sortFilter = sortFilter; @@ -20,17 +20,17 @@ public abstract class ListUrlIdHandler extends UrlIdHandler { } - public ListUrlIdHandler setQuery(String id) throws ParsingException { + public ListUIHFactory setQuery(String id) throws ParsingException { setQuery(id, new ArrayList(), ""); return this; } - public ListUrlIdHandler setUrl(String url) throws ParsingException { - return (ListUrlIdHandler) super.setUrl(url); + public ListUIHFactory setUrl(String url) throws ParsingException { + return (ListUIHFactory) super.setUrl(url); } - public ListUrlIdHandler setId(String id) throws ParsingException { - return (ListUrlIdHandler) super.setId(id); + public ListUIHFactory setId(String id) throws ParsingException { + return (ListUIHFactory) super.setId(id); } /** 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 d642a749..04b5ca85 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java @@ -1,14 +1,12 @@ package org.schabi.newpipe.extractor; -import com.sun.org.apache.xerces.internal.xs.StringList; import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.exceptions.ExtractionException; 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.SearchEngine; import org.schabi.newpipe.extractor.search.SearchExtractor; -import org.schabi.newpipe.extractor.search.SearchQueryUrlHandler; +import org.schabi.newpipe.extractor.search.SearchQIHFactory; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; @@ -69,51 +67,50 @@ public abstract class StreamingService { //////////////////////////////////////////// // Url Id handler //////////////////////////////////////////// - public abstract UrlIdHandler getStreamUrlIdHandler(); - public abstract ListUrlIdHandler getChannelUrlIdHandler(); - public abstract ListUrlIdHandler getPlaylistUrlIdHandler(); - public abstract SearchQueryUrlHandler getSearchQueryHandler(); + public abstract UIHFactory getStreamUIHFactory(); + public abstract ListUIHFactory getChannelUIHFactory(); + public abstract ListUIHFactory getPlaylistUIHFactory(); + public abstract SearchQIHFactory getSearchQIHFactory(); //////////////////////////////////////////// // Extractor //////////////////////////////////////////// - public abstract SearchEngine getSearchEngine(); - public abstract SearchExtractor getSearchExtractor(SearchQueryUrlHandler queryHandler, String contentCountry); + public abstract SearchExtractor getSearchExtractor(SearchQIHFactory queryHandler, String contentCountry); public abstract SuggestionExtractor getSuggestionExtractor(); public abstract SubscriptionExtractor getSubscriptionExtractor(); public abstract KioskList getKioskList() throws ExtractionException; - public abstract ChannelExtractor getChannelExtractor(ListUrlIdHandler urlIdHandler) throws ExtractionException; - public abstract PlaylistExtractor getPlaylistExtractor(ListUrlIdHandler urlIdHandler) throws ExtractionException; - public abstract StreamExtractor getStreamExtractor(UrlIdHandler urlIdHandler) 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 SearchExtractor getSearchExtractor(String query, List contentFilter, String sortFilter, String contentCountry) throws ExtractionException { - return getSearchExtractor(getSearchQueryHandler().setQuery(query, contentFilter, sortFilter), contentCountry); + return getSearchExtractor(getSearchQIHFactory().setQuery(query, contentFilter, sortFilter), contentCountry); } public ChannelExtractor getChannelExtractor(String id, List contentFilter, String sortFilter) throws ExtractionException { - return getChannelExtractor(getChannelUrlIdHandler().setQuery(id, contentFilter, sortFilter)); + return getChannelExtractor(getChannelUIHFactory().setQuery(id, contentFilter, sortFilter)); } public PlaylistExtractor getPlaylistExtractor(String id, List contentFilter, String sortFilter) throws ExtractionException { - return getPlaylistExtractor(getPlaylistUrlIdHandler().setQuery(id, contentFilter, sortFilter)); + return getPlaylistExtractor(getPlaylistUIHFactory().setQuery(id, contentFilter, sortFilter)); } public SearchExtractor getSearchExtractor(String query, String contentCountry) throws ExtractionException { - return getSearchExtractor(getSearchQueryHandler().setQuery(query), contentCountry); + return getSearchExtractor(getSearchQIHFactory().setQuery(query), contentCountry); } public ChannelExtractor getChannelExtractor(String url) throws ExtractionException { - return getChannelExtractor(getChannelUrlIdHandler().setUrl(url)); + return getChannelExtractor(getChannelUIHFactory().setUrl(url)); } public PlaylistExtractor getPlaylistExtractor(String url) throws ExtractionException { - return getPlaylistExtractor(getPlaylistUrlIdHandler().setUrl(url)); + return getPlaylistExtractor(getPlaylistUIHFactory().setUrl(url)); } public StreamExtractor getStreamExtractor(String url) throws ExtractionException { - return getStreamExtractor(getStreamUrlIdHandler().setUrl(url)); + return getStreamExtractor(getStreamUIHFactory().setUrl(url)); } @@ -122,9 +119,9 @@ public abstract class StreamingService { * figure out where the link is pointing to (a channel, video, playlist, etc.) */ public final LinkType getLinkTypeByUrl(String url) throws ParsingException { - UrlIdHandler sH = getStreamUrlIdHandler(); - UrlIdHandler cH = getChannelUrlIdHandler(); - UrlIdHandler pH = getPlaylistUrlIdHandler(); + UIHFactory sH = getStreamUIHFactory(); + UIHFactory cH = getChannelUIHFactory(); + UIHFactory pH = getPlaylistUIHFactory(); if (sH.acceptUrl(url)) { return LinkType.STREAM; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/UrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/UIHFactory.java similarity index 89% rename from extractor/src/main/java/org/schabi/newpipe/extractor/UrlIdHandler.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/UIHFactory.java index a9fda4d3..fbf4e7ef 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/UrlIdHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/UIHFactory.java @@ -1,13 +1,12 @@ package org.schabi.newpipe.extractor; -import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; /* * Created by Christian Schabesberger on 26.07.16. * * Copyright (C) Christian Schabesberger 2016 - * UrlIdHandler.java is part of NewPipe. + * UIHFactory.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 @@ -23,7 +22,7 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; * along with NewPipe. If not, see . */ -public abstract class UrlIdHandler { +public abstract class UIHFactory { protected String id = ""; protected String originalUrl = ""; @@ -33,14 +32,14 @@ public abstract class UrlIdHandler { public abstract boolean onAcceptUrl(final String url) throws ParsingException; - public UrlIdHandler setUrl(String url) throws ParsingException { + public UIHFactory setUrl(String url) throws ParsingException { if(url == null) throw new IllegalArgumentException("url can not be null"); originalUrl = url; id = onGetIdFromUrl(url); return this; } - public UrlIdHandler setId(String id) throws ParsingException { + public UIHFactory setId(String id) throws ParsingException { if(id == null) throw new IllegalArgumentException("id can not be null"); this.id = id; if(!acceptUrl(getUrl())) { 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 9d6bef52..b41f041e 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,15 +1,11 @@ package org.schabi.newpipe.extractor.channel; import org.schabi.newpipe.extractor.ListExtractor; -import org.schabi.newpipe.extractor.ListUrlIdHandler; +import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.StreamingService; -import org.schabi.newpipe.extractor.UrlIdHandler; -import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.stream.StreamInfoItem; -import javax.annotation.Nonnull; - /* * Created by Christian Schabesberger on 25.07.16. * @@ -32,7 +28,7 @@ import javax.annotation.Nonnull; public abstract class ChannelExtractor extends ListExtractor { - public ChannelExtractor(StreamingService service, ListUrlIdHandler urlIdHandler) { + public ChannelExtractor(StreamingService service, ListUIHFactory 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 38f2b6e4..372feaa9 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,7 +2,7 @@ package org.schabi.newpipe.extractor.channel; import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage; import org.schabi.newpipe.extractor.ListInfo; -import org.schabi.newpipe.extractor.ListUrlIdHandler; +import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; @@ -34,7 +34,7 @@ import java.io.IOException; public class ChannelInfo extends ListInfo { - public ChannelInfo(int serviceId, ListUrlIdHandler urlIdHandler, String name) throws ParsingException { + public ChannelInfo(int serviceId, ListUIHFactory urlIdHandler, String name) throws ParsingException { super(serviceId, urlIdHandler, name); } @@ -55,7 +55,7 @@ public class ChannelInfo extends ListInfo { public static ChannelInfo getInfo(ChannelExtractor extractor) throws IOException, ExtractionException { ChannelInfo info = new ChannelInfo(extractor.getServiceId(), - extractor.getUrlIdHandler(), + extractor.getUIHFactory(), 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 95ce34f5..c46de368 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,9 +21,8 @@ package org.schabi.newpipe.extractor.kiosk; */ import org.schabi.newpipe.extractor.ListExtractor; -import org.schabi.newpipe.extractor.ListUrlIdHandler; +import org.schabi.newpipe.extractor.ListUIHFactory; 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; @@ -34,7 +33,7 @@ public abstract class KioskExtractor extends ListExtractor { private final String id; public KioskExtractor(StreamingService streamingService, - ListUrlIdHandler urlIdHandler, + ListUIHFactory 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 56feb40e..afd02727 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 @@ -30,7 +30,7 @@ import java.io.IOException; public class KioskInfo extends ListInfo { - private KioskInfo(int serviceId, ListUrlIdHandler urlIdHandler, String name) throws ParsingException { + private KioskInfo(int serviceId, ListUIHFactory urlIdHandler, String name) throws ParsingException { super(serviceId, urlIdHandler, name); } @@ -67,7 +67,7 @@ public class KioskInfo extends ListInfo { public static KioskInfo getInfo(KioskExtractor extractor) throws ExtractionException { final KioskInfo info = new KioskInfo(extractor.getServiceId(), - extractor.getUrlIdHandler(), + extractor.getUIHFactory(), 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 11c8f141..a4739e63 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.UrlIdHandler; +import org.schabi.newpipe.extractor.UIHFactory; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import java.io.IOException; @@ -23,19 +23,19 @@ public class KioskList { private String defaultKiosk = null; private class KioskEntry { - public KioskEntry(KioskExtractorFactory ef, UrlIdHandler h) { + public KioskEntry(KioskExtractorFactory ef, UIHFactory h) { extractorFactory = ef; handler = h; } final KioskExtractorFactory extractorFactory; - final UrlIdHandler handler; + final UIHFactory handler; } public KioskList(int service_id) { this.service_id = service_id; } - public void addKioskEntry(KioskExtractorFactory extractorFactory, UrlIdHandler handler, String id) + public void addKioskEntry(KioskExtractorFactory extractorFactory, UIHFactory handler, String id) throws Exception { if(kioskList.get(id) != null) { throw new Exception("Kiosk with type " + id + " already exists."); @@ -92,7 +92,7 @@ public class KioskList { throw new ExtractionException("Could not find a kiosk that fits to the url: " + url); } - public UrlIdHandler getUrlIdHandlerByType(String type) { + public UIHFactory getUrlIdHandlerByType(String type) { return kioskList.get(type).handler; } } 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 490367fe..924ff8cb 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,18 +1,14 @@ package org.schabi.newpipe.extractor.playlist; import org.schabi.newpipe.extractor.ListExtractor; -import org.schabi.newpipe.extractor.ListUrlIdHandler; +import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.StreamingService; -import org.schabi.newpipe.extractor.UrlIdHandler; -import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.stream.StreamInfoItem; -import javax.annotation.Nonnull; - public abstract class PlaylistExtractor extends ListExtractor { - public PlaylistExtractor(StreamingService service, ListUrlIdHandler urlIdHandler) { + public PlaylistExtractor(StreamingService service, ListUIHFactory 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 cdc6c5fe..edcfe34e 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,7 +2,7 @@ package org.schabi.newpipe.extractor.playlist; import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage; import org.schabi.newpipe.extractor.ListInfo; -import org.schabi.newpipe.extractor.ListUrlIdHandler; +import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; @@ -14,7 +14,7 @@ import java.io.IOException; public class PlaylistInfo extends ListInfo { - public PlaylistInfo(int serviceId, ListUrlIdHandler urlIdHandler, String name) throws ParsingException { + public PlaylistInfo(int serviceId, ListUIHFactory urlIdHandler, String name) throws ParsingException { super(serviceId, urlIdHandler, name); } @@ -41,7 +41,7 @@ public class PlaylistInfo extends ListInfo { final PlaylistInfo info = new PlaylistInfo( extractor.getServiceId(), - extractor.getUrlIdHandler(), + extractor.getUIHFactory(), 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 ecbe5fca..68a10ded 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 @@ -17,14 +17,14 @@ public abstract class SearchExtractor extends ListExtractor { private final InfoItemsSearchCollector collector; private final String contentCountry; - public SearchExtractor(StreamingService service, SearchQueryUrlHandler urlIdHandler, String contentCountry) { + public SearchExtractor(StreamingService service, SearchQIHFactory urlIdHandler, String contentCountry) { super(service, urlIdHandler); collector = new InfoItemsSearchCollector(service.getServiceId()); this.contentCountry = contentCountry; } public String getSearchString() { - return getUrlIdHandler().getSearchString(); + return getUIHFactory().getSearchString(); } public abstract String getSearchSuggestion() throws ParsingException; @@ -34,13 +34,13 @@ public abstract class SearchExtractor extends ListExtractor { } @Override - public SearchQueryUrlHandler getUrlIdHandler() { - return (SearchQueryUrlHandler) super.getUrlIdHandler(); + public SearchQIHFactory getUIHFactory() { + return (SearchQIHFactory) super.getUIHFactory(); } @Override public String getName() { - return getUrlIdHandler().getSearchString(); + return getUIHFactory().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 6b7c8b8b..4d9ad12d 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,7 +2,7 @@ package org.schabi.newpipe.extractor.search; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.ListInfo; -import org.schabi.newpipe.extractor.ListUrlIdHandler; +import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; @@ -13,7 +13,7 @@ public class SearchInfo extends ListInfo { public SearchInfo(int serviceId, - ListUrlIdHandler urlIdHandler, + ListUIHFactory urlIdHandler, String searchString) throws ParsingException { super(serviceId, urlIdHandler, "Search"); this.searchString = searchString; @@ -23,7 +23,7 @@ public class SearchInfo extends ListInfo { public static SearchInfo getInfo(SearchExtractor extractor) throws ExtractionException { final SearchInfo info = new SearchInfo( extractor.getServiceId(), - extractor.getUrlIdHandler(), + extractor.getUIHFactory(), 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 new file mode 100644 index 00000000..2e96f434 --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQIHFactory.java @@ -0,0 +1,44 @@ +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/search/SearchQueryUrlHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQueryUrlHandler.java deleted file mode 100644 index d72dbb0a..00000000 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchQueryUrlHandler.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.schabi.newpipe.extractor.search; - -import org.schabi.newpipe.extractor.ListUrlIdHandler; -import org.schabi.newpipe.extractor.exceptions.ParsingException; - -import java.util.List; - -public abstract class SearchQueryUrlHandler extends ListUrlIdHandler { - - @Override - public String onGetIdFromUrl(String url) { - return "Search"; - } - - public String getSearchString() { - return getId(); - } - - @Override - public SearchQueryUrlHandler setQuery(String querry, - List contentFilter, - String sortFilter) throws ParsingException { - return (SearchQueryUrlHandler) super.setQuery(querry, contentFilter, sortFilter); - } - - - @Override - public SearchQueryUrlHandler setQuery(String querry) throws ParsingException { - return (SearchQueryUrlHandler) super.setQuery(querry); - } - - - @Override - public boolean onAcceptUrl(String url) { - return false; - } - - public SearchQueryUrlHandler 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 6c2aba0d..9eaeef46 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.ListUrlIdHandler; +import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.exceptions.ExtractionException; @@ -16,8 +16,6 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; import javax.annotation.Nonnull; import java.io.IOException; -import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps; - @SuppressWarnings("WeakerAccess") public class SoundcloudChannelExtractor extends ChannelExtractor { private String userId; @@ -26,14 +24,14 @@ public class SoundcloudChannelExtractor extends ChannelExtractor { private StreamInfoItemsCollector streamInfoItemsCollector = null; private String nextPageUrl = null; - public SoundcloudChannelExtractor(StreamingService service, ListUrlIdHandler urlIdHandler) { + public SoundcloudChannelExtractor(StreamingService service, ListUIHFactory urlIdHandler) { super(service, urlIdHandler); } @Override public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { - userId = getUrlIdHandler().getId(); + userId = getUIHFactory().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/SoundcloudChannelUrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelUIHFactory.java similarity index 69% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelUrlIdHandler.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelUIHFactory.java index 063ad7aa..142d8da3 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelUrlIdHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelUIHFactory.java @@ -1,22 +1,16 @@ package org.schabi.newpipe.extractor.services.soundcloud; -import org.jsoup.Jsoup; -import org.jsoup.nodes.Element; -import org.schabi.newpipe.extractor.ListUrlIdHandler; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.UrlIdHandler; +import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Utils; -import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps; - -public class SoundcloudChannelUrlIdHandler extends ListUrlIdHandler { - private static final SoundcloudChannelUrlIdHandler instance = new SoundcloudChannelUrlIdHandler(); +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_-]+" + "(/((tracks|albums|sets|reposts|followers|following)/?)?)?([#?].*)?$"; - public static SoundcloudChannelUrlIdHandler getInstance() { + public static SoundcloudChannelUIHFactory getInstance() { return instance; } 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 d2423fcb..24542dce 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,9 +1,8 @@ package org.schabi.newpipe.extractor.services.soundcloud; import org.schabi.newpipe.extractor.Downloader; -import org.schabi.newpipe.extractor.ListUrlIdHandler; +import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.StreamingService; -import org.schabi.newpipe.extractor.UrlIdHandler; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.kiosk.KioskExtractor; import org.schabi.newpipe.extractor.stream.StreamInfoItem; @@ -18,7 +17,7 @@ public class SoundcloudChartsExtractor extends KioskExtractor { private StreamInfoItemsCollector collector = null; private String nextPageUrl = null; - public SoundcloudChartsExtractor(StreamingService service, ListUrlIdHandler urlIdHandler, String kioskId) { + public SoundcloudChartsExtractor(StreamingService service, ListUIHFactory urlIdHandler, String kioskId) { super(service, urlIdHandler, kioskId); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUIHFactory.java similarity index 79% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandler.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUIHFactory.java index 03a846cb..f4b9109e 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUIHFactory.java @@ -1,11 +1,9 @@ package org.schabi.newpipe.extractor.services.soundcloud; -import org.schabi.newpipe.extractor.ListUrlIdHandler; -import org.schabi.newpipe.extractor.UrlIdHandler; -import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.utils.Parser; -public class SoundcloudChartsUrlIdHandler extends ListUrlIdHandler { +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)?/?([#?].*)?$"; 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 d6647539..00c61949 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.ListUrlIdHandler; +import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; @@ -15,8 +15,6 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; import javax.annotation.Nonnull; import java.io.IOException; -import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps; - @SuppressWarnings("WeakerAccess") public class SoundcloudPlaylistExtractor extends PlaylistExtractor { private String playlistId; @@ -25,14 +23,14 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor { private StreamInfoItemsCollector streamInfoItemsCollector = null; private String nextPageUrl = null; - public SoundcloudPlaylistExtractor(StreamingService service, ListUrlIdHandler urlIdHandler) { + public SoundcloudPlaylistExtractor(StreamingService service, ListUIHFactory urlIdHandler) { super(service, urlIdHandler); } @Override public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { - playlistId = getUrlIdHandler().getId(); + playlistId = getUIHFactory().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/SoundcloudPlaylistUrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistUIHFactory.java similarity index 80% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistUrlIdHandler.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistUIHFactory.java index 2855c1d5..18bd4f61 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistUrlIdHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistUIHFactory.java @@ -1,16 +1,16 @@ package org.schabi.newpipe.extractor.services.soundcloud; -import org.schabi.newpipe.extractor.ListUrlIdHandler; +import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Utils; -public class SoundcloudPlaylistUrlIdHandler extends ListUrlIdHandler { - private static final SoundcloudPlaylistUrlIdHandler instance = new SoundcloudPlaylistUrlIdHandler(); +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_-]+" + "/sets/[0-9a-z_-]+/?([#?].*)?$"; - public static SoundcloudPlaylistUrlIdHandler getInstance() { + public static SoundcloudPlaylistUIHFactory getInstance() { return instance; } 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 50452bc2..0ef3c86a 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.SearchQueryUrlHandler; +import org.schabi.newpipe.extractor.search.SearchQIHFactory; import org.schabi.newpipe.extractor.utils.Parser; import javax.annotation.Nonnull; @@ -19,14 +19,14 @@ import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; -import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudSearchQueryUrlHandler.ITEMS_PER_PAGE; +import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudSearchQIHFactory.ITEMS_PER_PAGE; public class SoundcloudSearchExtractor extends SearchExtractor { private JsonArray searchCollection; public SoundcloudSearchExtractor(StreamingService service, - SearchQueryUrlHandler urlIdHandler, + SearchQIHFactory urlIdHandler, String contentCountry) { super(service, urlIdHandler, contentCountry); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQueryUrlHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQIHFactory.java similarity index 93% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQueryUrlHandler.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQIHFactory.java index 92d4c6bc..349fd8bf 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQueryUrlHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQIHFactory.java @@ -2,13 +2,13 @@ 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.SearchQueryUrlHandler; +import org.schabi.newpipe.extractor.search.SearchQIHFactory; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; -public class SoundcloudSearchQueryUrlHandler extends SearchQueryUrlHandler { +public class SoundcloudSearchQIHFactory extends SearchQIHFactory { public static final String CHARSET_UTF_8 = "UTF-8"; public static final String TRACKS = "tracks"; 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 73334a34..b55c215e 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,9 +1,8 @@ package org.schabi.newpipe.extractor.services.soundcloud; -import org.schabi.newpipe.extractor.ListUrlIdHandler; -import org.schabi.newpipe.extractor.StreamingService; -import org.schabi.newpipe.extractor.SuggestionExtractor; -import org.schabi.newpipe.extractor.UrlIdHandler; +import org.schabi.newpipe.extractor.*; +import org.schabi.newpipe.extractor.ListUIHFactory; +import org.schabi.newpipe.extractor.UIHFactory; import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.kiosk.KioskExtractor; @@ -11,7 +10,7 @@ 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.SearchQueryUrlHandler; +import org.schabi.newpipe.extractor.search.SearchQIHFactory; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; @@ -25,48 +24,43 @@ public class SoundcloudService extends StreamingService { } @Override - public SearchEngine getSearchEngine() { - return new SoundcloudSearchEngine(getServiceId()); - } - - @Override - public SearchExtractor getSearchExtractor(SearchQueryUrlHandler queryHandler, String contentCountry) { + public SearchExtractor getSearchExtractor(SearchQIHFactory queryHandler, String contentCountry) { return new SoundcloudSearchExtractor(this, queryHandler, contentCountry); } @Override - public SearchQueryUrlHandler getSearchQueryHandler() { - return new SoundcloudSearchQueryUrlHandler(); + public SearchQIHFactory getSearchQIHFactory() { + return new SoundcloudSearchQIHFactory(); } @Override - public UrlIdHandler getStreamUrlIdHandler() { - return SoundcloudStreamUrlIdHandler.getInstance(); + public UIHFactory getStreamUIHFactory() { + return SoundcloudStreamUIHFactory.getInstance(); } @Override - public ListUrlIdHandler getChannelUrlIdHandler() { - return SoundcloudChannelUrlIdHandler.getInstance(); + public ListUIHFactory getChannelUIHFactory() { + return SoundcloudChannelUIHFactory.getInstance(); } @Override - public ListUrlIdHandler getPlaylistUrlIdHandler() { - return SoundcloudPlaylistUrlIdHandler.getInstance(); + public ListUIHFactory getPlaylistUIHFactory() { + return SoundcloudPlaylistUIHFactory.getInstance(); } @Override - public StreamExtractor getStreamExtractor(UrlIdHandler urlIdHandler) { - return new SoundcloudStreamExtractor(this, urlIdHandler); + public StreamExtractor getStreamExtractor(UIHFactory UIHFactory) { + return new SoundcloudStreamExtractor(this, UIHFactory); } @Override - public ChannelExtractor getChannelExtractor(ListUrlIdHandler urlIdHandler) { + public ChannelExtractor getChannelExtractor(ListUIHFactory urlIdHandler) { return new SoundcloudChannelExtractor(this, urlIdHandler); } @Override - public PlaylistExtractor getPlaylistExtractor(ListUrlIdHandler urlIdHandler) { + public PlaylistExtractor getPlaylistExtractor(ListUIHFactory urlIdHandler) { return new SoundcloudPlaylistExtractor(this, urlIdHandler); } @@ -84,14 +78,14 @@ public class SoundcloudService extends StreamingService { String id) throws ExtractionException { return new SoundcloudChartsExtractor(SoundcloudService.this, - new SoundcloudChartsUrlIdHandler().setUrl(url), id); + new SoundcloudChartsUIHFactory().setUrl(url), id); } }; KioskList list = new KioskList(getServiceId()); // add kiosks here e.g.: - final SoundcloudChartsUrlIdHandler h = new SoundcloudChartsUrlIdHandler(); + final SoundcloudChartsUIHFactory h = new SoundcloudChartsUIHFactory(); try { list.addKioskEntry(chartsFactory, h, "Top 50"); list.addKioskEntry(chartsFactory, h, "New & hot"); 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 46fb76fb..285743fe 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 @@ -17,13 +17,11 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps; - public class SoundcloudStreamExtractor extends StreamExtractor { private JsonObject track; - public SoundcloudStreamExtractor(StreamingService service, UrlIdHandler urlIdHandler) { - super(service, urlIdHandler); + public SoundcloudStreamExtractor(StreamingService service, UIHFactory UIHFactory) { + super(service, UIHFactory); } @Override diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUIHFactory.java similarity index 71% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUrlIdHandler.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUIHFactory.java index 7a760a2b..3aec24ec 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUrlIdHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUIHFactory.java @@ -1,24 +1,19 @@ package org.schabi.newpipe.extractor.services.soundcloud; -import org.jsoup.Jsoup; -import org.jsoup.nodes.Element; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.UrlIdHandler; +import org.schabi.newpipe.extractor.UIHFactory; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Utils; -import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps; - -public class SoundcloudStreamUrlIdHandler extends UrlIdHandler { - private static final SoundcloudStreamUrlIdHandler instance = new SoundcloudStreamUrlIdHandler(); +public class SoundcloudStreamUIHFactory extends UIHFactory { + private static final SoundcloudStreamUIHFactory instance = new SoundcloudStreamUIHFactory(); private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" + "/(?!(tracks|albums|sets|reposts|followers|following)/?$)[0-9a-z_-]+/?([#?].*)?$"; - private SoundcloudStreamUrlIdHandler() { + private SoundcloudStreamUIHFactory() { } - public static SoundcloudStreamUrlIdHandler getInstance() { + public static SoundcloudStreamUIHFactory getInstance() { return instance; } 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 d34a4f8d..5b5db292 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.getChannelUrlIdHandler().setUrl(getUrlFrom(channelUrl)).getId(); + id = service.getChannelUIHFactory().setUrl(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 fca63532..e425f1f5 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,9 +1,8 @@ package org.schabi.newpipe.extractor.services.youtube; -import org.schabi.newpipe.extractor.ListUrlIdHandler; -import org.schabi.newpipe.extractor.StreamingService; -import org.schabi.newpipe.extractor.SuggestionExtractor; -import org.schabi.newpipe.extractor.UrlIdHandler; +import org.schabi.newpipe.extractor.*; +import org.schabi.newpipe.extractor.ListUIHFactory; +import org.schabi.newpipe.extractor.UIHFactory; import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.kiosk.KioskExtractor; @@ -11,7 +10,7 @@ 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.SearchQueryUrlHandler; +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; @@ -48,47 +47,42 @@ public class YoutubeService extends StreamingService { } @Override - public SearchEngine getSearchEngine() { - return new YoutubeSearchEngine(getServiceId()); - } - - @Override - public SearchExtractor getSearchExtractor(SearchQueryUrlHandler query, String contentCountry) { + public SearchExtractor getSearchExtractor(SearchQIHFactory query, String contentCountry) { return new YoutubeSearchExtractor(this, query, contentCountry); } @Override - public UrlIdHandler getStreamUrlIdHandler() { - return YoutubeStreamUrlIdHandler.getInstance(); + public UIHFactory getStreamUIHFactory() { + return YoutubeStreamUIHFactory.getInstance(); } @Override - public ListUrlIdHandler getChannelUrlIdHandler() { - return YoutubeChannelUrlIdHandler.getInstance(); + public ListUIHFactory getChannelUIHFactory() { + return YoutubeChannelUIHFactory.getInstance(); } @Override - public ListUrlIdHandler getPlaylistUrlIdHandler() { - return YoutubePlaylistUrlIdHandler.getInstance(); + public ListUIHFactory getPlaylistUIHFactory() { + return YoutubePlaylistUIHFactory.getInstance(); } @Override - public SearchQueryUrlHandler getSearchQueryHandler() { - return YoutubeSearchQueryUrlHandler.getInstance(); + public SearchQIHFactory getSearchQIHFactory() { + return YoutubeSearchQIHFactory.getInstance(); } @Override - public StreamExtractor getStreamExtractor(UrlIdHandler urlIdHandler) throws ExtractionException { - return new YoutubeStreamExtractor(this, urlIdHandler); + public StreamExtractor getStreamExtractor(UIHFactory UIHFactory) throws ExtractionException { + return new YoutubeStreamExtractor(this, UIHFactory); } @Override - public ChannelExtractor getChannelExtractor(ListUrlIdHandler urlIdHandler) throws ExtractionException { + public ChannelExtractor getChannelExtractor(ListUIHFactory urlIdHandler) throws ExtractionException { return new YoutubeChannelExtractor(this, urlIdHandler); } @Override - public PlaylistExtractor getPlaylistExtractor(ListUrlIdHandler urlIdHandler) throws ExtractionException { + public PlaylistExtractor getPlaylistExtractor(ListUIHFactory urlIdHandler) throws ExtractionException { return new YoutubePlaylistExtractor(this, urlIdHandler); } @@ -108,9 +102,9 @@ public class YoutubeService extends StreamingService { public KioskExtractor createNewKiosk(StreamingService streamingService, String url, String id) throws ExtractionException { return new YoutubeTrendingExtractor(YoutubeService.this, - new YoutubeTrendingUrlIdHandler().setUrl(url), id); + new YoutubeTrendingUIHFactory().setUrl(url), id); } - }, new YoutubeTrendingUrlIdHandler(), "Trending"); + }, new YoutubeTrendingUIHFactory(), "Trending"); list.setDefaultKiosk("Trending"); } catch (Exception e) { throw new ExtractionException(e); 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 a602f0ea..7abd7039 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 @@ -48,7 +48,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor { private Document doc; - public YoutubeChannelExtractor(StreamingService service, ListUrlIdHandler urlIdHandler) { + public YoutubeChannelExtractor(StreamingService service, ListUIHFactory 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 13f31a6c..7654ce98 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 @@ -19,14 +19,12 @@ import org.schabi.newpipe.extractor.utils.Utils; import javax.annotation.Nonnull; import java.io.IOException; -import static org.schabi.newpipe.extractor.NewPipe.getDownloader; - @SuppressWarnings("WeakerAccess") public class YoutubePlaylistExtractor extends PlaylistExtractor { private Document doc; - public YoutubePlaylistExtractor(StreamingService service, ListUrlIdHandler urlIdHandler) throws ExtractionException { + public YoutubePlaylistExtractor(StreamingService service, ListUIHFactory urlIdHandler) throws ExtractionException { super(service, urlIdHandler); } @@ -175,7 +173,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { private void collectStreamsFrom(StreamInfoItemsCollector collector, Element element) throws ParsingException { collector.reset(); - final UrlIdHandler streamUrlIdHandler = getService().getStreamUrlIdHandler(); + final UIHFactory streamUIHFactory = getService().getStreamUIHFactory(); for (final Element li : element.children()) { if(isDeletedItem(li)) { continue; @@ -192,7 +190,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { @Override public String getUrl() throws ParsingException { try { - return streamUrlIdHandler.setId(li.attr("data-video-id")).getUrl(); + return streamUIHFactory.setId(li.attr("data-video-id")).getUrl(); } catch (Exception e) { throw new ParsingException("Could not get web page url for the video", e); } @@ -257,7 +255,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { @Override public String getThumbnailUrl() throws ParsingException { try { - return "https://i.ytimg.com/vi/" + streamUrlIdHandler.setUrl(getUrl()).getId() + "/hqdefault.jpg"; + return "https://i.ytimg.com/vi/" + streamUIHFactory.setUrl(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 5d51ed1e..af63be03 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 @@ -5,15 +5,12 @@ import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.schabi.newpipe.extractor.Downloader; import org.schabi.newpipe.extractor.InfoItem; -import org.schabi.newpipe.extractor.InfoItemsCollector; 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.search.InfoItemsSearchCollector; -import org.schabi.newpipe.extractor.search.SearchEngine; import org.schabi.newpipe.extractor.search.SearchExtractor; -import org.schabi.newpipe.extractor.search.SearchQueryUrlHandler; -import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeSearchQueryUrlHandler; +import org.schabi.newpipe.extractor.search.SearchQIHFactory; import org.schabi.newpipe.extractor.utils.Parser; import javax.annotation.Nonnull; @@ -27,7 +24,7 @@ public class YoutubeSearchExtractor extends SearchExtractor { private Document doc; public YoutubeSearchExtractor(StreamingService service, - SearchQueryUrlHandler urlIdHandler, + SearchQIHFactory 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 87571e8b..b1e1552f 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 @@ -84,8 +84,8 @@ public class YoutubeStreamExtractor extends StreamExtractor { private boolean isAgeRestricted; - public YoutubeStreamExtractor(StreamingService service, UrlIdHandler urlIdHandler) throws ExtractionException { - super(service, urlIdHandler); + public YoutubeStreamExtractor(StreamingService service, UIHFactory UIHFactory) throws ExtractionException { + super(service, UIHFactory); } /*////////////////////////////////////////////////////////////////////////// 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 94b9cc6c..d32125ca 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 @@ -25,13 +25,11 @@ 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.ListUrlIdHandler; +import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.StreamingService; -import org.schabi.newpipe.extractor.UrlIdHandler; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.kiosk.KioskExtractor; -import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeTrendingUrlIdHandler; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; @@ -42,7 +40,7 @@ public class YoutubeTrendingExtractor extends KioskExtractor { private Document doc; - public YoutubeTrendingExtractor(StreamingService service, ListUrlIdHandler urlIdHandler, String kioskId) + public YoutubeTrendingExtractor(StreamingService service, ListUIHFactory urlIdHandler, String kioskId) throws ExtractionException { super(service, urlIdHandler, kioskId); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeChannelUrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeChannelUIHFactory.java similarity index 82% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeChannelUrlIdHandler.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeChannelUIHFactory.java index e6dbf09b..c95413cd 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeChannelUrlIdHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeChannelUIHFactory.java @@ -1,6 +1,6 @@ package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers; -import org.schabi.newpipe.extractor.ListUrlIdHandler; +import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.utils.Parser; @@ -8,7 +8,7 @@ import org.schabi.newpipe.extractor.utils.Parser; * Created by Christian Schabesberger on 25.07.16. * * Copyright (C) Christian Schabesberger 2016 - * YoutubeChannelUrlIdHandler.java is part of NewPipe. + * YoutubeChannelUIHFactory.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 @@ -24,12 +24,12 @@ import org.schabi.newpipe.extractor.utils.Parser; * along with NewPipe. If not, see . */ -public class YoutubeChannelUrlIdHandler extends ListUrlIdHandler { +public class YoutubeChannelUIHFactory extends ListUIHFactory { - private static final YoutubeChannelUrlIdHandler instance = new YoutubeChannelUrlIdHandler(); + private static final YoutubeChannelUIHFactory instance = new YoutubeChannelUIHFactory(); private static final String ID_PATTERN = "/(user/[A-Za-z0-9_-]*|channel/[A-Za-z0-9_-]*)"; - public static YoutubeChannelUrlIdHandler getInstance() { + public static YoutubeChannelUIHFactory getInstance() { return instance; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubePlaylistUrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubePlaylistUIHFactory.java similarity index 78% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubePlaylistUrlIdHandler.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubePlaylistUIHFactory.java index 262cbfc2..d3daa3ea 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubePlaylistUrlIdHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubePlaylistUIHFactory.java @@ -1,16 +1,16 @@ package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers; -import org.schabi.newpipe.extractor.ListUrlIdHandler; +import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.utils.Parser; -public class YoutubePlaylistUrlIdHandler extends ListUrlIdHandler { +public class YoutubePlaylistUIHFactory extends ListUIHFactory { - private static final YoutubePlaylistUrlIdHandler instance = new YoutubePlaylistUrlIdHandler(); + private static final YoutubePlaylistUIHFactory instance = new YoutubePlaylistUIHFactory(); private static final String ID_PATTERN = "([\\-a-zA-Z0-9_]{10,})"; - public static YoutubePlaylistUrlIdHandler getInstance() { + public static YoutubePlaylistUIHFactory getInstance() { return instance; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeSearchQueryUrlHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeSearchQIHFactory.java similarity index 84% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeSearchQueryUrlHandler.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeSearchQIHFactory.java index a562f609..1dbb9e15 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeSearchQueryUrlHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeSearchQIHFactory.java @@ -1,12 +1,12 @@ package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers; import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.search.SearchQueryUrlHandler; +import org.schabi.newpipe.extractor.search.SearchQIHFactory; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; -public class YoutubeSearchQueryUrlHandler extends SearchQueryUrlHandler { +public class YoutubeSearchQIHFactory extends SearchQIHFactory { public static final String CHARSET_UTF_8 = "UTF-8"; @@ -15,8 +15,8 @@ public class YoutubeSearchQueryUrlHandler extends SearchQueryUrlHandler { public static final String PLAYLIST = "playlist"; public static final String ANY = "any"; - public static YoutubeSearchQueryUrlHandler getInstance() { - return new YoutubeSearchQueryUrlHandler(); + public static YoutubeSearchQIHFactory getInstance() { + return new YoutubeSearchQIHFactory(); } @Override diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeStreamUrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeStreamUIHFactory.java similarity index 94% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeStreamUrlIdHandler.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeStreamUIHFactory.java index 75870662..10efba8b 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeStreamUrlIdHandler.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.UrlIdHandler; +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.exceptions.ReCaptchaException; @@ -21,7 +21,7 @@ import java.net.URLDecoder; * Created by Christian Schabesberger on 02.02.16. * * Copyright (C) Christian Schabesberger 2016 - * YoutubeStreamUrlIdHandler.java is part of NewPipe. + * YoutubeStreamUIHFactory.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 @@ -37,15 +37,15 @@ import java.net.URLDecoder; * along with NewPipe. If not, see . */ -public class YoutubeStreamUrlIdHandler extends UrlIdHandler { +public class YoutubeStreamUIHFactory extends UIHFactory { - private static final YoutubeStreamUrlIdHandler instance = new YoutubeStreamUrlIdHandler(); + private static final YoutubeStreamUIHFactory instance = new YoutubeStreamUIHFactory(); private static final String ID_PATTERN = "([\\-a-zA-Z0-9_]{11})"; - private YoutubeStreamUrlIdHandler() { + private YoutubeStreamUIHFactory() { } - public static YoutubeStreamUrlIdHandler getInstance() { + public static YoutubeStreamUIHFactory getInstance() { return instance; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeTrendingUrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeTrendingUIHFactory.java similarity index 81% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeTrendingUrlIdHandler.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeTrendingUIHFactory.java index c3696cd7..9ee9a4e4 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeTrendingUrlIdHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeTrendingUIHFactory.java @@ -4,7 +4,7 @@ package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers; * Created by Christian Schabesberger on 12.08.17. * * Copyright (C) Christian Schabesberger 2017 - * YoutubeTrendingUrlIdHandler.java is part of NewPipe. + * YoutubeTrendingUIHFactory.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 @@ -20,12 +20,10 @@ package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers; * along with NewPipe. If not, see . */ -import org.schabi.newpipe.extractor.ListUrlIdHandler; -import org.schabi.newpipe.extractor.UrlIdHandler; -import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.utils.Parser; -public class YoutubeTrendingUrlIdHandler extends ListUrlIdHandler { +public class YoutubeTrendingUIHFactory extends ListUIHFactory { public String getUrl() { return "https://www.youtube.com/feed/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 ff8c9f41..1bfa5625 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,7 +23,7 @@ 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.UrlIdHandler; +import org.schabi.newpipe.extractor.UIHFactory; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.utils.Parser; @@ -39,8 +39,8 @@ public abstract class StreamExtractor extends Extractor { public static final int NO_AGE_LIMIT = 0; - public StreamExtractor(StreamingService service, UrlIdHandler urlIdHandler) { - super(service, urlIdHandler); + public StreamExtractor(StreamingService service, UIHFactory UIHFactory) { + super(service, UIHFactory); } @Nonnull diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java index a7723024..189e2f3d 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java @@ -15,7 +15,7 @@ import static org.junit.Assert.*; import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; /** - * Test for {@link SoundcloudChartsUrlIdHandler} + * Test for {@link SoundcloudChartsUIHFactory} */ public class SoundcloudChartsExtractorTest { diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandlerTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUIHFactoryTest.java similarity index 89% rename from extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandlerTest.java rename to extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUIHFactoryTest.java index 4fa09ffa..70920368 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandlerTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUIHFactoryTest.java @@ -11,14 +11,14 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** - * Test for {@link SoundcloudChartsUrlIdHandler} + * Test for {@link SoundcloudChartsUIHFactory} */ -public class SoundcloudChartsUrlIdHandlerTest { - private static SoundcloudChartsUrlIdHandler urlIdHandler; +public class SoundcloudChartsUIHFactoryTest { + private static SoundcloudChartsUIHFactory urlIdHandler; @BeforeClass public static void setUp() throws Exception { - urlIdHandler = new SoundcloudChartsUrlIdHandler(); + urlIdHandler = new SoundcloudChartsUIHFactory(); NewPipe.init(Downloader.getInstance()); } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUrlIdHandlerTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUIHFactoryTest.java similarity index 94% rename from extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUrlIdHandlerTest.java rename to extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUIHFactoryTest.java index 5c1d35cf..5fb597d5 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUrlIdHandlerTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUIHFactoryTest.java @@ -12,14 +12,14 @@ import java.util.List; import static org.junit.Assert.*; /** - * Test for {@link SoundcloudStreamUrlIdHandler} + * Test for {@link SoundcloudStreamUIHFactory} */ -public class SoundcloudStreamUrlIdHandlerTest { - private static SoundcloudStreamUrlIdHandler urlIdHandler; +public class SoundcloudStreamUIHFactoryTest { + private static SoundcloudStreamUIHFactory urlIdHandler; @BeforeClass public static void setUp() throws Exception { - urlIdHandler = SoundcloudStreamUrlIdHandler.getInstance(); + urlIdHandler = SoundcloudStreamUIHFactory.getInstance(); NewPipe.init(Downloader.getInstance()); } 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 e0e99803..c27569a9 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.UrlIdHandler; +import org.schabi.newpipe.extractor.UIHFactory; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionItem; @@ -21,13 +21,13 @@ import static org.junit.Assert.*; */ public class SoundcloudSubscriptionExtractorTest { private static SoundcloudSubscriptionExtractor subscriptionExtractor; - private static UrlIdHandler urlHandler; + private static UIHFactory urlHandler; @BeforeClass public static void setupClass() { NewPipe.init(Downloader.getInstance()); subscriptionExtractor = new SoundcloudSubscriptionExtractor(ServiceList.SoundCloud); - urlHandler = ServiceList.SoundCloud.getChannelUrlIdHandler(); + urlHandler = ServiceList.SoundCloud.getChannelUIHFactory(); } @Test 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 ecc5cbdc..109af202 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 @@ -4,7 +4,6 @@ import org.junit.BeforeClass; import org.junit.Test; import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudSearchExtractor; import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; @@ -19,36 +18,36 @@ public class SoundcloudSearchQUHTest { @Test public void testRegularValues() throws Exception { - assertEquals("https://api-v2.soundcloud.com/search?q=asdf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQueryHandler().setQuery("asdf").getUrl()); - assertEquals("https://api-v2.soundcloud.com/search?q=hans&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0",SoundCloud.getSearchQueryHandler().setQuery("hans").getUrl()); - assertEquals("https://api-v2.soundcloud.com/search?q=Poifj%26jaijf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQueryHandler().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.getSearchQueryHandler().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.getSearchQueryHandler().setQuery("?j$)H§B").getUrl()); + 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()); } @Test public void testGetContentFilter() throws Exception { - assertEquals("tracks", SoundCloud.getSearchQueryHandler() + assertEquals("tracks", SoundCloud.getSearchQIHFactory() .setQuery("", asList(new String[]{"tracks"}), "").getContentFilter().get(0)); - assertEquals("users", SoundCloud.getSearchQueryHandler() + assertEquals("users", SoundCloud.getSearchQIHFactory() .setQuery("asdf", asList(new String[]{"users"}), "").getContentFilter().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.getSearchQueryHandler() + 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.getSearchQueryHandler() + 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.getSearchQueryHandler() + 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.getSearchQueryHandler() + 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()); } @Test public void testGetAvailableContentFilter() { - final String[] contentFilter = SoundCloud.getSearchQueryHandler().getAvailableContentFilter(); + final String[] contentFilter = SoundCloud.getSearchQIHFactory().getAvailableContentFilter(); assertEquals(4, contentFilter.length); assertEquals("tracks", contentFilter[0]); assertEquals("users", contentFilter[1]); @@ -58,7 +57,7 @@ public class SoundcloudSearchQUHTest { @Test public void testGetAvailableSortFilter() { - final String[] contentFilter = SoundCloud.getSearchQueryHandler().getAvailableSortFilter(); + final String[] contentFilter = SoundCloud.getSearchQIHFactory().getAvailableSortFilter(); assertEquals(0, contentFilter.length); } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelUrlIdHandlerTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelUIHFactoryTest.java similarity index 91% rename from extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelUrlIdHandlerTest.java rename to extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelUIHFactoryTest.java index 345d8b95..aff6aa35 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelUrlIdHandlerTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelUIHFactoryTest.java @@ -5,21 +5,21 @@ import org.junit.Test; import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeChannelUrlIdHandler; +import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeChannelUIHFactory; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** - * Test for {@link YoutubeChannelUrlIdHandler} + * Test for {@link YoutubeChannelUIHFactory} */ -public class YoutubeChannelUrlIdHandlerTest { +public class YoutubeChannelUIHFactoryTest { - private static YoutubeChannelUrlIdHandler urlIdHandler; + private static YoutubeChannelUIHFactory urlIdHandler; @BeforeClass public static void setUp() { - urlIdHandler = YoutubeChannelUrlIdHandler.getInstance(); + urlIdHandler = YoutubeChannelUIHFactory.getInstance(); NewPipe.init(Downloader.getInstance()); } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorControversialTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorControversialTest.java index e36faeb2..a9a536d8 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorControversialTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorControversialTest.java @@ -8,7 +8,7 @@ import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; -import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeStreamUrlIdHandler; +import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeStreamUIHFactory; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.SubtitlesFormat; import org.schabi.newpipe.extractor.stream.VideoStream; @@ -22,7 +22,7 @@ import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; import static org.schabi.newpipe.extractor.ServiceList.YouTube; /** - * Test for {@link YoutubeStreamUrlIdHandler} + * Test for {@link YoutubeStreamUIHFactory} */ public class YoutubeStreamExtractorControversialTest { private static YoutubeStreamExtractor extractor; diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorRestrictedTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorRestrictedTest.java index 35d7760d..fd40a582 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorRestrictedTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorRestrictedTest.java @@ -8,7 +8,7 @@ import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; -import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeStreamUrlIdHandler; +import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeStreamUIHFactory; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.SubtitlesFormat; import org.schabi.newpipe.extractor.stream.VideoStream; @@ -22,7 +22,7 @@ import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; import static org.schabi.newpipe.extractor.ServiceList.YouTube; /** - * Test for {@link YoutubeStreamUrlIdHandler} + * Test for {@link YoutubeStreamUIHFactory} */ public class YoutubeStreamExtractorRestrictedTest { public static final String HTTPS = "https://"; diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUrlIdHandlerTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUIHFactoryTest.java similarity index 97% rename from extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUrlIdHandlerTest.java rename to extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUIHFactoryTest.java index 57f00079..57210b70 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUrlIdHandlerTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUIHFactoryTest.java @@ -6,7 +6,7 @@ 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.YoutubeStreamUrlIdHandler; +import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeStreamUIHFactory; import java.util.ArrayList; import java.util.List; @@ -14,15 +14,15 @@ import java.util.List; import static org.junit.Assert.*; /** - * Test for {@link YoutubeStreamUrlIdHandler} + * Test for {@link YoutubeStreamUIHFactory} */ -public class YoutubeStreamUrlIdHandlerTest { +public class YoutubeStreamUIHFactoryTest { private static String AD_URL = "https://googleads.g.doubleclick.net/aclk?sa=l&ai=C-2IPgeVTWPf4GcOStgfOnIOADf78n61GvKmmobYDrgIQASDj-5MDKAJg9ZXOgeAEoAGgy_T-A8gBAakC2gkpmquIsT6oAwGqBJMBT9BgD5kVgbN0dX602bFFaDw9vsxq-We-S8VkrXVBi6W_e7brZ36GCz1WO3EPEeklYuJjXLUowwCOKsd-8xr1UlS_tusuFJv9iX35xoBHKTRvs8-0aDbfEIm6in37QDfFuZjqgEMB8-tg0Jn_Pf1RU5OzbuU40B4Gy25NUTnOxhDKthOhKBUSZEksCEerUV8GMu10iAXCxquwApIFBggDEAEYAaAGGsgGlIjthrUDgAfItIsBqAemvhvYBwHSCAUIgGEQAbgT6AE&num=1&sig=AOD64_1DybDd4qAm5O7o9UAbTNRdqXXHFQ&ctype=21&video_id=dMO_IXYPZew&client=ca-pub-6219811747049371&adurl=http://www.youtube.com/watch%3Fv%3DdMO_IXYPZew"; - private static YoutubeStreamUrlIdHandler urlIdHandler; + private static YoutubeStreamUIHFactory urlIdHandler; @BeforeClass public static void setUp() { - urlIdHandler = YoutubeStreamUrlIdHandler.getInstance(); + urlIdHandler = YoutubeStreamUIHFactory.getInstance(); NewPipe.init(Downloader.getInstance()); } 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 6b5f2875..0e7adfbb 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.UrlIdHandler; +import org.schabi.newpipe.extractor.UIHFactory; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSubscriptionExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionItem; @@ -23,13 +23,13 @@ import static org.junit.Assert.*; */ public class YoutubeSubscriptionExtractorTest { private static YoutubeSubscriptionExtractor subscriptionExtractor; - private static UrlIdHandler urlHandler; + private static UIHFactory urlHandler; @BeforeClass public static void setupClass() { NewPipe.init(Downloader.getInstance()); subscriptionExtractor = new YoutubeSubscriptionExtractor(ServiceList.YouTube); - urlHandler = ServiceList.YouTube.getChannelUrlIdHandler(); + urlHandler = ServiceList.YouTube.getChannelUIHFactory(); } @Test diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java index ae8c9f61..8ea4d91a 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java @@ -26,7 +26,7 @@ import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeTrendingExtractor; -import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeTrendingUrlIdHandler; +import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeTrendingUIHFactory; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.utils.Utils; @@ -37,7 +37,7 @@ import static org.schabi.newpipe.extractor.ServiceList.YouTube; /** - * Test for {@link YoutubeTrendingUrlIdHandler} + * Test for {@link YoutubeTrendingUIHFactory} */ public class YoutubeTrendingExtractorTest { 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 55f374a1..5265fe1f 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.UrlIdHandler; +import org.schabi.newpipe.extractor.UIHFactory; import org.schabi.newpipe.extractor.kiosk.KioskInfo; import static org.junit.Assert.assertFalse; @@ -43,9 +43,9 @@ public class YoutubeTrendingKioskInfoTest { throws Exception { NewPipe.init(Downloader.getInstance()); StreamingService service = YouTube; - UrlIdHandler urlIdHandler = service.getKioskList().getUrlIdHandlerByType("Trending"); + UIHFactory UIHFactory = service.getKioskList().getUrlIdHandlerByType("Trending"); - kioskInfo = KioskInfo.getInfo(YouTube, urlIdHandler.setId("Trending").getUrl(), null); + kioskInfo = KioskInfo.getInfo(YouTube, UIHFactory.setId("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 new file mode 100644 index 00000000..fb9375e0 --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUIHFactoryTest.java @@ -0,0 +1,82 @@ +package org.schabi.newpipe.extractor.services.youtube; + +/* + * Created by Christian Schabesberger on 12.08.17. + * + * Copyright (C) Christian Schabesberger 2017 + * YoutubeTrendingUIHFactoryTest.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 . + */ + +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.services.youtube.urlIdHandlers.YoutubeTrendingUIHFactory; + +import static junit.framework.TestCase.assertFalse; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; + +/** + * Test for {@link YoutubeTrendingUIHFactory} + */ +public class YoutubeTrendingUIHFactoryTest { + private static UIHFactory UIHFactory; + + @BeforeClass + public static void setUp() throws Exception { + UIHFactory = YouTube.getKioskList().getUrlIdHandlerByType("Trending"); + NewPipe.init(Downloader.getInstance()); + } + + @Test + public void getUrl() + throws Exception { + assertEquals(UIHFactory.setId("").getUrl(), "https://www.youtube.com/feed/trending"); + } + + @Test + public void getId() + throws Exception { + assertEquals(UIHFactory.setUrl("").getId(), "Trending"); + } + + @Test + public void acceptUrl() { + 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")); + assertTrue(UIHFactory.acceptUrl("www.youtube.com/feed/trending")); + assertTrue(UIHFactory.acceptUrl("youtube.com/feed/trending")); + assertTrue(UIHFactory.acceptUrl("youtube.com/feed/trending?akdsakjf=dfije&kfj=dkjak")); + assertTrue(UIHFactory.acceptUrl("https://youtube.com/feed/trending")); + assertTrue(UIHFactory.acceptUrl("m.youtube.com/feed/trending")); + + assertFalse(UIHFactory.acceptUrl("https://youtu.be/feed/trending")); + assertFalse(UIHFactory.acceptUrl("kdskjfiiejfia")); + assertFalse(UIHFactory.acceptUrl("https://www.youtube.com/bullshit/feed/trending")); + assertFalse(UIHFactory.acceptUrl("https://www.youtube.com/feed/trending/bullshit")); + assertFalse(UIHFactory.acceptUrl("https://www.youtube.com/feed/bullshit/trending")); + assertFalse(UIHFactory.acceptUrl("peter klaut aepferl youtube.com/feed/trending")); + assertFalse(UIHFactory.acceptUrl("youtube.com/feed/trending askjkf")); + assertFalse(UIHFactory.acceptUrl("askdjfi youtube.com/feed/trending askjkf")); + assertFalse(UIHFactory.acceptUrl(" youtube.com/feed/trending")); + assertFalse(UIHFactory.acceptUrl("https://www.youtube.com/feed/trending.html")); + assertFalse(UIHFactory.acceptUrl("")); + } +} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUrlIdHandlerTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUrlIdHandlerTest.java deleted file mode 100644 index 315bdbfc..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUrlIdHandlerTest.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.schabi.newpipe.extractor.services.youtube; - -/* - * Created by Christian Schabesberger on 12.08.17. - * - * Copyright (C) Christian Schabesberger 2017 - * YoutubeTrendingUrlIdHandlerTest.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 . - */ - -import org.junit.BeforeClass; -import org.junit.Test; -import org.schabi.newpipe.Downloader; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.UrlIdHandler; -import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeTrendingUrlIdHandler; - -import static junit.framework.TestCase.assertFalse; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; - -/** - * Test for {@link YoutubeTrendingUrlIdHandler} - */ -public class YoutubeTrendingUrlIdHandlerTest { - private static UrlIdHandler urlIdHandler; - - @BeforeClass - public static void setUp() throws Exception { - urlIdHandler = YouTube.getKioskList().getUrlIdHandlerByType("Trending"); - NewPipe.init(Downloader.getInstance()); - } - - @Test - public void getUrl() - throws Exception { - assertEquals(urlIdHandler.setId("").getUrl(), "https://www.youtube.com/feed/trending"); - } - - @Test - public void getId() - throws Exception { - assertEquals(urlIdHandler.setUrl("").getId(), "Trending"); - } - - @Test - public void acceptUrl() { - assertTrue(urlIdHandler.acceptUrl("https://www.youtube.com/feed/trending")); - assertTrue(urlIdHandler.acceptUrl("https://www.youtube.com/feed/trending?adsf=fjaj#fhe")); - assertTrue(urlIdHandler.acceptUrl("http://www.youtube.com/feed/trending")); - assertTrue(urlIdHandler.acceptUrl("www.youtube.com/feed/trending")); - assertTrue(urlIdHandler.acceptUrl("youtube.com/feed/trending")); - assertTrue(urlIdHandler.acceptUrl("youtube.com/feed/trending?akdsakjf=dfije&kfj=dkjak")); - assertTrue(urlIdHandler.acceptUrl("https://youtube.com/feed/trending")); - assertTrue(urlIdHandler.acceptUrl("m.youtube.com/feed/trending")); - - assertFalse(urlIdHandler.acceptUrl("https://youtu.be/feed/trending")); - assertFalse(urlIdHandler.acceptUrl("kdskjfiiejfia")); - assertFalse(urlIdHandler.acceptUrl("https://www.youtube.com/bullshit/feed/trending")); - assertFalse(urlIdHandler.acceptUrl("https://www.youtube.com/feed/trending/bullshit")); - assertFalse(urlIdHandler.acceptUrl("https://www.youtube.com/feed/bullshit/trending")); - assertFalse(urlIdHandler.acceptUrl("peter klaut aepferl youtube.com/feed/trending")); - assertFalse(urlIdHandler.acceptUrl("youtube.com/feed/trending askjkf")); - assertFalse(urlIdHandler.acceptUrl("askdjfi youtube.com/feed/trending askjkf")); - assertFalse(urlIdHandler.acceptUrl(" youtube.com/feed/trending")); - assertFalse(urlIdHandler.acceptUrl("https://www.youtube.com/feed/trending.html")); - assertFalse(urlIdHandler.acceptUrl("")); - } -} 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 322c9e75..09d95f31 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 @@ -2,8 +2,6 @@ package org.schabi.newpipe.extractor.services.youtube.search; import org.junit.Test; -import java.util.ArrayList; - import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; import static org.schabi.newpipe.extractor.ServiceList.YouTube; @@ -12,36 +10,36 @@ public class YoutubeSearchQUHTest { @Test public void testRegularValues() throws Exception { - assertEquals("https://www.youtube.com/results?q=asdf", YouTube.getSearchQueryHandler().setQuery("asdf").getUrl()); - assertEquals("https://www.youtube.com/results?q=hans",YouTube.getSearchQueryHandler().setQuery("hans").getUrl()); - assertEquals("https://www.youtube.com/results?q=Poifj%26jaijf", YouTube.getSearchQueryHandler().setQuery("Poifj&jaijf").getUrl()); - assertEquals("https://www.youtube.com/results?q=G%C3%BCl%C3%BCm", YouTube.getSearchQueryHandler().setQuery("GÌlÌm").getUrl()); - assertEquals("https://www.youtube.com/results?q=%3Fj%24%29H%C2%A7B", YouTube.getSearchQueryHandler().setQuery("?j$)H§B").getUrl()); + 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()); } @Test public void testGetContentFilter() throws Exception { - assertEquals("stream", YouTube.getSearchQueryHandler() + assertEquals("stream", YouTube.getSearchQIHFactory() .setQuery("", asList(new String[]{"stream"}), "").getContentFilter().get(0)); - assertEquals("channel", YouTube.getSearchQueryHandler() + assertEquals("channel", YouTube.getSearchQIHFactory() .setQuery("asdf", asList(new String[]{"channel"}), "").getContentFilter().get(0)); } @Test public void testWithContentfilter() throws Exception { - assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQAVAU", YouTube.getSearchQueryHandler() + assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQAVAU", YouTube.getSearchQIHFactory() .setQuery("asdf", asList(new String[]{"stream"}), "").getUrl()); - assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQAlAU", YouTube.getSearchQueryHandler() + assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQAlAU", YouTube.getSearchQIHFactory() .setQuery("asdf", asList(new String[]{"channel"}), "").getUrl()); - assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQA1AU", YouTube.getSearchQueryHandler() + assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQA1AU", YouTube.getSearchQIHFactory() .setQuery("asdf", asList(new String[]{"playlist"}), "").getUrl()); - assertEquals("https://www.youtube.com/results?q=asdf", YouTube.getSearchQueryHandler() + assertEquals("https://www.youtube.com/results?q=asdf", YouTube.getSearchQIHFactory() .setQuery("asdf", asList(new String[]{"fjiijie"}), "").getUrl()); } @Test public void testGetAvailableContentFilter() { - final String[] contentFilter = YouTube.getSearchQueryHandler().getAvailableContentFilter(); + final String[] contentFilter = YouTube.getSearchQIHFactory().getAvailableContentFilter(); assertEquals(4, contentFilter.length); assertEquals("stream", contentFilter[0]); assertEquals("channel", contentFilter[1]); @@ -51,7 +49,7 @@ public class YoutubeSearchQUHTest { @Test public void testGetAvailableSortFilter() { - final String[] contentFilter = YouTube.getSearchQueryHandler().getAvailableSortFilter(); + final String[] contentFilter = YouTube.getSearchQIHFactory().getAvailableSortFilter(); assertEquals(0, contentFilter.length); } } From bd5423fe2a84c61312912266f1bba2ea64915b63 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 1 Jul 2018 16:21:40 +0200 Subject: [PATCH 07/20] 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 c3127874..8fd9e269 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 5918a00a..7eb80ad8 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 a07ecdde..adefb888 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 5d591a1e..7a2d6e87 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 88ec0e47..00000000 --- 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 04b5ca85..b20f117b 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 b41f041e..79b48e9e 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 372feaa9..a1692670 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 c46de368..4c64e390 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 afd02727..66a9db3c 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 a4739e63..04d8d7be 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 924ff8cb..d5008a50 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 edcfe34e..5e3f94dd 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 68a10ded..751152ca 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 4d9ad12d..5c1583c7 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 2e96f434..00000000 --- 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 9eaeef46..ea2195e3 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 142d8da3..5a8b1011 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 24542dce..ab9e92c3 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 f4b9109e..8fdb8f5e 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 00c61949..727486dd 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 18bd4f61..e4dc0cb2 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 0ef3c86a..8c547639 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 349fd8bf..9f053c18 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 b55c215e..901d1ef2 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 285743fe..853d17bc 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 3aec24ec..a4e5e604 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 5b5db292..b5bdcb53 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 e425f1f5..4490f138 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 7abd7039..72176d69 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 7654ce98..cc116ebb 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 af63be03..bdf55ac4 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 b1e1552f..133906a2 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 d32125ca..7feb0090 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 c95413cd..187933e9 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 d3daa3ea..c55057af 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 1dbb9e15..db688f32 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 10efba8b..95f9da49 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 9ee9a4e4..82351619 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 1bfa5625..a4409c7a 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 00000000..111ee045 --- /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 00000000..b9151fa7 --- /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 00000000..648dbd14 --- /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 00000000..891a38f6 --- /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 fbf4e7ef..08aebcae 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 00000000..5b0d3383 --- /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 70920368..e5d8ca2b 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 5fb597d5..4084ac3b 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 c27569a9..ebb5c351 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 9c164dcd..db38c8d4 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 c1816cb3..e1ca59b0 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 5dc5f63c..81329bd0 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 109af202..a21db113 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 aff6aa35..1be835aa 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 57210b70..e2e6f401 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 0e7adfbb..cd921ae5 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 5265fe1f..b7f0a50b 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 fb9375e0..3bbf7e94 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 09d95f31..eddf4310 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 From cf542db85395b9f8b5f0c6b2f43014482c8cfcfe Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 1 Jul 2018 18:50:21 +0200 Subject: [PATCH 08/20] getUIHandler() to getUIHFactory() --- .../java/org/schabi/newpipe/extractor/kiosk/KioskList.java | 2 +- .../services/youtube/YoutubeTrendingKioskInfoTest.java | 2 +- .../services/youtube/YoutubeTrendingUIHFactoryTest.java | 5 +---- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java b/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java index 04d8d7be..62c3acf6 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 @@ -92,7 +92,7 @@ public class KioskList { throw new ExtractionException("Could not find a kiosk that fits to the url: " + url); } - public UIHFactory getUrlIdHandlerByType(String type) { + public UIHFactory getUIHFactoryByType(String type) { return kioskList.get(type).handler; } } 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 b7f0a50b..6f3fc38b 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 @@ -43,7 +43,7 @@ public class YoutubeTrendingKioskInfoTest { throws Exception { NewPipe.init(Downloader.getInstance()); StreamingService service = YouTube; - UIHFactory UIHFactory = service.getKioskList().getUrlIdHandlerByType("Trending"); + UIHFactory UIHFactory = service.getKioskList().getUIHFactoryByType("Trending"); kioskInfo = KioskInfo.getInfo(YouTube, UIHFactory.fromId("Trending").getUrl(), null); } 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 3bbf7e94..9d1fd3b6 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,13 +24,10 @@ 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.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; @@ -44,7 +41,7 @@ public class YoutubeTrendingUIHFactoryTest { @BeforeClass public static void setUp() throws Exception { - UIHFactory = YouTube.getKioskList().getUrlIdHandlerByType("Trending"); + UIHFactory = YouTube.getKioskList().getUIHFactoryByType("Trending"); NewPipe.init(Downloader.getInstance()); } From 291de184188eb52758cb3f318939e633f8b8370b Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 1 Jul 2018 18:50:21 +0200 Subject: [PATCH 09/20] getUIHandler() to getUIHFactory() handler to handlerFactory in kiosk --- .../schabi/newpipe/extractor/kiosk/KioskList.java | 12 ++++++------ .../youtube/YoutubeTrendingKioskInfoTest.java | 2 +- .../youtube/YoutubeTrendingUIHFactoryTest.java | 5 +---- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java b/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java index 04d8d7be..1287d912 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 @@ -25,10 +25,10 @@ public class KioskList { private class KioskEntry { public KioskEntry(KioskExtractorFactory ef, UIHFactory h) { extractorFactory = ef; - handler = h; + handlerFactory = h; } final KioskExtractorFactory extractorFactory; - final UIHFactory handler; + final UIHFactory handlerFactory; } public KioskList(int service_id) { @@ -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.fromId(kioskId).getUrl(), kioskId); + ke.handlerFactory.fromId(kioskId).getUrl(), kioskId); } } @@ -85,14 +85,14 @@ public class KioskList { throws ExtractionException, IOException { for(Map.Entry e : kioskList.entrySet()) { KioskEntry ke = e.getValue(); - if(ke.handler.acceptUrl(url)) { + if(ke.handlerFactory.acceptUrl(url)) { return getExtractorById(e.getKey(), nextPageUrl); } } throw new ExtractionException("Could not find a kiosk that fits to the url: " + url); } - public UIHFactory getUrlIdHandlerByType(String type) { - return kioskList.get(type).handler; + public UIHFactory getUIHFactoryByType(String type) { + return kioskList.get(type).handlerFactory; } } 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 b7f0a50b..6f3fc38b 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 @@ -43,7 +43,7 @@ public class YoutubeTrendingKioskInfoTest { throws Exception { NewPipe.init(Downloader.getInstance()); StreamingService service = YouTube; - UIHFactory UIHFactory = service.getKioskList().getUrlIdHandlerByType("Trending"); + UIHFactory UIHFactory = service.getKioskList().getUIHFactoryByType("Trending"); kioskInfo = KioskInfo.getInfo(YouTube, UIHFactory.fromId("Trending").getUrl(), null); } 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 3bbf7e94..9d1fd3b6 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,13 +24,10 @@ 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.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; @@ -44,7 +41,7 @@ public class YoutubeTrendingUIHFactoryTest { @BeforeClass public static void setUp() throws Exception { - UIHFactory = YouTube.getKioskList().getUrlIdHandlerByType("Trending"); + UIHFactory = YouTube.getKioskList().getUIHFactoryByType("Trending"); NewPipe.init(Downloader.getInstance()); } From 812a78581142b23de930630566bff8aeb47f47de Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Mon, 2 Jul 2018 13:47:39 +0200 Subject: [PATCH 10/20] remove searchengine --- .../schabi/newpipe/extractor/ListInfo.java | 8 +- .../extractor/playlist/PlaylistInfo.java | 2 +- .../extractor/search/SearchEngine.java | 50 ------- .../newpipe/extractor/search/SearchInfo.java | 12 +- .../extractor/search/SearchResult.java | 71 ---------- .../soundcloud/SoundcloudSearchEngine.java | 84 ------------ .../soundcloud/SoundcloudSearchExtractor.java | 3 +- .../extractors/YoutubeSearchEngine.java | 124 ------------------ 8 files changed, 10 insertions(+), 344 deletions(-) delete mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchEngine.java delete mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchResult.java delete mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngine.java delete mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchEngine.java 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 7a2d6e87..5f9a59bd 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/ListInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/ListInfo.java @@ -1,16 +1,14 @@ 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; public abstract class ListInfo extends Info { private List relatedItems; private String nextPageUrl = null; - private List contentFilters = new ArrayList<>(); - private String sortFilter = ""; + private final List contentFilters; + private final String sortFilter; public ListInfo(int serviceId, String id, @@ -24,7 +22,7 @@ public abstract class ListInfo extends Info { this.sortFilter = sortFilter; } - public ListInfo(int serviceId, ListUIHandler listUrlIdHandler, String name) throws ParsingException { + public ListInfo(int serviceId, ListUIHandler listUrlIdHandler, String name) { super(serviceId, listUrlIdHandler, name); this.contentFilters = listUrlIdHandler.getContentFilters(); this.sortFilter = listUrlIdHandler.getSortFilter(); 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 5e3f94dd..b4f3ebc1 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 @@ -15,7 +15,7 @@ import java.io.IOException; public class PlaylistInfo extends ListInfo { - public PlaylistInfo(int serviceId, ListUIHandler urlIdHandler, String name) throws ParsingException { + private PlaylistInfo(int serviceId, ListUIHandler urlIdHandler, String name) throws ParsingException { super(serviceId, urlIdHandler, name); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchEngine.java b/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchEngine.java deleted file mode 100644 index ce32c5f6..00000000 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchEngine.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.schabi.newpipe.extractor.search; - -import org.schabi.newpipe.extractor.exceptions.ExtractionException; - -import java.io.IOException; - -/* - * Created by Christian Schabesberger on 10.08.15. - * - * Copyright (C) Christian Schabesberger 2015 - * SearchEngine.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 abstract class SearchEngine { - public enum Filter { - ANY, STREAM, CHANNEL, PLAYLIST - } - - public static class NothingFoundException extends ExtractionException { - public NothingFoundException(String message) { - super(message); - } - } - - private final InfoItemsSearchCollector collector; - - public SearchEngine(int serviceId) { - collector = new InfoItemsSearchCollector(serviceId); - } - - protected InfoItemsSearchCollector getInfoItemSearchCollector() { - return collector; - } - - public abstract InfoItemsSearchCollector search(String query, int page, String contentCountry, Filter filter) - throws IOException, ExtractionException; -} 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 5c1583c7..2d36bdf7 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,21 +2,19 @@ package org.schabi.newpipe.extractor.search; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.ListInfo; -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; +import org.schabi.newpipe.extractor.uih.SearchQIHandler; public class SearchInfo extends ListInfo { - private String searchString = ""; - private String searchSuggestion = ""; - + private String searchString; + private String searchSuggestion; public SearchInfo(int serviceId, - ListUIHandler urlIdHandler, + SearchQIHandler qIHandler, String searchString) throws ParsingException { - super(serviceId, urlIdHandler, "Search"); + super(serviceId, qIHandler, "Search"); this.searchString = searchString; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchResult.java b/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchResult.java deleted file mode 100644 index 0d4f1ac1..00000000 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/search/SearchResult.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.schabi.newpipe.extractor.search; - -import org.schabi.newpipe.extractor.InfoItem; -import org.schabi.newpipe.extractor.exceptions.ExtractionException; - -import javax.annotation.Nonnull; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/* - * Created by Christian Schabesberger on 29.02.16. - * - * Copyright (C) Christian Schabesberger 2016 - * SearchResult.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 SearchResult { - private final int serviceId; - public final String suggestion; - @Nonnull - public final List resultList; - @Nonnull - public final List errors; - - public SearchResult(int serviceId, String suggestion, List results, List errors) { - this.serviceId = serviceId; - this.suggestion = suggestion; - this.resultList = Collections.unmodifiableList(new ArrayList<>(results)); - this.errors = Collections.unmodifiableList(new ArrayList<>(errors)); - } - - public static SearchResult getSearchResult(@Nonnull final SearchEngine engine, final String query, final int page, - final String languageCode, final SearchEngine.Filter filter) - throws IOException, ExtractionException { - return null; - } - - public String getSuggestion() { - return suggestion; - } - - - @Nonnull - public List getResults() { - return Collections.unmodifiableList(resultList); - } - - @Nonnull - public List getErrors() { - return errors; - } - - public int getServiceId() { - return serviceId; - } -} diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngine.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngine.java deleted file mode 100644 index 3cd27031..00000000 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngine.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.schabi.newpipe.extractor.services.soundcloud; - -import com.grack.nanojson.JsonArray; -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.NewPipe; -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.SearchEngine; - -import java.io.IOException; -import java.net.URLEncoder; - -public class SoundcloudSearchEngine extends SearchEngine { - public static final String CHARSET_UTF_8 = "UTF-8"; - - public SoundcloudSearchEngine(int serviceId) { - super(serviceId); - } - - @Override - public InfoItemsSearchCollector search(String query, int page, String languageCode, Filter filter) throws IOException, ExtractionException { - InfoItemsSearchCollector collector = getInfoItemSearchCollector(); - - Downloader dl = NewPipe.getDownloader(); - - String url = "https://api-v2.soundcloud.com/search"; - - switch (filter) { - case STREAM: - url += "/tracks"; - break; - case CHANNEL: - url += "/users"; - break; - case PLAYLIST: - url += "/playlists"; - break; - case ANY: - // Don't append any parameter to search for everything - default: - break; - } - - url += "?q=" + URLEncoder.encode(query, CHARSET_UTF_8) - + "&client_id=" + SoundcloudParsingHelper.clientId() - + "&limit=10" - + "&offset=" + Integer.toString(page * 10); - - JsonArray searchCollection; - try { - searchCollection = JsonParser.object().from(dl.download(url)).getArray("collection"); - } catch (JsonParserException e) { - throw new ParsingException("Could not parse json response", e); - } - - if (searchCollection.size() == 0) { - throw new NothingFoundException("Nothing found"); - } - - for (Object result : searchCollection) { - if (!(result instanceof JsonObject)) continue; - //noinspection ConstantConditions - JsonObject searchResult = (JsonObject) result; - String kind = searchResult.getString("kind", ""); - switch (kind) { - case "user": - collector.commit(new SoundcloudChannelInfoItemExtractor(searchResult)); - break; - case "track": - collector.commit(new SoundcloudStreamInfoItemExtractor(searchResult)); - break; - case "playlist": - collector.commit(new SoundcloudPlaylistInfoItemExtractor(searchResult)); - break; - } - } - - return collector; - } -} 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 8c547639..c976ce2d 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 @@ -8,7 +8,6 @@ import org.schabi.newpipe.extractor.*; 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.SearchEngine; import org.schabi.newpipe.extractor.search.SearchExtractor; import org.schabi.newpipe.extractor.uih.SearchQIHandler; import org.schabi.newpipe.extractor.utils.Parser; @@ -70,7 +69,7 @@ public class SoundcloudSearchExtractor extends SearchExtractor { } if (searchCollection.size() == 0) { - throw new SearchEngine.NothingFoundException("Nothing found"); + throw new SearchExtractor.NothingFoundException("Nothing found"); } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchEngine.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchEngine.java deleted file mode 100644 index 7fda65dd..00000000 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchEngine.java +++ /dev/null @@ -1,124 +0,0 @@ -package org.schabi.newpipe.extractor.services.youtube.extractors; - -import org.jsoup.Jsoup; -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.exceptions.ExtractionException; -import org.schabi.newpipe.extractor.search.InfoItemsSearchCollector; -import org.schabi.newpipe.extractor.search.SearchEngine; - -import java.io.IOException; -import java.net.URLEncoder; - - -/* - * Created by Christian Schabesberger on 09.08.15. - * - * Copyright (C) Christian Schabesberger 2015 - * YoutubeSearchEngine.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 YoutubeSearchEngine extends SearchEngine { - - private static final String TAG = YoutubeSearchEngine.class.toString(); - public static final String CHARSET_UTF_8 = "UTF-8"; - - public YoutubeSearchEngine(int serviceId) { - super(serviceId); - } - - @Override - public InfoItemsSearchCollector search(String query, int page, String languageCode, Filter filter) - throws IOException, ExtractionException { - InfoItemsSearchCollector collector = getInfoItemSearchCollector(); - Downloader downloader = NewPipe.getDownloader(); - - String url = "https://www.youtube.com/results" - + "?q=" + URLEncoder.encode(query, CHARSET_UTF_8) - + "&page=" + Integer.toString(page + 1); - - switch (filter) { - case STREAM: - url += "&sp=EgIQAVAU"; - break; - case CHANNEL: - url += "&sp=EgIQAlAU"; //EgIQA( lowercase L )AU - break; - case PLAYLIST: - url += "&sp=EgIQA1AU"; //EgIQA( one )AU - break; - case ANY: - // Don't append any parameter to search for everything - default: - break; - } - - String site; - //String url = builder.build().toString(); - //if we've been passed a valid language code, append it to the URL - if (!languageCode.isEmpty()) { - //assert Pattern.matches("[a-z]{2}(-([A-Z]{2}|[0-9]{1,3}))?", languageCode); - site = downloader.download(url, languageCode); - } else { - site = downloader.download(url); - } - - Document doc = Jsoup.parse(site, url); - Element list = doc.select("ol[class=\"item-section\"]").first(); - - for (Element item : list.children()) { - /* First we need to determine which kind of item we are working with. - Youtube depicts five different kinds of items on its search result page. These are - regular videos, playlists, channels, two types of video suggestions, and a "no video - found" item. Since we only want videos, we need to filter out all the others. - An example for this can be seen here: - https://www.youtube.com/results?search_query=asdf&page=1 - - We already applied a filter to the url, so we don't need to care about channels and - playlists now. - */ - - Element el; - - // both types of spell correction item - if ((el = item.select("div[class*=\"spell-correction\"]").first()) != null) { - if (list.children().size() == 1) { - throw new NothingFoundException("Did you mean: " + el.select("a").first().text()); - } - // search message item - } else if ((el = item.select("div[class*=\"search-message\"]").first()) != null) { - throw new NothingFoundException(el.text()); - - // video item type - } else if ((el = item.select("div[class*=\"yt-lockup-video\"]").first()) != null) { - collector.commit(new YoutubeStreamInfoItemExtractor(el)); - } else if ((el = item.select("div[class*=\"yt-lockup-channel\"]").first()) != null) { - collector.commit(new YoutubeChannelInfoItemExtractor(el)); - } else if ((el = item.select("div[class*=\"yt-lockup-playlist\"]").first()) != null && - item.select(".yt-pl-icon-mix").isEmpty()) { - collector.commit(new YoutubePlaylistInfoItemExtractor(el)); - } else { - // noinspection ConstantConditions - // simply ignore not known items - // throw new ExtractionException("unexpected element found: \"" + item + "\""); - } - } - - return collector; - } -} From 2f351be772fe2e648c6c17d5917e96f48c913b0d Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 8 Jul 2018 14:32:31 +0200 Subject: [PATCH 11/20] add getMoreInfo to SearchInfo --- .../newpipe/extractor/search/SearchInfo.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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 2d36bdf7..95724112 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 @@ -1,11 +1,15 @@ package org.schabi.newpipe.extractor.search; import org.schabi.newpipe.extractor.InfoItem; +import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.ListInfo; +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.SearchQIHandler; +import java.io.IOException; + + public class SearchInfo extends ListInfo { private String searchString; @@ -13,13 +17,13 @@ public class SearchInfo extends ListInfo { public SearchInfo(int serviceId, SearchQIHandler qIHandler, - String searchString) throws ParsingException { + String searchString) { super(serviceId, qIHandler, "Search"); this.searchString = searchString; } - public static SearchInfo getInfo(SearchExtractor extractor) throws ExtractionException { + public static SearchInfo getInfo(SearchExtractor extractor) { final SearchInfo info = new SearchInfo( extractor.getServiceId(), extractor.getUIHandler(), @@ -34,6 +38,15 @@ public class SearchInfo extends ListInfo { return info; } + + public static ListExtractor.InfoItemsPage getMoreItems(StreamingService service, + SearchQIHandler query, + String contentCountry, + String pageUrl) + throws IOException, ExtractionException { + return service.getSearchExtractor(query, contentCountry).getPage(pageUrl); + } + // Getter public String getSearchString() { return searchString; From 31b0480e2274f01ace32464cb4635b75d72b65bf Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 8 Jul 2018 14:43:33 +0200 Subject: [PATCH 12/20] fix failing tests --- .../services/youtube/YoutubePlaylistExtractorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java index 2bfccbd0..7d8ebfae 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java @@ -127,7 +127,7 @@ public class YoutubePlaylistExtractorTest { public static void setUp() throws Exception { NewPipe.init(Downloader.getInstance()); extractor = (YoutubePlaylistExtractor) YouTube - .getPlaylistExtractor("https://www.youtube.com/playlist?list=PLOy0j9AvlVZPto6IkjKfpu0Scx--7PGTC"); + .getPlaylistExtractor("https://www.youtube.com/watch?v=lH1caqoAGe0&list=PL45xb3ujEhqUexNt53jb9WT2mS-uUaUrn"); extractor.fetchPage(); } From 4746a1c48a8682b3645c0aea626c59fb73cb1e24 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 8 Jul 2018 15:27:35 +0200 Subject: [PATCH 13/20] upgrade kisok uriIdhandler to ListUIHandler --- .../schabi/newpipe/extractor/kiosk/KioskList.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java b/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java index 1287d912..fcba9847 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,6 +2,8 @@ package org.schabi.newpipe.extractor.kiosk; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.extractor.uih.ListUIHFactory; +import org.schabi.newpipe.extractor.uih.ListUIHandler; import org.schabi.newpipe.extractor.uih.UIHFactory; import org.schabi.newpipe.extractor.exceptions.ExtractionException; @@ -23,24 +25,24 @@ public class KioskList { private String defaultKiosk = null; private class KioskEntry { - public KioskEntry(KioskExtractorFactory ef, UIHFactory h) { + public KioskEntry(KioskExtractorFactory ef, ListUIHFactory h) { extractorFactory = ef; handlerFactory = h; } final KioskExtractorFactory extractorFactory; - final UIHFactory handlerFactory; + final ListUIHFactory handlerFactory; } public KioskList(int service_id) { this.service_id = service_id; } - public void addKioskEntry(KioskExtractorFactory extractorFactory, UIHFactory handler, String id) + public void addKioskEntry(KioskExtractorFactory extractorFactory, ListUIHFactory handlerFactory, String id) throws Exception { if(kioskList.get(id) != null) { throw new Exception("Kiosk with type " + id + " already exists."); } - kioskList.put(id, new KioskEntry(extractorFactory, handler)); + kioskList.put(id, new KioskEntry(extractorFactory, handlerFactory)); } public void setDefaultKiosk(String kioskType) { @@ -92,7 +94,7 @@ public class KioskList { throw new ExtractionException("Could not find a kiosk that fits to the url: " + url); } - public UIHFactory getUIHFactoryByType(String type) { + public ListUIHFactory getUIHFactoryByType(String type) { return kioskList.get(type).handlerFactory; } } From 35b46900c14f0553388bf9621a13808c9a095ad9 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 8 Jul 2018 19:53:07 +0200 Subject: [PATCH 14/20] add outcomming items of searchextractor to searchinfo --- .../schabi/newpipe/extractor/search/SearchInfo.java | 5 ++++- .../services/youtube/YoutubePlaylistExtractorTest.java | 10 +++++----- 2 files changed, 9 insertions(+), 6 deletions(-) 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 95724112..71f8bc37 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 @@ -23,7 +23,7 @@ public class SearchInfo extends ListInfo { } - public static SearchInfo getInfo(SearchExtractor extractor) { + public static SearchInfo getInfo(SearchExtractor extractor) throws ExtractionException, IOException { final SearchInfo info = new SearchInfo( extractor.getServiceId(), extractor.getUIHandler(), @@ -35,6 +35,9 @@ public class SearchInfo extends ListInfo { info.addError(e); } + info.setRelatedItems(extractor.getInfoItemSearchCollector().getItems()); + info.setNextPageUrl(extractor.getNextPageUrl()); + return info; } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java index 7d8ebfae..ff57344c 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java @@ -153,22 +153,22 @@ public class YoutubePlaylistExtractorTest { @Test public void testName() throws Exception { String name = extractor.getName(); - assertTrue(name, name.contains("Important videos")); + assertTrue(name, name.contains("Korrekte Aussprache - Lektion 1")); } @Test public void testId() throws Exception { - assertEquals("PLOy0j9AvlVZPto6IkjKfpu0Scx--7PGTC", extractor.getId()); + assertEquals("PL45xb3ujEhqUexNt53jb9WT2mS-uUaUrn", extractor.getId()); } @Test public void testUrl() throws ParsingException { - assertEquals("https://www.youtube.com/playlist?list=PLOy0j9AvlVZPto6IkjKfpu0Scx--7PGTC", extractor.getUrl()); + assertEquals("https://www.youtube.com/playlist?list=PL45xb3ujEhqUexNt53jb9WT2mS-uUaUrn", extractor.getUrl()); } @Test public void testOriginalUrl() throws ParsingException { - assertEquals("https://www.youtube.com/playlist?list=PLOy0j9AvlVZPto6IkjKfpu0Scx--7PGTC", extractor.getOriginalUrl()); + assertEquals("https://www.youtube.com/watch?v=lH1caqoAGe0&list=PL45xb3ujEhqUexNt53jb9WT2mS-uUaUrn", extractor.getOriginalUrl()); } /*////////////////////////////////////////////////////////////////////////// @@ -216,7 +216,7 @@ public class YoutubePlaylistExtractorTest { @Test public void testUploaderName() throws Exception { - assertEquals("Crazy Horse", extractor.getUploaderName()); + assertEquals("Luksan Wunder", extractor.getUploaderName()); } @Test From 53f0bc9d8d3c958176ed48a53b2dcf40a0468081 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 8 Jul 2018 20:15:14 +0200 Subject: [PATCH 15/20] add getInfo without need for search extractor to searchinfo --- .../org/schabi/newpipe/extractor/search/SearchInfo.java | 7 +++++++ 1 file changed, 7 insertions(+) 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 71f8bc37..6a212124 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 @@ -5,6 +5,7 @@ import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.ListInfo; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.stream.Stream; import org.schabi.newpipe.extractor.uih.SearchQIHandler; import java.io.IOException; @@ -23,6 +24,12 @@ public class SearchInfo extends ListInfo { } + public static SearchInfo getInfo(StreamingService service, SearchQIHandler searchQuery, String contentCountry) throws ExtractionException, IOException { + SearchExtractor extractor = service.getSearchExtractor(searchQuery, contentCountry); + extractor.fetchPage(); + return getInfo(extractor); + } + public static SearchInfo getInfo(SearchExtractor extractor) throws ExtractionException, IOException { final SearchInfo info = new SearchInfo( extractor.getServiceId(), From a1aaca1bea034a3740691cc13a6841ff8163de22 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 8 Jul 2018 20:49:13 +0200 Subject: [PATCH 16/20] get info from initial page --- .../org/schabi/newpipe/extractor/search/SearchInfo.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 6a212124..c5406ba5 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 @@ -7,6 +7,7 @@ import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.stream.Stream; import org.schabi.newpipe.extractor.uih.SearchQIHandler; +import org.schabi.newpipe.extractor.utils.ExtractorHelper; import java.io.IOException; @@ -42,8 +43,9 @@ public class SearchInfo extends ListInfo { info.addError(e); } - info.setRelatedItems(extractor.getInfoItemSearchCollector().getItems()); - info.setNextPageUrl(extractor.getNextPageUrl()); + ListExtractor.InfoItemsPage page = ExtractorHelper.getItemsPageOrLogError(info, extractor); + info.setRelatedItems(page.getItems()); + info.setNextPageUrl(page.getNextPageUrl()); return info; } From 28788a05dba7700eebafa9deee939d7bc62c3a85 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Fri, 13 Jul 2018 18:02:40 +0200 Subject: [PATCH 17/20] rename uih and remove afiliate link foo --- .../schabi/newpipe/extractor/Extractor.java | 13 ++- .../org/schabi/newpipe/extractor/Info.java | 14 ++-- .../newpipe/extractor/ListExtractor.java | 10 +-- .../schabi/newpipe/extractor/ListInfo.java | 4 +- .../newpipe/extractor/StreamingService.java | 24 +++--- .../extractor/channel/ChannelExtractor.java | 4 +- .../extractor/channel/ChannelInfo.java | 5 +- .../extractor/kiosk/KioskExtractor.java | 5 +- .../newpipe/extractor/kiosk/KioskInfo.java | 5 +- .../newpipe/extractor/kiosk/KioskList.java | 12 ++- .../LinkHandler.java} | 8 +- .../LinkHandlerFactory.java} | 14 ++-- .../ListLinkHandler.java} | 22 ++--- .../ListLinkHandlerFactory.java} | 23 +++-- .../SearchQueryHandler.java} | 18 ++-- .../SearchQueryHandlerFactory.java} | 14 ++-- .../extractor/playlist/PlaylistExtractor.java | 5 +- .../extractor/playlist/PlaylistInfo.java | 5 +- .../extractor/search/SearchExtractor.java | 9 +- .../newpipe/extractor/search/SearchInfo.java | 9 +- .../SoundcloudChannelExtractor.java | 4 +- ... SoundcloudChannelLinkHandlerFactory.java} | 8 +- .../soundcloud/SoundcloudChartsExtractor.java | 4 +- ...> SoundcloudChartsLinkHandlerFactory.java} | 4 +- .../SoundcloudPlaylistExtractor.java | 4 +- ...SoundcloudPlaylistLinkHandlerFactory.java} | 8 +- .../soundcloud/SoundcloudSearchExtractor.java | 6 +- ... SoundcloudSearchQueryHandlerFactory.java} | 12 +-- .../soundcloud/SoundcloudService.java | 32 +++---- .../soundcloud/SoundcloudStreamExtractor.java | 14 +--- ...> SoundcloudStreamLinkHandlerFactory.java} | 10 +-- .../services/youtube/YoutubeService.java | 34 ++++---- .../extractors/YoutubeChannelExtractor.java | 5 +- .../extractors/YoutubePlaylistExtractor.java | 13 +-- .../extractors/YoutubeSearchExtractor.java | 4 +- .../extractors/YoutubeStreamExtractor.java | 41 +-------- .../YoutubeStreamInfoItemExtractor.java | 2 +- .../extractors/YoutubeTrendingExtractor.java | 4 +- .../YoutubeChannelLinkHandlerFactory.java} | 12 +-- .../YoutubeParsingHelper.java | 2 +- .../YoutubePlaylistLinkHandlerFactory.java} | 10 +-- .../YoutubeSearchQueryHandlerFactory.java} | 14 ++-- .../YoutubeStreamLinkHandlerFactory.java} | 14 ++-- .../YoutubeTrendingLinkHandlerFactory.java} | 8 +- .../extractor/stream/StreamExtractor.java | 10 +-- .../newpipe/extractor/stream/StreamInfo.java | 28 ------- .../SoundcloudChartsExtractorTest.java | 2 +- ...undcloudChartsLinkHandlerFactoryTest.java} | 8 +- ...undcloudStreamLinkHandlerFactoryTest.java} | 8 +- .../SoundcloudSubscriptionExtractorTest.java | 4 +- ...YoutubeChannelLinkHandlerFactoryTest.java} | 11 ++- ...utubeStreamExtractorControversialTest.java | 4 +- .../YoutubeStreamExtractorRestrictedTest.java | 4 +- ... YoutubeStreamLinkHandlerFactoryTest.java} | 10 +-- .../YoutubeSubscriptionExtractorTest.java | 4 +- .../youtube/YoutubeTrendingExtractorTest.java | 4 +- .../youtube/YoutubeTrendingKioskInfoTest.java | 6 +- ...YoutubeTrendingLinkHandlerFactoryTest.java | 83 +++++++++++++++++++ .../YoutubeTrendingUIHFactoryTest.java | 83 ------------------- 59 files changed, 334 insertions(+), 427 deletions(-) rename extractor/src/main/java/org/schabi/newpipe/extractor/{uih/UIHandler.java => linkhandler/LinkHandler.java} (68%) rename extractor/src/main/java/org/schabi/newpipe/extractor/{uih/UIHFactory.java => linkhandler/LinkHandlerFactory.java} (85%) rename extractor/src/main/java/org/schabi/newpipe/extractor/{uih/ListUIHandler.java => linkhandler/ListLinkHandler.java} (59%) rename extractor/src/main/java/org/schabi/newpipe/extractor/{uih/ListUIHFactory.java => linkhandler/ListLinkHandlerFactory.java} (67%) rename extractor/src/main/java/org/schabi/newpipe/extractor/{uih/SearchQIHandler.java => linkhandler/SearchQueryHandler.java} (54%) rename extractor/src/main/java/org/schabi/newpipe/extractor/{uih/SearchQIHFactory.java => linkhandler/SearchQueryHandlerFactory.java} (62%) rename extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/{SoundcloudChannelUIHFactory.java => SoundcloudChannelLinkHandlerFactory.java} (78%) rename extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/{SoundcloudChartsUIHFactory.java => SoundcloudChartsLinkHandlerFactory.java} (86%) rename extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/{SoundcloudPlaylistUIHFactory.java => SoundcloudPlaylistLinkHandlerFactory.java} (79%) rename extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/{SoundcloudSearchQIHFactory.java => SoundcloudSearchQueryHandlerFactory.java} (88%) rename extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/{SoundcloudStreamUIHFactory.java => SoundcloudStreamLinkHandlerFactory.java} (76%) rename extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/{urlIdHandlers/YoutubeChannelUIHFactory.java => linkHandler/YoutubeChannelLinkHandlerFactory.java} (77%) rename extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/{urlIdHandlers => linkHandler}/YoutubeParsingHelper.java (96%) rename extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/{urlIdHandlers/YoutubePlaylistUIHFactory.java => linkHandler/YoutubePlaylistLinkHandlerFactory.java} (72%) rename extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/{urlIdHandlers/YoutubeSearchQIHFactory.java => linkHandler/YoutubeSearchQueryHandlerFactory.java} (78%) rename extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/{urlIdHandlers/YoutubeStreamUIHFactory.java => linkHandler/YoutubeStreamLinkHandlerFactory.java} (93%) rename extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/{urlIdHandlers/YoutubeTrendingUIHFactory.java => linkHandler/YoutubeTrendingLinkHandlerFactory.java} (81%) rename extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/{SoundcloudChartsUIHFactoryTest.java => SoundcloudChartsLinkHandlerFactoryTest.java} (88%) rename extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/{SoundcloudStreamUIHFactoryTest.java => SoundcloudStreamLinkHandlerFactoryTest.java} (93%) rename extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/{YoutubeChannelUIHFactoryTest.java => YoutubeChannelLinkHandlerFactoryTest.java} (87%) rename extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/{YoutubeStreamUIHFactoryTest.java => YoutubeStreamLinkHandlerFactoryTest.java} (96%) create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingLinkHandlerFactoryTest.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUIHFactoryTest.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 8fd9e269..ac2d7ca3 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java @@ -2,8 +2,7 @@ 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 org.schabi.newpipe.extractor.linkhandler.LinkHandler; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -16,15 +15,15 @@ public abstract class Extractor { */ private final StreamingService service; - private final org.schabi.newpipe.extractor.uih.UIHandler uIHandler; + private final LinkHandler uIHandler; @Nullable private boolean pageFetched = false; private final Downloader downloader; - public Extractor(final StreamingService service, final UIHandler uIHandler) { + public Extractor(final StreamingService service, final LinkHandler uIHandler) { if(service == null) throw new NullPointerException("service is null"); - if(uIHandler == null) throw new NullPointerException("UIHandler is null"); + if(uIHandler == null) throw new NullPointerException("LinkHandler is null"); this.service = service; this.uIHandler = uIHandler; this.downloader = NewPipe.getDownloader(); @@ -32,10 +31,10 @@ public abstract class Extractor { } /** - * @return The {@link UIHandler} of the current extractor object (e.g. a ChannelExtractor should return a channel url handler). + * @return The {@link LinkHandler} of the current extractor object (e.g. a ChannelExtractor should return a channel url handler). */ @Nonnull - public UIHandler getUIHandler() { + public LinkHandler getUIHandler() { return uIHandler; } 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 7eb80ad8..853fb118 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/Info.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/Info.java @@ -1,8 +1,6 @@ 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 org.schabi.newpipe.extractor.linkhandler.LinkHandler; import java.io.Serializable; import java.util.ArrayList; @@ -20,7 +18,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 UIHandler#getUrl() + * @see LinkHandler#getUrl() * @see Extractor#getOriginalUrl() */ private final String url; @@ -50,11 +48,11 @@ public abstract class Info implements Serializable { this.name = name; } - public Info(int serviceId, UIHandler uiHandler, String name) { + public Info(int serviceId, LinkHandler linkHandler, String name) { this(serviceId, - uiHandler.getId(), - uiHandler.getUrl(), - uiHandler.getOriginalUrl(), + linkHandler.getId(), + linkHandler.getUrl(), + linkHandler.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 adefb888..51cabe92 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java @@ -1,11 +1,9 @@ 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 org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; import javax.annotation.Nonnull; -import javax.swing.plaf.ListUI; import java.io.IOException; import java.util.Collections; import java.util.List; @@ -15,7 +13,7 @@ import java.util.List; */ public abstract class ListExtractor extends Extractor { - public ListExtractor(StreamingService service, ListUIHandler uiHandler) { + public ListExtractor(StreamingService service, ListLinkHandler uiHandler) { super(service, uiHandler); } @@ -53,8 +51,8 @@ public abstract class ListExtractor extends Extractor { } @Override - public ListUIHandler getUIHandler() { - return (ListUIHandler) super.getUIHandler(); + public ListLinkHandler getUIHandler() { + return (ListLinkHandler) 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 5f9a59bd..1cb42e5d 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,6 @@ package org.schabi.newpipe.extractor; -import org.schabi.newpipe.extractor.uih.ListUIHandler; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; import java.util.List; @@ -22,7 +22,7 @@ public abstract class ListInfo extends Info { this.sortFilter = sortFilter; } - public ListInfo(int serviceId, ListUIHandler listUrlIdHandler, String name) { + public ListInfo(int serviceId, ListLinkHandler listUrlIdHandler, String name) { super(serviceId, listUrlIdHandler, name); this.contentFilters = listUrlIdHandler.getContentFilters(); this.sortFilter = listUrlIdHandler.getSortFilter(); 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 b20f117b..e3dd3224 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.uih.*; +import org.schabi.newpipe.extractor.linkhandler.*; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; @@ -67,23 +67,23 @@ public abstract class StreamingService { //////////////////////////////////////////// // Url Id handler //////////////////////////////////////////// - public abstract UIHFactory getStreamUIHFactory(); - public abstract ListUIHFactory getChannelUIHFactory(); - public abstract ListUIHFactory getPlaylistUIHFactory(); - public abstract SearchQIHFactory getSearchQIHFactory(); + public abstract LinkHandlerFactory getStreamUIHFactory(); + public abstract ListLinkHandlerFactory getChannelUIHFactory(); + public abstract ListLinkHandlerFactory getPlaylistUIHFactory(); + public abstract SearchQueryHandlerFactory getSearchQIHFactory(); //////////////////////////////////////////// // Extractor //////////////////////////////////////////// - public abstract SearchExtractor getSearchExtractor(SearchQIHandler queryHandler, String contentCountry); + public abstract SearchExtractor getSearchExtractor(SearchQueryHandler queryHandler, String contentCountry); public abstract SuggestionExtractor getSuggestionExtractor(); public abstract SubscriptionExtractor getSubscriptionExtractor(); public abstract KioskList getKioskList() 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 abstract ChannelExtractor getChannelExtractor(ListLinkHandler urlIdHandler) throws ExtractionException; + public abstract PlaylistExtractor getPlaylistExtractor(ListLinkHandler urlIdHandler) throws ExtractionException; + public abstract StreamExtractor getStreamExtractor(LinkHandler UIHFactory) throws ExtractionException; public SearchExtractor getSearchExtractor(String query, List contentFilter, String sortFilter, String contentCountry) throws ExtractionException { return getSearchExtractor(getSearchQIHFactory().fromQuery(query, contentFilter, sortFilter), contentCountry); @@ -119,9 +119,9 @@ public abstract class StreamingService { * figure out where the link is pointing to (a channel, video, playlist, etc.) */ public final LinkType getLinkTypeByUrl(String url) throws ParsingException { - UIHFactory sH = getStreamUIHFactory(); - UIHFactory cH = getChannelUIHFactory(); - UIHFactory pH = getPlaylistUIHFactory(); + LinkHandlerFactory sH = getStreamUIHFactory(); + LinkHandlerFactory cH = getChannelUIHFactory(); + LinkHandlerFactory pH = getPlaylistUIHFactory(); if (sH.acceptUrl(url)) { return LinkType.STREAM; 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 79b48e9e..a5895c19 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 @@ -4,7 +4,7 @@ import org.schabi.newpipe.extractor.ListExtractor; 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 org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; /* * Created by Christian Schabesberger on 25.07.16. @@ -28,7 +28,7 @@ import org.schabi.newpipe.extractor.uih.ListUIHandler; public abstract class ChannelExtractor extends ListExtractor { - public ChannelExtractor(StreamingService service, ListUIHandler urlIdHandler) { + public ChannelExtractor(StreamingService service, ListLinkHandler 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 a1692670..297b689e 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,13 +2,12 @@ package org.schabi.newpipe.extractor.channel; import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage; import org.schabi.newpipe.extractor.ListInfo; -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.linkhandler.ListLinkHandler; import org.schabi.newpipe.extractor.utils.ExtractorHelper; import java.io.IOException; @@ -35,7 +34,7 @@ import java.io.IOException; public class ChannelInfo extends ListInfo { - public ChannelInfo(int serviceId, ListUIHandler urlIdHandler, String name) throws ParsingException { + public ChannelInfo(int serviceId, ListLinkHandler urlIdHandler, String name) throws ParsingException { super(serviceId, urlIdHandler, name); } 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 4c64e390..c7c14dbf 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,11 +21,10 @@ package org.schabi.newpipe.extractor.kiosk; */ import org.schabi.newpipe.extractor.ListExtractor; -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 org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; import javax.annotation.Nonnull; @@ -34,7 +33,7 @@ public abstract class KioskExtractor extends ListExtractor { private final String id; public KioskExtractor(StreamingService streamingService, - ListUIHandler urlIdHandler, + ListLinkHandler 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 66a9db3c..6c357bd1 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,15 +24,14 @@ 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.linkhandler.ListLinkHandler; import org.schabi.newpipe.extractor.utils.ExtractorHelper; import java.io.IOException; public class KioskInfo extends ListInfo { - private KioskInfo(int serviceId, ListUIHandler urlIdHandler, String name) throws ParsingException { + private KioskInfo(int serviceId, ListLinkHandler urlIdHandler, String name) throws ParsingException { super(serviceId, urlIdHandler, name); } 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 fcba9847..263cf225 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,9 +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.uih.ListUIHFactory; -import org.schabi.newpipe.extractor.uih.ListUIHandler; -import org.schabi.newpipe.extractor.uih.UIHFactory; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import java.io.IOException; @@ -25,19 +23,19 @@ public class KioskList { private String defaultKiosk = null; private class KioskEntry { - public KioskEntry(KioskExtractorFactory ef, ListUIHFactory h) { + public KioskEntry(KioskExtractorFactory ef, ListLinkHandlerFactory h) { extractorFactory = ef; handlerFactory = h; } final KioskExtractorFactory extractorFactory; - final ListUIHFactory handlerFactory; + final ListLinkHandlerFactory handlerFactory; } public KioskList(int service_id) { this.service_id = service_id; } - public void addKioskEntry(KioskExtractorFactory extractorFactory, ListUIHFactory handlerFactory, String id) + public void addKioskEntry(KioskExtractorFactory extractorFactory, ListLinkHandlerFactory handlerFactory, String id) throws Exception { if(kioskList.get(id) != null) { throw new Exception("Kiosk with type " + id + " already exists."); @@ -94,7 +92,7 @@ public class KioskList { throw new ExtractionException("Could not find a kiosk that fits to the url: " + url); } - public ListUIHFactory getUIHFactoryByType(String type) { + public ListLinkHandlerFactory getUIHFactoryByType(String type) { return kioskList.get(type).handlerFactory; } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/uih/UIHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/LinkHandler.java similarity index 68% rename from extractor/src/main/java/org/schabi/newpipe/extractor/uih/UIHandler.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/LinkHandler.java index 5b0d3383..c28bc5c8 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/uih/UIHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/LinkHandler.java @@ -1,19 +1,19 @@ -package org.schabi.newpipe.extractor.uih; +package org.schabi.newpipe.extractor.linkhandler; import java.io.Serializable; -public class UIHandler implements Serializable { +public class LinkHandler implements Serializable { protected final String originalUrl; protected final String url; protected final String id; - public UIHandler(String originalUrl, String url, String id) { + public LinkHandler(String originalUrl, String url, String id) { this.originalUrl = originalUrl; this.url = url; this.id = id; } - public UIHandler(UIHandler handler) { + public LinkHandler(LinkHandler handler) { this(handler.originalUrl, handler.url, handler.id); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/uih/UIHFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/LinkHandlerFactory.java similarity index 85% rename from extractor/src/main/java/org/schabi/newpipe/extractor/uih/UIHFactory.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/LinkHandlerFactory.java index 08aebcae..60a65f5e 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/uih/UIHFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/LinkHandlerFactory.java @@ -1,4 +1,4 @@ -package org.schabi.newpipe.extractor.uih; +package org.schabi.newpipe.extractor.linkhandler; import org.schabi.newpipe.extractor.exceptions.FoundAdException; import org.schabi.newpipe.extractor.exceptions.ParsingException; @@ -7,7 +7,7 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; * Created by Christian Schabesberger on 26.07.16. * * Copyright (C) Christian Schabesberger 2016 - * UIHFactory.java is part of NewPipe. + * LinkHandlerFactory.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 @@ -23,7 +23,7 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; * along with NewPipe. If not, see . */ -public abstract class UIHFactory { +public abstract class LinkHandlerFactory { /////////////////////////////////// // To Override @@ -37,20 +37,20 @@ public abstract class UIHFactory { // Logic /////////////////////////////////// - public UIHandler fromUrl(String url) throws ParsingException { + public LinkHandler fromUrl(String url) throws ParsingException { if(url == null) throw new IllegalArgumentException("url can not be null"); if(!acceptUrl(url)) { throw new ParsingException("Malformed unacceptable url: " + url); } final String id = getId(url); - return new UIHandler(url, getUrl(id), id); + return new LinkHandler(url, getUrl(id), id); } - public UIHandler fromId(String id) throws ParsingException { + public LinkHandler 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); + return new LinkHandler(url, url, id); } /** diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/uih/ListUIHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/ListLinkHandler.java similarity index 59% rename from extractor/src/main/java/org/schabi/newpipe/extractor/uih/ListUIHandler.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/ListLinkHandler.java index b9151fa7..3e85fe1b 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/uih/ListUIHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/ListLinkHandler.java @@ -1,23 +1,23 @@ -package org.schabi.newpipe.extractor.uih; +package org.schabi.newpipe.extractor.linkhandler; import java.util.Collections; import java.util.List; -public class ListUIHandler extends UIHandler { +public class ListLinkHandler extends LinkHandler { protected final List contentFilters; protected final String sortFilter; - public ListUIHandler(String originalUrl, - String url, - String id, - List contentFilters, - String sortFilter) { + public ListLinkHandler(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) { + public ListLinkHandler(ListLinkHandler handler) { this(handler.originalUrl, handler.url, handler.id, @@ -25,9 +25,9 @@ public class ListUIHandler extends UIHandler { handler.sortFilter); } - public ListUIHandler(UIHandler handler, - List contentFilters, - String sortFilter) { + public ListLinkHandler(LinkHandler handler, + List contentFilters, + String sortFilter) { this(handler.originalUrl, handler.url, handler.id, diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/uih/ListUIHFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/ListLinkHandlerFactory.java similarity index 67% rename from extractor/src/main/java/org/schabi/newpipe/extractor/uih/ListUIHFactory.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/ListLinkHandlerFactory.java index 111ee045..a9c4e51a 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/uih/ListUIHFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/ListLinkHandlerFactory.java @@ -1,12 +1,11 @@ -package org.schabi.newpipe.extractor.uih; +package org.schabi.newpipe.extractor.linkhandler; 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 { +public abstract class ListLinkHandlerFactory extends LinkHandlerFactory { /////////////////////////////////// // To Override @@ -22,27 +21,27 @@ public abstract class ListUIHFactory extends UIHFactory { @Override - public ListUIHandler fromUrl(String url) throws ParsingException { + public ListLinkHandler 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)); + return new ListLinkHandler(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 ListLinkHandler fromId(String id) throws ParsingException { + return new ListLinkHandler(super.fromId(id), new ArrayList(0), ""); } - public ListUIHandler fromQuery(String id, - List contentFilters, - String sortFilter) throws ParsingException { + public ListLinkHandler fromQuery(String id, + List contentFilters, + String sortFilter) throws ParsingException { final String url = getUrl(id, contentFilters, sortFilter); - return new ListUIHandler(url, url, id, contentFilters, sortFilter); + return new ListLinkHandler(url, url, id, contentFilters, sortFilter); } /** - * For makeing ListUIHFactory compatible with UIHFactory we need to override this, + * For makeing ListLinkHandlerFactory compatible with LinkHandlerFactory 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 diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/uih/SearchQIHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/SearchQueryHandler.java similarity index 54% rename from extractor/src/main/java/org/schabi/newpipe/extractor/uih/SearchQIHandler.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/SearchQueryHandler.java index 891a38f6..6c1893c7 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/uih/SearchQIHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/SearchQueryHandler.java @@ -1,18 +1,18 @@ -package org.schabi.newpipe.extractor.uih; +package org.schabi.newpipe.extractor.linkhandler; import java.util.List; -public class SearchQIHandler extends ListUIHandler { +public class SearchQueryHandler extends ListLinkHandler { - public SearchQIHandler(String originalUrl, - String url, - String searchString, - List contentFilters, - String sortFilter) { + public SearchQueryHandler(String originalUrl, + String url, + String searchString, + List contentFilters, + String sortFilter) { super(originalUrl, url, searchString, contentFilters, sortFilter); } - public SearchQIHandler(ListUIHandler handler) { + public SearchQueryHandler(ListLinkHandler handler) { this(handler.originalUrl, handler.url, handler.id, @@ -22,7 +22,7 @@ public class SearchQIHandler extends ListUIHandler { /** - * Returns the search string. Since ListQIHandler is based on ListUIHandler + * Returns the search string. Since ListQIHandler is based on ListLinkHandler * getSearchString() is equivalent to calling getId(). * @return the search string */ diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/uih/SearchQIHFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/SearchQueryHandlerFactory.java similarity index 62% rename from extractor/src/main/java/org/schabi/newpipe/extractor/uih/SearchQIHFactory.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/SearchQueryHandlerFactory.java index 648dbd14..997e2d09 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/uih/SearchQIHFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/SearchQueryHandlerFactory.java @@ -1,11 +1,11 @@ -package org.schabi.newpipe.extractor.uih; +package org.schabi.newpipe.extractor.linkhandler; import org.schabi.newpipe.extractor.exceptions.ParsingException; import java.util.ArrayList; import java.util.List; -public abstract class SearchQIHFactory extends ListUIHFactory { +public abstract class SearchQueryHandlerFactory extends ListLinkHandlerFactory { /////////////////////////////////// // To Override @@ -23,13 +23,13 @@ public abstract class SearchQIHFactory extends ListUIHFactory { 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 SearchQueryHandler fromQuery(String querry, + List contentFilter, + String sortFilter) throws ParsingException { + return new SearchQueryHandler(super.fromQuery(querry, contentFilter, sortFilter)); } - public SearchQIHandler fromQuery(String querry) throws ParsingException { + public SearchQueryHandler fromQuery(String querry) throws ParsingException { return fromQuery(querry, new ArrayList(0), ""); } 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 d5008a50..cc511bc8 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,15 +1,14 @@ package org.schabi.newpipe.extractor.playlist; import org.schabi.newpipe.extractor.ListExtractor; -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.linkhandler.ListLinkHandler; import org.schabi.newpipe.extractor.stream.StreamInfoItem; -import org.schabi.newpipe.extractor.uih.ListUIHandler; public abstract class PlaylistExtractor extends ListExtractor { - public PlaylistExtractor(StreamingService service, ListUIHandler urlIdHandler) { + public PlaylistExtractor(StreamingService service, ListLinkHandler 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 b4f3ebc1..1eb35723 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,20 +2,19 @@ package org.schabi.newpipe.extractor.playlist; import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage; import org.schabi.newpipe.extractor.ListInfo; -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.linkhandler.ListLinkHandler; 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 { - private PlaylistInfo(int serviceId, ListUIHandler urlIdHandler, String name) throws ParsingException { + private PlaylistInfo(int serviceId, ListLinkHandler urlIdHandler, String name) throws ParsingException { super(serviceId, urlIdHandler, name); } 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 751152ca..ebbf76a6 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,8 +5,7 @@ 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; +import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler; public abstract class SearchExtractor extends ListExtractor { @@ -19,7 +18,7 @@ public abstract class SearchExtractor extends ListExtractor { private final InfoItemsSearchCollector collector; private final String contentCountry; - public SearchExtractor(StreamingService service, SearchQIHandler urlIdHandler, String contentCountry) { + public SearchExtractor(StreamingService service, SearchQueryHandler urlIdHandler, String contentCountry) { super(service, urlIdHandler); collector = new InfoItemsSearchCollector(service.getServiceId()); this.contentCountry = contentCountry; @@ -36,8 +35,8 @@ public abstract class SearchExtractor extends ListExtractor { } @Override - public SearchQIHandler getUIHandler() { - return (SearchQIHandler) super.getUIHandler(); + public SearchQueryHandler getUIHandler() { + return (SearchQueryHandler) super.getUIHandler(); } @Override 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 c5406ba5..27b62233 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 @@ -5,8 +5,7 @@ import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.ListInfo; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; -import org.schabi.newpipe.extractor.stream.Stream; -import org.schabi.newpipe.extractor.uih.SearchQIHandler; +import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler; import org.schabi.newpipe.extractor.utils.ExtractorHelper; import java.io.IOException; @@ -18,14 +17,14 @@ public class SearchInfo extends ListInfo { private String searchSuggestion; public SearchInfo(int serviceId, - SearchQIHandler qIHandler, + SearchQueryHandler qIHandler, String searchString) { super(serviceId, qIHandler, "Search"); this.searchString = searchString; } - public static SearchInfo getInfo(StreamingService service, SearchQIHandler searchQuery, String contentCountry) throws ExtractionException, IOException { + public static SearchInfo getInfo(StreamingService service, SearchQueryHandler searchQuery, String contentCountry) throws ExtractionException, IOException { SearchExtractor extractor = service.getSearchExtractor(searchQuery, contentCountry); extractor.fetchPage(); return getInfo(extractor); @@ -52,7 +51,7 @@ public class SearchInfo extends ListInfo { public static ListExtractor.InfoItemsPage getMoreItems(StreamingService service, - SearchQIHandler query, + SearchQueryHandler query, String contentCountry, String pageUrl) throws IOException, ExtractionException { 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 ea2195e3..1b677869 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.uih.ListUIHandler; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.exceptions.ExtractionException; @@ -24,7 +24,7 @@ public class SoundcloudChannelExtractor extends ChannelExtractor { private StreamInfoItemsCollector streamInfoItemsCollector = null; private String nextPageUrl = null; - public SoundcloudChannelExtractor(StreamingService service, ListUIHandler urlIdHandler) { + public SoundcloudChannelExtractor(StreamingService service, ListLinkHandler urlIdHandler) { super(service, urlIdHandler); } 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/SoundcloudChannelLinkHandlerFactory.java similarity index 78% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelUIHFactory.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelLinkHandlerFactory.java index 5a8b1011..ed5d9a98 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/SoundcloudChannelLinkHandlerFactory.java @@ -1,18 +1,18 @@ package org.schabi.newpipe.extractor.services.soundcloud; -import org.schabi.newpipe.extractor.uih.ListUIHFactory; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory; 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(); +public class SoundcloudChannelLinkHandlerFactory extends ListLinkHandlerFactory { + private static final SoundcloudChannelLinkHandlerFactory instance = new SoundcloudChannelLinkHandlerFactory(); private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" + "(/((tracks|albums|sets|reposts|followers|following)/?)?)?([#?].*)?$"; - public static SoundcloudChannelUIHFactory getInstance() { + public static SoundcloudChannelLinkHandlerFactory getInstance() { return instance; } 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 ab9e92c3..12223b8a 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.uih.ListUIHandler; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; 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, ListUIHandler urlIdHandler, String kioskId) { + public SoundcloudChartsExtractor(StreamingService service, ListLinkHandler 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/SoundcloudChartsLinkHandlerFactory.java similarity index 86% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUIHFactory.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsLinkHandlerFactory.java index 8fdb8f5e..ef7e700f 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/SoundcloudChartsLinkHandlerFactory.java @@ -1,11 +1,11 @@ package org.schabi.newpipe.extractor.services.soundcloud; -import org.schabi.newpipe.extractor.uih.ListUIHFactory; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory; import org.schabi.newpipe.extractor.utils.Parser; import java.util.List; -public class SoundcloudChartsUIHFactory extends ListUIHFactory { +public class SoundcloudChartsLinkHandlerFactory extends ListLinkHandlerFactory { 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)?/?([#?].*)?$"; 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 727486dd..20c454d6 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.uih.ListUIHandler; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; @@ -23,7 +23,7 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor { private StreamInfoItemsCollector streamInfoItemsCollector = null; private String nextPageUrl = null; - public SoundcloudPlaylistExtractor(StreamingService service, ListUIHandler urlIdHandler) { + public SoundcloudPlaylistExtractor(StreamingService service, ListLinkHandler urlIdHandler) { super(service, urlIdHandler); } 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/SoundcloudPlaylistLinkHandlerFactory.java similarity index 79% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistUIHFactory.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistLinkHandlerFactory.java index e4dc0cb2..17e4e7f2 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/SoundcloudPlaylistLinkHandlerFactory.java @@ -1,18 +1,18 @@ package org.schabi.newpipe.extractor.services.soundcloud; -import org.schabi.newpipe.extractor.uih.ListUIHFactory; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory; 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(); +public class SoundcloudPlaylistLinkHandlerFactory extends ListLinkHandlerFactory { + private static final SoundcloudPlaylistLinkHandlerFactory instance = new SoundcloudPlaylistLinkHandlerFactory(); private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" + "/sets/[0-9a-z_-]+/?([#?].*)?$"; - public static SoundcloudPlaylistUIHFactory getInstance() { + public static SoundcloudPlaylistLinkHandlerFactory getInstance() { return instance; } 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 c976ce2d..b2f4c8ad 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 @@ -9,7 +9,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.uih.SearchQIHandler; +import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler; import org.schabi.newpipe.extractor.utils.Parser; import javax.annotation.Nonnull; @@ -18,14 +18,14 @@ import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; -import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudSearchQIHFactory.ITEMS_PER_PAGE; +import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudSearchQueryHandlerFactory.ITEMS_PER_PAGE; public class SoundcloudSearchExtractor extends SearchExtractor { private JsonArray searchCollection; public SoundcloudSearchExtractor(StreamingService service, - SearchQIHandler urlIdHandler, + SearchQueryHandler 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/SoundcloudSearchQueryHandlerFactory.java similarity index 88% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQIHFactory.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQueryHandlerFactory.java index 9f053c18..a48285f8 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/SoundcloudSearchQueryHandlerFactory.java @@ -2,14 +2,14 @@ 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.uih.SearchQIHFactory; +import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.List; -public class SoundcloudSearchQIHFactory extends SearchQIHFactory { +public class SoundcloudSearchQueryHandlerFactory extends SearchQueryHandlerFactory { public static final String CHARSET_UTF_8 = "UTF-8"; public static final String TRACKS = "tracks"; @@ -58,9 +58,9 @@ public class SoundcloudSearchQIHFactory extends SearchQIHFactory { @Override public String[] getAvailableContentFilter() { return new String[] { - TRACKS, - USERS, - PLAYLIST, - ANY}; + ANY, + TRACKS, + USERS, + PLAYLIST}; } } 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 901d1ef2..17aa0284 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,7 +1,7 @@ package org.schabi.newpipe.extractor.services.soundcloud; import org.schabi.newpipe.extractor.*; -import org.schabi.newpipe.extractor.uih.*; +import org.schabi.newpipe.extractor.linkhandler.*; import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.kiosk.KioskExtractor; @@ -21,43 +21,43 @@ public class SoundcloudService extends StreamingService { } @Override - public SearchExtractor getSearchExtractor(SearchQIHandler queryHandler, String contentCountry) { + public SearchExtractor getSearchExtractor(SearchQueryHandler queryHandler, String contentCountry) { return new SoundcloudSearchExtractor(this, queryHandler, contentCountry); } @Override - public SearchQIHFactory getSearchQIHFactory() { - return new SoundcloudSearchQIHFactory(); + public SearchQueryHandlerFactory getSearchQIHFactory() { + return new SoundcloudSearchQueryHandlerFactory(); } @Override - public UIHFactory getStreamUIHFactory() { - return SoundcloudStreamUIHFactory.getInstance(); + public LinkHandlerFactory getStreamUIHFactory() { + return SoundcloudStreamLinkHandlerFactory.getInstance(); } @Override - public ListUIHFactory getChannelUIHFactory() { - return SoundcloudChannelUIHFactory.getInstance(); + public ListLinkHandlerFactory getChannelUIHFactory() { + return SoundcloudChannelLinkHandlerFactory.getInstance(); } @Override - public ListUIHFactory getPlaylistUIHFactory() { - return SoundcloudPlaylistUIHFactory.getInstance(); + public ListLinkHandlerFactory getPlaylistUIHFactory() { + return SoundcloudPlaylistLinkHandlerFactory.getInstance(); } @Override - public StreamExtractor getStreamExtractor(UIHandler UIHandler) { - return new SoundcloudStreamExtractor(this, UIHandler); + public StreamExtractor getStreamExtractor(LinkHandler LinkHandler) { + return new SoundcloudStreamExtractor(this, LinkHandler); } @Override - public ChannelExtractor getChannelExtractor(ListUIHandler urlIdHandler) { + public ChannelExtractor getChannelExtractor(ListLinkHandler urlIdHandler) { return new SoundcloudChannelExtractor(this, urlIdHandler); } @Override - public PlaylistExtractor getPlaylistExtractor(ListUIHandler urlIdHandler) { + public PlaylistExtractor getPlaylistExtractor(ListLinkHandler urlIdHandler) { return new SoundcloudPlaylistExtractor(this, urlIdHandler); } @@ -75,14 +75,14 @@ public class SoundcloudService extends StreamingService { String id) throws ExtractionException { return new SoundcloudChartsExtractor(SoundcloudService.this, - new SoundcloudChartsUIHFactory().fromUrl(url), id); + new SoundcloudChartsLinkHandlerFactory().fromUrl(url), id); } }; KioskList list = new KioskList(getServiceId()); // add kiosks here e.g.: - final SoundcloudChartsUIHFactory h = new SoundcloudChartsUIHFactory(); + final SoundcloudChartsLinkHandlerFactory h = new SoundcloudChartsLinkHandlerFactory(); try { list.addKioskEntry(chartsFactory, h, "Top 50"); list.addKioskEntry(chartsFactory, h, "New & hot"); 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 853d17bc..dbd9971c 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 @@ -7,8 +7,8 @@ import org.schabi.newpipe.extractor.*; 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.linkhandler.LinkHandler; import org.schabi.newpipe.extractor.stream.*; -import org.schabi.newpipe.extractor.uih.UIHandler; import javax.annotation.Nonnull; import java.io.IOException; @@ -21,7 +21,7 @@ import java.util.List; public class SoundcloudStreamExtractor extends StreamExtractor { private JsonObject track; - public SoundcloudStreamExtractor(StreamingService service, UIHandler uIHandler) { + public SoundcloudStreamExtractor(StreamingService service, LinkHandler uIHandler) { super(service, uIHandler); } @@ -202,16 +202,6 @@ public class SoundcloudStreamExtractor extends StreamExtractor { return collector; } - @Override - public String[] getDonationLinks() { - return new String[0]; - } - - @Override - public String[] getAffiliateLinks() { - return new String[0]; - } - @Override public String getErrorMessage() { return null; 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/SoundcloudStreamLinkHandlerFactory.java similarity index 76% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUIHFactory.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamLinkHandlerFactory.java index a4e5e604..3476eab1 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/SoundcloudStreamLinkHandlerFactory.java @@ -1,19 +1,19 @@ package org.schabi.newpipe.extractor.services.soundcloud; -import org.schabi.newpipe.extractor.uih.UIHFactory; +import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Utils; -public class SoundcloudStreamUIHFactory extends UIHFactory { - private static final SoundcloudStreamUIHFactory instance = new SoundcloudStreamUIHFactory(); +public class SoundcloudStreamLinkHandlerFactory extends LinkHandlerFactory { + private static final SoundcloudStreamLinkHandlerFactory instance = new SoundcloudStreamLinkHandlerFactory(); private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" + "/(?!(tracks|albums|sets|reposts|followers|following)/?$)[0-9a-z_-]+/?([#?].*)?$"; - private SoundcloudStreamUIHFactory() { + private SoundcloudStreamLinkHandlerFactory() { } - public static SoundcloudStreamUIHFactory getInstance() { + public static SoundcloudStreamLinkHandlerFactory getInstance() { return instance; } 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 4490f138..228827bf 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,7 +1,7 @@ package org.schabi.newpipe.extractor.services.youtube; import org.schabi.newpipe.extractor.*; -import org.schabi.newpipe.extractor.uih.*; +import org.schabi.newpipe.extractor.linkhandler.*; import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.kiosk.KioskExtractor; @@ -9,7 +9,7 @@ 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.services.youtube.extractors.*; -import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.*; +import org.schabi.newpipe.extractor.services.youtube.linkHandler.*; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; @@ -44,42 +44,42 @@ public class YoutubeService extends StreamingService { } @Override - public SearchExtractor getSearchExtractor(SearchQIHandler query, String contentCountry) { + public SearchExtractor getSearchExtractor(SearchQueryHandler query, String contentCountry) { return new YoutubeSearchExtractor(this, query, contentCountry); } @Override - public UIHFactory getStreamUIHFactory() { - return YoutubeStreamUIHFactory.getInstance(); + public LinkHandlerFactory getStreamUIHFactory() { + return YoutubeStreamLinkHandlerFactory.getInstance(); } @Override - public ListUIHFactory getChannelUIHFactory() { - return YoutubeChannelUIHFactory.getInstance(); + public ListLinkHandlerFactory getChannelUIHFactory() { + return YoutubeChannelLinkHandlerFactory.getInstance(); } @Override - public ListUIHFactory getPlaylistUIHFactory() { - return YoutubePlaylistUIHFactory.getInstance(); + public ListLinkHandlerFactory getPlaylistUIHFactory() { + return YoutubePlaylistLinkHandlerFactory.getInstance(); } @Override - public SearchQIHFactory getSearchQIHFactory() { - return YoutubeSearchQIHFactory.getInstance(); + public SearchQueryHandlerFactory getSearchQIHFactory() { + return YoutubeSearchQueryHandlerFactory.getInstance(); } @Override - public StreamExtractor getStreamExtractor(UIHandler uiHandler) throws ExtractionException { - return new YoutubeStreamExtractor(this, uiHandler); + public StreamExtractor getStreamExtractor(LinkHandler linkHandler) throws ExtractionException { + return new YoutubeStreamExtractor(this, linkHandler); } @Override - public ChannelExtractor getChannelExtractor(ListUIHandler urlIdHandler) throws ExtractionException { + public ChannelExtractor getChannelExtractor(ListLinkHandler urlIdHandler) throws ExtractionException { return new YoutubeChannelExtractor(this, urlIdHandler); } @Override - public PlaylistExtractor getPlaylistExtractor(ListUIHandler urlIdHandler) throws ExtractionException { + public PlaylistExtractor getPlaylistExtractor(ListLinkHandler urlIdHandler) throws ExtractionException { return new YoutubePlaylistExtractor(this, urlIdHandler); } @@ -99,9 +99,9 @@ public class YoutubeService extends StreamingService { public KioskExtractor createNewKiosk(StreamingService streamingService, String url, String id) throws ExtractionException { return new YoutubeTrendingExtractor(YoutubeService.this, - new YoutubeTrendingUIHFactory().fromUrl(url), id); + new YoutubeTrendingLinkHandlerFactory().fromUrl(url), id); } - }, new YoutubeTrendingUIHFactory(), "Trending"); + }, new YoutubeTrendingLinkHandlerFactory(), "Trending"); list.setDefaultKiosk("Trending"); } catch (Exception e) { throw new ExtractionException(e); 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 72176d69..e8680d11 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,8 +13,7 @@ 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.linkhandler.ListLinkHandler; import org.schabi.newpipe.extractor.utils.DonationLinkHelper; import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Utils; @@ -50,7 +49,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor { private Document doc; - public YoutubeChannelExtractor(StreamingService service, ListUIHandler urlIdHandler) { + public YoutubeChannelExtractor(StreamingService service, ListLinkHandler 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 cc116ebb..4852ceee 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 @@ -9,12 +9,13 @@ import org.jsoup.nodes.Element; import org.schabi.newpipe.extractor.*; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; import org.schabi.newpipe.extractor.playlist.PlaylistExtractor; -import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeParsingHelper; +import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper; 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; @@ -25,7 +26,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { private Document doc; - public YoutubePlaylistExtractor(StreamingService service, ListUIHandler urlIdHandler) throws ExtractionException { + public YoutubePlaylistExtractor(StreamingService service, ListLinkHandler urlIdHandler) throws ExtractionException { super(service, urlIdHandler); } @@ -174,7 +175,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { private void collectStreamsFrom(StreamInfoItemsCollector collector, Element element) { collector.reset(); - final org.schabi.newpipe.extractor.uih.UIHFactory streamUIHFactory = getService().getStreamUIHFactory(); + final LinkHandlerFactory streamLinkHandlerFactory = getService().getStreamUIHFactory(); for (final Element li : element.children()) { if(isDeletedItem(li)) { continue; @@ -191,7 +192,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { @Override public String getUrl() throws ParsingException { try { - return streamUIHFactory.fromId(li.attr("data-video-id")).getUrl(); + return streamLinkHandlerFactory.fromId(li.attr("data-video-id")).getUrl(); } catch (Exception e) { throw new ParsingException("Could not get web page url for the video", e); } @@ -256,7 +257,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { @Override public String getThumbnailUrl() throws ParsingException { try { - return "https://i.ytimg.com/vi/" + streamUIHFactory.fromUrl(getUrl()).getId() + "/hqdefault.jpg"; + return "https://i.ytimg.com/vi/" + streamLinkHandlerFactory.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 bdf55ac4..b74c948f 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.uih.SearchQIHandler; +import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler; import org.schabi.newpipe.extractor.utils.Parser; import javax.annotation.Nonnull; @@ -44,7 +44,7 @@ public class YoutubeSearchExtractor extends SearchExtractor { private Document doc; public YoutubeSearchExtractor(StreamingService service, - SearchQIHandler urlIdHandler, + SearchQueryHandler 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 133906a2..bd44ecf3 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 @@ -15,9 +15,9 @@ 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.exceptions.ReCaptchaException; +import org.schabi.newpipe.extractor.linkhandler.LinkHandler; 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; @@ -85,8 +85,8 @@ public class YoutubeStreamExtractor extends StreamExtractor { private boolean isAgeRestricted; - public YoutubeStreamExtractor(StreamingService service, UIHandler uiHandler) throws ExtractionException { - super(service, uiHandler); + public YoutubeStreamExtractor(StreamingService service, LinkHandler linkHandler) { + super(service, linkHandler); } /*////////////////////////////////////////////////////////////////////////// @@ -518,41 +518,6 @@ public class YoutubeStreamExtractor extends StreamExtractor { return errorReason != null ? errorReason.toString() : null; } - @Override - public String[] getDonationLinks() throws ParsingException { - try { - ArrayList donationLinks = new ArrayList<>(); - for (String s : Parser.getLinksFromString(getDescription())) { - if (DonationLinkHelper.getDonatoinServiceByLink(s) != DonationLinkHelper.DonationService.NO_DONATION) { - donationLinks.add(s); - } - } - String[] donlret = new String[donationLinks.size()]; - donlret = donationLinks.toArray(donlret); - return donlret; - } catch (Exception e) { - throw new ParsingException("Could not get donation links", e); - } - } - - @Override - public String[] getAffiliateLinks() throws ParsingException { - try { - ArrayList donationLinks = new ArrayList<>(); - for (String s : Parser.getLinksFromString(getDescription())) { - if (DonationLinkHelper.getAffiliateServiceByLink(s) != DonationLinkHelper.AffiliateService.NO_AFILIATE) { - donationLinks.add(s); - } - } - String[] donlret = new String[donationLinks.size()]; - donlret = donationLinks.toArray(donlret); - return donlret; - } catch (Exception e) { - throw new ParsingException("Could not get afiliate links", e); - } - } - - /*////////////////////////////////////////////////////////////////////////// // Fetch page //////////////////////////////////////////////////////////////////////////*/ diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamInfoItemExtractor.java index 3b1bb719..a948bfcf 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamInfoItemExtractor.java @@ -2,7 +2,7 @@ package org.schabi.newpipe.extractor.services.youtube.extractors; import org.jsoup.nodes.Element; import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeParsingHelper; +import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper; import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor; import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.extractor.utils.Utils; 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 7feb0090..b9cc118b 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 @@ -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.uih.ListUIHandler; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; @@ -41,7 +41,7 @@ public class YoutubeTrendingExtractor extends KioskExtractor { private Document doc; public YoutubeTrendingExtractor(StreamingService service, - ListUIHandler urlIdHandler, + ListLinkHandler 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/linkHandler/YoutubeChannelLinkHandlerFactory.java similarity index 77% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeChannelUIHFactory.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeChannelLinkHandlerFactory.java index 187933e9..950bab2b 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/linkHandler/YoutubeChannelLinkHandlerFactory.java @@ -1,6 +1,6 @@ -package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers; +package org.schabi.newpipe.extractor.services.youtube.linkHandler; -import org.schabi.newpipe.extractor.uih.ListUIHFactory; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.utils.Parser; @@ -10,7 +10,7 @@ import java.util.List; * Created by Christian Schabesberger on 25.07.16. * * Copyright (C) Christian Schabesberger 2018 - * YoutubeChannelUIHFactory.java is part of NewPipe. + * YoutubeChannelLinkHandlerFactory.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 @@ -26,12 +26,12 @@ import java.util.List; * along with NewPipe. If not, see . */ -public class YoutubeChannelUIHFactory extends ListUIHFactory { +public class YoutubeChannelLinkHandlerFactory extends ListLinkHandlerFactory { - private static final YoutubeChannelUIHFactory instance = new YoutubeChannelUIHFactory(); + private static final YoutubeChannelLinkHandlerFactory instance = new YoutubeChannelLinkHandlerFactory(); private static final String ID_PATTERN = "/(user/[A-Za-z0-9_-]*|channel/[A-Za-z0-9_-]*)"; - public static YoutubeChannelUIHFactory getInstance() { + public static YoutubeChannelLinkHandlerFactory getInstance() { return instance; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeParsingHelper.java similarity index 96% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeParsingHelper.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeParsingHelper.java index 90f464ed..fca0584c 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeParsingHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeParsingHelper.java @@ -1,4 +1,4 @@ -package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers; +package org.schabi.newpipe.extractor.services.youtube.linkHandler; import org.schabi.newpipe.extractor.exceptions.ParsingException; 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/linkHandler/YoutubePlaylistLinkHandlerFactory.java similarity index 72% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubePlaylistUIHFactory.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubePlaylistLinkHandlerFactory.java index c55057af..9954634f 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/linkHandler/YoutubePlaylistLinkHandlerFactory.java @@ -1,18 +1,18 @@ -package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers; +package org.schabi.newpipe.extractor.services.youtube.linkHandler; -import org.schabi.newpipe.extractor.uih.ListUIHFactory; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.utils.Parser; import java.util.List; -public class YoutubePlaylistUIHFactory extends ListUIHFactory { +public class YoutubePlaylistLinkHandlerFactory extends ListLinkHandlerFactory { - private static final YoutubePlaylistUIHFactory instance = new YoutubePlaylistUIHFactory(); + private static final YoutubePlaylistLinkHandlerFactory instance = new YoutubePlaylistLinkHandlerFactory(); private static final String ID_PATTERN = "([\\-a-zA-Z0-9_]{10,})"; - public static YoutubePlaylistUIHFactory getInstance() { + public static YoutubePlaylistLinkHandlerFactory getInstance() { return instance; } 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/linkHandler/YoutubeSearchQueryHandlerFactory.java similarity index 78% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeSearchQIHFactory.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeSearchQueryHandlerFactory.java index db688f32..803e7473 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/linkHandler/YoutubeSearchQueryHandlerFactory.java @@ -1,13 +1,13 @@ -package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers; +package org.schabi.newpipe.extractor.services.youtube.linkHandler; import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.uih.SearchQIHFactory; +import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.List; -public class YoutubeSearchQIHFactory extends SearchQIHFactory { +public class YoutubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory { public static final String CHARSET_UTF_8 = "UTF-8"; @@ -16,8 +16,8 @@ public class YoutubeSearchQIHFactory extends SearchQIHFactory { public static final String PLAYLIST = "playlist"; public static final String ANY = "any"; - public static YoutubeSearchQIHFactory getInstance() { - return new YoutubeSearchQIHFactory(); + public static YoutubeSearchQueryHandlerFactory getInstance() { + return new YoutubeSearchQueryHandlerFactory(); } @Override @@ -45,9 +45,9 @@ public class YoutubeSearchQIHFactory extends SearchQIHFactory { @Override public String[] getAvailableContentFilter() { return new String[] { + ANY, STREAM, CHANNEL, - PLAYLIST, - ANY}; + PLAYLIST}; } } 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/linkHandler/YoutubeStreamLinkHandlerFactory.java similarity index 93% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeStreamUIHFactory.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeStreamLinkHandlerFactory.java index 95f9da49..b159e3ad 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/linkHandler/YoutubeStreamLinkHandlerFactory.java @@ -1,11 +1,11 @@ -package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers; +package org.schabi.newpipe.extractor.services.youtube.linkHandler; import org.jsoup.Jsoup; 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.uih.UIHFactory; +import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory; import org.schabi.newpipe.extractor.exceptions.FoundAdException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; @@ -21,7 +21,7 @@ import java.net.URLDecoder; * Created by Christian Schabesberger on 02.02.16. * * Copyright (C) Christian Schabesberger 2018 - * YoutubeStreamUIHFactory.java is part of NewPipe. + * YoutubeStreamLinkHandlerFactory.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 @@ -37,15 +37,15 @@ import java.net.URLDecoder; * along with NewPipe. If not, see . */ -public class YoutubeStreamUIHFactory extends UIHFactory { +public class YoutubeStreamLinkHandlerFactory extends LinkHandlerFactory { - private static final YoutubeStreamUIHFactory instance = new YoutubeStreamUIHFactory(); + private static final YoutubeStreamLinkHandlerFactory instance = new YoutubeStreamLinkHandlerFactory(); private static final String ID_PATTERN = "([\\-a-zA-Z0-9_]{11})"; - private YoutubeStreamUIHFactory() { + private YoutubeStreamLinkHandlerFactory() { } - public static YoutubeStreamUIHFactory getInstance() { + public static YoutubeStreamLinkHandlerFactory getInstance() { return instance; } 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/linkHandler/YoutubeTrendingLinkHandlerFactory.java similarity index 81% rename from extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/urlIdHandlers/YoutubeTrendingUIHFactory.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeTrendingLinkHandlerFactory.java index 82351619..e61693b0 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/linkHandler/YoutubeTrendingLinkHandlerFactory.java @@ -1,10 +1,10 @@ -package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers; +package org.schabi.newpipe.extractor.services.youtube.linkHandler; /* * Created by Christian Schabesberger on 12.08.17. * * Copyright (C) Christian Schabesberger 2018 - * YoutubeTrendingUIHFactory.java is part of NewPipe. + * YoutubeTrendingLinkHandlerFactory.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 @@ -20,12 +20,12 @@ package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers; * along with NewPipe. If not, see . */ -import org.schabi.newpipe.extractor.uih.ListUIHFactory; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory; import org.schabi.newpipe.extractor.utils.Parser; import java.util.List; -public class YoutubeTrendingUIHFactory extends ListUIHFactory { +public class YoutubeTrendingLinkHandlerFactory extends ListLinkHandlerFactory { public String getUrl(String id, List contentFilters, String sortFilter) { return "https://www.youtube.com/feed/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 a4409c7a..765a9fae 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,10 +23,9 @@ 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.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.linkhandler.LinkHandler; import org.schabi.newpipe.extractor.utils.Parser; import javax.annotation.Nonnull; @@ -40,8 +39,8 @@ public abstract class StreamExtractor extends Extractor { public static final int NO_AGE_LIMIT = 0; - public StreamExtractor(StreamingService service, UIHandler uiHandler) { - super(service, uiHandler); + public StreamExtractor(StreamingService service, LinkHandler linkHandler) { + super(service, linkHandler); } @Nonnull @@ -136,9 +135,6 @@ public abstract class StreamExtractor extends Extractor { public abstract StreamInfoItem getNextVideo() throws IOException, ExtractionException; public abstract StreamInfoItemsCollector getRelatedVideos() throws IOException, ExtractionException; - public abstract String[] getDonationLinks() throws ExtractionException; - public abstract String[] getAffiliateLinks() throws ExtractionException; - /** * Analyses the webpage's document and extracts any error message there might be. * diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java index 9443e1ff..f2633533 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java @@ -242,16 +242,6 @@ public class StreamInfo extends Info { } catch (Exception e) { streamInfo.addError(e); } - try { - streamInfo.setAffiliateLinks(extractor.getAffiliateLinks()); - } catch (Exception e) { - streamInfo.addError(e); - } - try { - streamInfo.setDonationLinks(extractor.getDonationLinks()); - } catch (Exception e) { - streamInfo.addError(e); - } streamInfo.setRelatedStreams(ExtractorHelper.getRelatedVideosOrLogError(streamInfo, extractor)); return streamInfo; @@ -284,9 +274,6 @@ public class StreamInfo extends Info { private long startPosition = 0; private List subtitles; - private String[] donationLinks; - private String[] affiliateLinks; - /** * Get the stream type * @@ -480,19 +467,4 @@ public class StreamInfo extends Info { this.subtitles = subtitles; } - public String[] getDonationLinks() { - return donationLinks; - } - - public void setDonationLinks(String[] donationLinks) { - this.donationLinks = donationLinks; - } - - public String[] getAffiliateLinks() { - return affiliateLinks; - } - - public void setAffiliateLinks(String[] affiliateLinks) { - this.affiliateLinks = affiliateLinks; - } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java index 189e2f3d..b7c640f5 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java @@ -15,7 +15,7 @@ import static org.junit.Assert.*; import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; /** - * Test for {@link SoundcloudChartsUIHFactory} + * Test for {@link SoundcloudChartsLinkHandlerFactory} */ public class SoundcloudChartsExtractorTest { 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/SoundcloudChartsLinkHandlerFactoryTest.java similarity index 88% rename from extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUIHFactoryTest.java rename to extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsLinkHandlerFactoryTest.java index e5d8ca2b..10066d59 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/SoundcloudChartsLinkHandlerFactoryTest.java @@ -11,14 +11,14 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** - * Test for {@link SoundcloudChartsUIHFactory} + * Test for {@link SoundcloudChartsLinkHandlerFactory} */ -public class SoundcloudChartsUIHFactoryTest { - private static SoundcloudChartsUIHFactory urlIdHandler; +public class SoundcloudChartsLinkHandlerFactoryTest { + private static SoundcloudChartsLinkHandlerFactory urlIdHandler; @BeforeClass public static void setUp() throws Exception { - urlIdHandler = new SoundcloudChartsUIHFactory(); + urlIdHandler = new SoundcloudChartsLinkHandlerFactory(); NewPipe.init(Downloader.getInstance()); } 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/SoundcloudStreamLinkHandlerFactoryTest.java similarity index 93% rename from extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUIHFactoryTest.java rename to extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamLinkHandlerFactoryTest.java index 4084ac3b..c2acd423 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/SoundcloudStreamLinkHandlerFactoryTest.java @@ -12,14 +12,14 @@ import java.util.List; import static org.junit.Assert.*; /** - * Test for {@link SoundcloudStreamUIHFactory} + * Test for {@link SoundcloudStreamLinkHandlerFactory} */ -public class SoundcloudStreamUIHFactoryTest { - private static SoundcloudStreamUIHFactory urlIdHandler; +public class SoundcloudStreamLinkHandlerFactoryTest { + private static SoundcloudStreamLinkHandlerFactory urlIdHandler; @BeforeClass public static void setUp() throws Exception { - urlIdHandler = SoundcloudStreamUIHFactory.getInstance(); + urlIdHandler = SoundcloudStreamLinkHandlerFactory.getInstance(); NewPipe.init(Downloader.getInstance()); } 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 ebb5c351..6af12534 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.uih.UIHFactory; +import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionItem; @@ -21,7 +21,7 @@ import static org.junit.Assert.*; */ public class SoundcloudSubscriptionExtractorTest { private static SoundcloudSubscriptionExtractor subscriptionExtractor; - private static UIHFactory urlHandler; + private static LinkHandlerFactory urlHandler; @BeforeClass public static void setupClass() { 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/YoutubeChannelLinkHandlerFactoryTest.java similarity index 87% rename from extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelUIHFactoryTest.java rename to extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelLinkHandlerFactoryTest.java index 1be835aa..ccb8b425 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/YoutubeChannelLinkHandlerFactoryTest.java @@ -4,23 +4,22 @@ 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; +import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** - * Test for {@link YoutubeChannelUIHFactory} + * Test for {@link YoutubeChannelLinkHandlerFactory} */ -public class YoutubeChannelUIHFactoryTest { +public class YoutubeChannelLinkHandlerFactoryTest { - private static YoutubeChannelUIHFactory urlIdHandler; + private static YoutubeChannelLinkHandlerFactory urlIdHandler; @BeforeClass public static void setUp() { - urlIdHandler = YoutubeChannelUIHFactory.getInstance(); + urlIdHandler = YoutubeChannelLinkHandlerFactory.getInstance(); NewPipe.init(Downloader.getInstance()); } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorControversialTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorControversialTest.java index a9a536d8..1f594806 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorControversialTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorControversialTest.java @@ -8,7 +8,7 @@ import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; -import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeStreamUIHFactory; +import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.SubtitlesFormat; import org.schabi.newpipe.extractor.stream.VideoStream; @@ -22,7 +22,7 @@ import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; import static org.schabi.newpipe.extractor.ServiceList.YouTube; /** - * Test for {@link YoutubeStreamUIHFactory} + * Test for {@link YoutubeStreamLinkHandlerFactory} */ public class YoutubeStreamExtractorControversialTest { private static YoutubeStreamExtractor extractor; diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorRestrictedTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorRestrictedTest.java index fd40a582..b8bee1a3 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorRestrictedTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorRestrictedTest.java @@ -8,7 +8,7 @@ import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; -import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeStreamUIHFactory; +import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.SubtitlesFormat; import org.schabi.newpipe.extractor.stream.VideoStream; @@ -22,7 +22,7 @@ import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; import static org.schabi.newpipe.extractor.ServiceList.YouTube; /** - * Test for {@link YoutubeStreamUIHFactory} + * Test for {@link YoutubeStreamLinkHandlerFactory} */ public class YoutubeStreamExtractorRestrictedTest { public static final String HTTPS = "https://"; 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/YoutubeStreamLinkHandlerFactoryTest.java similarity index 96% rename from extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUIHFactoryTest.java rename to extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamLinkHandlerFactoryTest.java index e2e6f401..c71d1939 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/YoutubeStreamLinkHandlerFactoryTest.java @@ -6,7 +6,7 @@ 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.YoutubeStreamUIHFactory; +import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory; import java.util.ArrayList; import java.util.List; @@ -14,15 +14,15 @@ import java.util.List; import static org.junit.Assert.*; /** - * Test for {@link YoutubeStreamUIHFactory} + * Test for {@link YoutubeStreamLinkHandlerFactory} */ -public class YoutubeStreamUIHFactoryTest { +public class YoutubeStreamLinkHandlerFactoryTest { private static String AD_URL = "https://googleads.g.doubleclick.net/aclk?sa=l&ai=C-2IPgeVTWPf4GcOStgfOnIOADf78n61GvKmmobYDrgIQASDj-5MDKAJg9ZXOgeAEoAGgy_T-A8gBAakC2gkpmquIsT6oAwGqBJMBT9BgD5kVgbN0dX602bFFaDw9vsxq-We-S8VkrXVBi6W_e7brZ36GCz1WO3EPEeklYuJjXLUowwCOKsd-8xr1UlS_tusuFJv9iX35xoBHKTRvs8-0aDbfEIm6in37QDfFuZjqgEMB8-tg0Jn_Pf1RU5OzbuU40B4Gy25NUTnOxhDKthOhKBUSZEksCEerUV8GMu10iAXCxquwApIFBggDEAEYAaAGGsgGlIjthrUDgAfItIsBqAemvhvYBwHSCAUIgGEQAbgT6AE&num=1&sig=AOD64_1DybDd4qAm5O7o9UAbTNRdqXXHFQ&ctype=21&video_id=dMO_IXYPZew&client=ca-pub-6219811747049371&adurl=http://www.youtube.com/watch%3Fv%3DdMO_IXYPZew"; - private static YoutubeStreamUIHFactory urlIdHandler; + private static YoutubeStreamLinkHandlerFactory urlIdHandler; @BeforeClass public static void setUp() { - urlIdHandler = YoutubeStreamUIHFactory.getInstance(); + urlIdHandler = YoutubeStreamLinkHandlerFactory.getInstance(); NewPipe.init(Downloader.getInstance()); } 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 cd921ae5..a4ab4eeb 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.uih.UIHFactory; +import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSubscriptionExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionItem; @@ -23,7 +23,7 @@ import static org.junit.Assert.*; */ public class YoutubeSubscriptionExtractorTest { private static YoutubeSubscriptionExtractor subscriptionExtractor; - private static UIHFactory urlHandler; + private static LinkHandlerFactory urlHandler; @BeforeClass public static void setupClass() { diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java index 8ea4d91a..bf1ae8bb 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java @@ -26,7 +26,7 @@ import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeTrendingExtractor; -import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeTrendingUIHFactory; +import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeTrendingLinkHandlerFactory; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.utils.Utils; @@ -37,7 +37,7 @@ import static org.schabi.newpipe.extractor.ServiceList.YouTube; /** - * Test for {@link YoutubeTrendingUIHFactory} + * Test for {@link YoutubeTrendingLinkHandlerFactory} */ public class YoutubeTrendingExtractorTest { 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 6f3fc38b..a2b3ec47 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.uih.UIHFactory; +import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory; import org.schabi.newpipe.extractor.kiosk.KioskInfo; import static org.junit.Assert.assertFalse; @@ -43,9 +43,9 @@ public class YoutubeTrendingKioskInfoTest { throws Exception { NewPipe.init(Downloader.getInstance()); StreamingService service = YouTube; - UIHFactory UIHFactory = service.getKioskList().getUIHFactoryByType("Trending"); + LinkHandlerFactory LinkHandlerFactory = service.getKioskList().getUIHFactoryByType("Trending"); - kioskInfo = KioskInfo.getInfo(YouTube, UIHFactory.fromId("Trending").getUrl(), null); + kioskInfo = KioskInfo.getInfo(YouTube, LinkHandlerFactory.fromId("Trending").getUrl(), null); } @Test diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingLinkHandlerFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingLinkHandlerFactoryTest.java new file mode 100644 index 00000000..a6a18bd9 --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingLinkHandlerFactoryTest.java @@ -0,0 +1,83 @@ +package org.schabi.newpipe.extractor.services.youtube; + +/* + * Created by Christian Schabesberger on 12.08.17. + * + * Copyright (C) Christian Schabesberger 2017 + * YoutubeTrendingLinkHandlerFactoryTest.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 . + */ + +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.ParsingException; +import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory; +import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeTrendingLinkHandlerFactory; + +import static junit.framework.TestCase.assertFalse; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; + +/** + * Test for {@link YoutubeTrendingLinkHandlerFactory} + */ +public class YoutubeTrendingLinkHandlerFactoryTest { + private static LinkHandlerFactory LinkHandlerFactory; + + @BeforeClass + public static void setUp() throws Exception { + LinkHandlerFactory = YouTube.getKioskList().getUIHFactoryByType("Trending"); + NewPipe.init(Downloader.getInstance()); + } + + @Test + public void getUrl() + throws Exception { + assertEquals(LinkHandlerFactory.fromId("").getUrl(), "https://www.youtube.com/feed/trending"); + } + + @Test + public void getId() + throws Exception { + assertEquals(LinkHandlerFactory.fromUrl("https://www.youtube.com/feed/trending").getId(), "Trending"); + } + + @Test + public void acceptUrl() throws ParsingException { + assertTrue(LinkHandlerFactory.acceptUrl("https://www.youtube.com/feed/trending")); + assertTrue(LinkHandlerFactory.acceptUrl("https://www.youtube.com/feed/trending?adsf=fjaj#fhe")); + assertTrue(LinkHandlerFactory.acceptUrl("http://www.youtube.com/feed/trending")); + assertTrue(LinkHandlerFactory.acceptUrl("www.youtube.com/feed/trending")); + assertTrue(LinkHandlerFactory.acceptUrl("youtube.com/feed/trending")); + assertTrue(LinkHandlerFactory.acceptUrl("youtube.com/feed/trending?akdsakjf=dfije&kfj=dkjak")); + assertTrue(LinkHandlerFactory.acceptUrl("https://youtube.com/feed/trending")); + assertTrue(LinkHandlerFactory.acceptUrl("m.youtube.com/feed/trending")); + + assertFalse(LinkHandlerFactory.acceptUrl("https://youtu.be/feed/trending")); + assertFalse(LinkHandlerFactory.acceptUrl("kdskjfiiejfia")); + assertFalse(LinkHandlerFactory.acceptUrl("https://www.youtube.com/bullshit/feed/trending")); + assertFalse(LinkHandlerFactory.acceptUrl("https://www.youtube.com/feed/trending/bullshit")); + assertFalse(LinkHandlerFactory.acceptUrl("https://www.youtube.com/feed/bullshit/trending")); + assertFalse(LinkHandlerFactory.acceptUrl("peter klaut aepferl youtube.com/feed/trending")); + assertFalse(LinkHandlerFactory.acceptUrl("youtube.com/feed/trending askjkf")); + assertFalse(LinkHandlerFactory.acceptUrl("askdjfi youtube.com/feed/trending askjkf")); + assertFalse(LinkHandlerFactory.acceptUrl(" youtube.com/feed/trending")); + assertFalse(LinkHandlerFactory.acceptUrl("https://www.youtube.com/feed/trending.html")); + assertFalse(LinkHandlerFactory.acceptUrl("")); + } +} 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 deleted file mode 100644 index 9d1fd3b6..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUIHFactoryTest.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.schabi.newpipe.extractor.services.youtube; - -/* - * Created by Christian Schabesberger on 12.08.17. - * - * Copyright (C) Christian Schabesberger 2017 - * YoutubeTrendingUIHFactoryTest.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 . - */ - -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.ParsingException; -import org.schabi.newpipe.extractor.uih.UIHFactory; -import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeTrendingUIHFactory; - -import static junit.framework.TestCase.assertFalse; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; - -/** - * Test for {@link YoutubeTrendingUIHFactory} - */ -public class YoutubeTrendingUIHFactoryTest { - private static UIHFactory UIHFactory; - - @BeforeClass - public static void setUp() throws Exception { - UIHFactory = YouTube.getKioskList().getUIHFactoryByType("Trending"); - NewPipe.init(Downloader.getInstance()); - } - - @Test - public void getUrl() - throws Exception { - assertEquals(UIHFactory.fromId("").getUrl(), "https://www.youtube.com/feed/trending"); - } - - @Test - public void getId() - throws Exception { - assertEquals(UIHFactory.fromUrl("https://www.youtube.com/feed/trending").getId(), "Trending"); - } - - @Test - 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")); - assertTrue(UIHFactory.acceptUrl("www.youtube.com/feed/trending")); - assertTrue(UIHFactory.acceptUrl("youtube.com/feed/trending")); - assertTrue(UIHFactory.acceptUrl("youtube.com/feed/trending?akdsakjf=dfije&kfj=dkjak")); - assertTrue(UIHFactory.acceptUrl("https://youtube.com/feed/trending")); - assertTrue(UIHFactory.acceptUrl("m.youtube.com/feed/trending")); - - assertFalse(UIHFactory.acceptUrl("https://youtu.be/feed/trending")); - assertFalse(UIHFactory.acceptUrl("kdskjfiiejfia")); - assertFalse(UIHFactory.acceptUrl("https://www.youtube.com/bullshit/feed/trending")); - assertFalse(UIHFactory.acceptUrl("https://www.youtube.com/feed/trending/bullshit")); - assertFalse(UIHFactory.acceptUrl("https://www.youtube.com/feed/bullshit/trending")); - assertFalse(UIHFactory.acceptUrl("peter klaut aepferl youtube.com/feed/trending")); - assertFalse(UIHFactory.acceptUrl("youtube.com/feed/trending askjkf")); - assertFalse(UIHFactory.acceptUrl("askdjfi youtube.com/feed/trending askjkf")); - assertFalse(UIHFactory.acceptUrl(" youtube.com/feed/trending")); - assertFalse(UIHFactory.acceptUrl("https://www.youtube.com/feed/trending.html")); - assertFalse(UIHFactory.acceptUrl("")); - } -} From 8ee068fd98c6681e3dc173caca80631741636fe3 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Fri, 13 Jul 2018 19:08:50 +0200 Subject: [PATCH 18/20] fix names in kiosklist blub --- .../main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 263cf225..83d60adc 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 @@ -92,7 +92,7 @@ public class KioskList { throw new ExtractionException("Could not find a kiosk that fits to the url: " + url); } - public ListLinkHandlerFactory getUIHFactoryByType(String type) { + public ListLinkHandlerFactory getListLinkHandlerFactoryByType(String type) { return kioskList.get(type).handlerFactory; } } From 558a973e4393ee7062170f07ff1845755bdf8b3b Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Thu, 19 Jul 2018 16:06:44 +0200 Subject: [PATCH 19/20] rename search filters --- .../SoundcloudSearchQueryHandlerFactory.java | 6 +- .../YoutubeSearchQueryHandlerFactory.java | 24 ++++---- ...ndcloudSearchExtractorChannelOnlyTest.java | 5 +- .../YoutubeStreamExtractorDonationTest.java | 59 ------------------- .../youtube/YoutubeTrendingKioskInfoTest.java | 2 +- ...YoutubeTrendingLinkHandlerFactoryTest.java | 2 +- ...YoutubeSearchExtractorChannelOnlyTest.java | 5 +- 7 files changed, 23 insertions(+), 80 deletions(-) delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDonationTest.java diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQueryHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQueryHandlerFactory.java index a48285f8..2f7b45c6 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQueryHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQueryHandlerFactory.java @@ -15,7 +15,7 @@ public class SoundcloudSearchQueryHandlerFactory extends SearchQueryHandlerFacto public static final String TRACKS = "tracks"; public static final String USERS = "users"; public static final String PLAYLIST = "playlist"; - public static final String ANY = "any"; + public static final String ALL = "all"; public static final int ITEMS_PER_PAGE = 10; @@ -35,7 +35,7 @@ public class SoundcloudSearchQueryHandlerFactory extends SearchQueryHandlerFacto case PLAYLIST: url += "/playlists"; break; - case ANY: + case ALL: default: break; } @@ -58,7 +58,7 @@ public class SoundcloudSearchQueryHandlerFactory extends SearchQueryHandlerFacto @Override public String[] getAvailableContentFilter() { return new String[] { - ANY, + ALL, TRACKS, USERS, PLAYLIST}; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeSearchQueryHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeSearchQueryHandlerFactory.java index 803e7473..ba5ee152 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeSearchQueryHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeSearchQueryHandlerFactory.java @@ -11,10 +11,10 @@ public class YoutubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory public static final String CHARSET_UTF_8 = "UTF-8"; - public static final String STREAM = "stream"; - public static final String CHANNEL = "channel"; - public static final String PLAYLIST = "playlist"; - public static final String ANY = "any"; + public static final String VIDEOS = "videos"; + public static final String CHANNELS = "channels"; + public static final String PLAYLISTS = "playlists"; + public static final String ALL = "all"; public static YoutubeSearchQueryHandlerFactory getInstance() { return new YoutubeSearchQueryHandlerFactory(); @@ -28,10 +28,10 @@ public class YoutubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory 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"; - case ANY: + case VIDEOS: return url + "&sp=EgIQAVAU"; + case CHANNELS: return url + "&sp=EgIQAlAU"; + case PLAYLISTS: return url + "&sp=EgIQA1AU"; + case ALL: default: } } @@ -45,9 +45,9 @@ public class YoutubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory @Override public String[] getAvailableContentFilter() { return new String[] { - ANY, - STREAM, - CHANNEL, - PLAYLIST}; + ALL, + VIDEOS, + CHANNELS, + PLAYLISTS}; } } 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 e1ca59b0..3dc1e483 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 @@ -8,6 +8,7 @@ import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.channel.ChannelInfoItem; import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudSearchExtractor; +import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudSearchQueryHandlerFactory; import static java.util.Arrays.asList; import static org.junit.Assert.*; @@ -19,7 +20,7 @@ public class SoundcloudSearchExtractorChannelOnlyTest extends SoundcloudSearchEx public static void setUpClass() throws Exception { NewPipe.init(Downloader.getInstance()); extractor = (SoundcloudSearchExtractor) SoundCloud.getSearchExtractor("lill uzi vert", - asList(new String[]{"users"}), null, "de"); + asList(SoundcloudSearchQueryHandlerFactory.USERS), null, "de"); extractor.fetchPage(); itemsPage = extractor.getInitialPage(); } @@ -27,7 +28,7 @@ public class SoundcloudSearchExtractorChannelOnlyTest extends SoundcloudSearchEx @Test public void testGetSecondPage() throws Exception { SoundcloudSearchExtractor secondExtractor = (SoundcloudSearchExtractor) SoundCloud.getSearchExtractor("lill uzi vert", - asList(new String[]{"users"}), null, "de"); + asList(SoundcloudSearchQueryHandlerFactory.USERS), null, "de"); ListExtractor.InfoItemsPage secondPage = secondExtractor.getPage(itemsPage.getNextPageUrl()); assertTrue(Integer.toString(secondPage.getItems().size()), secondPage.getItems().size() >= 3); diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDonationTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDonationTest.java deleted file mode 100644 index 60ee0546..00000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDonationTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.schabi.newpipe.extractor.services.youtube; - - -/* - * Created by Christian Schabesberger on 30.12.15. - * - * Copyright (C) Christian Schabesberger 2018 - * YoutubeStreamExtractorDonationTest.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 . - */ - -import org.junit.BeforeClass; -import org.junit.Test; -import org.schabi.newpipe.Downloader; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; -import org.schabi.newpipe.extractor.stream.StreamExtractor; - -import static org.junit.Assert.assertTrue; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; - -/** - * Test for {@link StreamExtractor} - */ -public class YoutubeStreamExtractorDonationTest { - private static YoutubeStreamExtractor extractor; - - @BeforeClass - public static void setUp() throws Exception { - NewPipe.init(Downloader.getInstance()); - extractor = (YoutubeStreamExtractor) YouTube - .getStreamExtractor("https://www.youtube.com/watch?v=pXb3jERMoI0"); - extractor.fetchPage(); - } - - @Test - public void getDonationLinksTest() throws Exception { - assertTrue(String.valueOf(extractor.getDonationLinks().length), - extractor.getDonationLinks().length == 2); - } - - @Test - public void getAffiliateLinksTest() throws Exception { - assertTrue(String.valueOf(extractor.getAffiliateLinks().length), - extractor.getAffiliateLinks().length == 1); - } -} 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 a2b3ec47..66369170 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 @@ -43,7 +43,7 @@ public class YoutubeTrendingKioskInfoTest { throws Exception { NewPipe.init(Downloader.getInstance()); StreamingService service = YouTube; - LinkHandlerFactory LinkHandlerFactory = service.getKioskList().getUIHFactoryByType("Trending"); + LinkHandlerFactory LinkHandlerFactory = service.getKioskList().getListLinkHandlerFactoryByType("Trending"); kioskInfo = KioskInfo.getInfo(YouTube, LinkHandlerFactory.fromId("Trending").getUrl(), null); } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingLinkHandlerFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingLinkHandlerFactoryTest.java index a6a18bd9..ed3f0a01 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingLinkHandlerFactoryTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingLinkHandlerFactoryTest.java @@ -41,7 +41,7 @@ public class YoutubeTrendingLinkHandlerFactoryTest { @BeforeClass public static void setUp() throws Exception { - LinkHandlerFactory = YouTube.getKioskList().getUIHFactoryByType("Trending"); + LinkHandlerFactory = YouTube.getKioskList().getListLinkHandlerFactoryByType("Trending"); NewPipe.init(Downloader.getInstance()); } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java index f42ad407..b0c53a1f 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java @@ -8,6 +8,7 @@ import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.channel.ChannelInfoItem; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSearchExtractor; +import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory; import static java.util.Arrays.asList; import static org.junit.Assert.*; @@ -19,7 +20,7 @@ public class YoutubeSearchExtractorChannelOnlyTest extends YoutubeSearchExtracto public static void setUpClass() throws Exception { NewPipe.init(Downloader.getInstance()); extractor = (YoutubeSearchExtractor) YouTube.getSearchExtractor("pewdiepie", - asList(new String[]{"channel"}), null, "de"); + asList(YoutubeSearchQueryHandlerFactory.CHANNELS), null, "de"); extractor.fetchPage(); itemsPage = extractor.getInitialPage(); } @@ -27,7 +28,7 @@ public class YoutubeSearchExtractorChannelOnlyTest extends YoutubeSearchExtracto @Test public void testGetSecondPage() throws Exception { YoutubeSearchExtractor secondExtractor = (YoutubeSearchExtractor) YouTube.getSearchExtractor("pewdiepie", - asList(new String[]{"channel"}), null, "de"); + asList(YoutubeSearchQueryHandlerFactory.CHANNELS), null, "de"); ListExtractor.InfoItemsPage secondPage = secondExtractor.getPage(itemsPage.getNextPageUrl()); assertTrue(Integer.toString(secondPage.getItems().size()), secondPage.getItems().size() > 10); From 1eff8c5708c7bf1b4dbb0047d19aea0eba520626 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Thu, 19 Jul 2018 16:16:37 +0200 Subject: [PATCH 20/20] rename filter playlist to playlists --- .../soundcloud/SoundcloudSearchQueryHandlerFactory.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQueryHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQueryHandlerFactory.java index 2f7b45c6..8dbe287e 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQueryHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQueryHandlerFactory.java @@ -14,7 +14,7 @@ public class SoundcloudSearchQueryHandlerFactory extends SearchQueryHandlerFacto public static final String TRACKS = "tracks"; public static final String USERS = "users"; - public static final String PLAYLIST = "playlist"; + public static final String PLAYLISTS = "playlists"; public static final String ALL = "all"; public static final int ITEMS_PER_PAGE = 10; @@ -32,7 +32,7 @@ public class SoundcloudSearchQueryHandlerFactory extends SearchQueryHandlerFacto case USERS: url += "/users"; break; - case PLAYLIST: + case PLAYLISTS: url += "/playlists"; break; case ALL: @@ -61,6 +61,6 @@ public class SoundcloudSearchQueryHandlerFactory extends SearchQueryHandlerFacto ALL, TRACKS, USERS, - PLAYLIST}; + PLAYLISTS}; } }