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); } }