diff --git a/README.md b/README.md
index 9a5928b3..bf3cab89 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ To test changes quickly you can build the library locally. Using the local Maven
2. It's _recommended_ that you change the `version` of this library (e.g. `LOCAL_SNAPSHOT`).
3. Run gradle's `ìnstall` task to deploy this library to your local repository (using the wrapper, present in the root of this project: `./gradlew install`)
4. Change the dependency version used in your project to match the one you chose in step 2 (`implementation 'com.github.TeamNewPipe:NewPipeExtractor:LOCAL_SNAPSHOT'`)
-
+
> Tip for Android Studio users: After you make changes and run the `install` task, use the menu option `File → "Sync with File System"` to refresh the library in your project.
## Supported sites
diff --git a/build.gradle b/build.gradle
index 3d8ced48..97759443 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,7 +5,7 @@ allprojects {
sourceCompatibility = 1.7
targetCompatibility = 1.7
- version 'v0.18.0'
+ version 'v0.18.6'
group 'com.github.TeamNewPipe'
repositories {
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 b6e90d53..df1c2261 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java
@@ -1,10 +1,5 @@
package org.schabi.newpipe.extractor;
-import java.io.IOException;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
@@ -13,7 +8,11 @@ import org.schabi.newpipe.extractor.localization.ContentCountry;
import org.schabi.newpipe.extractor.localization.Localization;
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
-public abstract class Extractor{
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.io.IOException;
+
+public abstract class Extractor {
/**
* {@link StreamingService} currently related to this extractor.
* Useful for getting other things from a service (like the url handlers for cleaning/accepting/get id from urls).
@@ -21,19 +20,21 @@ public abstract class Extractor{
private final StreamingService service;
private final LinkHandler linkHandler;
- @Nullable private Localization forcedLocalization = null;
- @Nullable private ContentCountry forcedContentCountry = null;
+ @Nullable
+ private Localization forcedLocalization = null;
+ @Nullable
+ private ContentCountry forcedContentCountry = null;
private boolean pageFetched = false;
private final Downloader downloader;
public Extractor(final StreamingService service, final LinkHandler linkHandler) {
- if(service == null) throw new NullPointerException("service is null");
- if(linkHandler == null) throw new NullPointerException("LinkHandler is null");
+ if (service == null) throw new NullPointerException("service is null");
+ if (linkHandler == null) throw new NullPointerException("LinkHandler is null");
this.service = service;
this.linkHandler = linkHandler;
this.downloader = NewPipe.getDownloader();
- if(downloader == null) throw new NullPointerException("downloader is null");
+ if (downloader == null) throw new NullPointerException("downloader is null");
}
/**
@@ -46,11 +47,12 @@ public abstract class Extractor{
/**
* Fetch the current page.
- * @throws IOException if the page can not be loaded
+ *
+ * @throws IOException if the page can not be loaded
* @throws ExtractionException if the pages content is not understood
*/
public void fetchPage() throws IOException, ExtractionException {
- if(pageFetched) return;
+ if (pageFetched) return;
onFetchPage(downloader);
pageFetched = true;
}
@@ -65,8 +67,9 @@ public abstract class Extractor{
/**
* Fetch the current page.
+ *
* @param downloader the download to use
- * @throws IOException if the page can not be loaded
+ * @throws IOException if the page can not be loaded
* @throws ExtractionException if the pages content is not understood
*/
public abstract void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException;
@@ -78,6 +81,7 @@ public abstract class Extractor{
/**
* Get the name
+ *
* @return the name
* @throws ParsingException if the name cannot be extracted
*/
@@ -93,10 +97,10 @@ public abstract class Extractor{
public String getUrl() throws ParsingException {
return linkHandler.getUrl();
}
-
+
@Nonnull
public String getBaseUrl() throws ParsingException {
- return linkHandler.getBaseUrl();
+ return linkHandler.getBaseUrl();
}
@Nonnull
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/InfoItemsCollector.java b/extractor/src/main/java/org/schabi/newpipe/extractor/InfoItemsCollector.java
index 2a3cb5f3..72eca16e 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/InfoItemsCollector.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/InfoItemsCollector.java
@@ -27,7 +27,7 @@ import java.util.List;
* along with NewPipe. If not, see .
*/
-public abstract class InfoItemsCollector implements Collector {
+public abstract class InfoItemsCollector implements Collector {
private final List itemList = new ArrayList<>();
private final List errors = new ArrayList<>();
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/MediaFormat.java b/extractor/src/main/java/org/schabi/newpipe/extractor/MediaFormat.java
index c65283a5..6936568a 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/MediaFormat.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/MediaFormat.java
@@ -115,26 +115,28 @@ public enum MediaFormat {
}
/**
- * Get the media format by it's id.
+ * Get the media format by its id.
+ *
* @param id the id
* @return the id of the media format or null.
*/
public static MediaFormat getFormatById(int id) {
- for (MediaFormat vf: values()) {
+ for (MediaFormat vf : values()) {
if (vf.id == id) return vf;
}
return null;
}
public static MediaFormat getFromSuffix(String suffix) {
- for (MediaFormat vf: values()) {
+ for (MediaFormat vf : values()) {
if (vf.suffix.equals(suffix)) return vf;
}
return null;
}
-
+
/**
* Get the name of the format
+ *
* @return the name of the format
*/
public String getName() {
@@ -143,6 +145,7 @@ public enum MediaFormat {
/**
* Get the filename extension
+ *
* @return the filename extension
*/
public String getSuffix() {
@@ -151,10 +154,11 @@ public enum MediaFormat {
/**
* Get the mime type
+ *
* @return the mime type
*/
public String getMimeType() {
return mimeType;
}
-
+
}
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 742d342d..d91083bf 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/ServiceList.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/ServiceList.java
@@ -1,15 +1,15 @@
package org.schabi.newpipe.extractor;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
import org.schabi.newpipe.extractor.services.bandcamp.BandcampService;
import org.schabi.newpipe.extractor.services.media_ccc.MediaCCCService;
import org.schabi.newpipe.extractor.services.peertube.PeertubeService;
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudService;
import org.schabi.newpipe.extractor.services.youtube.YoutubeService;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
/*
* Copyright (C) Christian Schabesberger 2018
* ServiceList.java is part of NewPipe.
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 68398506..e21b17f3 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java
@@ -1,20 +1,12 @@
package org.schabi.newpipe.extractor;
-import java.util.Collections;
-import java.util.List;
-
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.comments.CommentsExtractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.feed.FeedExtractor;
import org.schabi.newpipe.extractor.kiosk.KioskList;
-import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
-import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
-import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
-import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
-import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
-import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory;
+import org.schabi.newpipe.extractor.linkhandler.*;
import org.schabi.newpipe.extractor.localization.ContentCountry;
import org.schabi.newpipe.extractor.localization.Localization;
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
@@ -26,6 +18,8 @@ import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
import javax.annotation.Nullable;
+import java.util.Collections;
+import java.util.List;
/*
* Copyright (C) Christian Schabesberger 2018
@@ -269,7 +263,7 @@ public abstract class StreamingService {
public CommentsExtractor getCommentsExtractor(String url) throws ExtractionException {
ListLinkHandlerFactory llhf = getCommentsLHFactory();
- if(null == llhf) {
+ if (llhf == null) {
return null;
}
return getCommentsExtractor(llhf.fromUrl(url));
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfoItemsCollector.java b/extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfoItemsCollector.java
index a60636b2..19abb1c2 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfoItemsCollector.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfoItemsCollector.java
@@ -33,7 +33,7 @@ public class ChannelInfoItemsCollector extends InfoItemsCollector{
+import java.io.IOException;
- private CommentsInfo(int serviceId, ListLinkHandler listUrlIdHandler, String name) {
- super(serviceId, listUrlIdHandler, name);
- // TODO Auto-generated constructor stub
- }
-
- public static CommentsInfo getInfo(String url) throws IOException, ExtractionException {
+public class CommentsInfo extends ListInfo {
+
+ private CommentsInfo(int serviceId, ListLinkHandler listUrlIdHandler, String name) {
+ super(serviceId, listUrlIdHandler, name);
+ }
+
+ public static CommentsInfo getInfo(String url) throws IOException, ExtractionException {
return getInfo(NewPipe.getServiceByUrl(url), url);
}
- public static CommentsInfo getInfo(StreamingService serviceByUrl, String url) throws ExtractionException, IOException {
- return getInfo(serviceByUrl.getCommentsExtractor(url));
- }
+ public static CommentsInfo getInfo(StreamingService serviceByUrl, String url) throws ExtractionException, IOException {
+ return getInfo(serviceByUrl.getCommentsExtractor(url));
+ }
private static CommentsInfo getInfo(CommentsExtractor commentsExtractor) throws IOException, ExtractionException {
// for services which do not have a comments extractor
@@ -44,21 +43,21 @@ public class CommentsInfo extends ListInfo{
return commentsInfo;
}
-
+
public static InfoItemsPage getMoreItems(CommentsInfo commentsInfo, String pageUrl)
throws ExtractionException, IOException {
return getMoreItems(NewPipe.getService(commentsInfo.getServiceId()), commentsInfo, pageUrl);
}
-
+
public static InfoItemsPage getMoreItems(StreamingService service, CommentsInfo commentsInfo,
- String pageUrl) throws IOException, ExtractionException {
+ String pageUrl) throws IOException, ExtractionException {
if (null == commentsInfo.getCommentsExtractor()) {
commentsInfo.setCommentsExtractor(service.getCommentsExtractor(commentsInfo.getUrl()));
commentsInfo.getCommentsExtractor().fetchPage();
}
return commentsInfo.getCommentsExtractor().getPage(pageUrl);
}
-
+
private transient CommentsExtractor commentsExtractor;
public CommentsExtractor getCommentsExtractor() {
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/downloader/Response.java b/extractor/src/main/java/org/schabi/newpipe/extractor/downloader/Response.java
index 59c3911c..b252d463 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/downloader/Response.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/downloader/Response.java
@@ -15,12 +15,16 @@ public class Response {
private final Map> responseHeaders;
private final String responseBody;
- public Response(int responseCode, String responseMessage, Map> responseHeaders, @Nullable String responseBody) {
+ private final String latestUrl;
+
+ public Response(int responseCode, String responseMessage, Map> responseHeaders,
+ @Nullable String responseBody, @Nullable String latestUrl) {
this.responseCode = responseCode;
this.responseMessage = responseMessage;
this.responseHeaders = responseHeaders != null ? responseHeaders : Collections.>emptyMap();
this.responseBody = responseBody == null ? "" : responseBody;
+ this.latestUrl = latestUrl;
}
public int responseCode() {
@@ -40,6 +44,16 @@ public class Response {
return responseBody;
}
+ /**
+ * Used for detecting a possible redirection, limited to the latest one.
+ *
+ * @return latest url known right before this response object was created
+ */
+ @Nonnull
+ public String latestUrl() {
+ return latestUrl;
+ }
+
/*//////////////////////////////////////////////////////////////////////////
// Utils
//////////////////////////////////////////////////////////////////////////*/
@@ -54,7 +68,8 @@ public class Response {
@Nullable
public String getHeader(String name) {
for (Map.Entry> headerEntry : responseHeaders.entrySet()) {
- if (headerEntry.getKey().equalsIgnoreCase(name)) {
+ final String key = headerEntry.getKey();
+ if (key != null && key.equalsIgnoreCase(name)) {
if (headerEntry.getValue().size() > 0) {
return headerEntry.getValue().get(0);
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java
index 7aef494d..44890524 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java
@@ -25,7 +25,6 @@ import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
-import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import javax.annotation.Nonnull;
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java b/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java
index 5a3be079..878fa8ce 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java
@@ -13,27 +13,30 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-public class KioskList {
+public class KioskList {
public interface KioskExtractorFactory {
KioskExtractor createNewKiosk(final StreamingService streamingService,
final String url,
final String kioskId)
- throws ExtractionException, IOException;
+ throws ExtractionException, IOException;
}
private final StreamingService service;
private final HashMap kioskList = new HashMap<>();
private String defaultKiosk = null;
- @Nullable private Localization forcedLocalization;
- @Nullable private ContentCountry forcedContentCountry;
+ @Nullable
+ private Localization forcedLocalization;
+ @Nullable
+ private ContentCountry forcedContentCountry;
private class KioskEntry {
public KioskEntry(KioskExtractorFactory ef, ListLinkHandlerFactory h) {
extractorFactory = ef;
handlerFactory = h;
}
+
final KioskExtractorFactory extractorFactory;
final ListLinkHandlerFactory handlerFactory;
}
@@ -43,8 +46,8 @@ public class KioskList {
}
public void addKioskEntry(KioskExtractorFactory extractorFactory, ListLinkHandlerFactory handlerFactory, String id)
- throws Exception {
- if(kioskList.get(id) != null) {
+ throws Exception {
+ if (kioskList.get(id) != null) {
throw new Exception("Kiosk with type " + id + " already exists.");
}
kioskList.put(id, new KioskEntry(extractorFactory, handlerFactory));
@@ -66,10 +69,10 @@ public class KioskList {
public KioskExtractor getDefaultKioskExtractor(String nextPageUrl, Localization localization)
throws ExtractionException, IOException {
- if(defaultKiosk != null && !defaultKiosk.equals("")) {
+ if (defaultKiosk != null && !defaultKiosk.equals("")) {
return getExtractorById(defaultKiosk, nextPageUrl, localization);
} else {
- if(!kioskList.isEmpty()) {
+ if (!kioskList.isEmpty()) {
// if not set get any entry
Object[] keySet = kioskList.keySet().toArray();
return getExtractorById(keySet[0].toString(), nextPageUrl, localization);
@@ -91,7 +94,7 @@ public class KioskList {
public KioskExtractor getExtractorById(String kioskId, String nextPageUrl, Localization localization)
throws ExtractionException, IOException {
KioskEntry ke = kioskList.get(kioskId);
- if(ke == null) {
+ if (ke == null) {
throw new ExtractionException("No kiosk found with the type: " + kioskId);
} else {
final KioskExtractor kioskExtractor = ke.extractorFactory.createNewKiosk(service,
@@ -109,15 +112,15 @@ public class KioskList {
}
public KioskExtractor getExtractorByUrl(String url, String nextPageUrl)
- throws ExtractionException, IOException{
+ throws ExtractionException, IOException {
return getExtractorByUrl(url, nextPageUrl, NewPipe.getPreferredLocalization());
}
public KioskExtractor getExtractorByUrl(String url, String nextPageUrl, Localization localization)
throws ExtractionException, IOException {
- for(Map.Entry e : kioskList.entrySet()) {
+ for (Map.Entry e : kioskList.entrySet()) {
KioskEntry ke = e.getValue();
- if(ke.handlerFactory.acceptUrl(url)) {
+ if (ke.handlerFactory.acceptUrl(url)) {
return getExtractorById(ke.handlerFactory.getId(url), nextPageUrl, localization);
}
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/LinkHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/LinkHandler.java
index 52510513..b7439c39 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/LinkHandler.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/LinkHandler.java
@@ -1,10 +1,10 @@
package org.schabi.newpipe.extractor.linkhandler;
-import java.io.Serializable;
-
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.utils.Utils;
+import java.io.Serializable;
+
public class LinkHandler implements Serializable {
protected final String originalUrl;
protected final String url;
@@ -31,8 +31,8 @@ public class LinkHandler implements Serializable {
public String getId() {
return id;
}
-
+
public String getBaseUrl() throws ParsingException {
- return Utils.getBaseUrl(url);
+ return Utils.getBaseUrl(url);
}
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/LinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/LinkHandlerFactory.java
index 3890c2b2..6bba7b4e 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/LinkHandlerFactory.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/LinkHandlerFactory.java
@@ -35,9 +35,9 @@ public abstract class LinkHandlerFactory {
public abstract boolean onAcceptUrl(final String url) throws ParsingException;
public String getUrl(String id, String baseUrl) throws ParsingException {
- return getUrl(id);
+ return getUrl(id);
}
-
+
///////////////////////////////////
// Logic
///////////////////////////////////
@@ -47,7 +47,7 @@ public abstract class LinkHandlerFactory {
final String baseUrl = Utils.getBaseUrl(url);
return fromUrl(url, baseUrl);
}
-
+
public LinkHandler fromUrl(String url, String baseUrl) throws ParsingException {
if (url == null) throw new IllegalArgumentException("url can not be null");
if (!acceptUrl(url)) {
@@ -55,9 +55,9 @@ public abstract class LinkHandlerFactory {
}
final String id = getId(url);
- return new LinkHandler(url, getUrl(id,baseUrl), id);
+ return new LinkHandler(url, getUrl(id, baseUrl), id);
}
-
+
public LinkHandler fromId(String id) throws ParsingException {
if (id == null) throw new IllegalArgumentException("id can not be null");
final String url = getUrl(id);
@@ -82,5 +82,5 @@ public abstract class LinkHandlerFactory {
throw fe;
}
}
-
+
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/ListLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/ListLinkHandlerFactory.java
index 83955265..9ea478b0 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/ListLinkHandlerFactory.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/ListLinkHandlerFactory.java
@@ -1,29 +1,35 @@
package org.schabi.newpipe.extractor.linkhandler;
-import java.util.ArrayList;
-import java.util.List;
-
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.utils.Utils;
+import java.util.ArrayList;
+import java.util.List;
+
public abstract class ListLinkHandlerFactory extends LinkHandlerFactory {
///////////////////////////////////
// To Override
///////////////////////////////////
- public List getContentFilter(String url) throws ParsingException { return new ArrayList<>(0);}
- public String getSortFilter(String url) throws ParsingException {return ""; }
+ public List getContentFilter(String url) throws ParsingException {
+ return new ArrayList<>(0);
+ }
+
+ public String getSortFilter(String url) throws ParsingException {
+ return "";
+ }
+
public abstract String getUrl(String id, List contentFilter, String sortFilter) throws ParsingException;
-
+
public String getUrl(String id, List contentFilter, String sortFilter, String baseUrl) throws ParsingException {
- return getUrl(id, contentFilter, sortFilter);
+ return getUrl(id, contentFilter, sortFilter);
}
///////////////////////////////////
// Logic
///////////////////////////////////
-
+
@Override
public ListLinkHandler fromUrl(String url) throws ParsingException {
String baseUrl = Utils.getBaseUrl(url);
@@ -32,7 +38,7 @@ public abstract class ListLinkHandlerFactory extends LinkHandlerFactory {
@Override
public ListLinkHandler fromUrl(String url, String baseUrl) throws ParsingException {
- if(url == null) throw new IllegalArgumentException("url may not be null");
+ if (url == null) throw new IllegalArgumentException("url may not be null");
return new ListLinkHandler(super.fromUrl(url, baseUrl), getContentFilter(url), getSortFilter(url));
}
@@ -41,7 +47,7 @@ public abstract class ListLinkHandlerFactory extends LinkHandlerFactory {
public ListLinkHandler fromId(String id) throws ParsingException {
return new ListLinkHandler(super.fromId(id), new ArrayList(0), "");
}
-
+
@Override
public ListLinkHandler fromId(String id, String baseUrl) throws ParsingException {
return new ListLinkHandler(super.fromId(id, baseUrl), new ArrayList(0), "");
@@ -53,7 +59,7 @@ public abstract class ListLinkHandlerFactory extends LinkHandlerFactory {
final String url = getUrl(id, contentFilters, sortFilter);
return new ListLinkHandler(url, url, id, contentFilters, sortFilter);
}
-
+
public ListLinkHandler fromQuery(String id,
List contentFilters,
String sortFilter, String baseUrl) throws ParsingException {
@@ -61,10 +67,11 @@ public abstract class ListLinkHandlerFactory extends LinkHandlerFactory {
return new ListLinkHandler(url, url, id, contentFilters, sortFilter);
}
-
+
/**
- * For makeing ListLinkHandlerFactory compatible with LinkHandlerFactory we need to override this,
+ * For making ListLinkHandlerFactory compatible with LinkHandlerFactory we need to override this,
* however it should not be overridden by the actual implementation.
+ *
* @param id
* @return the url coresponding to id without any filters applied
*/
@@ -76,7 +83,7 @@ public abstract class ListLinkHandlerFactory extends LinkHandlerFactory {
public String getUrl(String id, String baseUrl) throws ParsingException {
return getUrl(id, new ArrayList(0), "", baseUrl);
}
-
+
/**
* Will returns content filter the corresponding extractor can handle like "channels", "videos", "music", etc.
*
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/SearchQueryHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/SearchQueryHandler.java
index 6c1893c7..67dd7e49 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/SearchQueryHandler.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/SearchQueryHandler.java
@@ -24,6 +24,7 @@ public class SearchQueryHandler extends ListLinkHandler {
/**
* Returns the search string. Since ListQIHandler is based on ListLinkHandler
* getSearchString() is equivalent to calling getId().
+ *
* @return the search string
*/
public String getSearchString() {
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/SearchQueryHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/SearchQueryHandlerFactory.java
index 997e2d09..50977e20 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/SearchQueryHandlerFactory.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/SearchQueryHandlerFactory.java
@@ -13,14 +13,19 @@ public abstract class SearchQueryHandlerFactory extends ListLinkHandlerFactory {
@Override
public abstract String getUrl(String querry, List contentFilter, String sortFilter) throws ParsingException;
- public String getSearchString(String url) { return "";}
+
+ public String getSearchString(String url) {
+ return "";
+ }
///////////////////////////////////
// Logic
///////////////////////////////////
@Override
- public String getId(String url) { return getSearchString(url); }
+ public String getId(String url) {
+ return getSearchString(url);
+ }
@Override
public SearchQueryHandler fromQuery(String querry,
@@ -34,10 +39,13 @@ public abstract class SearchQueryHandlerFactory extends ListLinkHandlerFactory {
}
/**
- * It's not mandatorry for NewPipe to handle the Url
+ * It's not mandatory for NewPipe to handle the Url
+ *
* @param url
* @return
*/
@Override
- public boolean onAcceptUrl(String url) { return false; }
+ public boolean onAcceptUrl(String url) {
+ return false;
+ }
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/localization/Localization.java b/extractor/src/main/java/org/schabi/newpipe/extractor/localization/Localization.java
index 7461462a..02b89087 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/localization/Localization.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/localization/Localization.java
@@ -3,7 +3,10 @@ package org.schabi.newpipe.extractor.localization;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.Serializable;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
public class Localization implements Serializable {
public static final Localization DEFAULT = new Localization("en", "GB");
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/localization/TimeAgoParser.java b/extractor/src/main/java/org/schabi/newpipe/extractor/localization/TimeAgoParser.java
index aae9b14c..fe20135f 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/localization/TimeAgoParser.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/localization/TimeAgoParser.java
@@ -21,8 +21,9 @@ public class TimeAgoParser {
/**
* Creates a helper to parse upload dates in the format '2 days ago'.
*
- * Instantiate a new {@link TimeAgoParser} every time you extract a new batch of items.
+ * Instantiate a new {@link TimeAgoParser} every time you extract a new batch of items.
*
+ *
* @param patternsHolder An object that holds the "time ago" patterns, special cases, and the language word separator.
*/
public TimeAgoParser(PatternsHolder patternsHolder) {
@@ -164,6 +165,7 @@ public class TimeAgoParser {
/**
* Marks the time as approximated by setting minutes, seconds and milliseconds to 0.
+ *
* @param calendarTime Time to be marked as approximated
*/
private void markApproximatedTime(Calendar calendarTime) {
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 bad31ea2..206fb68f 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
@@ -5,7 +5,6 @@ import org.schabi.newpipe.extractor.InfoItemExtractor;
import org.schabi.newpipe.extractor.InfoItemsCollector;
import org.schabi.newpipe.extractor.channel.ChannelInfoItemExtractor;
import org.schabi.newpipe.extractor.channel.ChannelInfoItemsCollector;
-import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor;
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemsCollector;
@@ -34,7 +33,7 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
/**
* Collector for search results
- *
+ *
* This collector can handle the following extractor types:
*
*
{@link StreamInfoItemExtractor}
@@ -59,11 +58,11 @@ public class InfoItemsSearchCollector extends InfoItemsCollector getInitialPage() throws IOException, ExtractionException {
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
JsonArray events = conferenceData.getArray("events");
- for(int i = 0; i < events.size(); i++) {
+ for (int i = 0; i < events.size(); i++) {
collector.commit(new MediaCCCStreamInfoItemExtractor(events.getObject(i)));
}
return new InfoItemsPage<>(collector, null);
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCConferenceKiosk.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCConferenceKiosk.java
index 580f79b0..f9800b46 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCConferenceKiosk.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCConferenceKiosk.java
@@ -32,7 +32,7 @@ public class MediaCCCConferenceKiosk extends KioskExtractor {
public InfoItemsPage getInitialPage() throws IOException, ExtractionException {
JsonArray conferences = doc.getArray("conferences");
ChannelInfoItemsCollector collector = new ChannelInfoItemsCollector(getServiceId());
- for(int i = 0; i < conferences.size(); i++) {
+ for (int i = 0; i < conferences.size(); i++) {
collector.commit(new MediaCCCConferenceInfoItemExtractor(conferences.getObject(i)));
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCSearchExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCSearchExtractor.java
index 429445f2..6d740337 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCSearchExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCSearchExtractor.java
@@ -50,7 +50,7 @@ public class MediaCCCSearchExtractor extends SearchExtractor {
InfoItemsSearchCollector searchItems = getInfoItemSearchCollector();
searchItems.reset();
- if(getLinkHandler().getContentFilters().contains(CONFERENCES)
+ if (getLinkHandler().getContentFilters().contains(CONFERENCES)
|| getLinkHandler().getContentFilters().contains(ALL)
|| getLinkHandler().getContentFilters().isEmpty()) {
searchConferences(getSearchString(),
@@ -58,7 +58,7 @@ public class MediaCCCSearchExtractor extends SearchExtractor {
searchItems);
}
- if(getLinkHandler().getContentFilters().contains(EVENTS)
+ if (getLinkHandler().getContentFilters().contains(EVENTS)
|| getLinkHandler().getContentFilters().contains(ALL)
|| getLinkHandler().getContentFilters().isEmpty()) {
JsonArray events = doc.getArray("events");
@@ -82,8 +82,8 @@ public class MediaCCCSearchExtractor extends SearchExtractor {
@Override
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
- if(getLinkHandler().getContentFilters().contains(EVENTS)
- || getLinkHandler().getContentFilters().contains(ALL)
+ if (getLinkHandler().getContentFilters().contains(EVENTS)
+ || getLinkHandler().getContentFilters().contains(ALL)
|| getLinkHandler().getContentFilters().isEmpty()) {
final String site;
final String url = getUrl();
@@ -94,17 +94,17 @@ public class MediaCCCSearchExtractor extends SearchExtractor {
throw new ExtractionException("Could not parse json.", jpe);
}
}
- if(getLinkHandler().getContentFilters().contains(CONFERENCES)
+ if (getLinkHandler().getContentFilters().contains(CONFERENCES)
|| getLinkHandler().getContentFilters().contains(ALL)
|| getLinkHandler().getContentFilters().isEmpty())
- conferenceKiosk.fetchPage();
+ conferenceKiosk.fetchPage();
}
private void searchConferences(String searchString,
- List channelItems,
- InfoItemsSearchCollector collector) {
- for(final ChannelInfoItem item : channelItems) {
- if(item.getName().toUpperCase().contains(
+ List channelItems,
+ InfoItemsSearchCollector collector) {
+ for (final ChannelInfoItem item : channelItems) {
+ if (item.getName().toUpperCase().contains(
searchString.toUpperCase())) {
collector.commit(new ChannelInfoItemExtractor() {
@Override
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java
index a1dfd245..59bfe1f4 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java
@@ -16,7 +16,9 @@ import org.schabi.newpipe.extractor.stream.*;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
+import java.util.Locale;
public class MediaCCCStreamExtractor extends StreamExtractor {
@@ -47,8 +49,8 @@ public class MediaCCCStreamExtractor extends StreamExtractor {
@Nonnull
@Override
- public String getDescription() throws ParsingException {
- return data.getString("description");
+ public Description getDescription() throws ParsingException {
+ return new Description(data.getString("description"), Description.PLAIN_TEXT);
}
@Override
@@ -103,30 +105,30 @@ public class MediaCCCStreamExtractor extends StreamExtractor {
@Nonnull
@Override
public String getDashMpdUrl() throws ParsingException {
- return null;
+ return "";
}
@Nonnull
@Override
public String getHlsUrl() throws ParsingException {
- return null;
+ return "";
}
@Override
public List getAudioStreams() throws IOException, ExtractionException {
final JsonArray recordings = data.getArray("recordings");
final List audioStreams = new ArrayList<>();
- for(int i = 0; i < recordings.size(); i++) {
+ for (int i = 0; i < recordings.size(); i++) {
final JsonObject recording = recordings.getObject(i);
final String mimeType = recording.getString("mime_type");
- if(mimeType.startsWith("audio")) {
+ if (mimeType.startsWith("audio")) {
//first we need to resolve the actual video data from CDN
final MediaFormat mediaFormat;
- if(mimeType.endsWith("opus")) {
+ if (mimeType.endsWith("opus")) {
mediaFormat = MediaFormat.OPUS;
- } else if(mimeType.endsWith("mpeg")) {
+ } else if (mimeType.endsWith("mpeg")) {
mediaFormat = MediaFormat.MP3;
- } else if(mimeType.endsWith("ogg")){
+ } else if (mimeType.endsWith("ogg")) {
mediaFormat = MediaFormat.OGG;
} else {
throw new ExtractionException("Unknown media format: " + mimeType);
@@ -142,16 +144,16 @@ public class MediaCCCStreamExtractor extends StreamExtractor {
public List getVideoStreams() throws IOException, ExtractionException {
final JsonArray recordings = data.getArray("recordings");
final List videoStreams = new ArrayList<>();
- for(int i = 0; i < recordings.size(); i++) {
+ for (int i = 0; i < recordings.size(); i++) {
final JsonObject recording = recordings.getObject(i);
final String mimeType = recording.getString("mime_type");
- if(mimeType.startsWith("video")) {
+ if (mimeType.startsWith("video")) {
//first we need to resolve the actual video data from CDN
final MediaFormat mediaFormat;
- if(mimeType.endsWith("webm")) {
+ if (mimeType.endsWith("webm")) {
mediaFormat = MediaFormat.WEBM;
- } else if(mimeType.endsWith("mp4")) {
+ } else if (mimeType.endsWith("mp4")) {
mediaFormat = MediaFormat.MPEG_4;
} else {
throw new ExtractionException("Unknown media format: " + mimeType);
@@ -172,13 +174,13 @@ public class MediaCCCStreamExtractor extends StreamExtractor {
@Nonnull
@Override
public List getSubtitlesDefault() throws IOException, ExtractionException {
- return null;
+ return Collections.emptyList();
}
@Nonnull
@Override
- public List getSubtitles(MediaFormat format) throws IOException, ExtractionException {
- return null;
+ public List getSubtitles(final MediaFormat format) throws IOException, ExtractionException {
+ return Collections.emptyList();
}
@Override
@@ -211,7 +213,6 @@ public class MediaCCCStreamExtractor extends StreamExtractor {
} catch (JsonParserException jpe) {
throw new ExtractionException("Could not parse json returned by url: " + getLinkHandler().getUrl(), jpe);
}
-
}
@Nonnull
@@ -225,4 +226,41 @@ public class MediaCCCStreamExtractor extends StreamExtractor {
public String getOriginalUrl() throws ParsingException {
return data.getString("frontend_link");
}
+
+ @Override
+ public String getHost() throws ParsingException {
+ return "";
+ }
+
+ @Override
+ public String getPrivacy() throws ParsingException {
+ return "";
+ }
+
+ @Override
+ public String getCategory() throws ParsingException {
+ return "";
+ }
+
+ @Override
+ public String getLicence() throws ParsingException {
+ return "";
+ }
+
+ @Override
+ public Locale getLanguageInfo() throws ParsingException {
+ return null;
+ }
+
+ @Nonnull
+ @Override
+ public List getTags() throws ParsingException {
+ return new ArrayList<>();
+ }
+
+ @Nonnull
+ @Override
+ public String getSupportInfo() throws ParsingException {
+ return "";
+ }
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCConferenceLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCConferenceLinkHandlerFactory.java
index b1207a9a..f4074c0d 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCConferenceLinkHandlerFactory.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCConferenceLinkHandlerFactory.java
@@ -15,18 +15,23 @@ public class MediaCCCConferenceLinkHandlerFactory extends ListLinkHandlerFactory
@Override
public String getId(String url) throws ParsingException {
- if(url.startsWith("https://api.media.ccc.de/public/conferences/")) {
+ if (url.startsWith("https://api.media.ccc.de/public/conferences/")) {
return url.replace("https://api.media.ccc.de/public/conferences/", "");
- } else if(url.startsWith("https://media.ccc.de/c/")) {
+ } else if (url.startsWith("https://media.ccc.de/c/")) {
return Parser.matchGroup1("https://media.ccc.de/c/([^?#]*)", url);
- } else {
- throw new ParsingException("Could not get id from url: " + url);
+ } else if (url.startsWith("https://media.ccc.de/b/")) {
+ return Parser.matchGroup1("https://media.ccc.de/b/([^?#]*)", url);
}
+ throw new ParsingException("Could not get id from url: " + url);
}
@Override
public boolean onAcceptUrl(String url) throws ParsingException {
- return url.startsWith("https://api.media.ccc.de/public/conferences/")
- || url.startsWith("https://media.ccc.de/c/");
+ try {
+ getId(url);
+ return true;
+ } catch (ParsingException e) {
+ return false;
+ }
}
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCConferencesListLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCConferencesListLinkHandlerFactory.java
index 603f1ea2..d44dc538 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCConferencesListLinkHandlerFactory.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCConferencesListLinkHandlerFactory.java
@@ -1,7 +1,6 @@
package org.schabi.newpipe.extractor.services.media_ccc.linkHandler;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
-import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
import java.util.List;
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCSearchQueryHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCSearchQueryHandlerFactory.java
index fb6c705a..dcc0b29b 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCSearchQueryHandlerFactory.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCSearchQueryHandlerFactory.java
@@ -15,7 +15,7 @@ public class MediaCCCSearchQueryHandlerFactory extends SearchQueryHandlerFactory
@Override
public String[] getAvailableContentFilter() {
- return new String[] {
+ return new String[]{
ALL,
CONFERENCES,
EVENTS
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCStreamLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCStreamLinkHandlerFactory.java
index fc6bf39e..2c91d056 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCStreamLinkHandlerFactory.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCStreamLinkHandlerFactory.java
@@ -1,16 +1,39 @@
package org.schabi.newpipe.extractor.services.media_ccc.linkHandler;
+import org.schabi.newpipe.extractor.exceptions.FoundAdException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
+import org.schabi.newpipe.extractor.utils.Utils;
+
+import java.net.MalformedURLException;
+import java.net.URL;
public class MediaCCCStreamLinkHandlerFactory extends LinkHandlerFactory {
@Override
- public String getId(String url) throws ParsingException {
- if(url.startsWith("https://api.media.ccc.de/public/events/") &&
- !url.contains("?q=")) {
- return url.replace("https://api.media.ccc.de/public/events/", "");
+ public String getId(String urlString) throws ParsingException {
+ if (urlString.startsWith("https://api.media.ccc.de/public/events/") &&
+ !urlString.contains("?q=")) {
+ return urlString.substring(39); //remove api…/public/events part
}
+
+ URL url;
+ try {
+ url = Utils.stringToURL(urlString);
+ } catch (MalformedURLException e) {
+ throw new IllegalArgumentException("The given URL is not valid");
+ }
+
+ String path = url.getPath();
+ // remove leading "/" of URL-path if URL-path is given
+ if (!path.isEmpty()) {
+ path = path.substring(1);
+ }
+
+ if (path.startsWith("v/")) {
+ return path.substring(2);
+ }
+
throw new ParsingException("Could not get id from url: " + url);
}
@@ -21,7 +44,11 @@ public class MediaCCCStreamLinkHandlerFactory extends LinkHandlerFactory {
@Override
public boolean onAcceptUrl(String url) throws ParsingException {
- return url.startsWith("https://api.media.ccc.de/public/events/") &&
- !url.contains("?q=");
+ try {
+ getId(url);
+ return true;
+ } catch (ParsingException e) {
+ return false;
+ }
}
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/PeertubeInstance.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/PeertubeInstance.java
index 992b8eb6..82b67539 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/PeertubeInstance.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/PeertubeInstance.java
@@ -1,7 +1,8 @@
package org.schabi.newpipe.extractor.services.peertube;
-import java.io.IOException;
-
+import com.grack.nanojson.JsonObject;
+import com.grack.nanojson.JsonParser;
+import com.grack.nanojson.JsonParserException;
import org.jsoup.helper.StringUtil;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.downloader.Downloader;
@@ -10,22 +11,20 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
import org.schabi.newpipe.extractor.utils.JsonUtils;
-import com.grack.nanojson.JsonObject;
-import com.grack.nanojson.JsonParser;
-import com.grack.nanojson.JsonParserException;
+import java.io.IOException;
public class PeertubeInstance {
-
+
private final String url;
private String name;
public static final PeertubeInstance defaultInstance = new PeertubeInstance("https://framatube.org", "FramaTube");
-
+
public PeertubeInstance(String url) {
this.url = url;
this.name = "PeerTube";
}
-
- public PeertubeInstance(String url , String name) {
+
+ public PeertubeInstance(String url, String name) {
this.url = url;
this.name = name;
}
@@ -33,22 +32,22 @@ public class PeertubeInstance {
public String getUrl() {
return url;
}
-
+
public void fetchInstanceMetaData() throws Exception {
Downloader downloader = NewPipe.getDownloader();
Response response = null;
-
+
try {
response = downloader.get(url + "/api/v1/config");
} catch (ReCaptchaException | IOException e) {
throw new Exception("unable to configure instance " + url, e);
}
-
- if(null == response || StringUtil.isBlank(response.responseBody())) {
+
+ if (response == null || StringUtil.isBlank(response.responseBody())) {
throw new Exception("unable to configure instance " + url);
}
-
- try {
+
+ try {
JsonObject json = JsonParser.object().from(response.responseBody());
this.name = JsonUtils.getString(json, "instance.name");
} catch (JsonParserException | ParsingException e) {
@@ -59,5 +58,5 @@ public class PeertubeInstance {
public String getName() {
return name;
}
-
+
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/PeertubeParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/PeertubeParsingHelper.java
index f518faf9..7821aa29 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/PeertubeParsingHelper.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/PeertubeParsingHelper.java
@@ -1,32 +1,34 @@
package org.schabi.newpipe.extractor.services.peertube;
+import com.grack.nanojson.JsonObject;
+import org.jsoup.helper.StringUtil;
+import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
+import org.schabi.newpipe.extractor.exceptions.ParsingException;
+
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
-
-import org.jsoup.helper.StringUtil;
-import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
-import org.schabi.newpipe.extractor.exceptions.ParsingException;
-
-import com.grack.nanojson.JsonObject;
+import java.util.TimeZone;
public class PeertubeParsingHelper {
-
+
private PeertubeParsingHelper() {
}
public static void validate(JsonObject json) throws ContentNotAvailableException {
String error = json.getString("error");
- if(!StringUtil.isBlank(error)) {
+ if (!StringUtil.isBlank(error)) {
throw new ContentNotAvailableException(error);
}
}
-
+
public static Calendar parseDateFrom(String textualUploadDate) throws ParsingException {
Date date;
try {
- date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'").parse(textualUploadDate);
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'");
+ sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
+ date = sdf.parse(textualUploadDate);
} catch (ParseException e) {
throw new ParsingException("Could not parse date: \"" + textualUploadDate + "\"", e);
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/PeertubeService.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/PeertubeService.java
index 47271732..29cc2b1d 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/PeertubeService.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/PeertubeService.java
@@ -1,49 +1,35 @@
package org.schabi.newpipe.extractor.services.peertube;
-import static java.util.Arrays.asList;
-import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.COMMENTS;
-import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.VIDEO;
-
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.comments.CommentsExtractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
import org.schabi.newpipe.extractor.kiosk.KioskList;
-import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
-import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
-import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
-import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
-import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
-import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory;
+import org.schabi.newpipe.extractor.linkhandler.*;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.search.SearchExtractor;
-import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeChannelExtractor;
-import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeCommentsExtractor;
-import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeSearchExtractor;
-import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeStreamExtractor;
-import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeSuggestionExtractor;
-import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeTrendingExtractor;
-import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeChannelLinkHandlerFactory;
-import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeCommentsLinkHandlerFactory;
-import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeSearchQueryHandlerFactory;
-import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeStreamLinkHandlerFactory;
-import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeTrendingLinkHandlerFactory;
+import org.schabi.newpipe.extractor.services.peertube.extractors.*;
+import org.schabi.newpipe.extractor.services.peertube.linkHandler.*;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
+import static java.util.Arrays.asList;
+import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.COMMENTS;
+import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.VIDEO;
+
public class PeertubeService extends StreamingService {
-
+
private PeertubeInstance instance;
-
+
public PeertubeService(int id) {
this(id, PeertubeInstance.defaultInstance);
}
-
+
public PeertubeService(int id, PeertubeInstance instance) {
super(id, "PeerTube", asList(VIDEO, COMMENTS));
- this.instance = instance;
+ this.instance = instance;
}
@Override
@@ -117,15 +103,15 @@ public class PeertubeService extends StreamingService {
public String getBaseUrl() {
return instance.getUrl();
}
-
+
public PeertubeInstance getInstance() {
return this.instance;
}
-
+
public void setInstance(PeertubeInstance instance) {
this.instance = instance;
}
-
+
@Override
public KioskList getKioskList() throws ExtractionException {
KioskList.KioskExtractorFactory kioskFactory = new KioskList.KioskExtractorFactory() {
@@ -155,6 +141,6 @@ public class PeertubeService extends StreamingService {
return list;
}
-
+
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeChannelExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeChannelExtractor.java
index 8b214670..d53fb7ad 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeChannelExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeChannelExtractor.java
@@ -1,7 +1,9 @@
package org.schabi.newpipe.extractor.services.peertube.extractors;
-import java.io.IOException;
-
+import com.grack.nanojson.JsonArray;
+import com.grack.nanojson.JsonObject;
+import com.grack.nanojson.JsonParser;
+import com.grack.nanojson.JsonParserException;
import org.jsoup.helper.StringUtil;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
@@ -17,21 +19,18 @@ import org.schabi.newpipe.extractor.utils.JsonUtils;
import org.schabi.newpipe.extractor.utils.Parser;
import org.schabi.newpipe.extractor.utils.Parser.RegexException;
-import com.grack.nanojson.JsonArray;
-import com.grack.nanojson.JsonObject;
-import com.grack.nanojson.JsonParser;
-import com.grack.nanojson.JsonParserException;
+import java.io.IOException;
public class PeertubeChannelExtractor extends ChannelExtractor {
-
+
private static final String START_KEY = "start";
private static final String COUNT_KEY = "count";
private static final int ITEMS_PER_PAGE = 12;
private static final String START_PATTERN = "start=(\\d*)";
-
+
private InfoItemsPage initPage;
private long total;
-
+
private JsonObject json;
private final String baseUrl;
@@ -45,7 +44,7 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
String value;
try {
value = JsonUtils.getString(json, "avatar.path");
- }catch(Exception e) {
+ } catch (Exception e) {
value = "/client/assets/images/default-avatar.png";
}
return baseUrl + value;
@@ -71,7 +70,7 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
public String getDescription() throws ParsingException {
try {
return JsonUtils.getString(json, "description");
- }catch(ParsingException e) {
+ } catch (ParsingException e) {
return "No description";
}
}
@@ -86,18 +85,18 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
JsonArray contents;
try {
contents = (JsonArray) JsonUtils.getValue(json, "data");
- }catch(Exception e) {
+ } catch (Exception e) {
throw new ParsingException("unable to extract channel streams", e);
}
-
- for(Object c: contents) {
- if(c instanceof JsonObject) {
+
+ for (Object c : contents) {
+ if (c instanceof JsonObject) {
final JsonObject item = (JsonObject) c;
PeertubeStreamInfoItemExtractor extractor = new PeertubeStreamInfoItemExtractor(item, baseUrl);
collector.commit(extractor);
}
}
-
+
}
@Override
@@ -110,26 +109,26 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
public InfoItemsPage getPage(String pageUrl) throws IOException, ExtractionException {
Response response = getDownloader().get(pageUrl);
JsonObject json = null;
- if(null != response && !StringUtil.isBlank(response.responseBody())) {
+ if (null != response && !StringUtil.isBlank(response.responseBody())) {
try {
json = JsonParser.object().from(response.responseBody());
} catch (Exception e) {
throw new ParsingException("Could not parse json data for kiosk info", e);
}
}
-
+
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
- if(json != null) {
+ if (json != null) {
PeertubeParsingHelper.validate(json);
Number number = JsonUtils.getNumber(json, "total");
- if(number != null) this.total = number.longValue();
+ if (number != null) this.total = number.longValue();
collectStreamsFrom(collector, json, pageUrl);
} else {
- throw new ExtractionException("Unable to get peertube kiosk info");
+ throw new ExtractionException("Unable to get PeerTube kiosk info");
}
return new InfoItemsPage<>(collector, getNextPageUrl(pageUrl));
}
-
+
private String getNextPageUrl(String prevPageUrl) {
String prevStart;
@@ -138,30 +137,30 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
} catch (RegexException e) {
return "";
}
- if(StringUtil.isBlank(prevStart)) return "";
+ if (StringUtil.isBlank(prevStart)) return "";
long nextStart = 0;
try {
nextStart = Long.valueOf(prevStart) + ITEMS_PER_PAGE;
} catch (NumberFormatException e) {
return "";
}
-
- if(nextStart >= total) {
+
+ if (nextStart >= total) {
return "";
- }else {
+ } else {
return prevPageUrl.replace(START_KEY + "=" + prevStart, START_KEY + "=" + String.valueOf(nextStart));
}
}
-
+
@Override
public void onFetchPage(Downloader downloader) throws IOException, ExtractionException {
Response response = downloader.get(getUrl());
- if(null != response && null != response.responseBody()) {
+ if (null != response && null != response.responseBody()) {
setInitialData(response.responseBody());
- }else {
- throw new ExtractionException("Unable to extract peertube channel data");
+ } else {
+ throw new ExtractionException("Unable to extract PeerTube channel data");
}
-
+
String pageUrl = getUrl() + "/videos?" + START_KEY + "=0&" + COUNT_KEY + "=" + ITEMS_PER_PAGE;
this.initPage = getPage(pageUrl);
}
@@ -172,14 +171,14 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
} catch (JsonParserException e) {
throw new ExtractionException("Unable to extract peertube channel data", e);
}
- if(null == json) throw new ExtractionException("Unable to extract peertube channel data");
+ if (json == null) throw new ExtractionException("Unable to extract PeerTube channel data");
}
@Override
public String getName() throws ParsingException {
return JsonUtils.getString(json, "displayName");
}
-
+
@Override
public String getOriginalUrl() throws ParsingException {
return baseUrl + "/accounts/" + getId();
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsExtractor.java
index b7aba4fa..34477459 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsExtractor.java
@@ -1,7 +1,8 @@
package org.schabi.newpipe.extractor.services.peertube.extractors;
-import java.io.IOException;
-
+import com.grack.nanojson.JsonArray;
+import com.grack.nanojson.JsonObject;
+import com.grack.nanojson.JsonParser;
import org.jsoup.helper.StringUtil;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.comments.CommentsExtractor;
@@ -16,9 +17,7 @@ import org.schabi.newpipe.extractor.utils.JsonUtils;
import org.schabi.newpipe.extractor.utils.Parser;
import org.schabi.newpipe.extractor.utils.Parser.RegexException;
-import com.grack.nanojson.JsonArray;
-import com.grack.nanojson.JsonObject;
-import com.grack.nanojson.JsonParser;
+import java.io.IOException;
public class PeertubeCommentsExtractor extends CommentsExtractor {
@@ -26,10 +25,10 @@ public class PeertubeCommentsExtractor extends CommentsExtractor {
private static final String COUNT_KEY = "count";
private static final int ITEMS_PER_PAGE = 12;
private static final String START_PATTERN = "start=(\\d*)";
-
+
private InfoItemsPage initPage;
private long total;
-
+
public PeertubeCommentsExtractor(StreamingService service, ListLinkHandler uiHandler) {
super(service, uiHandler);
}
@@ -38,7 +37,7 @@ public class PeertubeCommentsExtractor extends CommentsExtractor {
public String getName() throws ParsingException {
return "Comments";
}
-
+
@Override
public InfoItemsPage getInitialPage() throws IOException, ExtractionException {
super.fetchPage();
@@ -49,18 +48,18 @@ public class PeertubeCommentsExtractor extends CommentsExtractor {
JsonArray contents;
try {
contents = (JsonArray) JsonUtils.getValue(json, "data");
- }catch(Exception e) {
+ } catch (Exception e) {
throw new ParsingException("unable to extract comments info", e);
}
-
- for(Object c: contents) {
- if(c instanceof JsonObject) {
+
+ for (Object c : contents) {
+ if (c instanceof JsonObject) {
final JsonObject item = (JsonObject) c;
PeertubeCommentsInfoItemExtractor extractor = new PeertubeCommentsInfoItemExtractor(item, this);
collector.commit(extractor);
}
}
-
+
}
@Override
@@ -73,18 +72,18 @@ public class PeertubeCommentsExtractor extends CommentsExtractor {
public InfoItemsPage getPage(String pageUrl) throws IOException, ExtractionException {
Response response = getDownloader().get(pageUrl);
JsonObject json = null;
- if(null != response && !StringUtil.isBlank(response.responseBody())) {
+ if (null != response && !StringUtil.isBlank(response.responseBody())) {
try {
json = JsonParser.object().from(response.responseBody());
} catch (Exception e) {
throw new ParsingException("Could not parse json data for comments info", e);
}
}
-
+
CommentsInfoItemsCollector collector = new CommentsInfoItemsCollector(getServiceId());
- if(json != null) {
+ if (json != null) {
Number number = JsonUtils.getNumber(json, "total");
- if(number != null) this.total = number.longValue();
+ if (number != null) this.total = number.longValue();
collectStreamsFrom(collector, json, pageUrl);
} else {
throw new ExtractionException("Unable to get peertube comments info");
@@ -97,7 +96,7 @@ public class PeertubeCommentsExtractor extends CommentsExtractor {
String pageUrl = getUrl() + "?" + START_KEY + "=0&" + COUNT_KEY + "=" + ITEMS_PER_PAGE;
this.initPage = getPage(pageUrl);
}
-
+
private String getNextPageUrl(String prevPageUrl) {
String prevStart;
try {
@@ -105,17 +104,17 @@ public class PeertubeCommentsExtractor extends CommentsExtractor {
} catch (RegexException e) {
return "";
}
- if(StringUtil.isBlank(prevStart)) return "";
+ if (StringUtil.isBlank(prevStart)) return "";
long nextStart = 0;
try {
nextStart = Long.valueOf(prevStart) + ITEMS_PER_PAGE;
} catch (NumberFormatException e) {
return "";
}
-
- if(nextStart >= total) {
+
+ if (nextStart >= total) {
return "";
- }else {
+ } else {
return prevPageUrl.replace(START_KEY + "=" + prevStart, START_KEY + "=" + String.valueOf(nextStart));
}
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsInfoItemExtractor.java
index edb59e1f..b7cbcec7 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsInfoItemExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsInfoItemExtractor.java
@@ -1,5 +1,6 @@
package org.schabi.newpipe.extractor.services.peertube.extractors;
+import com.grack.nanojson.JsonObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.schabi.newpipe.extractor.ServiceList;
@@ -9,8 +10,6 @@ import org.schabi.newpipe.extractor.localization.DateWrapper;
import org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper;
import org.schabi.newpipe.extractor.utils.JsonUtils;
-import com.grack.nanojson.JsonObject;
-
public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtractor {
@@ -34,7 +33,7 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
String value;
try {
value = JsonUtils.getString(item, "account.avatar.path");
- }catch(Exception e) {
+ } catch (Exception e) {
value = "/client/assets/images/default-avatar.png";
}
return baseUrl + value;
@@ -49,13 +48,13 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
public String getTextualPublishedTime() throws ParsingException {
return JsonUtils.getString(item, "createdAt");
}
-
+
@Override
public DateWrapper getPublishedTime() throws ParsingException {
String textualUploadDate = getTextualPublishedTime();
return new DateWrapper(PeertubeParsingHelper.parseDateFrom(textualUploadDate));
}
-
+
@Override
public int getLikeCount() throws ParsingException {
return -1;
@@ -67,7 +66,7 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
try {
Document doc = Jsoup.parse(htmlText);
return doc.body().text();
- }catch(Exception e) {
+ } catch (Exception e) {
return htmlText.replaceAll("(?s)<[^>]*>(\\s*<[^>]*>)*", "");
}
}
@@ -83,7 +82,7 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
String value;
try {
value = JsonUtils.getString(item, "account.avatar.path");
- }catch(Exception e) {
+ } catch (Exception e) {
value = "/client/assets/images/default-avatar.png";
}
return baseUrl + value;
@@ -91,7 +90,7 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
@Override
public String getAuthorName() throws ParsingException {
- return JsonUtils.getString(item, "account.displayName");
+ return JsonUtils.getString(item, "account.name") + "@" + JsonUtils.getString(item, "account.host");
}
@Override
@@ -100,5 +99,5 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
String host = JsonUtils.getString(item, "account.host");
return ServiceList.PeerTube.getChannelLHFactory().fromId(name + "@" + host, baseUrl).getUrl();
}
-
+
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubePlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubePlaylistExtractor.java
index 98d20b53..1a96111a 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubePlaylistExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubePlaylistExtractor.java
@@ -1,7 +1,5 @@
package org.schabi.newpipe.extractor.services.peertube.extractors;
-import java.io.IOException;
-
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
@@ -10,7 +8,9 @@ import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
-public class PeertubePlaylistExtractor extends PlaylistExtractor{
+import java.io.IOException;
+
+public class PeertubePlaylistExtractor extends PlaylistExtractor {
public PeertubePlaylistExtractor(StreamingService service, ListLinkHandler linkHandler) {
super(service, linkHandler);
@@ -73,8 +73,7 @@ public class PeertubePlaylistExtractor extends PlaylistExtractor{
@Override
public void onFetchPage(Downloader downloader) throws IOException, ExtractionException {
- // TODO Auto-generated method stub
-
+
}
@Override
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeSearchExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeSearchExtractor.java
index ff021f73..3840bf76 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeSearchExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeSearchExtractor.java
@@ -1,7 +1,8 @@
package org.schabi.newpipe.extractor.services.peertube.extractors;
-import java.io.IOException;
-
+import com.grack.nanojson.JsonArray;
+import com.grack.nanojson.JsonObject;
+import com.grack.nanojson.JsonParser;
import org.jsoup.helper.StringUtil;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.InfoItemExtractor;
@@ -18,9 +19,7 @@ import org.schabi.newpipe.extractor.utils.JsonUtils;
import org.schabi.newpipe.extractor.utils.Parser;
import org.schabi.newpipe.extractor.utils.Parser.RegexException;
-import com.grack.nanojson.JsonArray;
-import com.grack.nanojson.JsonObject;
-import com.grack.nanojson.JsonParser;
+import java.io.IOException;
public class PeertubeSearchExtractor extends SearchExtractor {
@@ -28,10 +27,10 @@ public class PeertubeSearchExtractor extends SearchExtractor {
private static final String COUNT_KEY = "count";
private static final int ITEMS_PER_PAGE = 12;
private static final String START_PATTERN = "start=(\\d*)";
-
+
private InfoItemsPage initPage;
private long total;
-
+
public PeertubeSearchExtractor(StreamingService service, SearchQueryHandler linkHandler) {
super(service, linkHandler);
}
@@ -40,7 +39,7 @@ public class PeertubeSearchExtractor extends SearchExtractor {
public String getSearchSuggestion() throws ParsingException {
return null;
}
-
+
@Override
public InfoItemsPage getInitialPage() throws IOException, ExtractionException {
super.fetchPage();
@@ -48,27 +47,27 @@ public class PeertubeSearchExtractor extends SearchExtractor {
}
private InfoItemsCollector collectStreamsFrom(JsonObject json) throws ParsingException {
-
+
final InfoItemsSearchCollector collector = getInfoItemSearchCollector();
-
+
JsonArray contents;
try {
contents = (JsonArray) JsonUtils.getValue(json, "data");
- }catch(Exception e) {
+ } catch (Exception e) {
throw new ParsingException("unable to extract search info", e);
}
-
+
String baseUrl = getBaseUrl();
- for(Object c: contents) {
- if(c instanceof JsonObject) {
+ for (Object c : contents) {
+ if (c instanceof JsonObject) {
final JsonObject item = (JsonObject) c;
PeertubeStreamInfoItemExtractor extractor = new PeertubeStreamInfoItemExtractor(item, baseUrl);
collector.commit(extractor);
}
}
-
+
return collector;
-
+
}
@Override
@@ -81,17 +80,17 @@ public class PeertubeSearchExtractor extends SearchExtractor {
public InfoItemsPage getPage(String pageUrl) throws IOException, ExtractionException {
Response response = getDownloader().get(pageUrl);
JsonObject json = null;
- if(null != response && !StringUtil.isBlank(response.responseBody())) {
+ if (null != response && !StringUtil.isBlank(response.responseBody())) {
try {
json = JsonParser.object().from(response.responseBody());
} catch (Exception e) {
throw new ParsingException("Could not parse json data for search info", e);
}
}
-
- if(json != null) {
+
+ if (json != null) {
Number number = JsonUtils.getNumber(json, "total");
- if(number != null) this.total = number.longValue();
+ if (number != null) this.total = number.longValue();
return new InfoItemsPage<>(collectStreamsFrom(json), getNextPageUrl(pageUrl));
} else {
throw new ExtractionException("Unable to get peertube search info");
@@ -103,7 +102,7 @@ public class PeertubeSearchExtractor extends SearchExtractor {
String pageUrl = getUrl() + "&" + START_KEY + "=0&" + COUNT_KEY + "=" + ITEMS_PER_PAGE;
this.initPage = getPage(pageUrl);
}
-
+
private String getNextPageUrl(String prevPageUrl) {
String prevStart;
try {
@@ -111,20 +110,20 @@ public class PeertubeSearchExtractor extends SearchExtractor {
} catch (RegexException e) {
return "";
}
- if(StringUtil.isBlank(prevStart)) return "";
+ if (StringUtil.isBlank(prevStart)) return "";
long nextStart = 0;
try {
nextStart = Long.valueOf(prevStart) + ITEMS_PER_PAGE;
} catch (NumberFormatException e) {
return "";
}
-
- if(nextStart >= total) {
+
+ if (nextStart >= total) {
return "";
- }else {
+ } else {
return prevPageUrl.replace(START_KEY + "=" + prevStart, START_KEY + "=" + String.valueOf(nextStart));
}
}
-
+
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java
index d8d0de00..76ead5d6 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java
@@ -1,15 +1,12 @@
package org.schabi.newpipe.extractor.services.peertube.extractors;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
+import com.grack.nanojson.JsonArray;
+import com.grack.nanojson.JsonObject;
+import com.grack.nanojson.JsonParser;
+import com.grack.nanojson.JsonParserException;
import org.jsoup.helper.StringUtil;
import org.schabi.newpipe.extractor.MediaFormat;
-import org.schabi.newpipe.extractor.ServiceList;
+import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.downloader.Response;
@@ -20,34 +17,30 @@ import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
import org.schabi.newpipe.extractor.localization.DateWrapper;
import org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper;
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeSearchQueryHandlerFactory;
-import org.schabi.newpipe.extractor.stream.AudioStream;
-import org.schabi.newpipe.extractor.stream.Stream;
-import org.schabi.newpipe.extractor.stream.StreamExtractor;
-import org.schabi.newpipe.extractor.stream.StreamInfoItem;
-import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
-import org.schabi.newpipe.extractor.stream.StreamType;
-import org.schabi.newpipe.extractor.stream.SubtitlesStream;
-import org.schabi.newpipe.extractor.stream.VideoStream;
+import org.schabi.newpipe.extractor.stream.*;
import org.schabi.newpipe.extractor.utils.JsonUtils;
-import org.schabi.newpipe.extractor.utils.Utils;
-import com.grack.nanojson.JsonArray;
-import com.grack.nanojson.JsonObject;
-import com.grack.nanojson.JsonParser;
-import com.grack.nanojson.JsonParserException;
+import javax.annotation.Nonnull;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
public class PeertubeStreamExtractor extends StreamExtractor {
-
+
+ private final String baseUrl;
private JsonObject json;
private List subtitles = new ArrayList<>();
- private final String baseUrl;
-
+
public PeertubeStreamExtractor(StreamingService service, LinkHandler linkHandler) throws ParsingException {
super(service, linkHandler);
this.baseUrl = getBaseUrl();
}
-
+
@Override
public String getTextualUploadDate() throws ParsingException {
return JsonUtils.getString(json, "publishedAt");
@@ -63,24 +56,42 @@ public class PeertubeStreamExtractor extends StreamExtractor {
return new DateWrapper(PeertubeParsingHelper.parseDateFrom(textualUploadDate));
}
-
+
@Override
public String getThumbnailUrl() throws ParsingException {
- return baseUrl + JsonUtils.getString(json, "thumbnailPath");
+ return baseUrl + JsonUtils.getString(json, "previewPath");
}
@Override
- public String getDescription() throws ParsingException {
+ public Description getDescription() throws ParsingException {
+ String text;
try {
- return JsonUtils.getString(json, "description");
- }catch(ParsingException e) {
- return "No description";
+ text = JsonUtils.getString(json, "description");
+ } catch (ParsingException e) {
+ return Description.emptyDescription;
}
+ if (text.length() == 250 && text.substring(247).equals("...")) {
+ //if description is shortened, get full description
+ Downloader dl = NewPipe.getDownloader();
+ try {
+ Response response = dl.get(getUrl() + "/description");
+ JsonObject jsonObject = JsonParser.object().from(response.responseBody());
+ text = JsonUtils.getString(jsonObject, "description");
+ } catch (ReCaptchaException | IOException | JsonParserException e) {
+ e.printStackTrace();
+ }
+ }
+ return new Description(text, Description.MARKDOWN);
}
@Override
public int getAgeLimit() throws ParsingException {
- return NO_AGE_LIMIT;
+ boolean isNSFW = JsonUtils.getBoolean(json, "nsfw");
+ if (isNSFW) {
+ return 18;
+ } else {
+ return NO_AGE_LIMIT;
+ }
}
@Override
@@ -130,7 +141,7 @@ public class PeertubeStreamExtractor extends StreamExtractor {
String value;
try {
value = JsonUtils.getString(json, "account.avatar.path");
- }catch(Exception e) {
+ } catch (Exception e) {
value = "/client/assets/images/default-avatar.png";
}
return baseUrl + value;
@@ -157,8 +168,8 @@ public class PeertubeStreamExtractor extends StreamExtractor {
List videoStreams = new ArrayList<>();
try {
JsonArray streams = json.getArray("files", new JsonArray());
- for(Object s: streams) {
- if(!(s instanceof JsonObject)) continue;
+ for (Object s : streams) {
+ if (!(s instanceof JsonObject)) continue;
JsonObject stream = (JsonObject) s;
String url = JsonUtils.getString(stream, "fileUrl");
String torrentUrl = JsonUtils.getString(stream, "torrentUrl");
@@ -192,8 +203,8 @@ public class PeertubeStreamExtractor extends StreamExtractor {
@Override
public List getSubtitles(final MediaFormat format) throws IOException, ExtractionException {
List filteredSubs = new ArrayList<>();
- for(SubtitlesStream sub: subtitles) {
- if(sub.getFormat() == format) {
+ for (SubtitlesStream sub : subtitles) {
+ if (sub.getFormat() == format) {
filteredSubs.add(sub);
}
}
@@ -215,29 +226,40 @@ public class PeertubeStreamExtractor extends StreamExtractor {
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
List tags = getTags();
String apiUrl = null;
- if(!tags.isEmpty()) {
+ if (!tags.isEmpty()) {
apiUrl = getRelatedStreamsUrl(tags);
-
- }else {
+
+ } else {
apiUrl = getUploaderUrl() + "/videos?start=0&count=8";
}
- if(!StringUtil.isBlank(apiUrl)) getStreamsFromApi(collector, apiUrl);
+ if (!StringUtil.isBlank(apiUrl)) getStreamsFromApi(collector, apiUrl);
return collector;
}
-
- private List getTags(){
+
+ @Override
+ public List getTags() {
try {
return (List) JsonUtils.getArray(json, "tags");
} catch (Exception e) {
return Collections.emptyList();
}
}
-
+
+ @Nonnull
+ @Override
+ public String getSupportInfo() throws ParsingException {
+ try {
+ return JsonUtils.getString(json, "support");
+ } catch (ParsingException e) {
+ return "";
+ }
+ }
+
private String getRelatedStreamsUrl(List tags) throws UnsupportedEncodingException {
String url = baseUrl + PeertubeSearchQueryHandlerFactory.SEARCH_ENDPOINT;
StringBuilder params = new StringBuilder();
params.append("start=0&count=8&sort=-createdAt");
- for(String tag : tags) {
+ for (String tag : tags) {
params.append("&tagsOneOf=");
params.append(URLEncoder.encode(tag, "UTF-8"));
}
@@ -247,38 +269,38 @@ public class PeertubeStreamExtractor extends StreamExtractor {
private void getStreamsFromApi(StreamInfoItemsCollector collector, String apiUrl) throws ReCaptchaException, IOException, ParsingException {
Response response = getDownloader().get(apiUrl);
JsonObject relatedVideosJson = null;
- if(null != response && !StringUtil.isBlank(response.responseBody())) {
+ if (null != response && !StringUtil.isBlank(response.responseBody())) {
try {
relatedVideosJson = JsonParser.object().from(response.responseBody());
} catch (JsonParserException e) {
throw new ParsingException("Could not parse json data for related videos", e);
}
}
-
- if(relatedVideosJson != null) {
+
+ if (relatedVideosJson != null) {
collectStreamsFrom(collector, relatedVideosJson);
}
}
-
+
private void collectStreamsFrom(StreamInfoItemsCollector collector, JsonObject json) throws ParsingException {
JsonArray contents;
try {
contents = (JsonArray) JsonUtils.getValue(json, "data");
- }catch(Exception e) {
+ } catch (Exception e) {
throw new ParsingException("unable to extract related videos", e);
}
-
- for(Object c: contents) {
- if(c instanceof JsonObject) {
+
+ for (Object c : contents) {
+ if (c instanceof JsonObject) {
final JsonObject item = (JsonObject) c;
PeertubeStreamInfoItemExtractor extractor = new PeertubeStreamInfoItemExtractor(item, baseUrl);
//do not add the same stream in related streams
- if(!extractor.getUrl().equals(getUrl())) collector.commit(extractor);
+ if (!extractor.getUrl().equals(getUrl())) collector.commit(extractor);
}
}
-
+
}
-
+
@Override
public String getErrorMessage() {
@@ -288,12 +310,12 @@ public class PeertubeStreamExtractor extends StreamExtractor {
@Override
public void onFetchPage(Downloader downloader) throws IOException, ExtractionException {
Response response = downloader.get(getUrl());
- if(null != response && null != response.responseBody()) {
+ if (null != response && null != response.responseBody()) {
setInitialData(response.responseBody());
- }else {
+ } else {
throw new ExtractionException("Unable to extract peertube channel data");
}
-
+
loadSubtitles();
}
@@ -303,24 +325,25 @@ public class PeertubeStreamExtractor extends StreamExtractor {
} catch (JsonParserException e) {
throw new ExtractionException("Unable to extract peertube stream data", e);
}
- if(null == json) throw new ExtractionException("Unable to extract peertube stream data");
+ if (null == json) throw new ExtractionException("Unable to extract peertube stream data");
PeertubeParsingHelper.validate(json);
}
-
+
private void loadSubtitles() {
if (subtitles.isEmpty()) {
try {
- Response response = getDownloader().get(getUrl() + "/captions");
+ Response response = getDownloader().get(getUrl() + "/captions");
JsonObject captionsJson = JsonParser.object().from(response.responseBody());
JsonArray captions = JsonUtils.getArray(captionsJson, "data");
- for(Object c: captions) {
- if(c instanceof JsonObject) {
- JsonObject caption = (JsonObject)c;
+ for (Object c : captions) {
+ if (c instanceof JsonObject) {
+ JsonObject caption = (JsonObject) c;
String url = baseUrl + JsonUtils.getString(caption, "captionPath");
String languageCode = JsonUtils.getString(caption, "language.id");
String ext = url.substring(url.lastIndexOf(".") + 1);
MediaFormat fmt = MediaFormat.getFromSuffix(ext);
- if(fmt != null && languageCode != null) subtitles.add(new SubtitlesStream(fmt, languageCode, url, false));
+ if (fmt != null && languageCode != null)
+ subtitles.add(new SubtitlesStream(fmt, languageCode, url, false));
}
}
} catch (Exception e) {
@@ -339,4 +362,32 @@ public class PeertubeStreamExtractor extends StreamExtractor {
return baseUrl + "/videos/watch/" + getId();
}
+ @Override
+ public String getHost() throws ParsingException {
+ return JsonUtils.getString(json, "account.host");
+ }
+
+ @Override
+ public String getPrivacy() throws ParsingException {
+ return JsonUtils.getString(json, "privacy.label");
+ }
+
+ @Override
+ public String getCategory() throws ParsingException {
+ return JsonUtils.getString(json, "category.label");
+ }
+
+ @Override
+ public String getLicence() throws ParsingException {
+ return JsonUtils.getString(json, "licence.label");
+ }
+
+ @Override
+ public Locale getLanguageInfo() throws ParsingException {
+ try {
+ return new Locale(JsonUtils.getString(json, "language.id"));
+ } catch (ParsingException e) {
+ return null;
+ }
+ }
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamInfoItemExtractor.java
index ca85270a..c4ed7730 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamInfoItemExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamInfoItemExtractor.java
@@ -1,5 +1,6 @@
package org.schabi.newpipe.extractor.services.peertube.extractors;
+import com.grack.nanojson.JsonObject;
import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.localization.DateWrapper;
@@ -8,58 +9,56 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.extractor.utils.JsonUtils;
-import com.grack.nanojson.JsonObject;
-
public class PeertubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
-
+
protected final JsonObject item;
private final String baseUrl;
-
+
public PeertubeStreamInfoItemExtractor(JsonObject item, String baseUrl) {
this.item = item;
this.baseUrl = baseUrl;
}
-
+
@Override
public String getUrl() throws ParsingException {
String uuid = JsonUtils.getString(item, "uuid");
return ServiceList.PeerTube.getStreamLHFactory().fromId(uuid, baseUrl).getUrl();
}
-
+
@Override
public String getThumbnailUrl() throws ParsingException {
String value = JsonUtils.getString(item, "thumbnailPath");
return baseUrl + value;
}
-
+
@Override
public String getName() throws ParsingException {
return JsonUtils.getString(item, "name");
}
-
+
@Override
public boolean isAd() throws ParsingException {
return false;
}
-
+
@Override
public long getViewCount() throws ParsingException {
Number value = JsonUtils.getNumber(item, "views");
return value.longValue();
}
-
+
@Override
public String getUploaderUrl() throws ParsingException {
String name = JsonUtils.getString(item, "account.name");
String host = JsonUtils.getString(item, "account.host");
return ServiceList.PeerTube.getChannelLHFactory().fromId(name + "@" + host, baseUrl).getUrl();
}
-
+
@Override
public String getUploaderName() throws ParsingException {
return JsonUtils.getString(item, "account.displayName");
}
-
+
@Override
public String getTextualUploadDate() throws ParsingException {
return JsonUtils.getString(item, "publishedAt");
@@ -75,12 +74,12 @@ public class PeertubeStreamInfoItemExtractor implements StreamInfoItemExtractor
return new DateWrapper(PeertubeParsingHelper.parseDateFrom(textualUploadDate));
}
-
+
@Override
public StreamType getStreamType() throws ParsingException {
return StreamType.VIDEO_STREAM;
}
-
+
@Override
public long getDuration() throws ParsingException {
Number value = JsonUtils.getNumber(item, "duration");
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeSubscriptionExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeSubscriptionExtractor.java
index a2b24614..17062900 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeSubscriptionExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeSubscriptionExtractor.java
@@ -1,10 +1,10 @@
package org.schabi.newpipe.extractor.services.peertube.extractors;
-import java.util.List;
-
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
+import java.util.List;
+
public class PeertubeSubscriptionExtractor extends SubscriptionExtractor {
public PeertubeSubscriptionExtractor(StreamingService service, List supportedSources) {
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeSuggestionExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeSuggestionExtractor.java
index 7e2ed4d9..a028e77a 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeSuggestionExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeSuggestionExtractor.java
@@ -1,14 +1,14 @@
package org.schabi.newpipe.extractor.services.peertube.extractors;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.List;
-
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
-public class PeertubeSuggestionExtractor extends SuggestionExtractor{
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+
+public class PeertubeSuggestionExtractor extends SuggestionExtractor {
public PeertubeSuggestionExtractor(StreamingService service) {
super(service);
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeTrendingExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeTrendingExtractor.java
index 1cb42046..e4bc1dff 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeTrendingExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeTrendingExtractor.java
@@ -1,7 +1,8 @@
package org.schabi.newpipe.extractor.services.peertube.extractors;
-import java.io.IOException;
-
+import com.grack.nanojson.JsonArray;
+import com.grack.nanojson.JsonObject;
+import com.grack.nanojson.JsonParser;
import org.jsoup.helper.StringUtil;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.downloader.Downloader;
@@ -16,17 +17,15 @@ import org.schabi.newpipe.extractor.utils.JsonUtils;
import org.schabi.newpipe.extractor.utils.Parser;
import org.schabi.newpipe.extractor.utils.Parser.RegexException;
-import com.grack.nanojson.JsonArray;
-import com.grack.nanojson.JsonObject;
-import com.grack.nanojson.JsonParser;
+import java.io.IOException;
public class PeertubeTrendingExtractor extends KioskExtractor {
-
+
private static final String START_KEY = "start";
private static final String COUNT_KEY = "count";
private static final int ITEMS_PER_PAGE = 12;
private static final String START_PATTERN = "start=(\\d*)";
-
+
private InfoItemsPage initPage;
private long total;
@@ -49,19 +48,19 @@ public class PeertubeTrendingExtractor extends KioskExtractor {
JsonArray contents;
try {
contents = (JsonArray) JsonUtils.getValue(json, "data");
- }catch(Exception e) {
- throw new ParsingException("unable to extract kiosk info", e);
+ } catch (Exception e) {
+ throw new ParsingException("Unable to extract kiosk info", e);
}
-
+
String baseUrl = getBaseUrl();
- for(Object c: contents) {
- if(c instanceof JsonObject) {
+ for (Object c : contents) {
+ if (c instanceof JsonObject) {
final JsonObject item = (JsonObject) c;
PeertubeStreamInfoItemExtractor extractor = new PeertubeStreamInfoItemExtractor(item, baseUrl);
collector.commit(extractor);
}
}
-
+
}
@Override
@@ -74,18 +73,18 @@ public class PeertubeTrendingExtractor extends KioskExtractor {
public InfoItemsPage getPage(String pageUrl) throws IOException, ExtractionException {
Response response = getDownloader().get(pageUrl);
JsonObject json = null;
- if(null != response && !StringUtil.isBlank(response.responseBody())) {
+ if (null != response && !StringUtil.isBlank(response.responseBody())) {
try {
json = JsonParser.object().from(response.responseBody());
} catch (Exception e) {
throw new ParsingException("Could not parse json data for kiosk info", e);
}
}
-
+
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
- if(json != null) {
+ if (json != null) {
Number number = JsonUtils.getNumber(json, "total");
- if(number != null) this.total = number.longValue();
+ if (number != null) this.total = number.longValue();
collectStreamsFrom(collector, json, pageUrl);
} else {
throw new ExtractionException("Unable to get peertube kiosk info");
@@ -98,7 +97,7 @@ public class PeertubeTrendingExtractor extends KioskExtractor {
String pageUrl = getUrl() + "&" + START_KEY + "=0&" + COUNT_KEY + "=" + ITEMS_PER_PAGE;
this.initPage = getPage(pageUrl);
}
-
+
private String getNextPageUrl(String prevPageUrl) {
String prevStart;
try {
@@ -106,17 +105,17 @@ public class PeertubeTrendingExtractor extends KioskExtractor {
} catch (RegexException e) {
return "";
}
- if(StringUtil.isBlank(prevStart)) return "";
+ if (StringUtil.isBlank(prevStart)) return "";
long nextStart = 0;
try {
nextStart = Long.valueOf(prevStart) + ITEMS_PER_PAGE;
} catch (NumberFormatException e) {
return "";
}
-
- if(nextStart >= total) {
+
+ if (nextStart >= total) {
return "";
- }else {
+ } else {
return prevPageUrl.replace(START_KEY + "=" + prevStart, START_KEY + "=" + String.valueOf(nextStart));
}
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeChannelLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeChannelLinkHandlerFactory.java
index 640f99e5..c1e3f570 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeChannelLinkHandlerFactory.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeChannelLinkHandlerFactory.java
@@ -1,12 +1,12 @@
package org.schabi.newpipe.extractor.services.peertube.linkHandler;
-import java.util.List;
-
import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
import org.schabi.newpipe.extractor.utils.Parser;
+import java.util.List;
+
public class PeertubeChannelLinkHandlerFactory extends ListLinkHandlerFactory {
private static final PeertubeChannelLinkHandlerFactory instance = new PeertubeChannelLinkHandlerFactory();
@@ -27,7 +27,7 @@ public class PeertubeChannelLinkHandlerFactory extends ListLinkHandlerFactory {
String baseUrl = ServiceList.PeerTube.getBaseUrl();
return getUrl(id, contentFilters, searchFilter, baseUrl);
}
-
+
@Override
public String getUrl(String id, List contentFilter, String sortFilter, String baseUrl)
throws ParsingException {
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeCommentsLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeCommentsLinkHandlerFactory.java
index 9faa3492..9c833750 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeCommentsLinkHandlerFactory.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeCommentsLinkHandlerFactory.java
@@ -1,13 +1,13 @@
package org.schabi.newpipe.extractor.services.peertube.linkHandler;
-import java.util.List;
-
import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.exceptions.FoundAdException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
import org.schabi.newpipe.extractor.utils.Parser;
+import java.util.List;
+
public class PeertubeCommentsLinkHandlerFactory extends ListLinkHandlerFactory {
private static final PeertubeCommentsLinkHandlerFactory instance = new PeertubeCommentsLinkHandlerFactory();
@@ -33,10 +33,10 @@ public class PeertubeCommentsLinkHandlerFactory extends ListLinkHandlerFactory {
String baseUrl = ServiceList.PeerTube.getBaseUrl();
return getUrl(id, contentFilter, sortFilter, baseUrl);
}
-
+
@Override
public String getUrl(String id, List contentFilter, String sortFilter, String baseUrl) throws ParsingException {
return baseUrl + String.format(COMMENTS_ENDPOINT, id);
}
-
+
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubePlaylistLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubePlaylistLinkHandlerFactory.java
index 64e291a5..dd1bd77f 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubePlaylistLinkHandlerFactory.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubePlaylistLinkHandlerFactory.java
@@ -1,13 +1,13 @@
package org.schabi.newpipe.extractor.services.peertube.linkHandler;
-import java.util.List;
-
import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
import org.schabi.newpipe.extractor.utils.Parser;
+import java.util.List;
+
public class PeertubePlaylistLinkHandlerFactory extends ListLinkHandlerFactory {
private static final PeertubePlaylistLinkHandlerFactory instance = new PeertubePlaylistLinkHandlerFactory();
@@ -23,12 +23,12 @@ public class PeertubePlaylistLinkHandlerFactory extends ListLinkHandlerFactory {
String baseUrl = ServiceList.PeerTube.getBaseUrl();
return getUrl(id, contentFilters, sortFilter, baseUrl);
}
-
+
@Override
public String getUrl(String id, List contentFilters, String sortFilter, String baseUrl) {
return baseUrl + VIDEO_CHANNELS_ENDPOINT + id;
}
-
+
@Override
public String getId(String url) throws ParsingException {
return Parser.matchGroup1(ID_PATTERN, url);
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeSearchQueryHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeSearchQueryHandlerFactory.java
index 69591167..8acf3e80 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeSearchQueryHandlerFactory.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeSearchQueryHandlerFactory.java
@@ -1,13 +1,13 @@
package org.schabi.newpipe.extractor.services.peertube.linkHandler;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.List;
-
import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.List;
+
public class PeertubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
public static final String CHARSET_UTF_8 = "UTF-8";
@@ -21,9 +21,9 @@ public class PeertubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory
@Override
public String getUrl(String searchString, List contentFilters, String sortFilter) throws ParsingException {
String baseUrl = ServiceList.PeerTube.getBaseUrl();
- return getUrl(searchString, contentFilters, sortFilter, baseUrl);
+ return getUrl(searchString, contentFilters, sortFilter, baseUrl);
}
-
+
@Override
public String getUrl(String searchString, List contentFilters, String sortFilter, String baseUrl) throws ParsingException {
try {
@@ -38,6 +38,6 @@ public class PeertubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory
@Override
public String[] getAvailableContentFilter() {
- return new String[] { VIDEOS };
+ return new String[]{VIDEOS};
}
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeStreamLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeStreamLinkHandlerFactory.java
index 3ee7744c..222dc129 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeStreamLinkHandlerFactory.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeStreamLinkHandlerFactory.java
@@ -24,7 +24,7 @@ public class PeertubeStreamLinkHandlerFactory extends LinkHandlerFactory {
String baseUrl = ServiceList.PeerTube.getBaseUrl();
return getUrl(id, baseUrl);
}
-
+
@Override
public String getUrl(String id, String baseUrl) {
return baseUrl + VIDEO_ENDPOINT + id;
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeTrendingLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeTrendingLinkHandlerFactory.java
index c0773c20..1d5609c1 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeTrendingLinkHandlerFactory.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeTrendingLinkHandlerFactory.java
@@ -1,26 +1,26 @@
package org.schabi.newpipe.extractor.services.peertube.linkHandler;
+import org.schabi.newpipe.extractor.ServiceList;
+import org.schabi.newpipe.extractor.exceptions.ParsingException;
+import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
+
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.schabi.newpipe.extractor.ServiceList;
-import org.schabi.newpipe.extractor.exceptions.ParsingException;
-import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
-
public class PeertubeTrendingLinkHandlerFactory extends ListLinkHandlerFactory {
-
-
+
+
private static final PeertubeTrendingLinkHandlerFactory instance = new PeertubeTrendingLinkHandlerFactory();
-
+
public static final Map KIOSK_MAP;
public static final Map REVERSE_KIOSK_MAP;
public static final String KIOSK_TRENDING = "Trending";
public static final String KIOSK_MOST_LIKED = "Most liked";
public static final String KIOSK_RECENT = "Recently added";
public static final String KIOSK_LOCAL = "Local";
-
+
static {
Map map = new HashMap<>();
map.put(KIOSK_TRENDING, "%s/api/v1/videos?sort=-trending");
@@ -28,24 +28,24 @@ public class PeertubeTrendingLinkHandlerFactory extends ListLinkHandlerFactory {
map.put(KIOSK_RECENT, "%s/api/v1/videos?sort=-publishedAt");
map.put(KIOSK_LOCAL, "%s/api/v1/videos?sort=-publishedAt&filter=local");
KIOSK_MAP = Collections.unmodifiableMap(map);
-
+
Map reverseMap = new HashMap<>();
- for(Map.Entry entry : KIOSK_MAP.entrySet()){
+ for (Map.Entry entry : KIOSK_MAP.entrySet()) {
reverseMap.put(entry.getValue(), entry.getKey());
}
REVERSE_KIOSK_MAP = Collections.unmodifiableMap(reverseMap);
}
-
+
public static PeertubeTrendingLinkHandlerFactory getInstance() {
return instance;
}
-
+
@Override
public String getUrl(String id, List contentFilters, String sortFilter) {
String baseUrl = ServiceList.PeerTube.getBaseUrl();
return getUrl(id, contentFilters, sortFilter, baseUrl);
}
-
+
@Override
public String getUrl(String id, List contentFilters, String sortFilter, String baseUrl) {
return String.format(KIOSK_MAP.get(id), baseUrl);
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractor.java
index 54541217..853b6fc1 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractor.java
@@ -4,9 +4,9 @@ import com.grack.nanojson.JsonArray;
import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser;
import com.grack.nanojson.JsonParserException;
-import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
+import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
@@ -86,7 +86,7 @@ public class SoundcloudChannelExtractor extends ChannelExtractor {
@Nonnull
@Override
public InfoItemsPage getInitialPage() throws ExtractionException {
- if(streamInfoItemsCollector == null) {
+ if (streamInfoItemsCollector == null) {
computeNextPageAndGetStreams();
}
return new InfoItemsPage<>(streamInfoItemsCollector, getNextPageUrl());
@@ -94,7 +94,7 @@ public class SoundcloudChannelExtractor extends ChannelExtractor {
@Override
public String getNextPageUrl() throws ExtractionException {
- if(nextPageUrl == null) {
+ if (nextPageUrl == null) {
computeNextPageAndGetStreams();
}
return nextPageUrl;
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelLinkHandlerFactory.java
index ed5d9a98..be1b9fcd 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelLinkHandlerFactory.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelLinkHandlerFactory.java
@@ -1,7 +1,7 @@
package org.schabi.newpipe.extractor.services.soundcloud;
-import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
+import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
import org.schabi.newpipe.extractor.utils.Parser;
import org.schabi.newpipe.extractor.utils.Utils;
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractor.java
index b773a935..b9f4894d 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractor.java
@@ -1,7 +1,7 @@
package org.schabi.newpipe.extractor.services.soundcloud;
-import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.StreamingService;
+import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
@@ -12,8 +12,8 @@ import javax.annotation.Nonnull;
import java.io.IOException;
public class SoundcloudChartsExtractor extends KioskExtractor {
- private StreamInfoItemsCollector collector = null;
- private String nextPageUrl = null;
+ private StreamInfoItemsCollector collector = null;
+ private String nextPageUrl = null;
public SoundcloudChartsExtractor(StreamingService service,
ListLinkHandler linkHandler,
@@ -68,7 +68,7 @@ public class SoundcloudChartsExtractor extends KioskExtractor {
@Override
public String getNextPageUrl() throws IOException, ExtractionException {
- if(nextPageUrl == null) {
+ if (nextPageUrl == null) {
computNextPageAndStreams();
}
return nextPageUrl;
@@ -77,7 +77,7 @@ public class SoundcloudChartsExtractor extends KioskExtractor {
@Nonnull
@Override
public InfoItemsPage getInitialPage() throws IOException, ExtractionException {
- if(collector == null) {
+ if (collector == null) {
computNextPageAndStreams();
}
return new InfoItemsPage<>(collector, getNextPageUrl());
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java
index 4617f916..b8f6af24 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java
@@ -31,9 +31,9 @@ import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps;
public class SoundcloudParsingHelper {
- private static final String HARDCODED_CLIENT_ID = "r5ELVSy3RkcjX7ilaL7n2v1Z8irA9SL8"; // Updated on 31/12/19
+ private static final String HARDCODED_CLIENT_ID = "t0h1jzYMsaZXy6ggnZO71gHK3Ms6CFwE"; // Updated on 14/03/20
private static String clientId;
-
+
private SoundcloudParsingHelper() {
}
@@ -103,7 +103,7 @@ public class SoundcloudParsingHelper {
/**
* Call the endpoint "/resolve" of the api.
- *
+ *
* See https://developers.soundcloud.com/docs/api/reference#resolve
*/
public static JsonObject resolveFor(Downloader downloader, String url) throws IOException, ExtractionException {
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractor.java
index 5bc30972..ca08f66c 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractor.java
@@ -3,8 +3,8 @@ package org.schabi.newpipe.extractor.services.soundcloud;
import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser;
import com.grack.nanojson.JsonParserException;
-import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.StreamingService;
+import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistLinkHandlerFactory.java
index 17e4e7f2..c7c882a9 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistLinkHandlerFactory.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistLinkHandlerFactory.java
@@ -1,7 +1,7 @@
package org.schabi.newpipe.extractor.services.soundcloud;
-import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
+import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
import org.schabi.newpipe.extractor.utils.Parser;
import org.schabi.newpipe.extractor.utils.Utils;
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchExtractor.java
index 9ed340fa..42cd8ae0 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchExtractor.java
@@ -4,7 +4,10 @@ import com.grack.nanojson.JsonArray;
import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser;
import com.grack.nanojson.JsonParserException;
-import org.schabi.newpipe.extractor.*;
+import org.schabi.newpipe.extractor.InfoItem;
+import org.schabi.newpipe.extractor.InfoItemExtractor;
+import org.schabi.newpipe.extractor.InfoItemsCollector;
+import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQueryHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQueryHandlerFactory.java
index 90057120..dffcc91f 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQueryHandlerFactory.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchQueryHandlerFactory.java
@@ -25,7 +25,7 @@ public class SoundcloudSearchQueryHandlerFactory extends SearchQueryHandlerFacto
try {
String url = "https://api-v2.soundcloud.com/search";
- if(contentFilter.size() > 0) {
+ if (contentFilter.size() > 0) {
switch (contentFilter.get(0)) {
case TRACKS:
url += "/tracks";
@@ -58,7 +58,7 @@ public class SoundcloudSearchQueryHandlerFactory extends SearchQueryHandlerFacto
@Override
public String[] getAvailableContentFilter() {
- return new String[] {
+ return new String[]{
ALL,
TRACKS,
USERS,
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 def9c386..30f2fc87 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudService.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudService.java
@@ -1,31 +1,26 @@
package org.schabi.newpipe.extractor.services.soundcloud;
-import static java.util.Collections.singletonList;
-import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.AUDIO;
-
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.comments.CommentsExtractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
import org.schabi.newpipe.extractor.kiosk.KioskList;
-import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
-import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
-import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
-import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
-import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
-import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory;
+import org.schabi.newpipe.extractor.linkhandler.*;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.search.SearchExtractor;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
+import static java.util.Collections.singletonList;
+import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.AUDIO;
+
public class SoundcloudService extends StreamingService {
public SoundcloudService(int id) {
super(id, "SoundCloud", singletonList(AUDIO));
}
-
+
@Override
public String getBaseUrl() {
return "https://soundcloud.com";
@@ -110,15 +105,15 @@ public class SoundcloudService extends StreamingService {
return new SoundcloudSubscriptionExtractor(this);
}
- @Override
- public ListLinkHandlerFactory getCommentsLHFactory() {
- return null;
- }
+ @Override
+ public ListLinkHandlerFactory getCommentsLHFactory() {
+ return null;
+ }
- @Override
+ @Override
public CommentsExtractor getCommentsExtractor(ListLinkHandler linkHandler)
throws ExtractionException {
return null;
}
-
+
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java
index 14f7023f..2919c89b 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java
@@ -4,7 +4,9 @@ import com.grack.nanojson.JsonArray;
import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser;
import com.grack.nanojson.JsonParserException;
-import org.schabi.newpipe.extractor.*;
+import org.schabi.newpipe.extractor.MediaFormat;
+import org.schabi.newpipe.extractor.NewPipe;
+import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
@@ -20,6 +22,7 @@ import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Locale;
public class SoundcloudStreamExtractor extends StreamExtractor {
private JsonObject track;
@@ -73,10 +76,9 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
return artworkUrlBetterResolution;
}
- @Nonnull
@Override
- public String getDescription() {
- return track.getString("description");
+ public Description getDescription() {
+ return new Description(track.getString("description"), Description.PLAIN_TEXT);
}
@Override
@@ -183,7 +185,7 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
try {
JsonObject mp3UrlObject = JsonParser.object().from(res);
// Links in this file are also only valid for a short period.
- audioStreams.add(new AudioStream(mp3UrlObject.getString("url"),
+ audioStreams.add(new AudioStream(mp3UrlObject.getString("url"),
MediaFormat.MP3, 128));
} catch (JsonParserException e) {
throw new ParsingException("Could not parse streamable url", e);
@@ -254,4 +256,41 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
public String getErrorMessage() {
return null;
}
+
+ @Override
+ public String getHost() throws ParsingException {
+ return "";
+ }
+
+ @Override
+ public String getPrivacy() throws ParsingException {
+ return "";
+ }
+
+ @Override
+ public String getCategory() throws ParsingException {
+ return "";
+ }
+
+ @Override
+ public String getLicence() throws ParsingException {
+ return "";
+ }
+
+ @Override
+ public Locale getLanguageInfo() throws ParsingException {
+ return null;
+ }
+
+ @Nonnull
+ @Override
+ public List getTags() throws ParsingException {
+ return new ArrayList<>();
+ }
+
+ @Nonnull
+ @Override
+ public String getSupportInfo() throws ParsingException {
+ return "";
+ }
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamLinkHandlerFactory.java
index 3476eab1..fc578411 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamLinkHandlerFactory.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamLinkHandlerFactory.java
@@ -1,7 +1,7 @@
package org.schabi.newpipe.extractor.services.soundcloud;
-import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
+import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
import org.schabi.newpipe.extractor.utils.Parser;
import org.schabi.newpipe.extractor.utils.Utils;
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSuggestionExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSuggestionExtractor.java
index b12f0467..924c4698 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSuggestionExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSuggestionExtractor.java
@@ -4,9 +4,9 @@ import com.grack.nanojson.JsonArray;
import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser;
import com.grack.nanojson.JsonParserException;
-import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
+import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
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 6137f029..eae3bcb9 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java
@@ -1,13 +1,5 @@
package org.schabi.newpipe.extractor.services.youtube;
-import static java.util.Arrays.asList;
-import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.AUDIO;
-import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.COMMENTS;
-import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.LIVE;
-import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.VIDEO;
-
-import java.util.List;
-
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.comments.CommentsExtractor;
@@ -15,28 +7,22 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.feed.FeedExtractor;
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
import org.schabi.newpipe.extractor.kiosk.KioskList;
-import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
-import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
-import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
-import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
-import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
-import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory;
+import org.schabi.newpipe.extractor.linkhandler.*;
import org.schabi.newpipe.extractor.localization.ContentCountry;
import org.schabi.newpipe.extractor.localization.Localization;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.search.SearchExtractor;
import org.schabi.newpipe.extractor.services.youtube.extractors.*;
-import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory;
-import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeCommentsLinkHandlerFactory;
-import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubePlaylistLinkHandlerFactory;
-import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory;
-import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory;
-import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeTrendingLinkHandlerFactory;
+import org.schabi.newpipe.extractor.services.youtube.linkHandler.*;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
import javax.annotation.Nonnull;
+import java.util.List;
+
+import static java.util.Arrays.asList;
+import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.*;
/*
* Created by Christian Schabesberger on 23.08.15.
@@ -125,7 +111,7 @@ public class YoutubeService extends StreamingService {
public KioskExtractor createNewKiosk(StreamingService streamingService,
String url,
String id)
- throws ExtractionException {
+ throws ExtractionException {
return new YoutubeTrendingExtractor(YoutubeService.this,
new YoutubeTrendingLinkHandlerFactory().fromUrl(url), id);
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java
index d675cb25..11dd8985 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java
@@ -1,28 +1,29 @@
package org.schabi.newpipe.extractor.services.youtube.extractors;
+import com.grack.nanojson.JsonArray;
import com.grack.nanojson.JsonObject;
-import com.grack.nanojson.JsonParser;
-import com.grack.nanojson.JsonParserException;
-import org.jsoup.Jsoup;
-import org.jsoup.nodes.Document;
-import org.jsoup.nodes.Element;
+
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.downloader.Downloader;
-import org.schabi.newpipe.extractor.downloader.Response;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
+import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory;
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
-import org.schabi.newpipe.extractor.utils.Parser;
import org.schabi.newpipe.extractor.utils.Utils;
-import javax.annotation.Nonnull;
import java.io.IOException;
+import javax.annotation.Nonnull;
+
+import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.fixThumbnailUrl;
+import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getJsonResponse;
+import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getTextFromObject;
+
/*
* Created by Christian Schabesberger on 25.07.16.
*
@@ -45,10 +46,8 @@ import java.io.IOException;
@SuppressWarnings("WeakerAccess")
public class YoutubeChannelExtractor extends ChannelExtractor {
- /*package-private*/ static final String CHANNEL_URL_BASE = "https://www.youtube.com/channel/";
- private static final String CHANNEL_URL_PARAMETERS = "/videos?view=0&flow=list&sort=dd&live_view=10000";
-
- private Document doc;
+ private JsonObject initialData;
+ private JsonObject videoTab;
public YoutubeChannelExtractor(StreamingService service, ListLinkHandler linkHandler) {
super(service, linkHandler);
@@ -56,21 +55,27 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
@Override
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
- String channelUrl = super.getUrl() + CHANNEL_URL_PARAMETERS;
- final Response response = downloader.get(channelUrl, getExtractorLocalization());
- doc = YoutubeParsingHelper.parseAndCheckPage(channelUrl, response);
+ final String url = super.getUrl() + "/videos?pbj=1&view=0&flow=grid";
+
+ final JsonArray ajaxJson = getJsonResponse(url, getExtractorLocalization());
+ initialData = ajaxJson.getObject(1).getObject("response");
+ YoutubeParsingHelper.defaultAlertsCheck(initialData);
}
+
@Override
public String getNextPageUrl() throws ExtractionException {
- return getNextPageUrlFrom(doc);
+ if (getVideoTab() == null) return "";
+ return getNextPageUrlFrom(getVideoTab().getObject("content").getObject("sectionListRenderer")
+ .getArray("contents").getObject(0).getObject("itemSectionRenderer")
+ .getArray("contents").getObject(0).getObject("gridRenderer").getArray("continuations"));
}
@Nonnull
@Override
public String getUrl() throws ParsingException {
try {
- return CHANNEL_URL_BASE + getId();
+ return YoutubeChannelLinkHandlerFactory.getInstance().getUrl("channel/" + getId());
} catch (ParsingException e) {
return super.getUrl();
}
@@ -80,15 +85,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
@Override
public String getId() throws ParsingException {
try {
- return doc.select("meta[itemprop=\"channelId\"]").first().attr("content");
- } catch (Exception ignored) {}
-
- // fallback method; does not work with channels that have no "Subscribe" button (e.g. EminemVEVO)
- try {
- Element element = doc.getElementsByClass("yt-uix-subscription-button").first();
- if (element == null) element = doc.getElementsByClass("yt-uix-subscription-preferences-button").first();
-
- return element.attr("data-channel-external-id");
+ return initialData.getObject("header").getObject("c4TabbedHeaderRenderer").getString("channelId");
} catch (Exception e) {
throw new ParsingException("Could not get channel id", e);
}
@@ -98,7 +95,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
@Override
public String getName() throws ParsingException {
try {
- return doc.select("meta[property=\"og:title\"]").first().attr("content");
+ return initialData.getObject("header").getObject("c4TabbedHeaderRenderer").getString("title");
} catch (Exception e) {
throw new ParsingException("Could not get channel name", e);
}
@@ -107,7 +104,10 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
@Override
public String getAvatarUrl() throws ParsingException {
try {
- return doc.select("img[class=\"channel-header-profile-image\"]").first().attr("abs:src");
+ String url = initialData.getObject("header").getObject("c4TabbedHeaderRenderer").getObject("avatar")
+ .getArray("thumbnails").getObject(0).getString("url");
+
+ return fixThumbnailUrl(url);
} catch (Exception e) {
throw new ParsingException("Could not get avatar", e);
}
@@ -116,13 +116,18 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
@Override
public String getBannerUrl() throws ParsingException {
try {
- Element el = doc.select("div[id=\"gh-banner\"]").first().select("style").first();
- String cssContent = el.html();
- String url = "https:" + Parser.matchGroup1("url\\(([^)]+)\\)", cssContent);
+ String url = null;
+ try {
+ url = initialData.getObject("header").getObject("c4TabbedHeaderRenderer").getObject("banner")
+ .getArray("thumbnails").getObject(0).getString("url");
+ } catch (Exception ignored) {}
+ if (url == null || url.contains("s.ytimg.com") || url.contains("default_banner")) {
+ return null;
+ }
- return url.contains("s.ytimg.com") || url.contains("default_banner") ? null : url;
+ return fixThumbnailUrl(url);
} catch (Exception e) {
- throw new ParsingException("Could not get Banner", e);
+ throw new ParsingException("Could not get banner", e);
}
}
@@ -137,25 +142,27 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
@Override
public long getSubscriberCount() throws ParsingException {
-
- final Element el = doc.select("span[class*=\"yt-subscription-button-subscriber-count\"]").first();
- if (el != null) {
- String elTitle = el.attr("title");
+ final JsonObject subscriberInfo = initialData.getObject("header").getObject("c4TabbedHeaderRenderer").getObject("subscriberCountText");
+ if (subscriberInfo != null) {
try {
- return Utils.mixedNumberWordToLong(elTitle);
+ return Utils.mixedNumberWordToLong(getTextFromObject(subscriberInfo));
} catch (NumberFormatException e) {
throw new ParsingException("Could not get subscriber count", e);
}
} else {
- // If the element is null, the channel have the subscriber count disabled
- return -1;
+ // If there's no subscribe button, the channel has the subscriber count disabled
+ if (initialData.getObject("header").getObject("c4TabbedHeaderRenderer").getObject("subscribeButton") == null) {
+ return -1;
+ } else {
+ return 0;
+ }
}
}
@Override
public String getDescription() throws ParsingException {
try {
- return doc.select("meta[name=\"description\"]").first().attr("content");
+ return initialData.getObject("metadata").getObject("channelMetadataRenderer").getString("description");
} catch (Exception e) {
throw new ParsingException("Could not get channel description", e);
}
@@ -165,8 +172,14 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
@Override
public InfoItemsPage getInitialPage() throws ExtractionException {
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
- Element ul = doc.select("ul[id=\"browse-items-primary\"]").first();
- collectStreamsFrom(collector, ul);
+
+ if (getVideoTab() != null) {
+ JsonArray videos = getVideoTab().getObject("content").getObject("sectionListRenderer").getArray("contents")
+ .getObject(0).getObject("itemSectionRenderer").getArray("contents").getObject(0)
+ .getObject("gridRenderer").getArray("items");
+ collectStreamsFrom(collector, videos);
+ }
+
return new InfoItemsPage<>(collector, getNextPageUrl());
}
@@ -181,106 +194,81 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
fetchPage();
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
- JsonObject ajaxJson;
- try {
- final String response = getDownloader().get(pageUrl, getExtractorLocalization()).responseBody();
- ajaxJson = JsonParser.object().from(response);
- } catch (JsonParserException pe) {
- throw new ParsingException("Could not parse json data for next streams", pe);
- }
+ final JsonArray ajaxJson = getJsonResponse(pageUrl, getExtractorLocalization());
- final Document ajaxHtml = Jsoup.parse(ajaxJson.getString("content_html"), pageUrl);
- collectStreamsFrom(collector, ajaxHtml.select("body").first());
+ JsonObject sectionListContinuation = ajaxJson.getObject(1).getObject("response")
+ .getObject("continuationContents").getObject("gridContinuation");
- return new InfoItemsPage<>(collector, getNextPageUrlFromAjaxPage(ajaxJson, pageUrl));
+ collectStreamsFrom(collector, sectionListContinuation.getArray("items"));
+
+ return new InfoItemsPage<>(collector, getNextPageUrlFrom(sectionListContinuation.getArray("continuations")));
}
- private String getNextPageUrlFromAjaxPage(final JsonObject ajaxJson, final String pageUrl)
- throws ParsingException {
- String loadMoreHtmlDataRaw = ajaxJson.getString("load_more_widget_html");
- if (!loadMoreHtmlDataRaw.isEmpty()) {
- return getNextPageUrlFrom(Jsoup.parse(loadMoreHtmlDataRaw, pageUrl));
- } else {
- return "";
- }
+
+ private String getNextPageUrlFrom(JsonArray continuations) {
+ if (continuations == null) return "";
+
+ JsonObject nextContinuationData = continuations.getObject(0).getObject("nextContinuationData");
+ String continuation = nextContinuationData.getString("continuation");
+ String clickTrackingParams = nextContinuationData.getString("clickTrackingParams");
+ return "https://www.youtube.com/browse_ajax?ctoken=" + continuation + "&continuation=" + continuation
+ + "&itct=" + clickTrackingParams;
}
- private String getNextPageUrlFrom(Document d) throws ParsingException {
- try {
- Element button = d.select("button[class*=\"yt-uix-load-more\"]").first();
- if (button != null) {
- return button.attr("abs:data-uix-load-more-href");
- } else {
- // Sometimes channels are simply so small, they don't have a more streams/videos
- return "";
- }
- } catch (Exception e) {
- throw new ParsingException("Could not get next page url", e);
- }
- }
-
- private void collectStreamsFrom(StreamInfoItemsCollector collector, Element element) throws ParsingException {
+ private void collectStreamsFrom(StreamInfoItemsCollector collector, JsonArray videos) throws ParsingException {
collector.reset();
final String uploaderName = getName();
final String uploaderUrl = getUrl();
final TimeAgoParser timeAgoParser = getTimeAgoParser();
- for (final Element li : element.children()) {
- if (li.select("div[class=\"feed-item-dismissable\"]").first() != null) {
- collector.commit(new YoutubeStreamInfoItemExtractor(li, timeAgoParser) {
+ for (Object video : videos) {
+ if (((JsonObject) video).getObject("gridVideoRenderer") != null) {
+ collector.commit(new YoutubeStreamInfoItemExtractor(
+ ((JsonObject) video).getObject("gridVideoRenderer"), timeAgoParser) {
@Override
- public String getUrl() throws ParsingException {
- try {
- Element el = li.select("div[class=\"feed-item-dismissable\"]").first();
- Element dl = el.select("h3").first().select("a").first();
- return dl.attr("abs:href");
- } catch (Exception e) {
- throw new ParsingException("Could not get web page url for the video", e);
- }
- }
-
- @Override
- public String getName() throws ParsingException {
- try {
- Element el = li.select("div[class=\"feed-item-dismissable\"]").first();
- Element dl = el.select("h3").first().select("a").first();
- return dl.text();
- } catch (Exception e) {
- throw new ParsingException("Could not get title", e);
- }
- }
-
- @Override
- public String getUploaderName() throws ParsingException {
+ public String getUploaderName() {
return uploaderName;
}
@Override
- public String getUploaderUrl() throws ParsingException {
+ public String getUploaderUrl() {
return uploaderUrl;
}
-
- @Override
- public String getThumbnailUrl() throws ParsingException {
- try {
- String url;
- Element te = li.select("span[class=\"yt-thumb-clip\"]").first()
- .select("img").first();
- url = te.attr("abs:src");
- // Sometimes youtube sends links to gif files which somehow seem to not exist
- // anymore. Items with such gif also offer a secondary image source. So we are going
- // to use that if we've caught such an item.
- if (url.contains(".gif")) {
- url = te.attr("abs:data-thumb");
- }
- return url;
- } catch (Exception e) {
- throw new ParsingException("Could not get thumbnail url", e);
- }
- }
});
}
}
}
+
+ private JsonObject getVideoTab() throws ParsingException {
+ if (this.videoTab != null) return this.videoTab;
+
+ JsonArray tabs = initialData.getObject("contents").getObject("twoColumnBrowseResultsRenderer")
+ .getArray("tabs");
+ JsonObject videoTab = null;
+
+ for (Object tab : tabs) {
+ if (((JsonObject) tab).getObject("tabRenderer") != null) {
+ if (((JsonObject) tab).getObject("tabRenderer").getString("title").equals("Videos")) {
+ videoTab = ((JsonObject) tab).getObject("tabRenderer");
+ break;
+ }
+ }
+ }
+
+ if (videoTab == null) {
+ throw new ParsingException("Could not find Videos tab");
+ }
+
+ try {
+ if (getTextFromObject(videoTab.getObject("content").getObject("sectionListRenderer")
+ .getArray("contents").getObject(0).getObject("itemSectionRenderer")
+ .getArray("contents").getObject(0).getObject("messageRenderer")
+ .getObject("text")).equals("This channel has no videos."))
+ return null;
+ } catch (Exception ignored) {}
+
+ this.videoTab = videoTab;
+ return videoTab;
+ }
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelInfoItemExtractor.java
index a687c050..29aa045b 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelInfoItemExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelInfoItemExtractor.java
@@ -1,12 +1,14 @@
package org.schabi.newpipe.extractor.services.youtube.extractors;
-import org.jsoup.nodes.Element;
+import com.grack.nanojson.JsonObject;
+
import org.schabi.newpipe.extractor.channel.ChannelInfoItemExtractor;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
+import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory;
import org.schabi.newpipe.extractor.utils.Utils;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.fixThumbnailUrl;
+import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getTextFromObject;
/*
* Created by Christian Schabesberger on 12.02.17.
@@ -29,87 +31,67 @@ import java.util.regex.Pattern;
*/
public class YoutubeChannelInfoItemExtractor implements ChannelInfoItemExtractor {
- private final Element el;
+ private JsonObject channelInfoItem;
- public YoutubeChannelInfoItemExtractor(Element el) {
- this.el = el;
+ public YoutubeChannelInfoItemExtractor(JsonObject channelInfoItem) {
+ this.channelInfoItem = channelInfoItem;
}
@Override
public String getThumbnailUrl() throws ParsingException {
- Element img = el.select("span[class*=\"yt-thumb-simple\"]").first()
- .select("img").first();
+ try {
+ String url = channelInfoItem.getObject("thumbnail").getArray("thumbnails").getObject(0).getString("url");
- String url = img.attr("abs:src");
-
- if (url.contains("gif")) {
- url = img.attr("abs:data-thumb");
+ return fixThumbnailUrl(url);
+ } catch (Exception e) {
+ throw new ParsingException("Could not get thumbnail url", e);
}
- return url;
}
@Override
public String getName() throws ParsingException {
- return el.select("a[class*=\"yt-uix-tile-link\"]").first()
- .text();
+ try {
+ return getTextFromObject(channelInfoItem.getObject("title"));
+ } catch (Exception e) {
+ throw new ParsingException("Could not get name", e);
+ }
}
@Override
public String getUrl() throws ParsingException {
try {
- String buttonTrackingUrl = el.select("button[class*=\"yt-uix-button\"]").first()
- .attr("abs:data-href");
-
- Pattern channelIdPattern = Pattern.compile("(?:.*?)\\%252Fchannel\\%252F([A-Za-z0-9\\-\\_]+)(?:.*)");
- Matcher match = channelIdPattern.matcher(buttonTrackingUrl);
-
- if (match.matches()) {
- return YoutubeChannelExtractor.CHANNEL_URL_BASE + match.group(1);
- }
- } catch(Exception ignored) {}
-
- // fallback method for channels without "Subscribe" button (or just in case yt changes things)
- // provides an url with "/user/NAME", inconsistent with stream and channel extractor: tests will fail
- try {
- return el.select("a[class*=\"yt-uix-tile-link\"]").first()
- .attr("abs:href");
+ String id = "channel/" + channelInfoItem.getString("channelId");
+ return YoutubeChannelLinkHandlerFactory.getInstance().getUrl(id);
} catch (Exception e) {
- throw new ParsingException("Could not get channel url", e);
+ throw new ParsingException("Could not get url", e);
}
}
@Override
public long getSubscriberCount() throws ParsingException {
- final Element subsEl = el.select("span[class*=\"yt-subscriber-count\"]").first();
- if (subsEl != null) {
- try {
- return Long.parseLong(Utils.removeNonDigitCharacters(subsEl.text()));
- } catch (NumberFormatException e) {
- throw new ParsingException("Could not get subscriber count", e);
- }
- } else {
- // If the element is null, the channel have the subscriber count disabled
- return -1;
+ try {
+ String subscribers = getTextFromObject(channelInfoItem.getObject("subscriberCountText"));
+ return Utils.mixedNumberWordToLong(subscribers);
+ } catch (Exception e) {
+ throw new ParsingException("Could not get subscriber count", e);
}
}
@Override
public long getStreamCount() throws ParsingException {
- Element metaEl = el.select("ul[class*=\"yt-lockup-meta-info\"]").first();
- if (metaEl == null) {
- return 0;
- } else {
- return Long.parseLong(Utils.removeNonDigitCharacters(metaEl.text()));
+ try {
+ return Long.parseLong(Utils.removeNonDigitCharacters(getTextFromObject(channelInfoItem.getObject("videoCountText"))));
+ } catch (Exception e) {
+ throw new ParsingException("Could not get stream count", e);
}
}
@Override
public String getDescription() throws ParsingException {
- Element desEl = el.select("div[class*=\"yt-lockup-description\"]").first();
- if (desEl == null) {
- return "";
- } else {
- return desEl.text();
+ try {
+ return getTextFromObject(channelInfoItem.getObject("descriptionSnippet"));
+ } catch (Exception e) {
+ throw new ParsingException("Could not get description", e);
}
}
}
diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsExtractor.java
index 1c377cc5..78eb59f3 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsExtractor.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsExtractor.java
@@ -3,7 +3,6 @@ package org.schabi.newpipe.extractor.services.youtube.extractors;
import com.grack.nanojson.JsonArray;
import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser;
-import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.comments.CommentsExtractor;
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
@@ -22,7 +21,9 @@ import javax.annotation.Nonnull;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
-import java.util.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.regex.Pattern;
import static java.util.Collections.singletonList;
@@ -58,14 +59,14 @@ public class YoutubeCommentsExtractor extends CommentsExtractor {
}
private String getNextPageUrl(JsonObject ajaxJson) throws IOException, ParsingException {
-
+
JsonArray arr;
try {
arr = JsonUtils.getArray(ajaxJson, "response.continuationContents.commentSectionContinuation.continuations");
} catch (Exception e) {
return "";
}
- if(arr.isEmpty()) {
+ if (arr.isEmpty()) {
return "";
}
String continuation;
@@ -107,11 +108,11 @@ public class YoutubeCommentsExtractor extends CommentsExtractor {
}
private void collectCommentsFrom(CommentsInfoItemsCollector collector, JsonObject ajaxJson) throws ParsingException {
-
+
JsonArray contents;
try {
contents = JsonUtils.getArray(ajaxJson, "response.continuationContents.commentSectionContinuation.items");
- }catch(Exception e) {
+ } catch (Exception e) {
//no comments
return;
}
@@ -119,12 +120,12 @@ public class YoutubeCommentsExtractor extends CommentsExtractor {
List
+ *
* @param numberWord string to be converted to a long
* @return a long
* @throws NumberFormatException
@@ -82,9 +86,6 @@ public class Utils {
}
}
- private static final String HTTP = "http://";
- private static final String HTTPS = "https://";
-
public static String replaceHttpWithHttps(final String url) {
if (url == null) return null;
@@ -165,17 +166,17 @@ public class Utils {
return setsNoPort || usesDefaultPort;
}
-
+
public static String removeUTF8BOM(String s) {
if (s.startsWith("\uFEFF")) {
s = s.substring(1);
}
if (s.endsWith("\uFEFF")) {
- s = s.substring(0, s.length()-1);
+ s = s.substring(0, s.length() - 1);
}
return s;
}
-
+
public static String getBaseUrl(String url) throws ParsingException {
URL uri;
try {
@@ -185,5 +186,4 @@ public class Utils {
}
return uri.getProtocol() + "://" + uri.getAuthority();
}
-
}
\ No newline at end of file
diff --git a/extractor/src/test/java/org/schabi/newpipe/DownloaderTestImpl.java b/extractor/src/test/java/org/schabi/newpipe/DownloaderTestImpl.java
index 948975a0..c93f31b7 100644
--- a/extractor/src/test/java/org/schabi/newpipe/DownloaderTestImpl.java
+++ b/extractor/src/test/java/org/schabi/newpipe/DownloaderTestImpl.java
@@ -20,7 +20,7 @@ import java.util.Map;
public class DownloaderTestImpl extends Downloader {
- private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0";
+ private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Firefox/68.0";
private static final String DEFAULT_HTTP_ACCEPT_LANGUAGE = "en";
private static DownloaderTestImpl instance = null;
@@ -99,19 +99,25 @@ public class DownloaderTestImpl extends Downloader {
final int responseCode = connection.getResponseCode();
final String responseMessage = connection.getResponseMessage();
final Map> responseHeaders = connection.getHeaderFields();
+ final String latestUrl = connection.getURL().toString();
- return new Response(responseCode, responseMessage, responseHeaders, response.toString());
+ return new Response(responseCode, responseMessage, responseHeaders, response.toString(), latestUrl);
} catch (Exception e) {
+ final int responseCode = connection.getResponseCode();
+
/*
* HTTP 429 == Too Many Request
* Receive from Youtube.com = ReCaptcha challenge request
* See : https://github.com/rg3/youtube-dl/issues/5138
*/
- if (connection.getResponseCode() == 429) {
+ if (responseCode == 429) {
throw new ReCaptchaException("reCaptcha Challenge requested", url);
+ } else if (responseCode != -1) {
+ final String latestUrl = connection.getURL().toString();
+ return new Response(responseCode, connection.getResponseMessage(), connection.getHeaderFields(), null, latestUrl);
}
- throw new IOException(connection.getResponseCode() + " " + connection.getResponseMessage(), e);
+ throw new IOException("Error occurred while fetching the content", e);
} finally {
if (outputStream != null) outputStream.close();
if (input != null) input.close();
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultTests.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultTests.java
index 8cf27094..6c2dd9ef 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultTests.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultTests.java
@@ -2,20 +2,29 @@ package org.schabi.newpipe.extractor.services;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor;
+import org.schabi.newpipe.extractor.NewPipe;
+import org.schabi.newpipe.extractor.StreamingService;
+import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
+import org.schabi.newpipe.extractor.exceptions.ParsingException;
+import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
+import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
import org.schabi.newpipe.extractor.localization.DateWrapper;
+import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import java.util.Calendar;
import java.util.List;
+import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.*;
+import static org.schabi.newpipe.extractor.StreamingService.*;
public final class DefaultTests {
- public static void defaultTestListOfItems(int expectedServiceId, List extends InfoItem> itemsList, List errors) {
- assertTrue("List of items is empty", !itemsList.isEmpty());
+ public static void defaultTestListOfItems(StreamingService expectedService, List extends InfoItem> itemsList, List errors) throws ParsingException {
+ assertFalse("List of items is empty", itemsList.isEmpty());
assertFalse("List of items contains a null element", itemsList.contains(null));
- assertEmptyErrors("Errors during stream list extraction", errors);
+ assertEmptyErrors("Errors during extraction", errors);
for (InfoItem item : itemsList) {
assertIsSecureUrl(item.getUrl());
@@ -23,12 +32,17 @@ public final class DefaultTests {
assertIsSecureUrl(item.getThumbnailUrl());
}
assertNotNull("InfoItem type not set: " + item, item.getInfoType());
- assertEquals("Service id doesn't match: " + item, expectedServiceId, item.getServiceId());
+ assertEquals("Unexpected item service id", expectedService.getServiceId(), item.getServiceId());
+ assertNotEmpty("Item name not set: " + item, item.getName());
if (item instanceof StreamInfoItem) {
StreamInfoItem streamInfoItem = (StreamInfoItem) item;
assertNotEmpty("Uploader name not set: " + item, streamInfoItem.getUploaderName());
assertNotEmpty("Uploader url not set: " + item, streamInfoItem.getUploaderUrl());
+ assertIsSecureUrl(streamInfoItem.getUploaderUrl());
+
+ assertExpectedLinkType(expectedService, streamInfoItem.getUrl(), LinkType.STREAM);
+ assertExpectedLinkType(expectedService, streamInfoItem.getUploaderUrl(), LinkType.CHANNEL);
final String textualUploadDate = streamInfoItem.getTextualUploadDate();
if (textualUploadDate != null && !textualUploadDate.isEmpty()) {
@@ -37,34 +51,56 @@ public final class DefaultTests {
assertTrue("Upload date not in the past", uploadDate.date().before(Calendar.getInstance()));
}
+ } else if (item instanceof ChannelInfoItem) {
+ final ChannelInfoItem channelInfoItem = (ChannelInfoItem) item;
+ assertExpectedLinkType(expectedService, channelInfoItem.getUrl(), LinkType.CHANNEL);
+
+ } else if (item instanceof PlaylistInfoItem) {
+ final PlaylistInfoItem playlistInfoItem = (PlaylistInfoItem) item;
+ assertExpectedLinkType(expectedService, playlistInfoItem.getUrl(), LinkType.PLAYLIST);
}
}
}
- public static ListExtractor.InfoItemsPage defaultTestRelatedItems(ListExtractor extractor, int expectedServiceId) throws Exception {
+ private static void assertExpectedLinkType(StreamingService expectedService, String url, LinkType expectedLinkType) throws ParsingException {
+ final LinkType linkTypeByUrl = expectedService.getLinkTypeByUrl(url);
+
+ assertNotEquals("Url is not recognized by its own service: \"" + url + "\"",
+ LinkType.NONE, linkTypeByUrl);
+ assertEquals("Service returned wrong link type for: \"" + url + "\"",
+ expectedLinkType, linkTypeByUrl);
+ }
+
+ public static void assertNoMoreItems(ListExtractor extractor) throws Exception {
+ assertFalse("More items available when it shouldn't", extractor.hasNextPage());
+ final String nextPageUrl = extractor.getNextPageUrl();
+ assertTrue("Next page is not empty or null", nextPageUrl == null || nextPageUrl.isEmpty());
+ }
+
+ public static ListExtractor.InfoItemsPage defaultTestRelatedItems(ListExtractor extractor) throws Exception {
final ListExtractor.InfoItemsPage page = extractor.getInitialPage();
final List itemsList = page.getItems();
List errors = page.getErrors();
- defaultTestListOfItems(expectedServiceId, itemsList, errors);
+ defaultTestListOfItems(extractor.getService(), itemsList, errors);
return page;
}
- public static ListExtractor.InfoItemsPage defaultTestMoreItems(ListExtractor extractor, int expectedServiceId) throws Exception {
+ public static ListExtractor.InfoItemsPage defaultTestMoreItems(ListExtractor extractor) throws Exception {
assertTrue("Doesn't have more items", extractor.hasNextPage());
ListExtractor.InfoItemsPage nextPage = extractor.getPage(extractor.getNextPageUrl());
final List items = nextPage.getItems();
- assertTrue("Next page is empty", !items.isEmpty());
+ assertFalse("Next page is empty", items.isEmpty());
assertEmptyErrors("Next page have errors", nextPage.getErrors());
- defaultTestListOfItems(expectedServiceId, nextPage.getItems(), nextPage.getErrors());
+ defaultTestListOfItems(extractor.getService(), nextPage.getItems(), nextPage.getErrors());
return nextPage;
}
- public static void defaultTestGetPageInNewExtractor(ListExtractor extends InfoItem> extractor, ListExtractor extends InfoItem> newExtractor, int expectedServiceId) throws Exception {
+ public static void defaultTestGetPageInNewExtractor(ListExtractor extends InfoItem> extractor, ListExtractor extends InfoItem> newExtractor) throws Exception {
final String nextPageUrl = extractor.getNextPageUrl();
final ListExtractor.InfoItemsPage extends InfoItem> page = newExtractor.getPage(nextPageUrl);
- defaultTestListOfItems(expectedServiceId, page.getItems(), page.getErrors());
+ defaultTestListOfItems(extractor.getService(), page.getItems(), page.getErrors());
}
}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCConferenceExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCConferenceExtractorTest.java
index b9c67c4e..258a55b0 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCConferenceExtractorTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCConferenceExtractorTest.java
@@ -4,47 +4,86 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.DownloaderTestImpl;
import org.schabi.newpipe.extractor.NewPipe;
-import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCConferenceExtractor;
import static junit.framework.TestCase.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.MediaCCC;
/**
* Test {@link MediaCCCConferenceExtractor}
*/
public class MediaCCCConferenceExtractorTest {
- private static ChannelExtractor extractor;
- @BeforeClass
- public static void setUpClass() throws Exception {
- NewPipe.init(DownloaderTestImpl.getInstance());
- extractor = MediaCCC.getChannelExtractor("https://api.media.ccc.de/public/conferences/froscon2017");
- extractor.fetchPage();
+ public static class FrOSCon2017 {
+ private static MediaCCCConferenceExtractor extractor;
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ NewPipe.init(DownloaderTestImpl.getInstance());
+ extractor = (MediaCCCConferenceExtractor) MediaCCC.getChannelExtractor("https://media.ccc.de/c/froscon2017");
+ extractor.fetchPage();
+ }
+
+ @Test
+ public void testName() throws Exception {
+ assertEquals("FrOSCon 2017", extractor.getName());
+ }
+
+ @Test
+ public void testGetUrl() throws Exception {
+ assertEquals("https://api.media.ccc.de/public/conferences/froscon2017", extractor.getUrl());
+ }
+
+ @Test
+ public void testGetOriginalUrl() throws Exception {
+ assertEquals("https://media.ccc.de/c/froscon2017", extractor.getOriginalUrl());
+ }
+
+ @Test
+ public void testGetThumbnailUrl() throws Exception {
+ assertEquals("https://static.media.ccc.de/media/events/froscon/2017/logo.png", extractor.getAvatarUrl());
+ }
+
+ @Test
+ public void testGetInitalPage() throws Exception {
+ assertEquals(97, extractor.getInitialPage().getItems().size());
+ }
}
- @Test
- public void testName() throws Exception {
- assertEquals("FrOSCon 2017", extractor.getName());
- }
+ public static class Oscal2019 {
+ private static MediaCCCConferenceExtractor extractor;
- @Test
- public void testGetUrl() throws Exception {
- assertEquals("https://api.media.ccc.de/public/conferences/froscon2017", extractor.getUrl());
- }
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ NewPipe.init(DownloaderTestImpl.getInstance());
+ extractor = (MediaCCCConferenceExtractor) MediaCCC.getChannelExtractor("https://media.ccc.de/c/oscal19");
+ extractor.fetchPage();
+ }
- @Test
- public void testGetOriginalUrl() throws Exception {
- assertEquals("https://media.ccc.de/c/froscon2017", extractor.getOriginalUrl());
- }
+ @Test
+ public void testName() throws Exception {
+ assertEquals("Open Source Conference Albania 2019", extractor.getName());
+ }
- @Test
- public void testGetThumbnailUrl() throws Exception {
- assertEquals("https://static.media.ccc.de/media/events/froscon/2017/logo.png", extractor.getAvatarUrl());
- }
+ @Test
+ public void testGetUrl() throws Exception {
+ assertEquals("https://api.media.ccc.de/public/conferences/oscal19", extractor.getUrl());
+ }
- @Test
- public void testGetInitalPage() throws Exception {
- assertEquals(97,extractor.getInitialPage().getItems().size());
+ @Test
+ public void testGetOriginalUrl() throws Exception {
+ assertEquals("https://media.ccc.de/c/oscal19", extractor.getOriginalUrl());
+ }
+
+ @Test
+ public void testGetThumbnailUrl() throws Exception {
+ assertEquals("https://static.media.ccc.de/media/events/oscal/2019/oscal-19.png", extractor.getAvatarUrl());
+ }
+
+ @Test
+ public void testGetInitalPage() throws Exception {
+ assertTrue(extractor.getInitialPage().getItems().size() >= 21);
+ }
}
}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCConferenceListExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCConferenceListExtractorTest.java
index 252e4dbb..90ebf028 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCConferenceListExtractorTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCConferenceListExtractorTest.java
@@ -24,7 +24,7 @@ public class MediaCCCConferenceListExtractorTest {
@BeforeClass
public static void setUpClass() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
- extractor = MediaCCC.getKioskList().getDefaultKioskExtractor();
+ extractor = MediaCCC.getKioskList().getDefaultKioskExtractor();
extractor.fetchPage();
}
@@ -49,8 +49,8 @@ public class MediaCCCConferenceListExtractorTest {
}
private boolean contains(List itemList, String name) {
- for(InfoItem item : itemList) {
- if(item.getName().equals(name))
+ for (InfoItem item : itemList) {
+ if (item.getName().equals(name))
return true;
}
return false;
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCOggTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCOggTest.java
index 781f9138..25116af3 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCOggTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCOggTest.java
@@ -22,7 +22,7 @@ public class MediaCCCOggTest {
public static void setUpClass() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
- extractor = MediaCCC.getStreamExtractor("https://api.media.ccc.de/public/events/1317");
+ extractor = MediaCCC.getStreamExtractor("https://api.media.ccc.de/public/events/1317");
extractor.fetchPage();
}
@@ -33,7 +33,7 @@ public class MediaCCCOggTest {
@Test
public void getAudioStreamsContainOgg() throws Exception {
- for(AudioStream stream : extractor.getAudioStreams()) {
+ for (AudioStream stream : extractor.getAudioStreams()) {
assertEquals("OGG", stream.getFormat().toString());
}
}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCSearchExtractorAllTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCSearchExtractorAllTest.java
index dc38338e..cd33c562 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCSearchExtractorAllTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCSearchExtractorAllTest.java
@@ -28,7 +28,7 @@ public class MediaCCCSearchExtractorAllTest {
@BeforeClass
public static void setUpClass() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
- extractor = MediaCCC.getSearchExtractor( new MediaCCCSearchQueryHandlerFactory()
+ extractor = MediaCCC.getSearchExtractor(new MediaCCCSearchQueryHandlerFactory()
.fromQuery("c3", Arrays.asList(new String[0]), ""));
extractor.fetchPage();
itemsPage = extractor.getInitialPage();
@@ -37,8 +37,8 @@ public class MediaCCCSearchExtractorAllTest {
@Test
public void testIfChannelInfoItemsAvailable() {
boolean isAvialable = false;
- for(InfoItem item : itemsPage.getItems()) {
- if(item instanceof ChannelInfoItem) {
+ for (InfoItem item : itemsPage.getItems()) {
+ if (item instanceof ChannelInfoItem) {
isAvialable = true;
}
}
@@ -48,8 +48,8 @@ public class MediaCCCSearchExtractorAllTest {
@Test
public void testIfStreamInfoitemsAvailable() {
boolean isAvialable = false;
- for(InfoItem item : itemsPage.getItems()) {
- if(item instanceof StreamInfoItem) {
+ for (InfoItem item : itemsPage.getItems()) {
+ if (item instanceof StreamInfoItem) {
isAvialable = true;
}
}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCSearchExtractorConferencesTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCSearchExtractorConferencesTest.java
index 18fbc234..f9ce2334 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCSearchExtractorConferencesTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCSearchExtractorConferencesTest.java
@@ -27,7 +27,7 @@ public class MediaCCCSearchExtractorConferencesTest {
@BeforeClass
public static void setUpClass() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
- extractor = MediaCCC.getSearchExtractor( new MediaCCCSearchQueryHandlerFactory()
+ extractor = MediaCCC.getSearchExtractor(new MediaCCCSearchQueryHandlerFactory()
.fromQuery("c3", Arrays.asList(new String[]{"conferences"}), ""));
extractor.fetchPage();
itemsPage = extractor.getInitialPage();
@@ -35,7 +35,7 @@ public class MediaCCCSearchExtractorConferencesTest {
@Test
public void testReturnTypeChannel() {
- for(InfoItem item : itemsPage.getItems()) {
+ for (InfoItem item : itemsPage.getItems()) {
assertTrue("Item is not of type channel", item instanceof ChannelInfoItem);
}
}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCSearchExtractorEventsTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCSearchExtractorEventsTest.java
index 1ed65a8d..29f90caf 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCSearchExtractorEventsTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCSearchExtractorEventsTest.java
@@ -28,7 +28,7 @@ public class MediaCCCSearchExtractorEventsTest {
@BeforeClass
public static void setUpClass() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
- extractor = MediaCCC.getSearchExtractor( new MediaCCCSearchQueryHandlerFactory()
+ extractor = MediaCCC.getSearchExtractor(new MediaCCCSearchQueryHandlerFactory()
.fromQuery("linux", Arrays.asList(new String[]{"events"}), ""));
extractor.fetchPage();
itemsPage = extractor.getInitialPage();
@@ -65,7 +65,7 @@ public class MediaCCCSearchExtractorEventsTest {
@Test
public void testReturnTypeStream() throws Exception {
- for(InfoItem item : itemsPage.getItems()) {
+ for (InfoItem item : itemsPage.getItems()) {
assertTrue("Item is not of type StreamInfoItem", item instanceof StreamInfoItem);
}
}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCStreamExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCStreamExtractorTest.java
index 71b1e779..8120e07a 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCStreamExtractorTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCStreamExtractorTest.java
@@ -6,96 +6,201 @@ import org.junit.Test;
import org.schabi.newpipe.DownloaderTestImpl;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
-import org.schabi.newpipe.extractor.services.BaseExtractorTest;
import org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCStreamExtractor;
-import org.schabi.newpipe.extractor.stream.StreamExtractor;
+import org.schabi.newpipe.extractor.stream.AudioStream;
+import org.schabi.newpipe.extractor.stream.VideoStream;
+import org.schabi.newpipe.extractor.utils.UtilsTest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
+import java.util.List;
import static java.util.Objects.requireNonNull;
import static junit.framework.TestCase.assertEquals;
+import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
import static org.schabi.newpipe.extractor.ServiceList.MediaCCC;
/**
* Test {@link MediaCCCStreamExtractor}
*/
-public class MediaCCCStreamExtractorTest implements BaseExtractorTest {
- private static StreamExtractor extractor;
+public class MediaCCCStreamExtractorTest {
- @BeforeClass
- public static void setUpClass() throws Exception {
- NewPipe.init(DownloaderTestImpl.getInstance());
+ public static class Gpn18Tmux {
+ private static MediaCCCStreamExtractor extractor;
- extractor = MediaCCC.getStreamExtractor("https://api.media.ccc.de/public/events/8afc16c2-d76a-53f6-85e4-90494665835d");
- extractor.fetchPage();
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ NewPipe.init(DownloaderTestImpl.getInstance());
+
+ extractor = (MediaCCCStreamExtractor) MediaCCC.getStreamExtractor("https://media.ccc.de/v/gpn18-105-tmux-warum-ein-schwarzes-fenster-am-bildschirm-reicht");
+ extractor.fetchPage();
+ }
+
+ @Test
+ public void testServiceId() throws Exception {
+ assertEquals(2, extractor.getServiceId());
+ }
+
+ @Test
+ public void testName() throws Exception {
+ assertEquals("tmux - Warum ein schwarzes Fenster am Bildschirm reicht", extractor.getName());
+ }
+
+ @Test
+ public void testId() throws Exception {
+ assertEquals("gpn18-105-tmux-warum-ein-schwarzes-fenster-am-bildschirm-reicht", extractor.getId());
+ }
+
+ @Test
+ public void testUrl() throws Exception {
+ assertIsSecureUrl(extractor.getUrl());
+ assertEquals("https://api.media.ccc.de/public/events/gpn18-105-tmux-warum-ein-schwarzes-fenster-am-bildschirm-reicht", extractor.getUrl());
+ }
+
+ @Test
+ public void testOriginalUrl() throws Exception {
+ assertIsSecureUrl(extractor.getOriginalUrl());
+ assertEquals("https://media.ccc.de/v/gpn18-105-tmux-warum-ein-schwarzes-fenster-am-bildschirm-reicht", extractor.getOriginalUrl());
+ }
+
+ @Test
+ public void testThumbnail() throws Exception {
+ assertIsSecureUrl(extractor.getThumbnailUrl());
+ assertEquals("https://static.media.ccc.de/media/events/gpn/gpn18/105-hd.jpg", extractor.getThumbnailUrl());
+ }
+
+ @Test
+ public void testUploaderName() throws Exception {
+ assertEquals("gpn18", extractor.getUploaderName());
+ }
+
+ @Test
+ public void testUploaderUrl() throws Exception {
+ assertIsSecureUrl(extractor.getUploaderUrl());
+ assertEquals("https://api.media.ccc.de/public/conferences/gpn18", extractor.getUploaderUrl());
+ }
+
+ @Test
+ public void testUploaderAvatarUrl() throws Exception {
+ assertIsSecureUrl(extractor.getUploaderAvatarUrl());
+ assertEquals("https://static.media.ccc.de/media/events/gpn/gpn18/logo.png", extractor.getUploaderAvatarUrl());
+ }
+
+ @Test
+ public void testVideoStreams() throws Exception {
+ List videoStreamList = extractor.getVideoStreams();
+ assertEquals(4, videoStreamList.size());
+ for (VideoStream stream : videoStreamList) {
+ assertIsSecureUrl(stream.getUrl());
+ }
+ }
+
+ @Test
+ public void testAudioStreams() throws Exception {
+ List audioStreamList = extractor.getAudioStreams();
+ assertEquals(2, audioStreamList.size());
+ for (AudioStream stream : audioStreamList) {
+ assertIsSecureUrl(stream.getUrl());
+ }
+ }
+
+ @Test
+ public void testGetTextualUploadDate() throws ParsingException {
+ Assert.assertEquals("2018-05-11T02:00:00.000+02:00", extractor.getTextualUploadDate());
+ }
+
+ @Test
+ public void testGetUploadDate() throws ParsingException, ParseException {
+ final Calendar instance = Calendar.getInstance();
+ instance.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("2018-05-11"));
+ assertEquals(instance, requireNonNull(extractor.getUploadDate()).date());
+ }
}
- @Override
- public void testServiceId() throws Exception {
- assertEquals(2, extractor.getServiceId());
- }
+ public static class _36c3PrivacyMessaging {
+ private static MediaCCCStreamExtractor extractor;
- @Override
- public void testName() throws Exception {
- assertEquals("tmux - Warum ein schwarzes Fenster am Bildschirm reicht", extractor.getName());
- }
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ NewPipe.init(DownloaderTestImpl.getInstance());
+ extractor = (MediaCCCStreamExtractor) MediaCCC.getStreamExtractor("https://media.ccc.de/v/36c3-10565-what_s_left_for_private_messaging");
+ extractor.fetchPage();
+ }
- @Override
- public void testId() throws Exception {
- assertEquals("", extractor.getId());
- }
+ @Test
+ public void testName() throws Exception {
+ assertEquals("What's left for private messaging?", extractor.getName());
+ }
- @Override
- public void testUrl() throws Exception {
- assertEquals("", extractor.getUrl());
- }
+ @Test
+ public void testId() throws Exception {
+ assertEquals("36c3-10565-what_s_left_for_private_messaging", extractor.getId());
+ }
- @Override
- public void testOriginalUrl() throws Exception {
- assertEquals("", extractor.getOriginalUrl());
- }
+ @Test
+ public void testUrl() throws Exception {
+ assertIsSecureUrl(extractor.getUrl());
+ assertEquals("https://api.media.ccc.de/public/events/36c3-10565-what_s_left_for_private_messaging", extractor.getUrl());
+ }
- @Test
- public void testThumbnail() throws Exception {
- assertEquals("https://static.media.ccc.de/media/events/gpn/gpn18/105-hd.jpg", extractor.getThumbnailUrl());
- }
+ @Test
+ public void testOriginalUrl() throws Exception {
+ assertIsSecureUrl(extractor.getOriginalUrl());
+ assertEquals("https://media.ccc.de/v/36c3-10565-what_s_left_for_private_messaging", extractor.getOriginalUrl());
+ }
- @Test
- public void testUploaderName() throws Exception {
- assertEquals("gpn18", extractor.getUploaderName());
- }
+ @Test
+ public void testThumbnail() throws Exception {
+ assertIsSecureUrl(extractor.getThumbnailUrl());
+ assertEquals("https://static.media.ccc.de/media/congress/2019/10565-hd.jpg", extractor.getThumbnailUrl());
+ }
- @Test
- public void testUploaderUrl() throws Exception {
- assertEquals("https://api.media.ccc.de/public/conferences/gpn18", extractor.getUploaderUrl());
- }
+ @Test
+ public void testUploaderName() throws Exception {
+ assertEquals("36c3", extractor.getUploaderName());
+ }
- @Test
- public void testUploaderAvatarUrl() throws Exception {
- assertEquals("https://static.media.ccc.de/media/events/gpn/gpn18/logo.png", extractor.getUploaderAvatarUrl());
- }
+ @Test
+ public void testUploaderUrl() throws Exception {
+ assertIsSecureUrl(extractor.getUploaderUrl());
+ assertEquals("https://api.media.ccc.de/public/conferences/36c3", extractor.getUploaderUrl());
+ }
- @Test
- public void testVideoStreams() throws Exception {
- assertEquals(4, extractor.getVideoStreams().size());
- }
+ @Test
+ public void testUploaderAvatarUrl() throws Exception {
+ assertIsSecureUrl(extractor.getUploaderAvatarUrl());
+ assertEquals("https://static.media.ccc.de/media/congress/2019/logo.png", extractor.getUploaderAvatarUrl());
+ }
- @Test
- public void testAudioStreams() throws Exception {
- assertEquals(2, extractor.getAudioStreams().size());
- }
+ @Test
+ public void testVideoStreams() throws Exception {
+ List videoStreamList = extractor.getVideoStreams();
+ assertEquals(8, videoStreamList.size());
+ for (VideoStream stream : videoStreamList) {
+ assertIsSecureUrl(stream.getUrl());
+ }
+ }
- @Test
- public void testGetTextualUploadDate() throws ParsingException {
- Assert.assertEquals("2018-05-11T02:00:00.000+02:00", extractor.getTextualUploadDate());
- }
+ @Test
+ public void testAudioStreams() throws Exception {
+ List audioStreamList = extractor.getAudioStreams();
+ assertEquals(2, audioStreamList.size());
+ for (AudioStream stream : audioStreamList) {
+ assertIsSecureUrl(stream.getUrl());
+ }
+ }
- @Test
- public void testGetUploadDate() throws ParsingException, ParseException {
- final Calendar instance = Calendar.getInstance();
- instance.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("2018-05-11"));
- assertEquals(instance, requireNonNull(extractor.getUploadDate()).date());
+ @Test
+ public void testGetTextualUploadDate() throws ParsingException {
+ Assert.assertEquals("2020-01-11T01:00:00.000+01:00", extractor.getTextualUploadDate());
+ }
+
+ @Test
+ public void testGetUploadDate() throws ParsingException, ParseException {
+ final Calendar instance = Calendar.getInstance();
+ instance.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("2020-01-11"));
+ assertEquals(instance, requireNonNull(extractor.getUploadDate()).date());
+ }
}
-}
+}
\ No newline at end of file
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelExtractorTest.java
index 3d8bdff3..7c7a9b80 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelExtractorTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelExtractorTest.java
@@ -1,15 +1,5 @@
package org.schabi.newpipe.extractor.services.peertube;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmpty;
-import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
-import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
-import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestGetPageInNewExtractor;
-import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestMoreItems;
-import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems;
-
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
@@ -20,6 +10,12 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest;
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeChannelExtractor;
+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.PeerTube;
+import static org.schabi.newpipe.extractor.services.DefaultTests.*;
+
/**
* Test for {@link PeertubeChannelExtractor}
*/
@@ -72,12 +68,12 @@ public class PeertubeChannelExtractorTest {
@Test
public void testRelatedItems() throws Exception {
- defaultTestRelatedItems(extractor, PeerTube.getServiceId());
+ defaultTestRelatedItems(extractor);
}
@Test
public void testMoreRelatedItems() throws Exception {
- defaultTestMoreItems(extractor, PeerTube.getServiceId());
+ defaultTestMoreItems(extractor);
}
/*//////////////////////////////////////////////////////////////////////////
@@ -131,7 +127,7 @@ public class PeertubeChannelExtractorTest {
@Test
public void testGetPageInNewExtractor() throws Exception {
final ChannelExtractor newExtractor = PeerTube.getChannelExtractor(extractor.getUrl());
- defaultTestGetPageInNewExtractor(extractor, newExtractor, PeerTube.getServiceId());
+ defaultTestGetPageInNewExtractor(extractor, newExtractor);
}
/*//////////////////////////////////////////////////////////////////////////
@@ -169,12 +165,12 @@ public class PeertubeChannelExtractorTest {
@Test
public void testRelatedItems() throws Exception {
- defaultTestRelatedItems(extractor, PeerTube.getServiceId());
+ defaultTestRelatedItems(extractor);
}
@Test
public void testMoreRelatedItems() throws Exception {
- defaultTestMoreItems(extractor, PeerTube.getServiceId());
+ defaultTestMoreItems(extractor);
}
/*//////////////////////////////////////////////////////////////////////////
@@ -204,7 +200,7 @@ public class PeertubeChannelExtractorTest {
@Test
public void testSubscriberCount() throws ParsingException {
- assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 2);
+ assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 1);
}
}
}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelLinkHandlerFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelLinkHandlerFactoryTest.java
index 633307a2..f9b0c69d 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelLinkHandlerFactoryTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelLinkHandlerFactoryTest.java
@@ -1,8 +1,5 @@
package org.schabi.newpipe.extractor.services.peertube;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.DownloaderTestImpl;
@@ -10,6 +7,9 @@ import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeChannelLinkHandlerFactory;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
/**
* Test for {@link PeertubeChannelLinkHandlerFactory}
*/
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsExtractorTest.java
index fef1c3ee..1241b0a8 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsExtractorTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsExtractorTest.java
@@ -1,12 +1,5 @@
package org.schabi.newpipe.extractor.services.peertube;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
-
-import java.io.IOException;
-import java.util.List;
-
import org.jsoup.helper.StringUtil;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -18,6 +11,13 @@ import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeCommentsExtractor;
+import java.io.IOException;
+import java.util.List;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
+
public class PeertubeCommentsExtractorTest {
private static PeertubeCommentsExtractor extractor;
@@ -26,7 +26,7 @@ public class PeertubeCommentsExtractorTest {
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = (PeertubeCommentsExtractor) PeerTube
- .getCommentsExtractor("https://peertube.mastodon.host/videos/watch/04af977f-4201-4697-be67-a8d8cae6fa7a");
+ .getCommentsExtractor("https://framatube.org/videos/watch/04af977f-4201-4697-be67-a8d8cae6fa7a");
}
@Test
@@ -46,7 +46,7 @@ public class PeertubeCommentsExtractorTest {
@Test
public void testGetCommentsFromCommentsInfo() throws IOException, ExtractionException {
boolean result = false;
- CommentsInfo commentsInfo = CommentsInfo.getInfo("https://peertube.mastodon.host/videos/watch/a8ea95b8-0396-49a6-8f30-e25e25fb2828");
+ CommentsInfo commentsInfo = CommentsInfo.getInfo("https://framatube.org/videos/watch/a8ea95b8-0396-49a6-8f30-e25e25fb2828");
assertTrue("Comments".equals(commentsInfo.getName()));
result = findInComments(commentsInfo.getRelatedItems(), "Loved it!!!");
@@ -59,11 +59,11 @@ public class PeertubeCommentsExtractorTest {
assertTrue(result);
}
-
+
@Test
public void testGetCommentsAllData() throws IOException, ExtractionException {
InfoItemsPage comments = extractor.getInitialPage();
- for(CommentsInfoItem c: comments.getItems()) {
+ for (CommentsInfoItem c : comments.getItems()) {
assertFalse(StringUtil.isBlank(c.getAuthorEndpoint()));
assertFalse(StringUtil.isBlank(c.getAuthorName()));
assertFalse(StringUtil.isBlank(c.getAuthorThumbnail()));
@@ -82,8 +82,8 @@ public class PeertubeCommentsExtractorTest {
}
private boolean findInComments(List comments, String comment) {
- for(CommentsInfoItem c: comments) {
- if(c.getCommentText().contains(comment)) {
+ for (CommentsInfoItem c : comments) {
+ if (c.getCommentText().contains(comment)) {
return true;
}
}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsLinkHandlerFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsLinkHandlerFactoryTest.java
index fcc27c54..f6fb91f7 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsLinkHandlerFactoryTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsLinkHandlerFactoryTest.java
@@ -1,8 +1,5 @@
package org.schabi.newpipe.extractor.services.peertube;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.DownloaderTestImpl;
@@ -10,6 +7,9 @@ import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeCommentsLinkHandlerFactory;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
/**
* Test for {@link PeertubeCommentsLinkHandlerFactory}
*/
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubePlaylistLinkHandlerFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubePlaylistLinkHandlerFactoryTest.java
index 9ad29102..ac04a01e 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubePlaylistLinkHandlerFactoryTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubePlaylistLinkHandlerFactoryTest.java
@@ -1,8 +1,5 @@
package org.schabi.newpipe.extractor.services.peertube;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.DownloaderTestImpl;
@@ -10,6 +7,9 @@ import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubePlaylistLinkHandlerFactory;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
/**
* Test for {@link PeertubePlaylistLinkHandlerFactory}
*/
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamExtractorDefaultTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamExtractorDefaultTest.java
index 75a692d4..e103e1a8 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamExtractorDefaultTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamExtractorDefaultTest.java
@@ -1,17 +1,5 @@
package org.schabi.newpipe.extractor.services.peertube;
-import static java.util.Objects.requireNonNull;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
-import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
-
-import java.io.IOException;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
@@ -24,21 +12,45 @@ 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 java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import static java.util.Objects.requireNonNull;
+import static org.junit.Assert.*;
+import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
+import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
+
/**
* Test for {@link StreamExtractor}
*/
public class PeertubeStreamExtractorDefaultTest {
private static PeertubeStreamExtractor extractor;
+ private static final String expectedLargeDescription = "**[Want to help to translate this video?](https://weblate.framasoft.org/projects/what-is-peertube-video/)**\r\n\r\n**Take back the control of your videos! [#JoinPeertube](https://joinpeertube.org)**\r\n*A decentralized video hosting network, based on free/libre software!*\r\n\r\n**Animation Produced by:** [LILA](https://libreart.info) - [ZeMarmot Team](https://film.zemarmot.net)\r\n*Directed by* Aryeom\r\n*Assistant* Jehan\r\n**Licence**: [CC-By-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)\r\n\r\n**Sponsored by** [Framasoft](https://framasoft.org)\r\n\r\n**Music**: [Red Step Forward](http://play.dogmazic.net/song.php?song_id=52491) - CC-By Ken Bushima\r\n\r\n**Movie Clip**: [Caminades 3: Llamigos](http://www.caminandes.com/) CC-By Blender Institute\r\n\r\n**Video sources**: https://gitlab.gnome.org/Jehan/what-is-peertube/";
+ private static final String expectedSmallDescription = "https://www.kickstarter.com/projects/1587081065/nothing-to-hide-the-documentary";
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
// setting instance might break test when running in parallel
- PeerTube.setInstance(new PeertubeInstance("https://peertube.mastodon.host", "PeerTube on Mastodon.host"));
- extractor = (PeertubeStreamExtractor) PeerTube.getStreamExtractor("https://peertube.mastodon.host/videos/watch/afe5bf12-c58b-4efd-b56e-29c5a59e04bc");
+ PeerTube.setInstance(new PeertubeInstance("https://framatube.org", "FramaTube"));
+ extractor = (PeertubeStreamExtractor) PeerTube.getStreamExtractor("https://framatube.org/videos/watch/9c9de5e8-0a1e-484a-b099-e80766180a6d");
extractor.fetchPage();
}
+ @Test
+ public void testGetUploadDate() throws ParsingException, ParseException {
+ final Calendar instance = Calendar.getInstance();
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'");
+ sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
+ instance.setTime(sdf.parse("2018-10-01T10:52:46.396Z"));
+ assertEquals(instance, requireNonNull(extractor.getUploadDate()).date());
+
+ }
+
@Test
public void testGetInvalidTimeStamp() throws ParsingException {
assertTrue(extractor.getTimeStamp() + "",
@@ -47,22 +59,37 @@ public class PeertubeStreamExtractorDefaultTest {
@Test
public void testGetTitle() throws ParsingException {
- assertEquals(extractor.getName(), "Power Corrupts the Best");
+ assertEquals("What is PeerTube?", extractor.getName());
}
@Test
- public void testGetDescription() throws ParsingException {
- assertEquals(extractor.getDescription(), "A short reading from Bakunin, made for the group Audible Anarchist https://audibleanarchist.github.io/Webpage/");
+ public void testGetLargeDescription() throws ParsingException {
+ assertEquals(expectedLargeDescription, extractor.getDescription().getContent());
+ }
+
+ @Test
+ public void testGetEmptyDescription() throws Exception {
+ PeertubeStreamExtractor extractorEmpty = (PeertubeStreamExtractor) PeerTube.getStreamExtractor("https://framatube.org/api/v1/videos/d5907aad-2252-4207-89ec-a4b687b9337d");
+ extractorEmpty.fetchPage();
+ assertEquals("", extractorEmpty.getDescription().getContent());
+ }
+
+ @Test
+ public void testGetSmallDescription() throws Exception {
+ PeerTube.setInstance(new PeertubeInstance("https://peertube.cpy.re", "PeerTube test server"));
+ PeertubeStreamExtractor extractorSmall = (PeertubeStreamExtractor) PeerTube.getStreamExtractor("https://peertube.cpy.re/videos/watch/d2a5ec78-5f85-4090-8ec5-dc1102e022ea");
+ extractorSmall.fetchPage();
+ assertEquals(expectedSmallDescription, extractorSmall.getDescription().getContent());
}
@Test
public void testGetUploaderName() throws ParsingException {
- assertEquals(extractor.getUploaderName(), "Rowsedower");
+ assertEquals("Framasoft", extractor.getUploaderName());
}
@Test
public void testGetLength() throws ParsingException {
- assertEquals(extractor.getLength(), 269);
+ assertEquals(113, extractor.getLength());
}
@Test
@@ -71,18 +98,10 @@ public class PeertubeStreamExtractorDefaultTest {
extractor.getViewCount() > 10);
}
- @Test
- public void testGetUploadDate() throws ParsingException, ParseException {
- final Calendar instance = Calendar.getInstance();
- instance.setTime(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'").parse("2018-09-30T14:08:24.378Z"));
- assertEquals(instance, requireNonNull(extractor.getUploadDate()).date());
-
- }
-
@Test
public void testGetUploaderUrl() throws ParsingException {
assertIsSecureUrl(extractor.getUploaderUrl());
- assertEquals("https://peertube.mastodon.host/api/v1/accounts/reddebrek@peertube.mastodon.host", extractor.getUploaderUrl());
+ assertEquals("https://framatube.org/api/v1/accounts/framasoft@framatube.org", extractor.getUploaderUrl());
}
@Test
@@ -115,11 +134,31 @@ public class PeertubeStreamExtractorDefaultTest {
@Test
public void testGetSubtitlesListDefault() throws IOException, ExtractionException {
- assertTrue(extractor.getSubtitlesDefault().isEmpty());
+ assertFalse(extractor.getSubtitlesDefault().isEmpty());
}
@Test
public void testGetSubtitlesList() throws IOException, ExtractionException {
- assertTrue(extractor.getSubtitlesDefault().isEmpty());
+ assertFalse(extractor.getSubtitlesDefault().isEmpty());
+ }
+
+ @Test
+ public void testGetAgeLimit() throws ExtractionException, IOException {
+ assertEquals(0, extractor.getAgeLimit());
+ PeertubeStreamExtractor ageLimit = (PeertubeStreamExtractor) PeerTube.getStreamExtractor("https://peertube.co.uk/videos/watch/3c0da7fb-e4d9-442e-84e3-a8c47004ee28");
+ ageLimit.fetchPage();
+ assertEquals(18, ageLimit.getAgeLimit());
+ }
+
+ @Test
+ public void testGetSupportInformation() throws ExtractionException, IOException {
+ PeertubeStreamExtractor supportInfoExtractor = (PeertubeStreamExtractor) PeerTube.getStreamExtractor("https://framatube.org/videos/watch/ee408ec8-07cd-4e35-b884-fb681a4b9d37");
+ supportInfoExtractor.fetchPage();
+ assertEquals("https://utip.io/chatsceptique", supportInfoExtractor.getSupportInfo());
+ }
+
+ @Test
+ public void testGetLanguageInformation() throws ParsingException {
+ assertEquals(new Locale("en"), extractor.getLanguageInfo());
}
}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamLinkHandlerFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamLinkHandlerFactoryTest.java
index 893b6eb8..af44f644 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamLinkHandlerFactoryTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamLinkHandlerFactoryTest.java
@@ -1,8 +1,5 @@
package org.schabi.newpipe.extractor.services.peertube;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.DownloaderTestImpl;
@@ -10,6 +7,9 @@ import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeStreamLinkHandlerFactory;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
/**
* Test for {@link PeertubeStreamLinkHandlerFactory}
*/
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeTrendingExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeTrendingExtractorTest.java
index bb4e1529..e7334fca 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeTrendingExtractorTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeTrendingExtractorTest.java
@@ -1,97 +1,79 @@
package org.schabi.newpipe.extractor.services.peertube;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
-
-import java.util.List;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.DownloaderTestImpl;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe;
+import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
+import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeTrendingExtractor;
+import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudChartsExtractor;
+import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeTrendingExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
-/**
- * Test for {@link PeertubeTrendingExtractor}
- */
+import java.util.List;
+
+import static org.junit.Assert.*;
+import static org.schabi.newpipe.extractor.ServiceList.*;
+import static org.schabi.newpipe.extractor.services.DefaultTests.*;
+
public class PeertubeTrendingExtractorTest {
+ public static class Trending implements BaseListExtractorTest {
+ private static PeertubeTrendingExtractor extractor;
- static KioskExtractor extractor;
-
- @BeforeClass
- public static void setUp() throws Exception {
- NewPipe.init(DownloaderTestImpl.getInstance());
- // setting instance might break test when running in parallel
- PeerTube.setInstance(new PeertubeInstance("https://peertube.mastodon.host", "PeerTube on Mastodon.host"));
- extractor = PeerTube
- .getKioskList()
- .getExtractorById("Trending", null);
- extractor.fetchPage();
- }
-
- @Test
- public void testGetDownloader() throws Exception {
- assertNotNull(NewPipe.getDownloader());
- }
-
- @Test
- public void testGetName() throws Exception {
- assertEquals(extractor.getName(), "Trending");
- }
-
- @Test
- public void testId() {
- assertEquals(extractor.getId(), "Trending");
- }
-
- @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("----------");
- }
+ @BeforeClass
+ public static void setUp() throws Exception {
+ NewPipe.init(DownloaderTestImpl.getInstance());
+ // setting instance might break test when running in parallel
+ PeerTube.setInstance(new PeertubeInstance("https://peertube.mastodon.host", "PeerTube on Mastodon.host"));
+ extractor = (PeertubeTrendingExtractor) PeerTube.getKioskList()
+ .getExtractorById("Trending", null);
+ extractor.fetchPage();
}
- 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());
- }
+ /*//////////////////////////////////////////////////////////////////////////
+ // Extractor
+ //////////////////////////////////////////////////////////////////////////*/
- @Test
- public void testHasMoreStreams() throws Exception {
- // Setup the streams
- extractor.getInitialPage();
- assertTrue("has more streams", extractor.hasNextPage());
- }
+ @Test
+ public void testServiceId() {
+ assertEquals(PeerTube.getServiceId(), extractor.getServiceId());
+ }
- @Test
- public void testGetNextPageUrl() throws Exception {
- assertTrue(extractor.hasNextPage());
- }
+ @Test
+ public void testName() throws Exception {
+ assertEquals("Trending", extractor.getName());
+ }
- @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 testId() throws Exception {
+ assertEquals("Trending", extractor.getId());
+ }
- @Test
- public void testGetCleanUrl() throws Exception {
- assertEquals(extractor.getUrl(), "https://peertube.mastodon.host/api/v1/videos?sort=-trending");
+ @Test
+ public void testUrl() throws ParsingException {
+ assertEquals("https://peertube.mastodon.host/api/v1/videos?sort=-trending", extractor.getUrl());
+ }
+
+ @Test
+ public void testOriginalUrl() throws ParsingException {
+ assertEquals("https://peertube.mastodon.host/api/v1/videos?sort=-trending", extractor.getOriginalUrl());
+ }
+
+ /*//////////////////////////////////////////////////////////////////////////
+ // ListExtractor
+ //////////////////////////////////////////////////////////////////////////*/
+
+ @Test
+ public void testRelatedItems() throws Exception {
+ defaultTestRelatedItems(extractor);
+ }
+
+ @Test
+ public void testMoreRelatedItems() throws Exception {
+ defaultTestMoreItems(extractor);
+ }
}
}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeTrendingLinkHandlerFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeTrendingLinkHandlerFactoryTest.java
index d192e8be..033be650 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeTrendingLinkHandlerFactoryTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeTrendingLinkHandlerFactoryTest.java
@@ -1,9 +1,5 @@
package org.schabi.newpipe.extractor.services.peertube;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.DownloaderTestImpl;
@@ -12,6 +8,10 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeTrendingLinkHandlerFactory;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
+
/**
* Test for {@link PeertubeTrendingLinkHandlerFactory}
*/
@@ -48,13 +48,13 @@ public class PeertubeTrendingLinkHandlerFactoryTest {
public void acceptUrl() throws ParsingException {
assertTrue(LinkHandlerFactory.acceptUrl("https://peertube.mastodon.host/videos/trending"));
assertTrue(LinkHandlerFactory.acceptUrl("https://peertube.mastodon.host/videos/trending?adsf=fjaj#fhe"));
-
+
assertTrue(LinkHandlerFactory.acceptUrl("https://peertube.mastodon.host/videos/most-liked"));
assertTrue(LinkHandlerFactory.acceptUrl("https://peertube.mastodon.host/videos/most-liked?adsf=fjaj#fhe"));
-
+
assertTrue(LinkHandlerFactory.acceptUrl("https://peertube.mastodon.host/videos/recently-added"));
assertTrue(LinkHandlerFactory.acceptUrl("https://peertube.mastodon.host/videos/recently-added?adsf=fjaj#fhe"));
-
+
assertTrue(LinkHandlerFactory.acceptUrl("https://peertube.mastodon.host/videos/local"));
assertTrue(LinkHandlerFactory.acceptUrl("https://peertube.mastodon.host/videos/local?adsf=fjaj#fhe"));
}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/search/PeertubeSearchExtractorBaseTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/search/PeertubeSearchExtractorBaseTest.java
index 08dd7a0a..030bd6c5 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/search/PeertubeSearchExtractorBaseTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/search/PeertubeSearchExtractorBaseTest.java
@@ -1,12 +1,12 @@
package org.schabi.newpipe.extractor.services.peertube.search;
-import static org.junit.Assert.assertTrue;
-
import org.junit.Test;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeSearchExtractor;
+import static org.junit.Assert.assertTrue;
+
/**
* Test for {@link PeertubeSearchExtractor}
*/
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/search/PeertubeSearchExtractorDefaultTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/search/PeertubeSearchExtractorDefaultTest.java
index dd9c6deb..eeebf526 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/search/PeertubeSearchExtractorDefaultTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/search/PeertubeSearchExtractorDefaultTest.java
@@ -1,10 +1,5 @@
package org.schabi.newpipe.extractor.services.peertube.search;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.DownloaderTestImpl;
@@ -15,6 +10,9 @@ import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance;
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeSearchExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
+import static org.junit.Assert.*;
+import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
+
/**
* Test for {@link PeertubeSearchExtractor}
*/
@@ -38,15 +36,15 @@ public class PeertubeSearchExtractorDefaultTest extends PeertubeSearchExtractorB
@Test
public void testResultList_FirstElement() {
InfoItem firstInfoItem = itemsPage.getItems().get(0);
-
+
assertTrue("search does not match", firstInfoItem.getName().toLowerCase().contains("kde"));
}
@Test
public void testResultListCheckIfContainsStreamItems() {
boolean hasStreams = false;
- for(InfoItem item : itemsPage.getItems()) {
- if(item instanceof StreamInfoItem) {
+ for (InfoItem item : itemsPage.getItems()) {
+ if (item instanceof StreamInfoItem) {
hasStreams = true;
}
}
@@ -67,7 +65,7 @@ public class PeertubeSearchExtractorDefaultTest extends PeertubeSearchExtractorB
boolean equals = true;
for (int i = 0; i < secondPage.getItems().size()
&& i < itemsPage.getItems().size(); i++) {
- if(!secondPage.getItems().get(i).getUrl().equals(
+ if (!secondPage.getItems().get(i).getUrl().equals(
itemsPage.getItems().get(i).getUrl())) {
equals = false;
}
@@ -75,7 +73,7 @@ public class PeertubeSearchExtractorDefaultTest extends PeertubeSearchExtractorB
assertFalse("First and second page are equal", equals);
assertEquals("https://peertube.mastodon.host/api/v1/search/videos?search=internet&start=24&count=12",
- secondPage.getNextPageUrl());
+ secondPage.getNextPageUrl());
}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/search/PeertubeSearchQHTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/search/PeertubeSearchQHTest.java
index 23e3100c..d7bd92aa 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/search/PeertubeSearchQHTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/search/PeertubeSearchQHTest.java
@@ -1,14 +1,14 @@
package org.schabi.newpipe.extractor.services.peertube.search;
-import static org.junit.Assert.assertEquals;
-import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance;
+import static org.junit.Assert.assertEquals;
+import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
+
public class PeertubeSearchQHTest {
-
+
@BeforeClass
public static void setUpClass() throws Exception {
// setting instance might break test when running in parallel
@@ -18,7 +18,7 @@ public class PeertubeSearchQHTest {
@Test
public void testRegularValues() throws Exception {
assertEquals("https://peertube.mastodon.host/api/v1/search/videos?search=asdf", PeerTube.getSearchQHFactory().fromQuery("asdf").getUrl());
- assertEquals("https://peertube.mastodon.host/api/v1/search/videos?search=hans",PeerTube.getSearchQHFactory().fromQuery("hans").getUrl());
+ assertEquals("https://peertube.mastodon.host/api/v1/search/videos?search=hans", PeerTube.getSearchQHFactory().fromQuery("hans").getUrl());
assertEquals("https://peertube.mastodon.host/api/v1/search/videos?search=Poifj%26jaijf", PeerTube.getSearchQHFactory().fromQuery("Poifj&jaijf").getUrl());
assertEquals("https://peertube.mastodon.host/api/v1/search/videos?search=G%C3%BCl%C3%BCm", PeerTube.getSearchQHFactory().fromQuery("Gülüm").getUrl());
assertEquals("https://peertube.mastodon.host/api/v1/search/videos?search=%3Fj%24%29H%C2%A7B", PeerTube.getSearchQHFactory().fromQuery("?j$)H§B").getUrl());
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
index 0de8e847..485462fb 100644
--- 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
@@ -64,12 +64,12 @@ public class SoundcloudChannelExtractorTest {
@Test
public void testRelatedItems() throws Exception {
- defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
+ defaultTestRelatedItems(extractor);
}
@Test
public void testMoreRelatedItems() throws Exception {
- defaultTestMoreItems(extractor, SoundCloud.getServiceId());
+ defaultTestMoreItems(extractor);
}
/*//////////////////////////////////////////////////////////////////////////
@@ -120,7 +120,7 @@ public class SoundcloudChannelExtractorTest {
@Test
public void testGetPageInNewExtractor() throws Exception {
final ChannelExtractor newExtractor = SoundCloud.getChannelExtractor(extractor.getUrl());
- defaultTestGetPageInNewExtractor(extractor, newExtractor, SoundCloud.getServiceId());
+ defaultTestGetPageInNewExtractor(extractor, newExtractor);
}
/*//////////////////////////////////////////////////////////////////////////
@@ -158,12 +158,12 @@ public class SoundcloudChannelExtractorTest {
@Test
public void testRelatedItems() throws Exception {
- defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
+ defaultTestRelatedItems(extractor);
}
@Test
public void testMoreRelatedItems() throws Exception {
- defaultTestMoreItems(extractor, SoundCloud.getServiceId());
+ defaultTestMoreItems(extractor);
}
/*//////////////////////////////////////////////////////////////////////////
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java
index d96b4c6e..189be417 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java
@@ -1,92 +1,131 @@
package org.schabi.newpipe.extractor.services.soundcloud;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import org.schabi.newpipe.DownloaderTestImpl;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe;
+import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
+import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
+import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeTrendingExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import java.util.List;
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
+import static org.schabi.newpipe.extractor.ServiceList.YouTube;
+import static org.schabi.newpipe.extractor.services.DefaultTests.*;
-/**
- * Test for {@link SoundcloudChartsLinkHandlerFactory}
- */
public class SoundcloudChartsExtractorTest {
+ public static class NewAndHot implements BaseListExtractorTest {
+ private static SoundcloudChartsExtractor extractor;
- static KioskExtractor extractor;
-
- @BeforeClass
- public static void setUp() throws Exception {
- NewPipe.init(DownloaderTestImpl.getInstance());
- extractor = SoundCloud
- .getKioskList()
- .getExtractorById("Top 50", null);
- extractor.fetchPage();
- }
-
- @Test
- public void testGetDownloader() throws Exception {
- assertNotNull(NewPipe.getDownloader());
- }
-
- @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("----------");
- }
+ @BeforeClass
+ public static void setUp() throws Exception {
+ NewPipe.init(DownloaderTestImpl.getInstance());
+ extractor = (SoundcloudChartsExtractor) SoundCloud.getKioskList()
+ .getExtractorById("New & hot", null);
+ extractor.fetchPage();
+ }
+
+ /*//////////////////////////////////////////////////////////////////////////
+ // Extractor
+ //////////////////////////////////////////////////////////////////////////*/
+
+ @Test
+ public void testServiceId() {
+ assertEquals(SoundCloud.getServiceId(), extractor.getServiceId());
+ }
+
+ @Test
+ public void testName() {
+ assertEquals("New & hot", extractor.getName());
+ }
+
+ @Test
+ public void testId() {
+ assertEquals("New & hot", extractor.getId());
+ }
+
+ @Test
+ public void testUrl() throws ParsingException {
+ assertEquals("https://soundcloud.com/charts/new", extractor.getUrl());
+ }
+
+ @Test
+ public void testOriginalUrl() throws ParsingException {
+ assertEquals("https://soundcloud.com/charts/new", extractor.getOriginalUrl());
+ }
+
+ /*//////////////////////////////////////////////////////////////////////////
+ // ListExtractor
+ //////////////////////////////////////////////////////////////////////////*/
+
+ @Test
+ public void testRelatedItems() throws Exception {
+ defaultTestRelatedItems(extractor);
+ }
+
+ @Test
+ public void testMoreRelatedItems() throws Exception {
+ defaultTestMoreItems(extractor);
}
- 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());
- }
+ public static class Top50Charts implements BaseListExtractorTest {
+ private static SoundcloudChartsExtractor extractor;
- @Test
- public void testHasMoreStreams() throws Exception {
- // Setup the streams
- extractor.getInitialPage();
- assertTrue("has more streams", extractor.hasNextPage());
- }
+ @BeforeClass
+ public static void setUp() throws Exception {
+ NewPipe.init(DownloaderTestImpl.getInstance());
+ extractor = (SoundcloudChartsExtractor) SoundCloud.getKioskList()
+ .getExtractorById("Top 50", null);
+ extractor.fetchPage();
+ }
- @Test
- public void testGetNextPageUrl() throws Exception {
- assertTrue(extractor.hasNextPage());
- }
+ /*//////////////////////////////////////////////////////////////////////////
+ // Extractor
+ //////////////////////////////////////////////////////////////////////////*/
- @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 testServiceId() {
+ assertEquals(SoundCloud.getServiceId(), extractor.getServiceId());
+ }
- @Test
- public void testGetCleanUrl() throws Exception {
- assertEquals(extractor.getUrl(), "https://soundcloud.com/charts/top");
+ @Test
+ public void testName() {
+ assertEquals("Top 50", extractor.getName());
+ }
+
+ @Test
+ public void testId() {
+ assertEquals("Top 50", extractor.getId());
+ }
+
+ @Test
+ public void testUrl() throws ParsingException {
+ assertEquals("https://soundcloud.com/charts/top", extractor.getUrl());
+ }
+
+ @Test
+ public void testOriginalUrl() throws ParsingException {
+ assertEquals("https://soundcloud.com/charts/top", extractor.getOriginalUrl());
+ }
+
+ /*//////////////////////////////////////////////////////////////////////////
+ // ListExtractor
+ //////////////////////////////////////////////////////////////////////////*/
+
+ @Test
+ public void testRelatedItems() throws Exception {
+ defaultTestRelatedItems(extractor);
+ }
+
+ @Test
+ public void testMoreRelatedItems() throws Exception {
+ defaultTestMoreItems(extractor);
+ }
}
}
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
index 1c4f4159..16089aab 100644
--- 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
@@ -1,10 +1,12 @@
package org.schabi.newpipe.extractor.services.soundcloud;
-import org.junit.*;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
import org.schabi.newpipe.DownloaderTestImpl;
import org.schabi.newpipe.extractor.NewPipe;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
public class SoundcloudParsingHelperTest {
@BeforeClass
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
index c27dfdf8..b93c2cfb 100644
--- 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
@@ -7,7 +7,6 @@ import org.junit.Test;
import org.schabi.newpipe.DownloaderTestImpl;
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;
@@ -67,13 +66,13 @@ public class SoundcloudPlaylistExtractorTest {
@Test
public void testRelatedItems() throws Exception {
- defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
+ defaultTestRelatedItems(extractor);
}
@Test
public void testMoreRelatedItems() {
try {
- defaultTestMoreItems(extractor, SoundCloud.getServiceId());
+ defaultTestMoreItems(extractor);
} catch (Throwable ignored) {
return;
}
@@ -165,12 +164,12 @@ public class SoundcloudPlaylistExtractorTest {
@Test
public void testRelatedItems() throws Exception {
- defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
+ defaultTestRelatedItems(extractor);
}
@Test
public void testMoreRelatedItems() throws Exception {
- defaultTestMoreItems(extractor, SoundCloud.getServiceId());
+ defaultTestMoreItems(extractor);
}
/*//////////////////////////////////////////////////////////////////////////
@@ -226,11 +225,10 @@ public class SoundcloudPlaylistExtractorTest {
// Additional Testing
//////////////////////////////////////////////////////////////////////////*/
- @Ignore
@Test
public void testGetPageInNewExtractor() throws Exception {
final PlaylistExtractor newExtractor = SoundCloud.getPlaylistExtractor(extractor.getUrl());
- defaultTestGetPageInNewExtractor(extractor, newExtractor, SoundCloud.getServiceId());
+ defaultTestGetPageInNewExtractor(extractor, newExtractor);
}
/*//////////////////////////////////////////////////////////////////////////
@@ -269,18 +267,18 @@ public class SoundcloudPlaylistExtractorTest {
@Ignore
@Test
public void testRelatedItems() throws Exception {
- defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
+ defaultTestRelatedItems(extractor);
}
//TODO: FUCK THIS: This triggers a 500 at sever
@Ignore
@Test
public void testMoreRelatedItems() throws Exception {
- ListExtractor.InfoItemsPage currentPage = defaultTestMoreItems(extractor, ServiceList.SoundCloud.getServiceId());
+ ListExtractor.InfoItemsPage currentPage = defaultTestMoreItems(extractor);
// Test for 2 more levels
for (int i = 0; i < 2; i++) {
currentPage = extractor.getPage(currentPage.getNextPageUrl());
- defaultTestListOfItems(SoundCloud.getServiceId(), currentPage.getItems(), currentPage.getErrors());
+ defaultTestListOfItems(SoundCloud, currentPage.getItems(), currentPage.getErrors());
}
}
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
index 8a3883fd..0ffe0622 100644
--- 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
@@ -53,7 +53,7 @@ public class SoundcloudStreamExtractorDefaultTest {
@Test
public void testGetDescription() throws ParsingException {
- assertEquals("The Perfect LUV Tape®️", extractor.getDescription());
+ assertEquals("The Perfect LUV Tape®️", extractor.getDescription().getContent());
}
@Test
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorChannelOnlyTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorChannelOnlyTest.java
index abd26951..04e7e0ab 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorChannelOnlyTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorChannelOnlyTest.java
@@ -38,7 +38,7 @@ public class SoundcloudSearchExtractorChannelOnlyTest extends SoundcloudSearchEx
boolean equals = true;
for (int i = 0; i < secondPage.getItems().size()
&& i < itemsPage.getItems().size(); i++) {
- if(!secondPage.getItems().get(i).getUrl().equals(
+ if (!secondPage.getItems().get(i).getUrl().equals(
itemsPage.getItems().get(i).getUrl())) {
equals = false;
}
@@ -57,8 +57,8 @@ public class SoundcloudSearchExtractorChannelOnlyTest extends SoundcloudSearchEx
@Test
public void testOnlyContainChannels() {
- for(InfoItem item : itemsPage.getItems()) {
- if(!(item instanceof ChannelInfoItem)) {
+ for (InfoItem item : itemsPage.getItems()) {
+ if (!(item instanceof ChannelInfoItem)) {
fail("The following item is no channel item: " + item.toString());
}
}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorDefaultTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorDefaultTest.java
index 685c52d7..ca0d7d59 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorDefaultTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorDefaultTest.java
@@ -60,8 +60,8 @@ public class SoundcloudSearchExtractorDefaultTest extends SoundcloudSearchExtrac
@Test
public void testResultListCheckIfContainsStreamItems() {
boolean hasStreams = false;
- for(InfoItem item : itemsPage.getItems()) {
- if(item instanceof StreamInfoItem) {
+ for (InfoItem item : itemsPage.getItems()) {
+ if (item instanceof StreamInfoItem) {
hasStreams = true;
}
}
@@ -80,7 +80,7 @@ public class SoundcloudSearchExtractorDefaultTest extends SoundcloudSearchExtrac
boolean equals = true;
for (int i = 0; i < secondPage.getItems().size()
&& i < itemsPage.getItems().size(); i++) {
- if(!secondPage.getItems().get(i).getUrl().equals(
+ if (!secondPage.getItems().get(i).getUrl().equals(
itemsPage.getItems().get(i).getUrl())) {
equals = false;
}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java
index 251ae246..dfcaee40 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java
@@ -1,29 +1,46 @@
package org.schabi.newpipe.extractor.services.youtube;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
-import static org.schabi.newpipe.extractor.ServiceList.YouTube;
-import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestGetPageInNewExtractor;
-import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestMoreItems;
-import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.DownloaderTestImpl;
import org.schabi.newpipe.extractor.NewPipe;
-import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
+import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
-import org.schabi.newpipe.extractor.localization.Localization;
import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest;
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeChannelExtractor;
+import static org.junit.Assert.*;
+import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
+import static org.schabi.newpipe.extractor.ServiceList.YouTube;
+import static org.schabi.newpipe.extractor.services.DefaultTests.*;
+
/**
* Test for {@link ChannelExtractor}
*/
public class YoutubeChannelExtractorTest {
+
+ public static class NotAvailable {
+ @BeforeClass
+ public static void setUp() {
+ NewPipe.init(DownloaderTestImpl.getInstance());
+ }
+
+ @Test(expected = ContentNotAvailableException.class)
+ public void deletedFetch() throws Exception {
+ final ChannelExtractor extractor =
+ YouTube.getChannelExtractor("https://www.youtube.com/channel/UCAUc4iz6edWerIjlnL8OSSw");
+ extractor.fetchPage();
+ }
+
+ @Test(expected = ContentNotAvailableException.class)
+ public void nonExistentFetch() throws Exception {
+ final ChannelExtractor extractor =
+ YouTube.getChannelExtractor("https://www.youtube.com/channel/DOESNT-EXIST");
+ extractor.fetchPage();
+ }
+ }
+
public static class Gronkh implements BaseChannelExtractorTest {
private static YoutubeChannelExtractor extractor;
@@ -70,12 +87,12 @@ public class YoutubeChannelExtractorTest {
@Test
public void testRelatedItems() throws Exception {
- defaultTestRelatedItems(extractor, YouTube.getServiceId());
+ defaultTestRelatedItems(extractor);
}
@Test
public void testMoreRelatedItems() throws Exception {
- defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
+ defaultTestMoreItems(extractor);
}
/*//////////////////////////////////////////////////////////////////////////
@@ -160,12 +177,12 @@ public class YoutubeChannelExtractorTest {
@Test
public void testRelatedItems() throws Exception {
- defaultTestRelatedItems(extractor, YouTube.getServiceId());
+ defaultTestRelatedItems(extractor);
}
@Test
public void testMoreRelatedItems() throws Exception {
- defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
+ defaultTestMoreItems(extractor);
}
/*//////////////////////////////////////////////////////////////////////////
@@ -175,7 +192,7 @@ public class YoutubeChannelExtractorTest {
@Test
public void testDescription() throws Exception {
assertTrue("What it actually was: " + extractor.getDescription(),
- extractor.getDescription().contains("Our World is Amazing. Questions? Ideas? Tweet me:"));
+ extractor.getDescription().contains("Our World is Amazing. \n\nQuestions? Ideas? Tweet me:"));
}
@Test
@@ -223,7 +240,7 @@ public class YoutubeChannelExtractorTest {
@Test
public void testGetPageInNewExtractor() throws Exception {
final ChannelExtractor newExtractor = YouTube.getChannelExtractor(extractor.getUrl());
- defaultTestGetPageInNewExtractor(extractor, newExtractor, YouTube.getServiceId());
+ defaultTestGetPageInNewExtractor(extractor, newExtractor);
}
/*//////////////////////////////////////////////////////////////////////////
@@ -262,12 +279,12 @@ public class YoutubeChannelExtractorTest {
@Test
public void testRelatedItems() throws Exception {
- defaultTestRelatedItems(extractor, YouTube.getServiceId());
+ defaultTestRelatedItems(extractor);
}
@Test
public void testMoreRelatedItems() throws Exception {
- defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
+ defaultTestMoreItems(extractor);
}
/*//////////////////////////////////////////////////////////////////////////
@@ -353,12 +370,12 @@ public class YoutubeChannelExtractorTest {
@Test
public void testRelatedItems() throws Exception {
- defaultTestRelatedItems(extractor, YouTube.getServiceId());
+ defaultTestRelatedItems(extractor);
}
@Test
public void testMoreRelatedItems() throws Exception {
- defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
+ defaultTestMoreItems(extractor);
}
/*//////////////////////////////////////////////////////////////////////////
@@ -443,12 +460,12 @@ public class YoutubeChannelExtractorTest {
@Test
public void testRelatedItems() throws Exception {
- defaultTestRelatedItems(extractor, YouTube.getServiceId());
+ defaultTestRelatedItems(extractor);
}
@Test
public void testMoreRelatedItems() throws Exception {
- defaultTestMoreItems(extractor, YouTube.getServiceId());
+ defaultTestMoreItems(extractor);
}
/*//////////////////////////////////////////////////////////////////////////
@@ -489,7 +506,6 @@ public class YoutubeChannelExtractorTest {
}
-
public static class RandomChannel implements BaseChannelExtractorTest {
private static YoutubeChannelExtractor extractor;
@@ -536,13 +552,13 @@ public class YoutubeChannelExtractorTest {
@Test
public void testRelatedItems() throws Exception {
- defaultTestRelatedItems(extractor, YouTube.getServiceId());
+ defaultTestRelatedItems(extractor);
}
@Test
public void testMoreRelatedItems() {
try {
- defaultTestMoreItems(extractor, YouTube.getServiceId());
+ defaultTestMoreItems(extractor);
} catch (Throwable ignored) {
return;
}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelLinkHandlerFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelLinkHandlerFactoryTest.java
index 25f097a0..fc409ffa 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelLinkHandlerFactoryTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelLinkHandlerFactoryTest.java
@@ -38,10 +38,10 @@ public class YoutubeChannelLinkHandlerFactoryTest {
assertTrue(linkHandler.acceptUrl("https://hooktube.com/channel/UClq42foiSgl7sSpLupnugGA"));
assertTrue(linkHandler.acceptUrl("https://hooktube.com/channel/UClq42foiSgl7sSpLupnugGA/videos?disable_polymer=1"));
-
+
assertTrue(linkHandler.acceptUrl("https://invidio.us/user/Gronkh"));
assertTrue(linkHandler.acceptUrl("https://invidio.us/user/Netzkino/videos"));
-
+
assertTrue(linkHandler.acceptUrl("https://invidio.us/channel/UClq42foiSgl7sSpLupnugGA"));
assertTrue(linkHandler.acceptUrl("https://invidio.us/channel/UClq42foiSgl7sSpLupnugGA/videos?disable_polymer=1"));
}
@@ -60,10 +60,10 @@ public class YoutubeChannelLinkHandlerFactoryTest {
assertEquals("channel/UClq42foiSgl7sSpLupnugGA", linkHandler.fromUrl("https://hooktube.com/channel/UClq42foiSgl7sSpLupnugGA").getId());
assertEquals("channel/UClq42foiSgl7sSpLupnugGA", linkHandler.fromUrl("https://hooktube.com/channel/UClq42foiSgl7sSpLupnugGA/videos?disable_polymer=1").getId());
-
+
assertEquals("user/Gronkh", linkHandler.fromUrl("https://invidio.us/user/Gronkh").getId());
assertEquals("user/Netzkino", linkHandler.fromUrl("https://invidio.us/user/Netzkino/videos").getId());
-
+
assertEquals("channel/UClq42foiSgl7sSpLupnugGA", linkHandler.fromUrl("https://invidio.us/channel/UClq42foiSgl7sSpLupnugGA").getId());
assertEquals("channel/UClq42foiSgl7sSpLupnugGA", linkHandler.fromUrl("https://invidio.us/channel/UClq42foiSgl7sSpLupnugGA/videos?disable_polymer=1").getId());
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelLocalizationTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelLocalizationTest.java
index 29f3d032..d5a629b0 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelLocalizationTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelLocalizationTest.java
@@ -49,7 +49,7 @@ public class YoutubeChannelLocalizationTest {
final ChannelExtractor extractor = YouTube.getChannelExtractor(channelUrl);
extractor.forceLocalization(currentLocalization);
extractor.fetchPage();
- itemsPage = defaultTestRelatedItems(extractor, YouTube.getServiceId());
+ itemsPage = defaultTestRelatedItems(extractor);
} catch (Throwable e) {
System.out.println("[!] " + currentLocalization + " → failed");
throw e;
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsExtractorTest.java
index 3345ae3a..4349727b 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsExtractorTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsExtractorTest.java
@@ -84,7 +84,7 @@ public class YoutubeCommentsExtractorTest {
public void testGetCommentsAllData() throws IOException, ExtractionException {
InfoItemsPage comments = extractorYT.getInitialPage();
- DefaultTests.defaultTestListOfItems(YouTube.getServiceId(), comments.getItems(), comments.getErrors());
+ DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors());
for (CommentsInfoItem c : comments.getItems()) {
assertFalse(StringUtil.isBlank(c.getAuthorEndpoint()));
assertFalse(StringUtil.isBlank(c.getAuthorName()));
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeFeedExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeFeedExtractorTest.java
index c7f1b1c1..a6a10ac5 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeFeedExtractorTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeFeedExtractorTest.java
@@ -10,6 +10,7 @@ import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeFeedExtra
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
+import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoMoreItems;
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems;
public class YoutubeFeedExtractorTest {
@@ -60,13 +61,12 @@ public class YoutubeFeedExtractorTest {
@Test
public void testRelatedItems() throws Exception {
- defaultTestRelatedItems(extractor, YouTube.getServiceId());
+ defaultTestRelatedItems(extractor);
}
@Test
- public void testMoreRelatedItems() {
- assertFalse(extractor.hasNextPage());
- assertNull(extractor.getNextPageUrl());
+ public void testMoreRelatedItems() throws Exception {
+ assertNoMoreItems(extractor);
}
}
}
\ No newline at end of file
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeKioskExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeKioskExtractorTest.java
new file mode 100644
index 00000000..bbe8a76c
--- /dev/null
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeKioskExtractorTest.java
@@ -0,0 +1,70 @@
+package org.schabi.newpipe.extractor.services.youtube;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.schabi.newpipe.DownloaderTestImpl;
+import org.schabi.newpipe.extractor.NewPipe;
+import org.schabi.newpipe.extractor.exceptions.ParsingException;
+import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
+import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeTrendingExtractor;
+
+import static org.junit.Assert.assertEquals;
+import static org.schabi.newpipe.extractor.ServiceList.YouTube;
+import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoMoreItems;
+import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems;
+
+public class YoutubeKioskExtractorTest {
+ public static class Trending implements BaseListExtractorTest {
+ private static YoutubeTrendingExtractor extractor;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ NewPipe.init(DownloaderTestImpl.getInstance());
+ extractor = (YoutubeTrendingExtractor) YouTube.getKioskList().getDefaultKioskExtractor();
+ extractor.fetchPage();
+ }
+
+ /*//////////////////////////////////////////////////////////////////////////
+ // Extractor
+ //////////////////////////////////////////////////////////////////////////*/
+
+ @Test
+ public void testServiceId() {
+ assertEquals(YouTube.getServiceId(), extractor.getServiceId());
+ }
+
+ @Test
+ public void testName() throws Exception {
+ assertEquals("Trending", extractor.getName());
+ }
+
+ @Test
+ public void testId() throws Exception {
+ assertEquals("Trending", extractor.getId());
+ }
+
+ @Test
+ public void testUrl() throws ParsingException {
+ assertEquals("https://www.youtube.com/feed/trending", extractor.getUrl());
+ }
+
+ @Test
+ public void testOriginalUrl() throws ParsingException {
+ assertEquals("https://www.youtube.com/feed/trending", extractor.getOriginalUrl());
+ }
+
+ /*//////////////////////////////////////////////////////////////////////////
+ // ListExtractor
+ //////////////////////////////////////////////////////////////////////////*/
+
+ @Test
+ public void testRelatedItems() throws Exception {
+ defaultTestRelatedItems(extractor);
+ }
+
+ @Test
+ public void testMoreRelatedItems() throws Exception {
+ assertNoMoreItems(extractor);
+ }
+ }
+}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelperTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelperTest.java
new file mode 100644
index 00000000..87dbbd75
--- /dev/null
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelperTest.java
@@ -0,0 +1,25 @@
+package org.schabi.newpipe.extractor.services.youtube;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.schabi.newpipe.DownloaderTestImpl;
+import org.schabi.newpipe.extractor.NewPipe;
+import org.schabi.newpipe.extractor.exceptions.ExtractionException;
+import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertTrue;
+
+public class YoutubeParsingHelperTest {
+ @BeforeClass
+ public static void setUp() {
+ NewPipe.init(DownloaderTestImpl.getInstance());
+ }
+
+ @Test
+ public void testIsHardcodedClientVersionValid() throws IOException, ExtractionException {
+ assertTrue("Hardcoded client version is not valid anymore",
+ YoutubeParsingHelper.isHardcodedClientVersionValid());
+ }
+}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java
index d4de9175..65bb7f99 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java
@@ -6,7 +6,8 @@ import org.junit.Test;
import org.schabi.newpipe.DownloaderTestImpl;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe;
-import org.schabi.newpipe.extractor.ServiceList;
+
+import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.services.BasePlaylistExtractorTest;
@@ -23,6 +24,28 @@ import static org.schabi.newpipe.extractor.services.DefaultTests.*;
* Test for {@link YoutubePlaylistExtractor}
*/
public class YoutubePlaylistExtractorTest {
+
+ public static class NotAvailable {
+ @BeforeClass
+ public static void setUp() {
+ NewPipe.init(DownloaderTestImpl.getInstance());
+ }
+
+ @Test(expected = ContentNotAvailableException.class)
+ public void nonExistentFetch() throws Exception {
+ final PlaylistExtractor extractor =
+ YouTube.getPlaylistExtractor("https://www.youtube.com/playlist?list=PL11111111111111111111111111111111");
+ extractor.fetchPage();
+ }
+
+ @Test(expected = ContentNotAvailableException.class)
+ public void invalidId() throws Exception {
+ final PlaylistExtractor extractor =
+ YouTube.getPlaylistExtractor("https://www.youtube.com/playlist?list=INVALID_ID");
+ extractor.fetchPage();
+ }
+ }
+
public static class TimelessPopHits implements BasePlaylistExtractorTest {
private static YoutubePlaylistExtractor extractor;
@@ -70,12 +93,12 @@ public class YoutubePlaylistExtractorTest {
@Test
public void testRelatedItems() throws Exception {
- defaultTestRelatedItems(extractor, YouTube.getServiceId());
+ defaultTestRelatedItems(extractor);
}
@Test
public void testMoreRelatedItems() throws Exception {
- defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
+ defaultTestMoreItems(extractor);
}
/*//////////////////////////////////////////////////////////////////////////
@@ -138,7 +161,7 @@ public class YoutubePlaylistExtractorTest {
@Test
public void testGetPageInNewExtractor() throws Exception {
final PlaylistExtractor newExtractor = YouTube.getPlaylistExtractor(extractor.getUrl());
- defaultTestGetPageInNewExtractor(extractor, newExtractor, YouTube.getServiceId());
+ defaultTestGetPageInNewExtractor(extractor, newExtractor);
}
/*//////////////////////////////////////////////////////////////////////////
@@ -177,18 +200,17 @@ public class YoutubePlaylistExtractorTest {
@Test
public void testRelatedItems() throws Exception {
- defaultTestRelatedItems(extractor, YouTube.getServiceId());
+ defaultTestRelatedItems(extractor);
}
@Test
public void testMoreRelatedItems() throws Exception {
- ListExtractor.InfoItemsPage currentPage
- = defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
+ ListExtractor.InfoItemsPage currentPage = defaultTestMoreItems(extractor);
// test for 2 more levels
for (int i = 0; i < 2; i++) {
currentPage = extractor.getPage(currentPage.getNextPageUrl());
- defaultTestListOfItems(YouTube.getServiceId(), currentPage.getItems(), currentPage.getErrors());
+ defaultTestListOfItems(YouTube, currentPage.getItems(), currentPage.getErrors());
}
}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamLinkHandlerFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamLinkHandlerFactoryTest.java
index 796238f9..908642fd 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamLinkHandlerFactoryTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamLinkHandlerFactoryTest.java
@@ -77,8 +77,8 @@ public class YoutubeStreamLinkHandlerFactoryTest {
assertEquals("jZViOEv90dI", linkHandler.fromUrl("http://www.Youtube.com/embed/jZViOEv90dI").getId());
assertEquals("jZViOEv90dI", linkHandler.fromUrl("http://www.youtube-nocookie.com/embed/jZViOEv90dI").getId());
assertEquals("EhxJLojIE_o", linkHandler.fromUrl("http://www.youtube.com/attribution_link?a=JdfC0C9V6ZI&u=%2Fwatch%3Fv%3DEhxJLojIE_o%26feature%3Dshare").getId());
- assertEquals("jZViOEv90dI", linkHandler.fromUrl("vnd.youtube://www.youtube.com/watch?v=jZViOEv90dI", "youtube.com").getId());
- assertEquals("jZViOEv90dI", linkHandler.fromUrl("vnd.youtube:jZViOEv90dI", "youtube.com").getId());
+ assertEquals("jZViOEv90dI", linkHandler.fromUrl("vnd.youtube://www.youtube.com/watch?v=jZViOEv90dI").getId());
+ assertEquals("jZViOEv90dI", linkHandler.fromUrl("vnd.youtube:jZViOEv90dI").getId());
assertEquals("O0EDx9WAelc", linkHandler.fromUrl("https://music.youtube.com/watch?v=O0EDx9WAelc").getId());
}
@@ -123,7 +123,7 @@ public class YoutubeStreamLinkHandlerFactoryTest {
assertEquals("3msbfr6pBNE", linkHandler.fromUrl("hooktube.com/v/3msbfr6pBNE").getId());
assertEquals("3msbfr6pBNE", linkHandler.fromUrl("hooktube.com/embed/3msbfr6pBNE").getId());
}
-
+
@Test
public void testAcceptInvidioUrl() throws ParsingException {
assertTrue(linkHandler.acceptUrl("https://invidio.us/watch?v=TglNG-yjabU"));
@@ -133,7 +133,7 @@ public class YoutubeStreamLinkHandlerFactoryTest {
assertTrue(linkHandler.acceptUrl("https://invidio.us/watch?v=ocH3oSnZG3c&test=PLS2VU1j4vzuZwooPjV26XM9UEBY2CPNn2"));
assertTrue(linkHandler.acceptUrl("invidio.us/embed/3msbfr6pBNE"));
}
-
+
@Test
public void testGetInvidioIdfromUrl() throws ParsingException {
assertEquals("TglNG-yjabU", linkHandler.fromUrl("https://invidio.us/watch?v=TglNG-yjabU").getId());
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java
deleted file mode 100644
index 4931fc50..00000000
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package org.schabi.newpipe.extractor.services.youtube;
-
-/*
- * Created by Christian Schabesberger on 12.08.17.
- *
- * Copyright (C) Christian Schabesberger 2017
- * YoutubeTrendingExtractorTest.java is part of NewPipe.
- *
- * NewPipe is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * NewPipe is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with NewPipe. If not, see .
- */
-
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.schabi.newpipe.DownloaderTestImpl;
-import org.schabi.newpipe.extractor.ListExtractor;
-import org.schabi.newpipe.extractor.NewPipe;
-import org.schabi.newpipe.extractor.localization.ContentCountry;
-import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeTrendingExtractor;
-import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeTrendingLinkHandlerFactory;
-import org.schabi.newpipe.extractor.stream.StreamInfoItem;
-import org.schabi.newpipe.extractor.utils.Utils;
-
-import static junit.framework.TestCase.assertFalse;
-import static org.junit.Assert.*;
-import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmptyErrors;
-import static org.schabi.newpipe.extractor.ServiceList.YouTube;
-
-
-/**
- * Test for {@link YoutubeTrendingLinkHandlerFactory}
- */
-public class YoutubeTrendingExtractorTest {
-
- static YoutubeTrendingExtractor extractor;
-
- @BeforeClass
- public static void setUp() throws Exception {
- NewPipe.init(DownloaderTestImpl.getInstance());
- extractor = (YoutubeTrendingExtractor) YouTube
- .getKioskList()
- .getExtractorById("Trending", null);
- extractor.forceContentCountry(new ContentCountry("de"));
- extractor.fetchPage();
- }
-
- @Test
- public void testGetDownloader() throws Exception {
- assertNotNull(NewPipe.getDownloader());
- }
-
- @Test
- public void testGetName() throws Exception {
- assertFalse(extractor.getName().isEmpty());
- }
-
- @Test
- public void testId() throws Exception {
- assertEquals(extractor.getId(), "Trending");
- }
-
- @Test
- public void testGetStreamsQuantity() throws Exception {
- ListExtractor.InfoItemsPage page = extractor.getInitialPage();
- Utils.printErrors(page.getErrors());
- assertTrue("no streams are received", page.getItems().size() >= 20);
- }
-
- @Test
- public void testGetStreamsErrors() throws Exception {
- assertEmptyErrors("errors during stream list extraction", extractor.getInitialPage().getErrors());
- }
-
- @Test
- public void testHasMoreStreams() throws Exception {
- // Setup the streams
- extractor.getInitialPage();
- assertFalse("has more streams", extractor.hasNextPage());
- }
-
- @Test
- public void testGetNextPage() {
- assertTrue("extractor has next streams", extractor.getPage(extractor.getNextPageUrl()) == null
- || extractor.getPage(extractor.getNextPageUrl()).getItems().isEmpty());
- }
-
- @Test
- public void testGetUrl() throws Exception {
- assertEquals(extractor.getUrl(), extractor.getUrl(), "https://www.youtube.com/feed/trending");
- }
-}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingKioskInfoTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingKioskInfoTest.java
index c8e23c06..c85d6b52 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingKioskInfoTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingKioskInfoTest.java
@@ -1,24 +1,24 @@
package org.schabi.newpipe.extractor.services.youtube;
- /*
- * Created by Christian Schabesberger on 12.08.17.
- *
- * Copyright (C) Christian Schabesberger 2017
- * YoutubeTrendingKioskInfoTest.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 .
- */
+/*
+ * Created by Christian Schabesberger on 12.08.17.
+ *
+ * Copyright (C) Christian Schabesberger 2017
+ * YoutubeTrendingKioskInfoTest.java is part of NewPipe.
+ *
+ * NewPipe is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * NewPipe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with NewPipe. If not, see .
+ */
import org.junit.BeforeClass;
import org.junit.Test;
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorBaseTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorBaseTest.java
index 8b19b11e..729254ad 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorBaseTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorBaseTest.java
@@ -3,10 +3,8 @@ package org.schabi.newpipe.extractor.services.youtube.search;
import org.junit.Test;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor;
-import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSearchExtractor;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java
index 91cbebd9..cb72622b 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java
@@ -12,8 +12,17 @@ import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSearchExtractor;
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory;
+import java.net.URL;
+import java.net.URLDecoder;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
import static java.util.Arrays.asList;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
public class YoutubeSearchExtractorChannelOnlyTest extends YoutubeSearchExtractorBaseTest {
@@ -45,19 +54,32 @@ public class YoutubeSearchExtractorChannelOnlyTest extends YoutubeSearchExtracto
}
}
assertFalse("First and second page are equal", equals);
-
- assertEquals("https://www.youtube.com/results?q=pewdiepie&sp=EgIQAlAU&gl=GB&page=3", secondPage.getNextPageUrl());
}
@Test
public void testGetSecondPageUrl() throws Exception {
- assertEquals("https://www.youtube.com/results?q=pewdiepie&sp=EgIQAlAU&gl=GB&page=2", extractor.getNextPageUrl());
+ URL url = new URL(extractor.getNextPageUrl());
+
+ assertEquals(url.getHost(), "www.youtube.com");
+ assertEquals(url.getPath(), "/results");
+
+ Map queryPairs = new LinkedHashMap<>();
+ for (String queryPair : url.getQuery().split("&")) {
+ int index = queryPair.indexOf("=");
+ queryPairs.put(URLDecoder.decode(queryPair.substring(0, index), "UTF-8"),
+ URLDecoder.decode(queryPair.substring(index + 1), "UTF-8"));
+ }
+
+ assertEquals("pewdiepie", queryPairs.get("search_query"));
+ assertEquals(queryPairs.get("ctoken"), queryPairs.get("continuation"));
+ assertTrue(queryPairs.get("continuation").length() > 5);
+ assertTrue(queryPairs.get("itct").length() > 5);
}
@Ignore
@Test
public void testOnlyContainChannels() {
- for(InfoItem item : itemsPage.getItems()) {
+ for (InfoItem item : itemsPage.getItems()) {
if (!(item instanceof ChannelInfoItem)) {
fail("The following item is no channel item: " + item.toString());
}
@@ -66,17 +88,22 @@ public class YoutubeSearchExtractorChannelOnlyTest extends YoutubeSearchExtracto
@Test
public void testChannelUrl() {
- for(InfoItem item : itemsPage.getItems()) {
+ for (InfoItem item : itemsPage.getItems()) {
if (item instanceof ChannelInfoItem) {
ChannelInfoItem channel = (ChannelInfoItem) item;
- if (channel.getSubscriberCount() > 5e7) { // the real PewDiePie
+ if (channel.getSubscriberCount() > 1e8) { // the real PewDiePie
assertEquals("https://www.youtube.com/channel/UC-lHJZR3Gqxm24_Vd_AJ5Yw", item.getUrl());
- } else {
- assertThat(item.getUrl(), CoreMatchers.startsWith("https://www.youtube.com/channel/"));
+ break;
}
}
}
+
+ for (InfoItem item : itemsPage.getItems()) {
+ if (item instanceof ChannelInfoItem) {
+ assertThat(item.getUrl(), CoreMatchers.startsWith("https://www.youtube.com/channel/"));
+ }
+ }
}
@Test
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorDefaultTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorDefaultTest.java
index 49e3520d..1f905bde 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorDefaultTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorDefaultTest.java
@@ -6,11 +6,15 @@ import org.schabi.newpipe.DownloaderTestImpl;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe;
-import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSearchExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
+import java.net.URL;
+import java.net.URLDecoder;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
@@ -49,13 +53,28 @@ public class YoutubeSearchExtractorDefaultTest extends YoutubeSearchExtractorBas
@Test
public void testGetUrl() throws Exception {
- assertEquals("https://www.youtube.com/results?q=pewdiepie&gl=GB", extractor.getUrl());
+ assertEquals("https://www.youtube.com/results?search_query=pewdiepie&gl=GB", extractor.getUrl());
}
@Test
public void testGetSecondPageUrl() throws Exception {
- assertEquals("https://www.youtube.com/results?q=pewdiepie&gl=GB&page=2", extractor.getNextPageUrl());
+ URL url = new URL(extractor.getNextPageUrl());
+
+ assertEquals(url.getHost(), "www.youtube.com");
+ assertEquals(url.getPath(), "/results");
+
+ Map queryPairs = new LinkedHashMap<>();
+ for (String queryPair : url.getQuery().split("&")) {
+ int index = queryPair.indexOf("=");
+ queryPairs.put(URLDecoder.decode(queryPair.substring(0, index), "UTF-8"),
+ URLDecoder.decode(queryPair.substring(index + 1), "UTF-8"));
+ }
+
+ assertEquals("pewdiepie", queryPairs.get("search_query"));
+ assertEquals(queryPairs.get("ctoken"), queryPairs.get("continuation"));
+ assertTrue(queryPairs.get("continuation").length() > 5);
+ assertTrue(queryPairs.get("itct").length() > 5);
}
@Test
@@ -76,8 +95,8 @@ public class YoutubeSearchExtractorDefaultTest extends YoutubeSearchExtractorBas
@Test
public void testResultListCheckIfContainsStreamItems() {
boolean hasStreams = false;
- for(InfoItem item : itemsPage.getItems()) {
- if(item instanceof StreamInfoItem) {
+ for (InfoItem item : itemsPage.getItems()) {
+ if (item instanceof StreamInfoItem) {
hasStreams = true;
}
}
@@ -96,20 +115,18 @@ public class YoutubeSearchExtractorDefaultTest extends YoutubeSearchExtractorBas
boolean equals = true;
for (int i = 0; i < secondPage.getItems().size()
&& i < itemsPage.getItems().size(); i++) {
- if(!secondPage.getItems().get(i).getUrl().equals(
+ if (!secondPage.getItems().get(i).getUrl().equals(
itemsPage.getItems().get(i).getUrl())) {
equals = false;
}
}
assertFalse("First and second page are equal", equals);
-
- assertEquals("https://www.youtube.com/results?q=pewdiepie&gl=GB&page=3", secondPage.getNextPageUrl());
}
@Test
public void testSuggestionNotNull() throws Exception {
//todo write a real test
- assertTrue(extractor.getSearchSuggestion() != null);
+ assertNotNull(extractor.getSearchSuggestion());
}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchPagingTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchPagingTest.java
index 7df7b0cb..656e197a 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchPagingTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchPagingTest.java
@@ -1,15 +1,5 @@
package org.schabi.newpipe.extractor.services.youtube.search;
-import static java.util.Collections.singletonList;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.schabi.newpipe.extractor.ServiceList.YouTube;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.DownloaderTestImpl;
@@ -19,6 +9,14 @@ import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSearchExtractor;
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static java.util.Collections.singletonList;
+import static org.junit.Assert.*;
+import static org.schabi.newpipe.extractor.ServiceList.YouTube;
+
public class YoutubeSearchPagingTest {
private static ListExtractor.InfoItemsPage page1;
private static ListExtractor.InfoItemsPage page2;
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchQHTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchQHTest.java
index c3d3f93c..fc6af4c4 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchQHTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchQHTest.java
@@ -1,24 +1,21 @@
package org.schabi.newpipe.extractor.services.youtube.search;
import org.junit.Test;
-import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
-import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.CHANNELS;
-import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.PLAYLISTS;
-import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.VIDEOS;
+import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.*;
public class YoutubeSearchQHTest {
@Test
public void testRegularValues() throws Exception {
- assertEquals("https://www.youtube.com/results?q=asdf", YouTube.getSearchQHFactory().fromQuery("asdf").getUrl());
- assertEquals("https://www.youtube.com/results?q=hans",YouTube.getSearchQHFactory().fromQuery("hans").getUrl());
- assertEquals("https://www.youtube.com/results?q=Poifj%26jaijf", YouTube.getSearchQHFactory().fromQuery("Poifj&jaijf").getUrl());
- assertEquals("https://www.youtube.com/results?q=G%C3%BCl%C3%BCm", YouTube.getSearchQHFactory().fromQuery("Gülüm").getUrl());
- assertEquals("https://www.youtube.com/results?q=%3Fj%24%29H%C2%A7B", YouTube.getSearchQHFactory().fromQuery("?j$)H§B").getUrl());
+ assertEquals("https://www.youtube.com/results?search_query=asdf", YouTube.getSearchQHFactory().fromQuery("asdf").getUrl());
+ assertEquals("https://www.youtube.com/results?search_query=hans", YouTube.getSearchQHFactory().fromQuery("hans").getUrl());
+ assertEquals("https://www.youtube.com/results?search_query=Poifj%26jaijf", YouTube.getSearchQHFactory().fromQuery("Poifj&jaijf").getUrl());
+ assertEquals("https://www.youtube.com/results?search_query=G%C3%BCl%C3%BCm", YouTube.getSearchQHFactory().fromQuery("Gülüm").getUrl());
+ assertEquals("https://www.youtube.com/results?search_query=%3Fj%24%29H%C2%A7B", YouTube.getSearchQHFactory().fromQuery("?j$)H§B").getUrl());
}
@Test
@@ -31,13 +28,13 @@ public class YoutubeSearchQHTest {
@Test
public void testWithContentfilter() throws Exception {
- assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQAVAU", YouTube.getSearchQHFactory()
+ assertEquals("https://www.youtube.com/results?search_query=asdf&sp=EgIQAQ%253D%253D", YouTube.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{VIDEOS}), "").getUrl());
- assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQAlAU", YouTube.getSearchQHFactory()
+ assertEquals("https://www.youtube.com/results?search_query=asdf&sp=EgIQAg%253D%253D", YouTube.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{CHANNELS}), "").getUrl());
- assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQA1AU", YouTube.getSearchQHFactory()
+ assertEquals("https://www.youtube.com/results?search_query=asdf&sp=EgIQAw%253D%253D", YouTube.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{PLAYLISTS}), "").getUrl());
- assertEquals("https://www.youtube.com/results?q=asdf", YouTube.getSearchQHFactory()
+ assertEquals("https://www.youtube.com/results?search_query=asdf", YouTube.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{"fjiijie"}), "").getUrl());
}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorAgeRestrictedTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorAgeRestrictedTest.java
index b9da6d17..3710b4ee 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorAgeRestrictedTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorAgeRestrictedTest.java
@@ -64,7 +64,7 @@ public class YoutubeStreamExtractorAgeRestrictedTest {
@Test
public void testGetDescription() throws ParsingException {
assertNotNull(extractor.getDescription());
- assertFalse(extractor.getDescription().isEmpty());
+ assertFalse(extractor.getDescription().getContent().isEmpty());
}
@Test
@@ -117,7 +117,7 @@ public class YoutubeStreamExtractorAgeRestrictedTest {
streams.addAll(extractor.getVideoStreams());
streams.addAll(extractor.getVideoOnlyStreams());
- assertTrue(Integer.toString(streams.size()),streams.size() > 0);
+ assertTrue(Integer.toString(streams.size()), streams.size() > 0);
for (VideoStream s : streams) {
assertTrue(s.getUrl(),
s.getUrl().contains(HTTPS));
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorControversialTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorControversialTest.java
index f0bd7715..915f42ae 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorControversialTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorControversialTest.java
@@ -65,7 +65,7 @@ public class YoutubeStreamExtractorControversialTest {
@Test
public void testGetDescription() throws ParsingException {
assertNotNull(extractor.getDescription());
- assertFalse(extractor.getDescription().isEmpty());
+ assertFalse(extractor.getDescription().getContent().isEmpty());
}
@Test
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java
index 5f21df55..0d36fd9a 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java
@@ -7,20 +7,28 @@ import org.schabi.newpipe.DownloaderTestImpl;
import org.schabi.newpipe.extractor.ExtractorAsserts;
import org.schabi.newpipe.extractor.MediaFormat;
import org.schabi.newpipe.extractor.NewPipe;
+import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor;
-import org.schabi.newpipe.extractor.stream.*;
+import org.schabi.newpipe.extractor.stream.Frameset;
+import org.schabi.newpipe.extractor.stream.StreamExtractor;
+import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
+import org.schabi.newpipe.extractor.stream.StreamType;
+import org.schabi.newpipe.extractor.stream.VideoStream;
import org.schabi.newpipe.extractor.utils.Utils;
-import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
-import static java.util.Objects.*;
-import static org.junit.Assert.*;
+import static java.util.Objects.requireNonNull;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
@@ -49,6 +57,27 @@ import static org.schabi.newpipe.extractor.ServiceList.YouTube;
*/
public class YoutubeStreamExtractorDefaultTest {
+ public static class NotAvailable {
+ @BeforeClass
+ public static void setUp() {
+ NewPipe.init(DownloaderTestImpl.getInstance());
+ }
+
+ @Test(expected = ContentNotAvailableException.class)
+ public void nonExistentFetch() throws Exception {
+ final StreamExtractor extractor =
+ YouTube.getStreamExtractor("https://www.youtube.com/watch?v=don-t-exist");
+ extractor.fetchPage();
+ }
+
+ @Test(expected = ParsingException.class)
+ public void invalidId() throws Exception {
+ final StreamExtractor extractor =
+ YouTube.getStreamExtractor("https://www.youtube.com/watch?v=INVALID_ID_INVALID_ID");
+ extractor.fetchPage();
+ }
+ }
+
/**
* Test for {@link StreamExtractor}
*/
@@ -83,13 +112,12 @@ public class YoutubeStreamExtractorDefaultTest {
@Test
public void testGetDescription() throws ParsingException {
assertNotNull(extractor.getDescription());
- assertFalse(extractor.getDescription().isEmpty());
+ assertFalse(extractor.getDescription().getContent().isEmpty());
}
@Test
public void testGetFullLinksInDescription() throws ParsingException {
- assertTrue(extractor.getDescription().contains("http://adele.com"));
- assertFalse(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQi..."));
+ assertTrue(extractor.getDescription().getContent().contains("http://adele.com"));
}
@Test
@@ -126,7 +154,7 @@ public class YoutubeStreamExtractorDefaultTest {
public void testGetUploaderUrl() throws ParsingException {
String url = extractor.getUploaderUrl();
if (!url.equals("https://www.youtube.com/channel/UCsRM0YB_dabtEPGPTKo-gcw") &&
- !url.equals("https://www.youtube.com/channel/UComP_epzeKzvBX156r6pm1Q")) {
+ !url.equals("https://www.youtube.com/channel/UComP_epzeKzvBX156r6pm1Q")) {
fail("Uploader url is neither the music channel one nor the Vevo one");
}
}
@@ -142,12 +170,12 @@ public class YoutubeStreamExtractorDefaultTest {
}
@Test
- public void testGetAudioStreams() throws IOException, ExtractionException {
+ public void testGetAudioStreams() throws ExtractionException {
assertFalse(extractor.getAudioStreams().isEmpty());
}
@Test
- public void testGetVideoStreams() throws IOException, ExtractionException {
+ public void testGetVideoStreams() throws ExtractionException {
for (VideoStream s : extractor.getVideoStreams()) {
assertIsSecureUrl(s.url);
assertTrue(s.resolution.length() > 0);
@@ -169,7 +197,7 @@ public class YoutubeStreamExtractorDefaultTest {
}
@Test
- public void testGetRelatedVideos() throws ExtractionException, IOException {
+ public void testGetRelatedVideos() throws ExtractionException {
StreamInfoItemsCollector relatedVideos = extractor.getRelatedStreams();
Utils.printErrors(relatedVideos.getErrors());
assertFalse(relatedVideos.getItems().isEmpty());
@@ -177,13 +205,13 @@ public class YoutubeStreamExtractorDefaultTest {
}
@Test
- public void testGetSubtitlesListDefault() throws IOException, ExtractionException {
+ public void testGetSubtitlesListDefault() {
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
assertTrue(extractor.getSubtitlesDefault().isEmpty());
}
@Test
- public void testGetSubtitlesList() throws IOException, ExtractionException {
+ public void testGetSubtitlesList() {
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
assertTrue(extractor.getSubtitles(MediaFormat.TTML).isEmpty());
}
@@ -215,18 +243,14 @@ public class YoutubeStreamExtractorDefaultTest {
@Test
public void testGetDescription() throws ParsingException {
assertNotNull(extractor.getDescription());
- assertFalse(extractor.getDescription().isEmpty());
+ assertFalse(extractor.getDescription().getContent().isEmpty());
}
@Test
public void testGetFullLinksInDescription() throws ParsingException {
- assertTrue(extractor.getDescription().contains("https://www.reddit.com/r/PewdiepieSubmissions/"));
- assertTrue(extractor.getDescription().contains("https://www.youtube.com/channel/UC3e8EMTOn4g6ZSKggHTnNng"));
- assertTrue(extractor.getDescription().contains("https://usa.clutchchairz.com/product/pewdiepie-edition-throttle-series/"));
-
- assertFalse(extractor.getDescription().contains("https://www.reddit.com/r/PewdiepieSub..."));
- assertFalse(extractor.getDescription().contains("https://www.youtube.com/channel/UC3e8..."));
- assertFalse(extractor.getDescription().contains("https://usa.clutchchairz.com/product/..."));
+ assertTrue(extractor.getDescription().getContent().contains("https://www.reddit.com/r/PewdiepieSubmissions/"));
+ assertTrue(extractor.getDescription().getContent().contains("https://www.youtube.com/channel/UC3e8EMTOn4g6ZSKggHTnNng"));
+ assertTrue(extractor.getDescription().getContent().contains("https://usa.clutchchairz.com/product/pewdiepie-edition-throttle-series/"));
}
}
@@ -244,20 +268,16 @@ public class YoutubeStreamExtractorDefaultTest {
@Test
public void testGetDescription() throws ParsingException {
assertNotNull(extractor.getDescription());
- assertFalse(extractor.getDescription().isEmpty());
+ assertFalse(extractor.getDescription().getContent().isEmpty());
}
@Test
public void testGetFullLinksInDescription() throws ParsingException {
- assertTrue(extractor.getDescription().contains("https://www.youtube.com/watch?v=X7FLCHVXpsA&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34"));
- assertTrue(extractor.getDescription().contains("https://www.youtube.com/watch?v=Lqv6G0pDNnw&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34"));
- assertTrue(extractor.getDescription().contains("https://www.youtube.com/watch?v=XxaRBPyrnBU&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34"));
- assertTrue(extractor.getDescription().contains("https://www.youtube.com/watch?v=U-9tUEOFKNU&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34"));
-
- assertFalse(extractor.getDescription().contains("https://youtu.be/X7FLCHVXpsA?list=PL7..."));
- assertFalse(extractor.getDescription().contains("https://youtu.be/Lqv6G0pDNnw?list=PL7..."));
- assertFalse(extractor.getDescription().contains("https://youtu.be/XxaRBPyrnBU?list=PL7..."));
- assertFalse(extractor.getDescription().contains("https://youtu.be/U-9tUEOFKNU?list=PL7..."));
+ final String description = extractor.getDescription().getContent();
+ assertTrue(description.contains("https://www.youtube.com/watch?v=X7FLCHVXpsA&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34"));
+ assertTrue(description.contains("https://www.youtube.com/watch?v=Lqv6G0pDNnw&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34"));
+ assertTrue(description.contains("https://www.youtube.com/watch?v=XxaRBPyrnBU&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34"));
+ assertTrue(description.contains("https://www.youtube.com/watch?v=U-9tUEOFKNU&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34"));
}
}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorLivestreamTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorLivestreamTest.java
index eb2541ed..f5c7fe10 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorLivestreamTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorLivestreamTest.java
@@ -13,9 +13,12 @@ import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.extractor.stream.VideoStream;
import org.schabi.newpipe.extractor.utils.Utils;
-import java.io.IOException;
-
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
@@ -26,7 +29,7 @@ public class YoutubeStreamExtractorLivestreamTest {
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = (YoutubeStreamExtractor) YouTube
- .getStreamExtractor("https://www.youtube.com/watch?v=EcEMX-63PKY");
+ .getStreamExtractor("https://www.youtube.com/watch?v=5qap5aO4i9A");
extractor.fetchPage();
}
@@ -44,13 +47,12 @@ public class YoutubeStreamExtractorLivestreamTest {
@Test
public void testGetDescription() throws ParsingException {
assertNotNull(extractor.getDescription());
- assertFalse(extractor.getDescription().isEmpty());
+ assertFalse(extractor.getDescription().getContent().isEmpty());
}
@Test
public void testGetFullLinksInDescription() throws ParsingException {
- assertTrue(extractor.getDescription().contains("https://www.instagram.com/nathalie.baraton/"));
- assertFalse(extractor.getDescription().contains("https://www.instagram.com/nathalie.ba..."));
+ assertTrue(extractor.getDescription().getContent().contains("https://bit.ly/chilledcow-playlists"));
}
@Test
@@ -119,7 +121,7 @@ public class YoutubeStreamExtractorLivestreamTest {
}
@Test
- public void testGetRelatedVideos() throws ExtractionException, IOException {
+ public void testGetRelatedVideos() throws ExtractionException {
StreamInfoItemsCollector relatedVideos = extractor.getRelatedStreams();
Utils.printErrors(relatedVideos.getErrors());
assertFalse(relatedVideos.getItems().isEmpty());
@@ -127,12 +129,12 @@ public class YoutubeStreamExtractorLivestreamTest {
}
@Test
- public void testGetSubtitlesListDefault() throws IOException, ExtractionException {
+ public void testGetSubtitlesListDefault() {
assertTrue(extractor.getSubtitlesDefault().isEmpty());
}
@Test
- public void testGetSubtitlesList() throws IOException, ExtractionException {
+ public void testGetSubtitlesList() {
assertTrue(extractor.getSubtitles(MediaFormat.TTML).isEmpty());
}
}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorUnlistedTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorUnlistedTest.java
new file mode 100644
index 00000000..5dcd73ec
--- /dev/null
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorUnlistedTest.java
@@ -0,0 +1,166 @@
+package org.schabi.newpipe.extractor.services.youtube.stream;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.schabi.newpipe.DownloaderTestImpl;
+import org.schabi.newpipe.extractor.MediaFormat;
+import org.schabi.newpipe.extractor.NewPipe;
+import org.schabi.newpipe.extractor.exceptions.ExtractionException;
+import org.schabi.newpipe.extractor.exceptions.ParsingException;
+import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor;
+import org.schabi.newpipe.extractor.stream.AudioStream;
+import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
+import org.schabi.newpipe.extractor.stream.StreamType;
+import org.schabi.newpipe.extractor.stream.VideoStream;
+import org.schabi.newpipe.extractor.utils.Utils;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.List;
+
+import static org.junit.Assert.*;
+import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
+import static org.schabi.newpipe.extractor.ServiceList.YouTube;
+
+public class YoutubeStreamExtractorUnlistedTest {
+ private static YoutubeStreamExtractor extractor;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ NewPipe.init(DownloaderTestImpl.getInstance());
+ extractor = (YoutubeStreamExtractor) YouTube
+ .getStreamExtractor("https://www.youtube.com/watch?v=udsB8KnIJTg");
+ extractor.fetchPage();
+ }
+
+ @Test
+ public void testGetInvalidTimeStamp() throws ParsingException {
+ assertTrue(extractor.getTimeStamp() + "",
+ extractor.getTimeStamp() <= 0);
+ }
+
+ @Test
+ public void testGetTitle() throws ParsingException {
+ assertFalse(extractor.getName().isEmpty());
+ }
+
+ @Test
+ public void testGetDescription() throws ParsingException {
+ assertNotNull(extractor.getDescription());
+ assertFalse(extractor.getDescription().getContent().isEmpty());
+ }
+
+ @Test
+ public void testGetFullLinksInDescription() throws ParsingException {
+ assertTrue(extractor.getDescription().getContent().contains("https://www.youtube.com/user/Roccowschiptune"));
+ }
+
+ @Test
+ public void testGetUploaderName() throws ParsingException {
+ assertNotNull(extractor.getUploaderName());
+ assertFalse(extractor.getUploaderName().isEmpty());
+ }
+
+
+ @Test
+ public void testGetLength() throws ParsingException {
+ assertEquals(2488, extractor.getLength());
+ }
+
+ @Test
+ public void testGetViewCount() throws ParsingException {
+ long count = extractor.getViewCount();
+ assertTrue(Long.toString(count), count >= /* specific to that video */ 1225);
+ }
+
+ @Test
+ public void testGetTextualUploadDate() throws ParsingException {
+ Assert.assertEquals("2017-09-22", extractor.getTextualUploadDate());
+ }
+
+ @Test
+ public void testGetUploadDate() throws ParsingException, ParseException {
+ final Calendar instance = Calendar.getInstance();
+ instance.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("2017-09-22"));
+ assertNotNull(extractor.getUploadDate());
+ assertEquals(instance, extractor.getUploadDate().date());
+ }
+
+ @Test
+ public void testGetUploaderUrl() throws ParsingException {
+ assertEquals("https://www.youtube.com/channel/UCPysfiuOv4VKBeXFFPhKXyw", 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 ExtractionException {
+ List audioStreams = extractor.getAudioStreams();
+ assertFalse(audioStreams.isEmpty());
+ for (AudioStream s : audioStreams) {
+ assertIsSecureUrl(s.url);
+ assertTrue(Integer.toString(s.getFormatId()),
+ 0x100 <= s.getFormatId() && s.getFormatId() < 0x1000);
+ }
+ }
+
+ @Test
+ public void testGetVideoStreams() throws ExtractionException {
+ for (VideoStream s : extractor.getVideoStreams()) {
+ assertIsSecureUrl(s.url);
+ assertTrue(s.resolution.length() > 0);
+ assertTrue(Integer.toString(s.getFormatId()),
+ 0 <= s.getFormatId() && s.getFormatId() < 0x100);
+ }
+ }
+
+ @Test
+ public void testStreamType() throws ParsingException {
+ assertSame(StreamType.VIDEO_STREAM, extractor.getStreamType());
+ }
+
+ @Test
+ public void testGetNextVideo() throws ExtractionException {
+ assertNull(extractor.getNextStream());
+ }
+
+ @Test
+ public void testGetRelatedVideos() throws ExtractionException {
+ StreamInfoItemsCollector relatedVideos = extractor.getRelatedStreams();
+ Utils.printErrors(relatedVideos.getErrors());
+ assertFalse(relatedVideos.getItems().isEmpty());
+ assertTrue(relatedVideos.getErrors().isEmpty());
+ }
+
+ @Test
+ public void testGetSubtitlesListDefault() {
+ assertFalse(extractor.getSubtitlesDefault().isEmpty());
+ }
+
+ @Test
+ public void testGetSubtitlesList() {
+ assertFalse(extractor.getSubtitles(MediaFormat.TTML).isEmpty());
+ }
+
+ @Test
+ public void testGetLikeCount() throws ParsingException {
+ long likeCount = extractor.getLikeCount();
+ assertTrue("" + likeCount, likeCount >= 96);
+ }
+
+ @Test
+ public void testGetDislikeCount() throws ParsingException {
+ long dislikeCount = extractor.getDislikeCount();
+ assertTrue("" + dislikeCount, dislikeCount >= 0);
+ }
+}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/utils/JsonUtilsTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/utils/JsonUtilsTest.java
index dc8f2b04..925a647c 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/utils/JsonUtilsTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/utils/JsonUtilsTest.java
@@ -1,47 +1,46 @@
package org.schabi.newpipe.extractor.utils;
-import static org.junit.Assert.assertTrue;
-
-import java.util.List;
-
-import org.junit.Test;
-import org.schabi.newpipe.extractor.exceptions.ParsingException;
-
import com.grack.nanojson.JsonArray;
import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser;
import com.grack.nanojson.JsonParserException;
+import org.junit.Test;
+import org.schabi.newpipe.extractor.exceptions.ParsingException;
+
+import java.util.List;
+
+import static org.junit.Assert.assertTrue;
public class JsonUtilsTest {
-
+
@Test
public void testGetValueFlat() throws JsonParserException, ParsingException {
JsonObject obj = JsonParser.object().from("{\"name\":\"John\",\"age\":30,\"cars\":{\"car1\":\"Ford\",\"car2\":\"BMW\",\"car3\":\"Fiat\"}}");
- assertTrue("John".equals(JsonUtils.getValue(obj, "name")));
+ assertTrue("John".equals(JsonUtils.getValue(obj, "name")));
}
-
+
@Test
public void testGetValueNested() throws JsonParserException, ParsingException {
JsonObject obj = JsonParser.object().from("{\"name\":\"John\",\"age\":30,\"cars\":{\"car1\":\"Ford\",\"car2\":\"BMW\",\"car3\":\"Fiat\"}}");
assertTrue("BMW".equals(JsonUtils.getValue(obj, "cars.car2")));
}
-
+
@Test
public void testGetArray() throws JsonParserException, ParsingException {
JsonObject obj = JsonParser.object().from("{\"id\":\"0001\",\"type\":\"donut\",\"name\":\"Cake\",\"ppu\":0.55,\"batters\":{\"batter\":[{\"id\":\"1001\",\"type\":\"Regular\"},{\"id\":\"1002\",\"type\":\"Chocolate\"},{\"id\":\"1003\",\"type\":\"Blueberry\"},{\"id\":\"1004\",\"type\":\"Devil's Food\"}]},\"topping\":[{\"id\":\"5001\",\"type\":\"None\"},{\"id\":\"5002\",\"type\":\"Glazed\"},{\"id\":\"5005\",\"type\":\"Sugar\"},{\"id\":\"5007\",\"type\":\"Powdered Sugar\"},{\"id\":\"5006\",\"type\":\"Chocolate with Sprinkles\"},{\"id\":\"5003\",\"type\":\"Chocolate\"},{\"id\":\"5004\",\"type\":\"Maple\"}]}");
JsonArray arr = (JsonArray) JsonUtils.getValue(obj, "batters.batter");
assertTrue(!arr.isEmpty());
}
-
+
@Test
public void testGetValues() throws JsonParserException, ParsingException {
JsonObject obj = JsonParser.object().from("{\"id\":\"0001\",\"type\":\"donut\",\"name\":\"Cake\",\"ppu\":0.55,\"batters\":{\"batter\":[{\"id\":\"1001\",\"type\":\"Regular\"},{\"id\":\"1002\",\"type\":\"Chocolate\"},{\"id\":\"1003\",\"type\":\"Blueberry\"},{\"id\":\"1004\",\"type\":\"Devil's Food\"}]},\"topping\":[{\"id\":\"5001\",\"type\":\"None\"},{\"id\":\"5002\",\"type\":\"Glazed\"},{\"id\":\"5005\",\"type\":\"Sugar\"},{\"id\":\"5007\",\"type\":\"Powdered Sugar\"},{\"id\":\"5006\",\"type\":\"Chocolate with Sprinkles\"},{\"id\":\"5003\",\"type\":\"Chocolate\"},{\"id\":\"5004\",\"type\":\"Maple\"}]}");
JsonArray arr = (JsonArray) JsonUtils.getValue(obj, "topping");
List types = JsonUtils.getValues(arr, "type");
assertTrue(types.contains("Chocolate with Sprinkles"));
-
+
}
}