diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a5db2b918..60ed8c9dc1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,9 +1,9 @@ name: CI on: - schedule: - # once per day - - cron: 0 0 * * * + # schedule: + # # once per day + # - cron: 0 0 * * * push: branches: - dev diff --git a/build.gradle b/build.gradle index 88074257a4..a9dea55c6e 100644 --- a/build.gradle +++ b/build.gradle @@ -29,8 +29,8 @@ allprojects { ext { nanojsonVersion = "1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751" spotbugsVersion = "4.8.6" - junitVersion = "5.11.0" - checkstyleVersion = "10.4" + junitVersion = "5.11.2" + checkstyleVersion = "10.12.2" } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelHelper.java index 74335017ae..cab4d3de69 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelHelper.java @@ -11,7 +11,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.Optional; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.defaultAlertsCheck; @@ -19,6 +18,7 @@ import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; +import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; /** * Shared functions for extracting YouTube channel pages and tabs. @@ -67,7 +67,7 @@ public static String resolveChannelId(@Nonnull final String idOrPath) prepareDesktopJsonBuilder(Localization.DEFAULT, ContentCountry.DEFAULT) .value("url", "https://www.youtube.com/" + idOrPath) .done()) - .getBytes(StandardCharsets.UTF_8); + .getBytes(UTF_8); final JsonObject jsonResponse = getJsonPostResponse( "navigation/resolve_url", body, Localization.DEFAULT); @@ -159,7 +159,7 @@ public static ChannelResponseData getChannelResponse(@Nonnull final String chann .value(BROWSE_ID, id) .value("params", parameters) .done()) - .getBytes(StandardCharsets.UTF_8); + .getBytes(UTF_8); final JsonObject jsonResponse = getJsonPostResponse( "browse", body, localization); 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 53031e7341..b52040bc0f 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 @@ -25,6 +25,7 @@ import static org.schabi.newpipe.extractor.utils.Utils.HTTPS; import static org.schabi.newpipe.extractor.utils.Utils.getStringResultFromRegexArray; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; +import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonBuilder; @@ -54,7 +55,6 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; -import java.nio.charset.StandardCharsets; import java.time.LocalDate; import java.time.OffsetDateTime; import java.time.ZoneOffset; @@ -559,7 +559,7 @@ public static boolean isHardcodedClientVersionValid() .end() .end() .value("fetchLiveState", true) - .end().done().getBytes(StandardCharsets.UTF_8); + .end().done().getBytes(UTF_8); // @formatter:on final var headers = getClientHeaders(WEB_CLIENT_ID, HARDCODED_CLIENT_VERSION); @@ -752,7 +752,7 @@ public static boolean isHardcodedYoutubeMusicClientVersionValid() throws IOExcep .end() .end() .value("input", "") - .end().done().getBytes(StandardCharsets.UTF_8); + .end().done().getBytes(UTF_8); // @formatter:on final var headers = new HashMap<>(getOriginReferrerHeaders(YOUTUBE_MUSIC_URL)); @@ -1319,7 +1319,7 @@ public static JsonObject getWebPlayerResponse( .value(CONTENT_CHECK_OK, true) .value(RACY_CHECK_OK, true) .done()) - .getBytes(StandardCharsets.UTF_8); + .getBytes(UTF_8); final String url = YOUTUBEI_V1_URL + "player" + "?" + DISABLE_PRETTY_PRINT_PARAMETER + "&$fields=microformat,playabilityStatus,storyboards,videoDetails"; @@ -1334,7 +1334,7 @@ public static byte[] createTvHtml5EmbedPlayerBody( @Nonnull final ContentCountry contentCountry, @Nonnull final String videoId, @Nonnull final Integer sts, - @Nonnull final String contentPlaybackNonce) { + @Nonnull final String contentPlaybackNonce) throws IOException { // @formatter:off return JsonWriter.string( prepareTvHtml5EmbedJsonBuilder(localization, contentCountry, videoId) @@ -1351,7 +1351,7 @@ public static byte[] createTvHtml5EmbedPlayerBody( .value(CONTENT_CHECK_OK, true) .value(RACY_CHECK_OK, true) .done()) - .getBytes(StandardCharsets.UTF_8); + .getBytes(UTF_8); // @formatter:on } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/dashmanifestcreators/YoutubeDashManifestCreatorsUtils.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/dashmanifestcreators/YoutubeDashManifestCreatorsUtils.java index 5e0fb6d4cf..16743d3b1a 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/dashmanifestcreators/YoutubeDashManifestCreatorsUtils.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/dashmanifestcreators/YoutubeDashManifestCreatorsUtils.java @@ -8,6 +8,7 @@ import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isTvHtml5SimplyEmbeddedPlayerStreamingUrl; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isWebStreamingUrl; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; +import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.NewPipe; @@ -25,7 +26,6 @@ import java.io.IOException; import java.io.StringWriter; -import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Locale; import java.util.Map; @@ -620,7 +620,7 @@ public static Response getInitializationResponse(@Nonnull String baseStreamingUr final var headers = Map.of("User-Agent", List.of(isAndroidStreamingUrl ? getAndroidUserAgent(null) : getIosUserAgent(null))); - final byte[] emptyBody = "".getBytes(StandardCharsets.UTF_8); + final byte[] emptyBody = "".getBytes(UTF_8); return downloader.post(baseStreamingUrl, headers, emptyBody); } catch (final IOException | ExtractionException e) { throw new CreationException("Could not get the " diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelTabExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelTabExtractor.java index 6aa88c67d4..914a3644bd 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelTabExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelTabExtractor.java @@ -20,7 +20,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Optional; @@ -31,6 +30,7 @@ import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonPostResponse; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; +import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; /** * A {@link ChannelTabExtractor} implementation for the YouTube service. @@ -438,7 +438,7 @@ private Page getNextPageFrom(final JsonObject continuations, useVisitorData && channelIds.size() >= 3 ? channelIds.get(2) : null) .value("continuation", continuation) .done()) - .getBytes(StandardCharsets.UTF_8); + .getBytes(UTF_8); return new Page(YOUTUBEI_V1_URL + "browse?" + DISABLE_PRETTY_PRINT_PARAMETER, null, channelIds, null, body); 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 8667768a4b..353ee42ada 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,6 +3,7 @@ import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonWriter; + import org.schabi.newpipe.extractor.Page; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.comments.CommentsExtractor; @@ -20,12 +21,12 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.Collections; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonPostResponse; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder; +import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; public class YoutubeCommentsExtractor extends CommentsExtractor { @@ -208,7 +209,7 @@ public InfoItemsPage getPage(final Page page) prepareDesktopJsonBuilder(localization, getExtractorContentCountry()) .value("continuation", page.getId()) .done()) - .getBytes(StandardCharsets.UTF_8); + .getBytes(UTF_8); // @formatter:on final JsonObject jsonObject = getJsonPostResponse("next", body, localization); @@ -348,7 +349,7 @@ public void onFetchPage(@Nonnull final Downloader downloader) prepareDesktopJsonBuilder(localization, getExtractorContentCountry()) .value("videoId", getId()) .done()) - .getBytes(StandardCharsets.UTF_8); + .getBytes(UTF_8); // @formatter:on final String initialToken = @@ -363,7 +364,7 @@ public void onFetchPage(@Nonnull final Downloader downloader) prepareDesktopJsonBuilder(localization, getExtractorContentCountry()) .value("continuation", initialToken) .done()) - .getBytes(StandardCharsets.UTF_8); + .getBytes(UTF_8); // @formatter:on ajaxJson = getJsonPostResponse("next", ajaxBody, localization); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMixPlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMixPlaylistExtractor.java index 1df90f967f..8777fda19a 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMixPlaylistExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMixPlaylistExtractor.java @@ -10,6 +10,7 @@ import static org.schabi.newpipe.extractor.utils.Utils.getQueryValue; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; import static org.schabi.newpipe.extractor.utils.Utils.stringToURL; +import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonBuilder; @@ -40,7 +41,6 @@ import java.io.IOException; import java.net.URL; -import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -96,7 +96,7 @@ public void onFetchPage(@Nonnull final Downloader downloader) jsonBody.value("playlistIndex", Integer.parseInt(playlistIndexString)); } - final byte[] body = JsonWriter.string(jsonBody.done()).getBytes(StandardCharsets.UTF_8); + final byte[] body = JsonWriter.string(jsonBody.done()).getBytes(UTF_8); // Cookie is required due to consent final var headers = getYouTubeHeaders(); @@ -222,7 +222,7 @@ private Page getNextPageFrom(@Nonnull final JsonObject playlistJson, .value("playlistIndex", index) .value("params", params) .done()) - .getBytes(StandardCharsets.UTF_8); + .getBytes(UTF_8); return new Page(YOUTUBEI_V1_URL + "next?" + DISABLE_PRETTY_PRINT_PARAMETER, null, null, cookies, body); 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 4ed5449fc9..fc88cf68a0 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 @@ -11,6 +11,7 @@ import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_SONGS; import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_VIDEOS; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; +import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonObject; @@ -31,7 +32,6 @@ import org.schabi.newpipe.extractor.utils.JsonUtils; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -102,7 +102,7 @@ public void onFetchPage(@Nonnull final Downloader downloader) .end() .value("query", getSearchString()) .value("params", params) - .end().done().getBytes(StandardCharsets.UTF_8); + .end().done().getBytes(UTF_8); // @formatter:on final String responseBody = getValidJsonResponseBody( @@ -226,7 +226,7 @@ public InfoItemsPage getPage(final Page page) .value("lockedSafetyMode", false) .end() .end() - .end().done().getBytes(StandardCharsets.UTF_8); + .end().done().getBytes(UTF_8); // @formatter:on final String responseBody = getValidJsonResponseBody( 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 79afd55421..ba40dc31ef 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistExtractor.java @@ -9,6 +9,7 @@ import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getUrlFromNavigationEndpoint; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; +import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonObject; @@ -32,7 +33,6 @@ import org.schabi.newpipe.extractor.utils.Utils; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.List; import javax.annotation.Nonnull; @@ -70,7 +70,7 @@ public void onFetchPage(@Nonnull final Downloader downloader) throws IOException .value("browseId", "VL" + getId()) .value("params", "wgYCCAA%3D") // Show unavailable videos .done()) - .getBytes(StandardCharsets.UTF_8); + .getBytes(UTF_8); browseResponse = getJsonPostResponse("browse", body, localization); YoutubeParsingHelper.defaultAlertsCheck(browseResponse); @@ -384,7 +384,7 @@ private Page getNextPageFrom(final JsonArray contents) getExtractorLocalization(), getExtractorContentCountry()) .value("continuation", continuation) .done()) - .getBytes(StandardCharsets.UTF_8); + .getBytes(UTF_8); return new Page(YOUTUBEI_V1_URL + "browse?" + DISABLE_PRETTY_PRINT_PARAMETER, body); } else { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java index a0be72cc8f..228f64e3ea 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java @@ -11,6 +11,7 @@ import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.VIDEOS; import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.getSearchParameter; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; +import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonBuilder; @@ -33,7 +34,6 @@ import org.schabi.newpipe.extractor.utils.JsonUtils; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Objects; @@ -100,7 +100,7 @@ public void onFetchPage(@Nonnull final Downloader downloader) throws IOException jsonBody.value("params", params); } - final byte[] body = JsonWriter.string(jsonBody.done()).getBytes(StandardCharsets.UTF_8); + final byte[] body = JsonWriter.string(jsonBody.done()).getBytes(UTF_8); initialData = getJsonPostResponse("search", body, localization); } @@ -202,7 +202,7 @@ public InfoItemsPage getPage(final Page page) throws IOException, getExtractorContentCountry()) .value("continuation", page.getId()) .done()) - .getBytes(StandardCharsets.UTF_8); + .getBytes(UTF_8); // @formatter:on final JsonObject ajaxJson = getJsonPostResponse("search", json, localization); 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 e6fb7c1b4a..d9658f74e6 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 @@ -40,6 +40,7 @@ import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareIosMobileJsonBuilder; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; +import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonObject; @@ -87,7 +88,6 @@ import org.schabi.newpipe.extractor.utils.Utils; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.time.LocalDate; import java.time.OffsetDateTime; import java.time.format.DateTimeFormatter; @@ -841,7 +841,7 @@ public void onFetchPage(@Nonnull final Downloader downloader) .value(CONTENT_CHECK_OK, true) .value(RACY_CHECK_OK, true) .done()) - .getBytes(StandardCharsets.UTF_8); + .getBytes(UTF_8); nextResponse = getJsonPostResponse(NEXT, body, localization); } @@ -918,7 +918,7 @@ private void fetchAndroidMobileJsonPlayer(@Nonnull final ContentCountry contentC .value(CONTENT_CHECK_OK, true) .value(RACY_CHECK_OK, true) .done()) - .getBytes(StandardCharsets.UTF_8); + .getBytes(UTF_8); final JsonObject androidPlayerResponse = getJsonAndroidPostResponse( "reel/reel_item_watch", @@ -957,7 +957,7 @@ private void fetchIosMobileJsonPlayer(@Nonnull final ContentCountry contentCount .value(CONTENT_CHECK_OK, true) .value(RACY_CHECK_OK, true) .done()) - .getBytes(StandardCharsets.UTF_8); + .getBytes(UTF_8); final JsonObject iosPlayerResponse = getJsonIosPostResponse(PLAYER, mobileBody, localization, "&t=" + generateTParameter() diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeTrendingExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeTrendingExtractor.java index 2976edc4db..62953ce137 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeTrendingExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeTrendingExtractor.java @@ -24,6 +24,7 @@ import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextAtKey; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; +import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; import com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonWriter; @@ -40,7 +41,6 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.stream.Stream; import javax.annotation.Nonnull; @@ -68,7 +68,7 @@ public void onFetchPage(@Nonnull final Downloader downloader) .value("browseId", "FEtrending") .value("params", VIDEOS_TAB_PARAMS) .done()) - .getBytes(StandardCharsets.UTF_8); + .getBytes(UTF_8); // @formatter:on initialData = getJsonPostResponse("browse", body, getExtractorLocalization()); 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 c061ce30fa..d2cc95482f 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 @@ -6,7 +6,7 @@ import java.net.URL; import java.net.URLDecoder; import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; +import java.io.UnsupportedEncodingException; import java.util.Arrays; import java.util.Collection; import java.util.Map; @@ -22,6 +22,7 @@ public final class Utils { public static final String HTTPS = "https://"; private static final Pattern M_PATTERN = Pattern.compile("(https?)?://m\\."); private static final Pattern WWW_PATTERN = Pattern.compile("(https?)?://www\\."); + public static final String UTF_8 = "UTF-8"; private Utils() { // no instance @@ -34,7 +35,12 @@ private Utils() { * @return The encoded URL. */ public static String encodeUrlUtf8(final String string) { - return URLEncoder.encode(string, StandardCharsets.UTF_8); + try { + // TODO: Switch to URLEncoder.encode(String, Charset) in Java 10. + return URLEncoder.encode(string, UTF_8); + } catch (final UnsupportedEncodingException e) { + throw new RuntimeException("UTF-8 not supported error: " + e.getMessage(), e); + } } /** @@ -43,7 +49,12 @@ public static String encodeUrlUtf8(final String string) { * @return The decoded URL. */ public static String decodeUrlUtf8(final String url) { - return URLDecoder.decode(url, StandardCharsets.UTF_8); + // TODO: Switch to URLDecoder.decode(String, Charset) in Java 10. + try { + return URLDecoder.decode(url, UTF_8); + } catch (final UnsupportedEncodingException e) { + throw new RuntimeException("UTF-8 not supported error: " + e.getMessage(), e); + } } /**