changed all == null || isEmpty() to isNullOrEmpty()
This commit is contained in:
parent
202a73516c
commit
de26e00079
17 changed files with 55 additions and 37 deletions
|
@ -18,6 +18,7 @@ import javax.annotation.Nonnull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING;
|
import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING;
|
||||||
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
public class SoundcloudChannelExtractor extends ChannelExtractor {
|
public class SoundcloudChannelExtractor extends ChannelExtractor {
|
||||||
|
@ -132,7 +133,7 @@ public class SoundcloudChannelExtractor extends ChannelExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InfoItemsPage<StreamInfoItem> getPage(final String pageUrl) throws IOException, ExtractionException {
|
public InfoItemsPage<StreamInfoItem> getPage(final String pageUrl) throws IOException, ExtractionException {
|
||||||
if (pageUrl == null || pageUrl.isEmpty()) {
|
if (isNullOrEmpty(pageUrl)) {
|
||||||
throw new ExtractionException(new IllegalArgumentException("Page url is empty or null"));
|
throw new ExtractionException(new IllegalArgumentException("Page url is empty or null"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import javax.annotation.Nonnull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||||
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
|
|
||||||
public class SoundcloudChartsExtractor extends KioskExtractor<StreamInfoItem> {
|
public class SoundcloudChartsExtractor extends KioskExtractor<StreamInfoItem> {
|
||||||
private StreamInfoItemsCollector collector = null;
|
private StreamInfoItemsCollector collector = null;
|
||||||
|
@ -36,7 +37,7 @@ public class SoundcloudChartsExtractor extends KioskExtractor<StreamInfoItem> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InfoItemsPage<StreamInfoItem> getPage(String pageUrl) throws IOException, ExtractionException {
|
public InfoItemsPage<StreamInfoItem> getPage(String pageUrl) throws IOException, ExtractionException {
|
||||||
if (pageUrl == null || pageUrl.isEmpty()) {
|
if (isNullOrEmpty(pageUrl)) {
|
||||||
throw new ExtractionException(new IllegalArgumentException("Page url is empty or null"));
|
throw new ExtractionException(new IllegalArgumentException("Page url is empty or null"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -162,7 +162,7 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InfoItemsPage<StreamInfoItem> getPage(String pageUrl) throws IOException, ExtractionException {
|
public InfoItemsPage<StreamInfoItem> getPage(String pageUrl) throws IOException, ExtractionException {
|
||||||
if (pageUrl == null || pageUrl.isEmpty()) {
|
if (isNullOrEmpty(pageUrl)) {
|
||||||
throw new ExtractionException(new IllegalArgumentException("Page url is empty or null"));
|
throw new ExtractionException(new IllegalArgumentException("Page url is empty or null"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -391,7 +391,7 @@ public class YoutubeParsingHelper {
|
||||||
* @return text in the JSON object or {@code null}
|
* @return text in the JSON object or {@code null}
|
||||||
*/
|
*/
|
||||||
public static String getTextFromObject(JsonObject textObject, boolean html) throws ParsingException {
|
public static String getTextFromObject(JsonObject textObject, boolean html) throws ParsingException {
|
||||||
if (textObject == null || textObject.isEmpty()) return null;
|
if (isNullOrEmpty(textObject)) return null;
|
||||||
|
|
||||||
if (textObject.has("simpleText")) return textObject.getString("simpleText");
|
if (textObject.has("simpleText")) return textObject.getString("simpleText");
|
||||||
|
|
||||||
|
|
|
@ -245,7 +245,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InfoItemsPage<StreamInfoItem> getPage(String pageUrl) throws IOException, ExtractionException {
|
public InfoItemsPage<StreamInfoItem> getPage(String pageUrl) throws IOException, ExtractionException {
|
||||||
if (pageUrl == null || pageUrl.isEmpty()) {
|
if (isNullOrEmpty(pageUrl)) {
|
||||||
throw new ExtractionException(new IllegalArgumentException("Page url is empty or null"));
|
throw new ExtractionException(new IllegalArgumentException("Page url is empty or null"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
||||||
|
|
||||||
|
|
||||||
private String getNextPageUrlFrom(JsonArray continuations) {
|
private String getNextPageUrlFrom(JsonArray continuations) {
|
||||||
if (continuations == null || continuations.isEmpty()) {
|
if (isNullOrEmpty(continuations)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.util.Map;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
|
|
||||||
|
|
||||||
public class YoutubeCommentsExtractor extends CommentsExtractor {
|
public class YoutubeCommentsExtractor extends CommentsExtractor {
|
||||||
|
@ -91,7 +92,7 @@ public class YoutubeCommentsExtractor extends CommentsExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InfoItemsPage<CommentsInfoItem> getPage(String pageUrl) throws IOException, ExtractionException {
|
public InfoItemsPage<CommentsInfoItem> getPage(String pageUrl) throws IOException, ExtractionException {
|
||||||
if (pageUrl == null || pageUrl.isEmpty()) {
|
if (isNullOrEmpty(pageUrl)) {
|
||||||
throw new ExtractionException(new IllegalArgumentException("Page url is empty or null"));
|
throw new ExtractionException(new IllegalArgumentException("Page url is empty or null"));
|
||||||
}
|
}
|
||||||
String ajaxResponse = makeAjaxRequest(pageUrl);
|
String ajaxResponse = makeAjaxRequest(pageUrl);
|
||||||
|
|
|
@ -167,7 +167,7 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InfoItemsPage<InfoItem> getPage(final String pageUrl) throws IOException, ExtractionException {
|
public InfoItemsPage<InfoItem> getPage(final String pageUrl) throws IOException, ExtractionException {
|
||||||
if (pageUrl == null || pageUrl.isEmpty()) {
|
if (isNullOrEmpty(pageUrl)) {
|
||||||
throw new ExtractionException(new IllegalArgumentException("Page url is empty or null"));
|
throw new ExtractionException(new IllegalArgumentException("Page url is empty or null"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,7 +470,7 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getNextPageUrlFrom(final JsonArray continuations) throws ParsingException, IOException, ReCaptchaException {
|
private String getNextPageUrlFrom(final JsonArray continuations) throws ParsingException, IOException, ReCaptchaException {
|
||||||
if (continuations == null || continuations.isEmpty()) {
|
if (isNullOrEmpty(continuations)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonResponse;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonResponse;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getUrlFromNavigationEndpoint;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getUrlFromNavigationEndpoint;
|
||||||
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
public class YoutubePlaylistExtractor extends PlaylistExtractor {
|
public class YoutubePlaylistExtractor extends PlaylistExtractor {
|
||||||
|
@ -93,11 +94,11 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
|
||||||
String url = playlistInfo.getObject("thumbnailRenderer").getObject("playlistVideoThumbnailRenderer")
|
String url = playlistInfo.getObject("thumbnailRenderer").getObject("playlistVideoThumbnailRenderer")
|
||||||
.getObject("thumbnail").getArray("thumbnails").getObject(0).getString("url");
|
.getObject("thumbnail").getArray("thumbnails").getObject(0).getString("url");
|
||||||
|
|
||||||
if (url == null || url.isEmpty()) {
|
if (isNullOrEmpty(url)) {
|
||||||
url = initialData.getObject("microformat").getObject("microformatDataRenderer").getObject("thumbnail")
|
url = initialData.getObject("microformat").getObject("microformatDataRenderer").getObject("thumbnail")
|
||||||
.getArray("thumbnails").getObject(0).getString("url");
|
.getArray("thumbnails").getObject(0).getString("url");
|
||||||
|
|
||||||
if (url == null || url.isEmpty()) throw new ParsingException("Could not get playlist thumbnail");
|
if (isNullOrEmpty(url)) throw new ParsingException("Could not get playlist thumbnail");
|
||||||
}
|
}
|
||||||
|
|
||||||
return fixThumbnailUrl(url);
|
return fixThumbnailUrl(url);
|
||||||
|
@ -166,7 +167,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InfoItemsPage<StreamInfoItem> getPage(final String pageUrl) throws IOException, ExtractionException {
|
public InfoItemsPage<StreamInfoItem> getPage(final String pageUrl) throws IOException, ExtractionException {
|
||||||
if (pageUrl == null || pageUrl.isEmpty()) {
|
if (isNullOrEmpty(pageUrl)) {
|
||||||
throw new ExtractionException(new IllegalArgumentException("Page url is empty or null"));
|
throw new ExtractionException(new IllegalArgumentException("Page url is empty or null"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,7 +183,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getNextPageUrlFrom(JsonArray continuations) {
|
private String getNextPageUrlFrom(JsonArray continuations) {
|
||||||
if (continuations == null || continuations.isEmpty()) {
|
if (isNullOrEmpty(continuations)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonResponse;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonResponse;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
|
||||||
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Created by Christian Schabesberger on 22.07.2018
|
* Created by Christian Schabesberger on 22.07.2018
|
||||||
|
@ -99,7 +100,7 @@ public class YoutubeSearchExtractor extends SearchExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InfoItemsPage<InfoItem> getPage(final String pageUrl) throws IOException, ExtractionException {
|
public InfoItemsPage<InfoItem> getPage(final String pageUrl) throws IOException, ExtractionException {
|
||||||
if (pageUrl == null || pageUrl.isEmpty()) {
|
if (isNullOrEmpty(pageUrl)) {
|
||||||
throw new ExtractionException(new IllegalArgumentException("Page url is empty or null"));
|
throw new ExtractionException(new IllegalArgumentException("Page url is empty or null"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +134,7 @@ public class YoutubeSearchExtractor extends SearchExtractor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getNextPageUrlFrom(final JsonArray continuations) throws ParsingException {
|
private String getNextPageUrlFrom(final JsonArray continuations) throws ParsingException {
|
||||||
if (continuations == null || continuations.isEmpty()) {
|
if (isNullOrEmpty(continuations)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@ import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.*;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.*;
|
||||||
import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING;
|
import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING;
|
||||||
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Created by Christian Schabesberger on 06.08.15.
|
* Created by Christian Schabesberger on 06.08.15.
|
||||||
|
@ -116,10 +117,10 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
assertPageFetched();
|
assertPageFetched();
|
||||||
String title = getTextFromObject(getVideoPrimaryInfoRenderer().getObject("title"));
|
String title = getTextFromObject(getVideoPrimaryInfoRenderer().getObject("title"));
|
||||||
|
|
||||||
if (title == null || title.isEmpty()) {
|
if (isNullOrEmpty(title)) {
|
||||||
title = playerResponse.getObject("videoDetails").getString("title");
|
title = playerResponse.getObject("videoDetails").getString("title");
|
||||||
|
|
||||||
if (title == null || title.isEmpty()) throw new ParsingException("Could not get name");
|
if (isNullOrEmpty(title)) throw new ParsingException("Could not get name");
|
||||||
}
|
}
|
||||||
|
|
||||||
return title;
|
return title;
|
||||||
|
@ -167,7 +168,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
public DateWrapper getUploadDate() throws ParsingException {
|
public DateWrapper getUploadDate() throws ParsingException {
|
||||||
final String textualUploadDate = getTextualUploadDate();
|
final String textualUploadDate = getTextualUploadDate();
|
||||||
|
|
||||||
if (textualUploadDate == null || textualUploadDate.isEmpty()) {
|
if (isNullOrEmpty(textualUploadDate)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +205,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAgeLimit() {
|
public int getAgeLimit() {
|
||||||
if (initialData == null || initialData.isEmpty()) throw new IllegalStateException("initialData is not parsed yet");
|
if (isNullOrEmpty(initialData)) throw new IllegalStateException("initialData is not parsed yet");
|
||||||
|
|
||||||
return ageLimit;
|
return ageLimit;
|
||||||
}
|
}
|
||||||
|
@ -248,10 +249,10 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
String views = getTextFromObject(getVideoPrimaryInfoRenderer().getObject("viewCount")
|
String views = getTextFromObject(getVideoPrimaryInfoRenderer().getObject("viewCount")
|
||||||
.getObject("videoViewCountRenderer").getObject("viewCount"));
|
.getObject("videoViewCountRenderer").getObject("viewCount"));
|
||||||
|
|
||||||
if (views == null || views.isEmpty()) {
|
if (isNullOrEmpty(views)) {
|
||||||
views = playerResponse.getObject("videoDetails").getString("viewCount");
|
views = playerResponse.getObject("videoDetails").getString("viewCount");
|
||||||
|
|
||||||
if (views == null || views.isEmpty()) throw new ParsingException("Could not get view count");
|
if (isNullOrEmpty(views)) throw new ParsingException("Could not get view count");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (views.toLowerCase().contains("no views")) return 0;
|
if (views.toLowerCase().contains("no views")) return 0;
|
||||||
|
@ -329,10 +330,10 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
String uploaderName = getTextFromObject(getVideoSecondaryInfoRenderer().getObject("owner")
|
String uploaderName = getTextFromObject(getVideoSecondaryInfoRenderer().getObject("owner")
|
||||||
.getObject("videoOwnerRenderer").getObject("title"));
|
.getObject("videoOwnerRenderer").getObject("title"));
|
||||||
|
|
||||||
if (uploaderName == null || uploaderName.isEmpty()) {
|
if (isNullOrEmpty(uploaderName)) {
|
||||||
uploaderName = playerResponse.getObject("videoDetails").getString("author");
|
uploaderName = playerResponse.getObject("videoDetails").getString("author");
|
||||||
|
|
||||||
if (uploaderName == null || uploaderName.isEmpty()) throw new ParsingException("Could not get uploader name");
|
if (isNullOrEmpty(uploaderName)) throw new ParsingException("Could not get uploader name");
|
||||||
}
|
}
|
||||||
|
|
||||||
return uploaderName;
|
return uploaderName;
|
||||||
|
|
|
@ -106,7 +106,7 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
|
||||||
|
|
||||||
String duration = getTextFromObject(videoInfo.getObject("lengthText"));
|
String duration = getTextFromObject(videoInfo.getObject("lengthText"));
|
||||||
|
|
||||||
if (duration == null || duration.isEmpty()) {
|
if (isNullOrEmpty(duration)) {
|
||||||
for (Object thumbnailOverlay : videoInfo.getArray("thumbnailOverlays")) {
|
for (Object thumbnailOverlay : videoInfo.getArray("thumbnailOverlays")) {
|
||||||
if (((JsonObject) thumbnailOverlay).has("thumbnailOverlayTimeStatusRenderer")) {
|
if (((JsonObject) thumbnailOverlay).has("thumbnailOverlayTimeStatusRenderer")) {
|
||||||
duration = getTextFromObject(((JsonObject) thumbnailOverlay)
|
duration = getTextFromObject(((JsonObject) thumbnailOverlay)
|
||||||
|
@ -114,7 +114,7 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (duration == null || duration.isEmpty()) throw new ParsingException("Could not get duration");
|
if (isNullOrEmpty(duration)) throw new ParsingException("Could not get duration");
|
||||||
}
|
}
|
||||||
|
|
||||||
return YoutubeParsingHelper.parseDurationString(duration);
|
return YoutubeParsingHelper.parseDurationString(duration);
|
||||||
|
@ -124,13 +124,13 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
|
||||||
public String getUploaderName() throws ParsingException {
|
public String getUploaderName() throws ParsingException {
|
||||||
String name = getTextFromObject(videoInfo.getObject("longBylineText"));
|
String name = getTextFromObject(videoInfo.getObject("longBylineText"));
|
||||||
|
|
||||||
if (name == null || name.isEmpty()) {
|
if (isNullOrEmpty(name)) {
|
||||||
name = getTextFromObject(videoInfo.getObject("ownerText"));
|
name = getTextFromObject(videoInfo.getObject("ownerText"));
|
||||||
|
|
||||||
if (name == null || name.isEmpty()) {
|
if (isNullOrEmpty(name)) {
|
||||||
name = getTextFromObject(videoInfo.getObject("shortBylineText"));
|
name = getTextFromObject(videoInfo.getObject("shortBylineText"));
|
||||||
|
|
||||||
if (name == null || name.isEmpty()) throw new ParsingException("Could not get uploader name");
|
if (isNullOrEmpty(name)) throw new ParsingException("Could not get uploader name");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,15 +142,15 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
|
||||||
String url = getUrlFromNavigationEndpoint(videoInfo.getObject("longBylineText")
|
String url = getUrlFromNavigationEndpoint(videoInfo.getObject("longBylineText")
|
||||||
.getArray("runs").getObject(0).getObject("navigationEndpoint"));
|
.getArray("runs").getObject(0).getObject("navigationEndpoint"));
|
||||||
|
|
||||||
if (url == null || url.isEmpty()) {
|
if (isNullOrEmpty(url)) {
|
||||||
url = getUrlFromNavigationEndpoint(videoInfo.getObject("ownerText")
|
url = getUrlFromNavigationEndpoint(videoInfo.getObject("ownerText")
|
||||||
.getArray("runs").getObject(0).getObject("navigationEndpoint"));
|
.getArray("runs").getObject(0).getObject("navigationEndpoint"));
|
||||||
|
|
||||||
if (url == null || url.isEmpty()) {
|
if (isNullOrEmpty(url)) {
|
||||||
url = getUrlFromNavigationEndpoint(videoInfo.getObject("shortBylineText")
|
url = getUrlFromNavigationEndpoint(videoInfo.getObject("shortBylineText")
|
||||||
.getArray("runs").getObject(0).getObject("navigationEndpoint"));
|
.getArray("runs").getObject(0).getObject("navigationEndpoint"));
|
||||||
|
|
||||||
if (url == null || url.isEmpty()) throw new ParsingException("Could not get uploader url");
|
if (isNullOrEmpty(url)) throw new ParsingException("Could not get uploader url");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@ import org.schabi.newpipe.extractor.MediaFormat;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a stream object from url, format and optional torrent url
|
* Creates a stream object from url, format and optional torrent url
|
||||||
*/
|
*/
|
||||||
|
@ -61,7 +63,7 @@ public abstract class Stream implements Serializable {
|
||||||
* Check if the list already contains one stream with equals stats
|
* Check if the list already contains one stream with equals stats
|
||||||
*/
|
*/
|
||||||
public static boolean containSimilarStream(Stream stream, List<? extends Stream> streamList) {
|
public static boolean containSimilarStream(Stream stream, List<? extends Stream> streamList) {
|
||||||
if (stream == null || streamList == null) return false;
|
if (isNullOrEmpty(streamList)) return false;
|
||||||
for (Stream cmpStream : streamList) {
|
for (Stream cmpStream : streamList) {
|
||||||
if (stream.equalStats(cmpStream)) return true;
|
if (stream.equalStats(cmpStream)) return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ public class StreamInfo extends Info {
|
||||||
String name = extractor.getName();
|
String name = extractor.getName();
|
||||||
int ageLimit = extractor.getAgeLimit();
|
int ageLimit = extractor.getAgeLimit();
|
||||||
|
|
||||||
if ((streamType == StreamType.NONE) || (url == null || url.isEmpty()) || (id == null || id.isEmpty())
|
if ((streamType == StreamType.NONE) || isNullOrEmpty(url) || (isNullOrEmpty(id))
|
||||||
|| (name == null /* streamInfo.title can be empty of course */) || (ageLimit == -1)) {
|
|| (name == null /* streamInfo.title can be empty of course */) || (ageLimit == -1)) {
|
||||||
throw new ExtractionException("Some important stream information was not given.");
|
throw new ExtractionException("Some important stream information was not given.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.schabi.newpipe.extractor.utils;
|
package org.schabi.newpipe.extractor.utils;
|
||||||
|
|
||||||
|
import com.grack.nanojson.JsonObject;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
@ -8,6 +9,7 @@ import java.net.URL;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
|
||||||
|
@ -72,7 +74,7 @@ public class Utils {
|
||||||
* @param url the url to be tested
|
* @param url the url to be tested
|
||||||
*/
|
*/
|
||||||
public static void checkUrl(String pattern, String url) throws ParsingException {
|
public static void checkUrl(String pattern, String url) throws ParsingException {
|
||||||
if (url == null || url.isEmpty()) {
|
if (isNullOrEmpty(url)) {
|
||||||
throw new IllegalArgumentException("Url can't be null or empty");
|
throw new IllegalArgumentException("Url can't be null or empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +195,13 @@ public class Utils {
|
||||||
return str == null || str.isEmpty();
|
return str == null || str.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// can be used for JsonArrays
|
||||||
public static boolean isNullOrEmpty(final Collection<?> collection) {
|
public static boolean isNullOrEmpty(final Collection<?> collection) {
|
||||||
return collection == null || collection.isEmpty();
|
return collection == null || collection.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// can be used for JsonObjects
|
||||||
|
public static boolean isNullOrEmpty(final Map map) {
|
||||||
|
return map == null || map.isEmpty();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -8,6 +8,7 @@ import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmpty;
|
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmpty;
|
||||||
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
|
|
||||||
public abstract class DefaultSearchExtractorTest extends DefaultListExtractorTest<SearchExtractor>
|
public abstract class DefaultSearchExtractorTest extends DefaultListExtractorTest<SearchExtractor>
|
||||||
implements BaseSearchExtractorTest {
|
implements BaseSearchExtractorTest {
|
||||||
|
@ -25,7 +26,7 @@ public abstract class DefaultSearchExtractorTest extends DefaultListExtractorTes
|
||||||
@Override
|
@Override
|
||||||
public void testSearchSuggestion() throws Exception {
|
public void testSearchSuggestion() throws Exception {
|
||||||
final String expectedSearchSuggestion = expectedSearchSuggestion();
|
final String expectedSearchSuggestion = expectedSearchSuggestion();
|
||||||
if (expectedSearchSuggestion == null || expectedSearchSuggestion.isEmpty()) {
|
if (isNullOrEmpty(expectedSearchSuggestion)) {
|
||||||
assertEmpty("Suggestion was expected to be empty", extractor().getSearchSuggestion());
|
assertEmpty("Suggestion was expected to be empty", extractor().getSearchSuggestion());
|
||||||
} else {
|
} else {
|
||||||
assertEquals(expectedSearchSuggestion, extractor().getSearchSuggestion());
|
assertEquals(expectedSearchSuggestion, extractor().getSearchSuggestion());
|
||||||
|
|
|
@ -86,7 +86,7 @@ public final class DefaultTests {
|
||||||
public static <T extends InfoItem> void assertNoMoreItems(ListExtractor<T> extractor) throws Exception {
|
public static <T extends InfoItem> void assertNoMoreItems(ListExtractor<T> extractor) throws Exception {
|
||||||
assertFalse("More items available when it shouldn't", extractor.hasNextPage());
|
assertFalse("More items available when it shouldn't", extractor.hasNextPage());
|
||||||
final String nextPageUrl = extractor.getNextPageUrl();
|
final String nextPageUrl = extractor.getNextPageUrl();
|
||||||
assertTrue("Next page is not empty or null", nextPageUrl == null || nextPageUrl.isEmpty());
|
assertTrue("Next page is not empty or null", isNullOrEmpty(nextPageUrl));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertNoDuplicatedItems(StreamingService expectedService,
|
public static void assertNoDuplicatedItems(StreamingService expectedService,
|
||||||
|
|
|
@ -20,6 +20,7 @@ import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmptyErrors;
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||||
import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoDuplicatedItems;
|
import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoDuplicatedItems;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.*;
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.*;
|
||||||
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
|
|
||||||
public class YoutubeSearchExtractorTest {
|
public class YoutubeSearchExtractorTest {
|
||||||
public static class All extends DefaultSearchExtractorTest {
|
public static class All extends DefaultSearchExtractorTest {
|
||||||
|
@ -170,7 +171,7 @@ public class YoutubeSearchExtractorTest {
|
||||||
|
|
||||||
assertFalse("More items available when it shouldn't", nextEmptyPage.hasNextPage());
|
assertFalse("More items available when it shouldn't", nextEmptyPage.hasNextPage());
|
||||||
final String nextPageUrl = nextEmptyPage.getNextPageUrl();
|
final String nextPageUrl = nextEmptyPage.getNextPageUrl();
|
||||||
assertTrue("Next page is not empty or null", nextPageUrl == null || nextPageUrl.isEmpty());
|
assertTrue("Next page is not empty or null", isNullOrEmpty(nextPageUrl));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue