From 557934cb1720554a177151b22bc86b7e1f9c8c46 Mon Sep 17 00:00:00 2001 From: bopol Date: Sun, 7 Feb 2021 22:42:21 +0100 Subject: [PATCH] use EMPTY_STRING --- .../newpipe/extractor/kiosk/KioskList.java | 4 +- .../SearchQueryHandlerFactory.java | 10 ++-- .../PeertubeCommentsInfoItemExtractor.java | 5 +- .../soundcloud/SoundcloudParsingHelper.java | 1 - .../SoundcloudChannelExtractor.java | 6 +-- .../SoundcloudChannelInfoItemExtractor.java | 2 +- .../SoundcloudPlaylistInfoItemExtractor.java | 2 +- .../extractors/SoundcloudSearchExtractor.java | 15 ++---- .../extractors/SoundcloudStreamExtractor.java | 8 ++-- .../SoundcloudStreamInfoItemExtractor.java | 2 +- .../youtube/YoutubeParsingHelper.java | 1 - .../extractors/YoutubeChannelExtractor.java | 2 +- .../YoutubeCommentsInfoItemExtractor.java | 10 ++-- .../YoutubeMusicSearchExtractor.java | 4 +- .../extractors/YoutubePlaylistExtractor.java | 2 +- .../extractors/YoutubeStreamExtractor.java | 48 +++++-------------- .../YoutubeStreamInfoItemExtractor.java | 6 +-- .../newpipe/extractor/stream/Description.java | 4 +- .../newpipe/extractor/utils/JsonUtils.java | 1 - .../schabi/newpipe/extractor/utils/Utils.java | 3 +- .../search/YoutubeSearchExtractorTest.java | 1 + .../youtube/search/YoutubeSearchQHTest.java | 27 ++++++----- .../YoutubeStreamExtractorDefaultTest.java | 20 ++++++-- 23 files changed, 82 insertions(+), 102 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java b/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java index 5eef4adb6..913cbe26b 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 @@ -14,6 +14,8 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; +import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; + public class KioskList { public interface KioskExtractorFactory { @@ -70,7 +72,7 @@ public class KioskList { public KioskExtractor getDefaultKioskExtractor(Page nextPage, Localization localization) throws ExtractionException, IOException { - if (defaultKiosk != null && !defaultKiosk.equals("")) { + if (!isNullOrEmpty(defaultKiosk)) { return getExtractorById(defaultKiosk, nextPage, localization); } else { if (!kioskList.isEmpty()) { 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 efd5ad022..4f5ae58c8 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 @@ -5,6 +5,8 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; import java.util.ArrayList; import java.util.List; +import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING; + public abstract class SearchQueryHandlerFactory extends ListLinkHandlerFactory { /////////////////////////////////// @@ -28,14 +30,14 @@ public abstract class SearchQueryHandlerFactory extends ListLinkHandlerFactory { } @Override - public SearchQueryHandler fromQuery(String querry, + public SearchQueryHandler fromQuery(String query, List contentFilter, String sortFilter) throws ParsingException { - return new SearchQueryHandler(super.fromQuery(querry, contentFilter, sortFilter)); + return new SearchQueryHandler(super.fromQuery(query, contentFilter, sortFilter)); } - public SearchQueryHandler fromQuery(String querry) throws ParsingException { - return fromQuery(querry, new ArrayList(0), ""); + public SearchQueryHandler fromQuery(String query) throws ParsingException { + return fromQuery(query, new ArrayList(0), EMPTY_STRING); } /** 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 6112cdcb9..38c819886 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,7 +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; @@ -13,6 +12,8 @@ import org.schabi.newpipe.extractor.utils.JsonUtils; import java.util.Objects; +import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING; + public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtractor { private final JsonObject item; private final String url; @@ -68,7 +69,7 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac final Document doc = Jsoup.parse(htmlText); return doc.body().text(); } catch (Exception e) { - return htmlText.replaceAll("(?s)<[^>]*>(\\s*<[^>]*>)*", ""); + return htmlText.replaceAll("(?s)<[^>]*>(\\s*<[^>]*>)*", EMPTY_STRING); } } 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 23d9ff535..c9a49f694 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 @@ -37,7 +37,6 @@ import java.util.List; import static java.util.Collections.singletonList; import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; -import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING; import static org.schabi.newpipe.extractor.utils.Utils.*; public class SoundcloudParsingHelper { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChannelExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChannelExtractor.java index 351a9e38e..52151d3d0 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChannelExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChannelExtractor.java @@ -3,7 +3,6 @@ package org.schabi.newpipe.extractor.services.soundcloud.extractors; import com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonParser; import com.grack.nanojson.JsonParserException; - import org.schabi.newpipe.extractor.Page; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.channel.ChannelExtractor; @@ -15,11 +14,10 @@ import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; +import javax.annotation.Nonnull; import java.io.IOException; -import javax.annotation.Nonnull; - -import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING; +import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; @SuppressWarnings("WeakerAccess") diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChannelInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChannelInfoItemExtractor.java index 7fcc28a6c..ef5270e7c 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChannelInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChannelInfoItemExtractor.java @@ -3,7 +3,7 @@ package org.schabi.newpipe.extractor.services.soundcloud.extractors; import com.grack.nanojson.JsonObject; import org.schabi.newpipe.extractor.channel.ChannelInfoItemExtractor; -import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING; +import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING; import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps; public class SoundcloudChannelInfoItemExtractor implements ChannelInfoItemExtractor { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistInfoItemExtractor.java index 7c4631258..e243780a9 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistInfoItemExtractor.java @@ -4,7 +4,7 @@ import com.grack.nanojson.JsonObject; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor; -import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING; +import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING; import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps; public class SoundcloudPlaylistInfoItemExtractor implements PlaylistInfoItemExtractor { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudSearchExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudSearchExtractor.java index b644778fe..d5eebe984 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudSearchExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudSearchExtractor.java @@ -4,13 +4,7 @@ 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.InfoItem; -import org.schabi.newpipe.extractor.InfoItemExtractor; -import org.schabi.newpipe.extractor.InfoItemsCollector; -import org.schabi.newpipe.extractor.MetaInfo; -import org.schabi.newpipe.extractor.Page; -import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.extractor.*; import org.schabi.newpipe.extractor.downloader.Downloader; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; @@ -19,6 +13,7 @@ import org.schabi.newpipe.extractor.search.InfoItemsSearchCollector; import org.schabi.newpipe.extractor.search.SearchExtractor; import org.schabi.newpipe.extractor.utils.Parser; +import javax.annotation.Nonnull; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; @@ -26,10 +21,8 @@ import java.net.URL; import java.util.Collections; import java.util.List; -import javax.annotation.Nonnull; - import static org.schabi.newpipe.extractor.services.soundcloud.linkHandler.SoundcloudSearchQueryHandlerFactory.ITEMS_PER_PAGE; -import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING; +import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; public class SoundcloudSearchExtractor extends SearchExtractor { @@ -50,7 +43,7 @@ public class SoundcloudSearchExtractor extends SearchExtractor { return false; } - @Nonnull + @Nonnull @Override public List getMetaInfo() { return Collections.emptyList(); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java index 94df8599e..9e4ed6bb2 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java @@ -28,9 +28,7 @@ import java.util.Collections; import java.util.List; import java.util.Locale; -import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING; -import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; -import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; +import static org.schabi.newpipe.extractor.utils.Utils.*; public class SoundcloudStreamExtractor extends StreamExtractor { private JsonObject track; @@ -52,7 +50,7 @@ public class SoundcloudStreamExtractor extends StreamExtractor { @Nonnull @Override public String getId() { - return track.getInt("id") + ""; + return track.getInt("id") + EMPTY_STRING; } @Nonnull @@ -66,7 +64,7 @@ public class SoundcloudStreamExtractor extends StreamExtractor { public String getTextualUploadDate() { return track.getString("created_at") .replace("T", " ") - .replace("Z", ""); + .replace("Z", EMPTY_STRING); } @Nonnull diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamInfoItemExtractor.java index 7da3ab5d1..4e1762318 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamInfoItemExtractor.java @@ -7,7 +7,7 @@ import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper; import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor; import org.schabi.newpipe.extractor.stream.StreamType; -import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING; +import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING; import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps; public class SoundcloudStreamInfoItemExtractor implements StreamInfoItemExtractor { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java index e81141324..b3fc3b935 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java @@ -33,7 +33,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.schabi.newpipe.extractor.NewPipe.getDownloader; -import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING; import static org.schabi.newpipe.extractor.utils.Utils.*; /* 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 1bc4f8092..db046f8b3 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 @@ -21,7 +21,7 @@ import javax.annotation.Nonnull; import java.io.IOException; 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.Utils.EMPTY_STRING; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; /* diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsInfoItemExtractor.java index ec97e7302..4276800bb 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsInfoItemExtractor.java @@ -2,7 +2,6 @@ package org.schabi.newpipe.extractor.services.youtube.extractors; import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonObject; - import org.schabi.newpipe.extractor.comments.CommentsInfoItemExtractor; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.localization.DateWrapper; @@ -13,6 +12,7 @@ import org.schabi.newpipe.extractor.utils.Utils; import javax.annotation.Nullable; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject; +import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING; public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtractor { @@ -46,7 +46,7 @@ public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtract try { return getTextFromObject(JsonUtils.getObject(json, "authorText")); } catch (Exception e) { - return ""; + return EMPTY_STRING; } } @@ -86,7 +86,7 @@ public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtract if (contentText.isEmpty()) { // completely empty comments as described in // https://github.com/TeamNewPipe/NewPipeExtractor/issues/380#issuecomment-668808584 - return ""; + return EMPTY_STRING; } final String commentText = getTextFromObject(contentText); // youtube adds U+FEFF in some comments. eg. https://www.youtube.com/watch?v=Nj4F63E59io @@ -130,7 +130,7 @@ public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtract try { return getTextFromObject(JsonUtils.getObject(json, "authorText")); } catch (Exception e) { - return ""; + return EMPTY_STRING; } } @@ -139,7 +139,7 @@ public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtract try { return "https://youtube.com/channel/" + JsonUtils.getString(json, "authorEndpoint.browseEndpoint.browseId"); } catch (Exception e) { - return ""; + return EMPTY_STRING; } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java index 7871f9307..a0c2e99c7 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java @@ -28,9 +28,7 @@ import java.util.Map; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.*; import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.*; -import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING; -import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; -import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; +import static org.schabi.newpipe.extractor.utils.Utils.*; public class YoutubeMusicSearchExtractor extends SearchExtractor { private JsonObject initialData; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistExtractor.java index 1cc29eb63..0e2ad2a43 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistExtractor.java @@ -82,7 +82,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { @Override public String getName() throws ParsingException { final String name = getTextFromObject(playlistInfo.getObject("title")); - if (name != null && !name.isEmpty()) return name; + if (!isNullOrEmpty(name)) return name; return initialData.getObject("microformat").getObject("microformatDataRenderer").getString("title"); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index 3e2225523..a0c9361b4 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -4,7 +4,6 @@ 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; @@ -29,17 +28,7 @@ import org.schabi.newpipe.extractor.localization.TimeAgoPatternsManager; import org.schabi.newpipe.extractor.services.youtube.ItagItem; import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper; import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory; -import org.schabi.newpipe.extractor.stream.AudioStream; -import org.schabi.newpipe.extractor.stream.Description; -import org.schabi.newpipe.extractor.stream.Frameset; -import org.schabi.newpipe.extractor.stream.Stream; -import org.schabi.newpipe.extractor.stream.StreamExtractor; -import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor; -import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; -import org.schabi.newpipe.extractor.stream.StreamSegment; -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.Parser; import org.schabi.newpipe.extractor.utils.Utils; @@ -47,26 +36,13 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.io.IOException; import java.io.UnsupportedEncodingException; -import java.net.MalformedURLException; -import java.net.URL; import java.time.LocalDate; import java.time.OffsetDateTime; import java.time.format.DateTimeFormatter; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Objects; +import java.util.*; -import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.fixThumbnailUrl; -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.getUrlFromNavigationEndpoint; -import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING; +import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.*; +import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; /* @@ -102,17 +78,21 @@ public class YoutubeStreamExtractor extends StreamExtractor { /*//////////////////////////////////////////////////////////////////////////*/ - @Nullable private static String cachedDeobfuscationCode = null; - @Nullable private String playerJsUrl = null; + @Nullable + private static String cachedDeobfuscationCode = null; + @Nullable + private String playerJsUrl = null; private JsonArray initialAjaxJson; private JsonObject initialData; - @Nonnull private final Map videoInfoPage = new HashMap<>(); + @Nonnull + private final Map videoInfoPage = new HashMap<>(); private JsonObject playerResponse; private JsonObject videoPrimaryInfoRenderer; private JsonObject videoSecondaryInfoRenderer; private int ageLimit = -1; - @Nullable private List subtitles = null; + @Nullable + private List subtitles = null; public YoutubeStreamExtractor(StreamingService service, LinkHandler linkHandler) { super(service, linkHandler); @@ -787,8 +767,6 @@ public class YoutubeStreamExtractor extends StreamExtractor { } - - private String getDeobfuscationFuncName(final String playerCode) throws DeobfuscateException { Parser.RegexException exception = null; for (final String regex : REGEXES) { @@ -1138,6 +1116,6 @@ public class YoutubeStreamExtractor extends StreamExtractor { public List getMetaInfo() throws ParsingException { return YoutubeParsingHelper.getMetaInfo( initialData.getObject("contents").getObject("twoColumnWatchNextResults") - .getObject("results").getObject("results").getArray("contents")); + .getObject("results").getObject("results").getArray("contents")); } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamInfoItemExtractor.java index ae784f206..42e39b728 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamInfoItemExtractor.java @@ -17,10 +17,8 @@ import java.time.OffsetDateTime; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; -import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.fixThumbnailUrl; -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.utils.JsonUtils.EMPTY_STRING; +import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.*; +import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; /* diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/Description.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/Description.java index b19b8de36..a8c038577 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/Description.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/Description.java @@ -2,12 +2,14 @@ package org.schabi.newpipe.extractor.stream; import java.io.Serializable; +import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING; + public class Description implements Serializable { public static final int HTML = 1; public static final int MARKDOWN = 2; public static final int PLAIN_TEXT = 3; - public static final Description emptyDescription = new Description("", PLAIN_TEXT); + public static final Description emptyDescription = new Description(EMPTY_STRING, PLAIN_TEXT); private String content; private int type; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/JsonUtils.java b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/JsonUtils.java index e69240a01..ad132b5ac 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/JsonUtils.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/JsonUtils.java @@ -13,7 +13,6 @@ import java.util.List; public class JsonUtils { public static final JsonObject EMPTY_OBJECT = new JsonObject(); public static final JsonArray EMPTY_ARRAY = new JsonArray(); - public static final String EMPTY_STRING = ""; private JsonUtils() { } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java index ed2295774..721bc96c3 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java @@ -13,6 +13,7 @@ public class Utils { public static final String HTTP = "http://"; public static final String HTTPS = "https://"; public static final String UTF_8 = "UTF-8"; + public static final String EMPTY_STRING = ""; private Utils() { //no instance @@ -234,7 +235,7 @@ public class Utils { } public static boolean isBlank(final String string) { - if (string == null || string.isEmpty()) { + if (isNullOrEmpty(string)) { return true; } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorTest.java index b6f298837..0e3222c14 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorTest.java @@ -31,6 +31,7 @@ import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoDuplica 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.utils.Utils.EMPTY_STRING; public class YoutubeSearchExtractorTest { 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 ab16861d7..5f114e333 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 @@ -7,6 +7,7 @@ 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.*; +import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING; public class YoutubeSearchQHTest { @@ -19,37 +20,37 @@ public class YoutubeSearchQHTest { 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()); - assertEquals("https://music.youtube.com/search?q=asdf", YouTube.getSearchQHFactory().fromQuery("asdf", asList(new String[]{MUSIC_SONGS}), "").getUrl()); - assertEquals("https://music.youtube.com/search?q=hans", YouTube.getSearchQHFactory().fromQuery("hans", asList(new String[]{MUSIC_SONGS}), "").getUrl()); - assertEquals("https://music.youtube.com/search?q=Poifj%26jaijf", YouTube.getSearchQHFactory().fromQuery("Poifj&jaijf", asList(new String[]{MUSIC_SONGS}), "").getUrl()); - assertEquals("https://music.youtube.com/search?q=G%C3%BCl%C3%BCm", YouTube.getSearchQHFactory().fromQuery("Gülüm", asList(new String[]{MUSIC_SONGS}), "").getUrl()); - assertEquals("https://music.youtube.com/search?q=%3Fj%24%29H%C2%A7B", YouTube.getSearchQHFactory().fromQuery("?j$)H§B", asList(new String[]{MUSIC_SONGS}), "").getUrl()); + assertEquals("https://music.youtube.com/search?q=asdf", YouTube.getSearchQHFactory().fromQuery("asdf", asList(new String[]{MUSIC_SONGS}), EMPTY_STRING).getUrl()); + assertEquals("https://music.youtube.com/search?q=hans", YouTube.getSearchQHFactory().fromQuery("hans", asList(new String[]{MUSIC_SONGS}), EMPTY_STRING).getUrl()); + assertEquals("https://music.youtube.com/search?q=Poifj%26jaijf", YouTube.getSearchQHFactory().fromQuery("Poifj&jaijf", asList(new String[]{MUSIC_SONGS}), EMPTY_STRING).getUrl()); + assertEquals("https://music.youtube.com/search?q=G%C3%BCl%C3%BCm", YouTube.getSearchQHFactory().fromQuery("Gülüm", asList(new String[]{MUSIC_SONGS}), EMPTY_STRING).getUrl()); + assertEquals("https://music.youtube.com/search?q=%3Fj%24%29H%C2%A7B", YouTube.getSearchQHFactory().fromQuery("?j$)H§B", asList(new String[]{MUSIC_SONGS}), EMPTY_STRING).getUrl()); } @Test public void testGetContentFilter() throws Exception { assertEquals(VIDEOS, YouTube.getSearchQHFactory() - .fromQuery("", asList(new String[]{VIDEOS}), "").getContentFilters().get(0)); + .fromQuery(EMPTY_STRING, asList(new String[]{VIDEOS}), EMPTY_STRING).getContentFilters().get(0)); assertEquals(CHANNELS, YouTube.getSearchQHFactory() - .fromQuery("asdf", asList(new String[]{CHANNELS}), "").getContentFilters().get(0)); + .fromQuery("asdf", asList(new String[]{CHANNELS}), EMPTY_STRING).getContentFilters().get(0)); assertEquals(MUSIC_SONGS, YouTube.getSearchQHFactory() - .fromQuery("asdf", asList(new String[]{MUSIC_SONGS}), "").getContentFilters().get(0)); + .fromQuery("asdf", asList(new String[]{MUSIC_SONGS}), EMPTY_STRING).getContentFilters().get(0)); } @Test public void testWithContentfilter() throws Exception { assertEquals("https://www.youtube.com/results?search_query=asdf&sp=EgIQAQ%253D%253D", YouTube.getSearchQHFactory() - .fromQuery("asdf", asList(new String[]{VIDEOS}), "").getUrl()); + .fromQuery("asdf", asList(new String[]{VIDEOS}), EMPTY_STRING).getUrl()); assertEquals("https://www.youtube.com/results?search_query=asdf&sp=EgIQAg%253D%253D", YouTube.getSearchQHFactory() - .fromQuery("asdf", asList(new String[]{CHANNELS}), "").getUrl()); + .fromQuery("asdf", asList(new String[]{CHANNELS}), EMPTY_STRING).getUrl()); assertEquals("https://www.youtube.com/results?search_query=asdf&sp=EgIQAw%253D%253D", YouTube.getSearchQHFactory() - .fromQuery("asdf", asList(new String[]{PLAYLISTS}), "").getUrl()); + .fromQuery("asdf", asList(new String[]{PLAYLISTS}), EMPTY_STRING).getUrl()); assertEquals("https://www.youtube.com/results?search_query=asdf", YouTube.getSearchQHFactory() - .fromQuery("asdf", asList(new String[]{"fjiijie"}), "").getUrl()); + .fromQuery("asdf", asList(new String[]{"fjiijie"}), EMPTY_STRING).getUrl()); assertEquals("https://music.youtube.com/search?q=asdf", YouTube.getSearchQHFactory() - .fromQuery("asdf", asList(new String[]{MUSIC_SONGS}), "").getUrl()); + .fromQuery("asdf", asList(new String[]{MUSIC_SONGS}), EMPTY_STRING).getUrl()); } @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 5a9621729..311725f61 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 @@ -16,6 +16,7 @@ import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.StreamSegment; import org.schabi.newpipe.extractor.stream.StreamType; +import javax.annotation.Nullable; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; @@ -23,11 +24,10 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import javax.annotation.Nullable; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.schabi.newpipe.extractor.ServiceList.YouTube; +import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING; /* * Created by Christian Schabesberger on 30.12.15. @@ -88,6 +88,7 @@ public class YoutubeStreamExtractorDefaultTest { extractor.fetchPage(); } + // @formatter:off @Override public StreamExtractor extractor() { return extractor; } @Override public StreamingService expectedService() { return YouTube; } @Override public String expectedName() { return "Marzia & Felix - Wedding 19.08.2019"; } @@ -110,6 +111,7 @@ public class YoutubeStreamExtractorDefaultTest { @Override public long expectedLikeCountAtLeast() { return 5212900; } @Override public long expectedDislikeCountAtLeast() { return 30600; } @Override public int expectedStreamSegmentsCount() { return 0; } + // @formatter:on } public static class DescriptionTestUnboxing extends DefaultStreamExtractorTest { @@ -125,6 +127,7 @@ public class YoutubeStreamExtractorDefaultTest { extractor.fetchPage(); } + // @formatter:off @Override public StreamExtractor extractor() { return extractor; } @Override public StreamingService expectedService() { return YouTube; } @Override public String expectedName() { return "This Smartphone Changes Everything..."; } @@ -147,13 +150,14 @@ public class YoutubeStreamExtractorDefaultTest { @Nullable @Override public String expectedTextualUploadDate() { return "2018-06-19"; } @Override public long expectedLikeCountAtLeast() { return 340100; } @Override public long expectedDislikeCountAtLeast() { return 18700; } - + // @formatter:on @Override @Test @Ignore("TODO fix") public void testDescription() throws Exception { super.testDescription(); } + } @Ignore("TODO fix") @@ -171,6 +175,7 @@ public class YoutubeStreamExtractorDefaultTest { extractor.fetchPage(); } + // @formatter:off @Override public StreamExtractor extractor() { return extractor; } @Override public StreamingService expectedService() { return YouTube; } @Override public String expectedName() { return "AlphaOmegaSin Fanboy Logic: Likes/Dislikes Disabled = Point Invalid Lol wtf?"; } @@ -189,6 +194,7 @@ public class YoutubeStreamExtractorDefaultTest { @Nullable @Override public String expectedTextualUploadDate() { return "2019-01-02"; } @Override public long expectedLikeCountAtLeast() { return -1; } @Override public long expectedDislikeCountAtLeast() { return -1; } + // @formatter:on } public static class StreamSegmentsTestOstCollection extends DefaultStreamExtractorTest { @@ -205,6 +211,7 @@ public class YoutubeStreamExtractorDefaultTest { extractor.fetchPage(); } + // @formatter:off @Override public StreamExtractor extractor() { return extractor; } @Override public StreamingService expectedService() { return YouTube; } @Override public String expectedName() { return "1 Hour - Most Epic Anime Mix - Battle Anime OST"; } @@ -235,6 +242,7 @@ public class YoutubeStreamExtractorDefaultTest { assertEquals(BASE_URL + ID + "?t=589", segment.getUrl()); assertNotNull(segment.getPreviewUrl()); } + // @formatter:on } public static class StreamSegmentsTestMaiLab extends DefaultStreamExtractorTest { @@ -304,6 +312,7 @@ public class YoutubeStreamExtractorDefaultTest { extractor.fetchPage(); } + // @formatter:off @Override public StreamExtractor extractor() { return extractor; } @Override public StreamingService expectedService() { return YouTube; } @Override public String expectedName() { return "Was verbirgt sich am tiefsten Punkt des Ozeans?"; } @@ -324,13 +333,13 @@ public class YoutubeStreamExtractorDefaultTest { @Override public long expectedDislikeCountAtLeast() { return 500; } @Override public List expectedMetaInfo() throws MalformedURLException { return Collections.singletonList(new MetaInfo( - "", + EMPTY_STRING, new Description("Funk is a German public broadcast service.", Description.PLAIN_TEXT), Collections.singletonList(new URL("https://de.wikipedia.org/wiki/Funk_(Medienangebot)?wprov=yicw1")), Collections.singletonList("Wikipedia (German)") )); } - + // @formatter:on @Override @Ignore("TODO fix") @Test @@ -344,6 +353,7 @@ public class YoutubeStreamExtractorDefaultTest { public void testMetaInfo() throws Exception { super.testMetaInfo(); } + } }