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 86d2c9a248..c557ade283 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; @@ -56,7 +57,6 @@ import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; -import java.nio.charset.StandardCharsets; import java.security.SecureRandom; import java.time.LocalDate; import java.time.OffsetDateTime; @@ -556,7 +556,7 @@ public static boolean areHardcodedClientVersionAndKeyValid() .end() .value("fetchLiveState", true) .end() - .end().done().getBytes(StandardCharsets.UTF_8); + .end().done().getBytes(UTF_8); // @formatter:on final var headers = getClientHeaders("1", HARDCODED_CLIENT_VERSION); @@ -797,7 +797,7 @@ public static boolean isHardcodedYoutubeMusicKeyValid() throws IOException, .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)); @@ -1228,7 +1228,7 @@ public static Page getNextPageFromContinuationItemRenderer(final JsonObject item final byte[] body = JsonWriter .string(prepareDesktopJsonBuilder(localization, contentCountry) .value("continuation", token).done()) - .getBytes(StandardCharsets.UTF_8); + .getBytes(UTF_8); return new Page(YOUTUBEI_V1_URL + "browse?key=" + getKey() + DISABLE_PRETTY_PRINT_PARAMETER, body); @@ -1435,7 +1435,7 @@ public static byte[] createDesktopPlayerBody( .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 33fe3207ca..a01ce0e017 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; @@ -623,7 +623,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/YoutubeChannelExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java index c553fc44d3..96baa8dc8d 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 @@ -7,6 +7,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; import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonObject; @@ -29,7 +30,6 @@ import org.schabi.newpipe.extractor.utils.Utils; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -95,7 +95,7 @@ public void onFetchPage(@Nonnull final Downloader downloader) getExtractorLocalization(), getExtractorContentCountry()) .value("url", "https://www.youtube.com/" + channelPath) .done()) - .getBytes(StandardCharsets.UTF_8); + .getBytes(UTF_8); final JsonObject jsonResponse = getJsonPostResponse("navigation/resolve_url", body, getExtractorLocalization()); @@ -133,7 +133,7 @@ public void onFetchPage(@Nonnull final Downloader downloader) .value("browseId", id) .value("params", "EgZ2aWRlb3M%3D") // Equal to videos .done()) - .getBytes(StandardCharsets.UTF_8); + .getBytes(UTF_8); final JsonObject jsonResponse = getJsonPostResponse("browse", body, getExtractorLocalization()); @@ -426,7 +426,7 @@ private Page getNextPageFrom(final JsonObject continuations, getExtractorContentCountry()) .value("continuation", continuation) .done()) - .getBytes(StandardCharsets.UTF_8); + .getBytes(UTF_8); return new Page(YOUTUBEI_V1_URL + "browse?key=" + getKey() + 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 84e6c3e1e1..f954b3c2e9 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; @@ -19,13 +20,13 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; 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 { @@ -191,7 +192,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); @@ -272,7 +273,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 = @@ -287,7 +288,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 eefc10a94d..2c089e3e63 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 @@ -11,6 +11,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; @@ -38,7 +39,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; @@ -87,7 +87,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(); @@ -212,7 +212,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?key=" + getKey(), 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 ae6b10a652..2a4329d002 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 @@ -12,6 +12,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; @@ -38,7 +39,6 @@ import org.schabi.newpipe.extractor.utils.Utils; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -112,7 +112,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( @@ -240,7 +240,7 @@ public InfoItemsPage getPage(final Page page) .value("enableSafetyMode", 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 2f6b5565b6..516d290a86 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 @@ -7,6 +7,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; @@ -29,7 +30,6 @@ import org.schabi.newpipe.extractor.utils.Utils; import java.io.IOException; -import java.nio.charset.StandardCharsets; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -63,7 +63,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); 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 7d374e9e6c..92ebfab37d 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 @@ -8,6 +8,7 @@ import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder; 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; @@ -30,7 +31,6 @@ import org.schabi.newpipe.extractor.utils.JsonUtils; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.List; import javax.annotation.Nonnull; @@ -87,7 +87,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); } @@ -190,7 +190,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 113f2d4a3d..8ba8f02632 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 @@ -39,6 +39,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; @@ -88,7 +89,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; @@ -878,7 +878,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); // streamType can only have LIVE_STREAM, POST_LIVE_STREAM and VIDEO_STREAM values (see @@ -987,7 +987,7 @@ private void fetchAndroidMobileJsonPlayer(@Nonnull final ContentCountry contentC // 10.29.2022 .value("params", "8AEB") .done()) - .getBytes(StandardCharsets.UTF_8); + .getBytes(UTF_8); final JsonObject androidPlayerResponse = getJsonAndroidPostResponse(PLAYER, mobileBody, localization, "&t=" + generateTParameter() @@ -1022,7 +1022,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 13996817e0..40c22201c0 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; @@ -65,7 +65,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 dd990c0ead..18a613258b 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 @@ -7,7 +7,6 @@ import java.net.URL; import java.net.URLDecoder; import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collection; import java.util.Map; @@ -23,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 @@ -37,7 +37,7 @@ private Utils() { */ public static String encodeUrlUtf8(final String string) throws UnsupportedEncodingException { // TODO: Switch to URLEncoder.encode(String, Charset) in Java 10. - return URLEncoder.encode(string, StandardCharsets.UTF_8.name()); + return URLEncoder.encode(string, UTF_8); } /** @@ -48,7 +48,7 @@ public static String encodeUrlUtf8(final String string) throws UnsupportedEncodi */ public static String decodeUrlUtf8(final String url) throws UnsupportedEncodingException { // TODO: Switch to URLDecoder.decode(String, Charset) in Java 10. - return URLDecoder.decode(url, StandardCharsets.UTF_8.name()); + return URLDecoder.decode(url, UTF_8); } /**