diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCSearchQueryHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCSearchQueryHandlerFactory.java index 83930d1e0..54fa04795 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCSearchQueryHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCSearchQueryHandlerFactory.java @@ -5,10 +5,9 @@ import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.List; -import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; - public class MediaCCCSearchQueryHandlerFactory extends SearchQueryHandlerFactory { public static final String ALL = "all"; public static final String CONFERENCES = "conferences"; @@ -33,7 +32,7 @@ public class MediaCCCSearchQueryHandlerFactory extends SearchQueryHandlerFactory final String sortFilter) throws ParsingException { try { return "https://media.ccc.de/public/events/search?q=" - + URLEncoder.encode(query, UTF_8); + + URLEncoder.encode(query, StandardCharsets.UTF_8.name()); } catch (final UnsupportedEncodingException e) { throw new ParsingException("Could not create search string with query: " + query, e); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java index d70abf11d..9b7d83827 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java @@ -1,7 +1,6 @@ package org.schabi.newpipe.extractor.services.peertube.extractors; import static org.schabi.newpipe.extractor.stream.AudioStream.UNKNOWN_BITRATE; -import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; import com.grack.nanojson.JsonArray; @@ -37,6 +36,7 @@ import org.schabi.newpipe.extractor.utils.Utils; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -328,7 +328,7 @@ public class PeertubeStreamExtractor extends StreamExtractor { params.append("start=0&count=8&sort=-createdAt"); for (final String tag : tags) { params.append("&tagsOneOf="); - params.append(URLEncoder.encode(tag, UTF_8)); + params.append(URLEncoder.encode(tag, StandardCharsets.UTF_8.name())); } return url + "?" + params; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeSearchQueryHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeSearchQueryHandlerFactory.java index 09c14df63..18013129e 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeSearchQueryHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeSearchQueryHandlerFactory.java @@ -6,10 +6,9 @@ import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.List; -import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; - public final class PeertubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory { public static final String VIDEOS = "videos"; @@ -43,7 +42,8 @@ public final class PeertubeSearchQueryHandlerFactory extends SearchQueryHandlerF final String sortFilter, final String baseUrl) throws ParsingException { try { - return baseUrl + SEARCH_ENDPOINT + "?search=" + URLEncoder.encode(searchString, UTF_8); + return baseUrl + SEARCH_ENDPOINT + "?search=" + URLEncoder.encode(searchString, + StandardCharsets.UTF_8.name()); } catch (final UnsupportedEncodingException e) { throw new ParsingException("Could not encode query", e); } 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 592a77add..1f6535176 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 @@ -1,7 +1,6 @@ package org.schabi.newpipe.extractor.services.soundcloud; import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; -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.replaceHttpWithHttps; @@ -33,6 +32,7 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.time.OffsetDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; @@ -109,7 +109,7 @@ public final class SoundcloudParsingHelper { public static JsonObject resolveFor(@Nonnull final Downloader downloader, final String url) throws IOException, ExtractionException { final String apiUrl = SOUNDCLOUD_API_V2_URL + "resolve" - + "?url=" + URLEncoder.encode(url, UTF_8) + + "?url=" + URLEncoder.encode(url, StandardCharsets.UTF_8.name()) + "&client_id=" + clientId(); try { @@ -131,7 +131,8 @@ public final class SoundcloudParsingHelper { ReCaptchaException { final String response = NewPipe.getDownloader().get("https://w.soundcloud.com/player/?url=" - + URLEncoder.encode(apiUrl, UTF_8), SoundCloud.getLocalization()).responseBody(); + + URLEncoder.encode(apiUrl, StandardCharsets.UTF_8.name()), + SoundCloud.getLocalization()).responseBody(); return Jsoup.parse(response).select("link[rel=\"canonical\"]").first() .attr("abs:href"); @@ -162,7 +163,7 @@ public final class SoundcloudParsingHelper { try { final String widgetUrl = "https://api-widget.soundcloud.com/resolve?url=" - + URLEncoder.encode(url.toString(), UTF_8) + + URLEncoder.encode(url.toString(), StandardCharsets.UTF_8.name()) + "&format=json&client_id=" + SoundcloudParsingHelper.clientId(); final String response = NewPipe.getDownloader().get(widgetUrl, SoundCloud.getLocalization()).responseBody(); 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 0d28ed954..b87ac5ece 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 @@ -4,7 +4,6 @@ import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsing import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.clientId; import static org.schabi.newpipe.extractor.stream.AudioStream.UNKNOWN_BITRATE; import static org.schabi.newpipe.extractor.stream.Stream.ID_UNKNOWN; -import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; import com.grack.nanojson.JsonArray; @@ -36,6 +35,7 @@ import org.schabi.newpipe.extractor.stream.VideoStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -320,7 +320,7 @@ public class SoundcloudStreamExtractor extends StreamExtractor { private static String urlEncode(final String value) { try { - return URLEncoder.encode(value, UTF_8); + return URLEncoder.encode(value, StandardCharsets.UTF_8.name()); } catch (final UnsupportedEncodingException e) { throw new IllegalStateException(e); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudSuggestionExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudSuggestionExtractor.java index edb3cc4aa..1e6beafb7 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudSuggestionExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudSuggestionExtractor.java @@ -1,9 +1,12 @@ package org.schabi.newpipe.extractor.services.soundcloud.extractors; +import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL; + 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.NewPipe; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.downloader.Downloader; @@ -14,12 +17,10 @@ import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor; import java.io.IOException; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; -import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL; -import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; - public class SoundcloudSuggestionExtractor extends SuggestionExtractor { public SoundcloudSuggestionExtractor(final StreamingService service) { @@ -32,7 +33,7 @@ public class SoundcloudSuggestionExtractor extends SuggestionExtractor { final List suggestions = new ArrayList<>(); final Downloader dl = NewPipe.getDownloader(); final String url = SOUNDCLOUD_API_V2_URL + "search/queries" + "?q=" - + URLEncoder.encode(query, UTF_8) + "&client_id=" + + URLEncoder.encode(query, StandardCharsets.UTF_8.name()) + "&client_id=" + SoundcloudParsingHelper.clientId() + "&limit=10"; final String response = dl.get(url, getExtractorLocalization()).responseBody(); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/linkHandler/SoundcloudSearchQueryHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/linkHandler/SoundcloudSearchQueryHandlerFactory.java index deb3d8b6e..33df3a1b6 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/linkHandler/SoundcloudSearchQueryHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/linkHandler/SoundcloudSearchQueryHandlerFactory.java @@ -1,5 +1,7 @@ package org.schabi.newpipe.extractor.services.soundcloud.linkHandler; +import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL; + import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; @@ -9,11 +11,9 @@ import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.List; -import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL; -import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; - public class SoundcloudSearchQueryHandlerFactory extends SearchQueryHandlerFactory { public static final String TRACKS = "tracks"; @@ -48,9 +48,9 @@ public class SoundcloudSearchQueryHandlerFactory extends SearchQueryHandlerFacto } } - return url + "?q=" + URLEncoder.encode(id, UTF_8) + "&client_id=" - + SoundcloudParsingHelper.clientId() + "&limit=" + ITEMS_PER_PAGE - + "&offset=0"; + return url + "?q=" + URLEncoder.encode(id, StandardCharsets.UTF_8.name()) + + "&client_id=" + SoundcloudParsingHelper.clientId() + + "&limit=" + ITEMS_PER_PAGE + "&offset=0"; } catch (final UnsupportedEncodingException e) { throw new ParsingException("Could not encode query", e); 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 be38fa9ae..ab748b36f 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 @@ -23,7 +23,6 @@ package org.schabi.newpipe.extractor.services.youtube; import static org.schabi.newpipe.extractor.NewPipe.getDownloader; import static org.schabi.newpipe.extractor.utils.Utils.HTTP; import static org.schabi.newpipe.extractor.utils.Utils.HTTPS; -import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; import static org.schabi.newpipe.extractor.utils.Utils.getStringResultFromRegexArray; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; import static java.util.Collections.singletonList; @@ -575,7 +574,7 @@ public final class YoutubeParsingHelper { .end() .value("fetchLiveState", true) .end() - .end().done().getBytes(UTF_8); + .end().done().getBytes(StandardCharsets.UTF_8); // @formatter:on final Map> headers = new HashMap<>(); @@ -820,7 +819,7 @@ public final class YoutubeParsingHelper { .end() .end() .value("input", "") - .end().done().getBytes(UTF_8); + .end().done().getBytes(StandardCharsets.UTF_8); // @formatter:on final Map> headers = new HashMap<>(); @@ -892,7 +891,8 @@ public final class YoutubeParsingHelper { for (final String param : params) { if (param.split("=")[0].equals("q")) { try { - return URLDecoder.decode(param.split("=")[1], UTF_8); + return URLDecoder.decode(param.split("=")[1], + StandardCharsets.UTF_8.name()); } catch (final UnsupportedEncodingException e) { return null; } 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 1622fbe1f..86a16409a 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 @@ -9,7 +9,6 @@ import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getValidJsonResponseBody; 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; import com.grack.nanojson.JsonArray; @@ -35,6 +34,7 @@ import org.schabi.newpipe.extractor.utils.JsonUtils; import org.schabi.newpipe.extractor.utils.Utils; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -98,7 +98,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor { getExtractorLocalization(), getExtractorContentCountry()) .value("url", "https://www.youtube.com/" + channelPath) .done()) - .getBytes(UTF_8); + .getBytes(StandardCharsets.UTF_8); final JsonObject jsonResponse = getJsonPostResponse("navigation/resolve_url", body, getExtractorLocalization()); @@ -146,7 +146,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor { .value("browseId", id) .value("params", "EgZ2aWRlb3M%3D") // Equal to videos .done()) - .getBytes(UTF_8); + .getBytes(StandardCharsets.UTF_8); final JsonObject jsonResponse = getJsonPostResponse("browse", body, getExtractorLocalization()); @@ -397,7 +397,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor { getExtractorContentCountry()) .value("continuation", continuation) .done()) - .getBytes(UTF_8); + .getBytes(StandardCharsets.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/YoutubeMusicSearchExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java index e93c171f3..b7bcb5b6e 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 @@ -10,7 +10,6 @@ import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeS import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_PLAYLISTS; 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.UTF_8; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; import com.grack.nanojson.JsonArray; @@ -38,6 +37,7 @@ import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Utils; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -113,7 +113,7 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor { .end() .value("query", getSearchString()) .value("params", params) - .end().done().getBytes(UTF_8); + .end().done().getBytes(StandardCharsets.UTF_8); // @formatter:on final Map> headers = new HashMap<>(); @@ -248,7 +248,7 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor { .value("enableSafetyMode", false) .end() .end() - .end().done().getBytes(UTF_8); + .end().done().getBytes(StandardCharsets.UTF_8); // @formatter:on final Map> headers = new HashMap<>(); 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 de937cb02..1489963e6 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,7 +8,6 @@ import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getValidJsonResponseBody; 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.UTF_8; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; import com.grack.nanojson.JsonArray; @@ -20,6 +19,7 @@ import com.grack.nanojson.JsonWriter; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.MetaInfo; +import org.schabi.newpipe.extractor.MultiInfoItemsCollector; import org.schabi.newpipe.extractor.Page; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.downloader.Downloader; @@ -28,12 +28,12 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler; import org.schabi.newpipe.extractor.localization.Localization; import org.schabi.newpipe.extractor.localization.TimeAgoParser; -import org.schabi.newpipe.extractor.MultiInfoItemsCollector; import org.schabi.newpipe.extractor.search.SearchExtractor; import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper; import org.schabi.newpipe.extractor.utils.JsonUtils; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.List; @@ -90,7 +90,7 @@ public class YoutubeSearchExtractor extends SearchExtractor { jsonBody.value("params", params); } - final byte[] body = JsonWriter.string(jsonBody.done()).getBytes(UTF_8); + final byte[] body = JsonWriter.string(jsonBody.done()).getBytes(StandardCharsets.UTF_8); initialData = getJsonPostResponse("search", body, localization); } @@ -184,7 +184,7 @@ public class YoutubeSearchExtractor extends SearchExtractor { getExtractorContentCountry()) .value("continuation", page.getId()) .done()) - .getBytes(UTF_8); + .getBytes(StandardCharsets.UTF_8); // @formatter:on final String responseBody = getValidJsonResponseBody(getDownloader().post( diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSuggestionExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSuggestionExtractor.java index f25fea05d..0a014a293 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSuggestionExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSuggestionExtractor.java @@ -1,7 +1,6 @@ package org.schabi.newpipe.extractor.services.youtube.extractors; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getCookieHeader; -import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonParser; @@ -16,6 +15,7 @@ import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor; import java.io.IOException; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -54,8 +54,9 @@ public class YoutubeSuggestionExtractor extends SuggestionExtractor { + "?client=" + "youtube" //"firefox" for JSON, 'toolbar' for xml + "&jsonp=" + "JP" + "&ds=" + "yt" - + "&gl=" + URLEncoder.encode(getExtractorContentCountry().getCountryCode(), UTF_8) - + "&q=" + URLEncoder.encode(query, UTF_8); + + "&gl=" + URLEncoder.encode(getExtractorContentCountry().getCountryCode(), + StandardCharsets.UTF_8.name()) + + "&q=" + URLEncoder.encode(query, StandardCharsets.UTF_8.name()); String response = dl.get(url, getCookieHeader(), getExtractorLocalization()).responseBody(); // trim JSONP part "JP(...)" 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 ea53d936d..6804909d1 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 @@ -18,7 +18,10 @@ * along with NewPipe Extractor. If not, see . */ -package org.schabi.newpipe.extractor.services.youtube.extractors; +import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonPostResponse; +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 com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonWriter; @@ -35,15 +38,10 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; import java.io.IOException; +import java.nio.charset.StandardCharsets; import javax.annotation.Nonnull; -import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonPostResponse; -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.UTF_8; -import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; - public class YoutubeTrendingExtractor extends KioskExtractor { private JsonObject initialData; @@ -61,7 +59,7 @@ public class YoutubeTrendingExtractor extends KioskExtractor { getExtractorContentCountry()) .value("browseId", "FEtrending") .done()) - .getBytes(UTF_8); + .getBytes(StandardCharsets.UTF_8); // @formatter:on initialData = getJsonPostResponse("browse", body, getExtractorLocalization()); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeSearchQueryHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeSearchQueryHandlerFactory.java index 798a2347c..0bbc76da5 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeSearchQueryHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeSearchQueryHandlerFactory.java @@ -1,15 +1,16 @@ package org.schabi.newpipe.extractor.services.youtube.linkHandler; +import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; + import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory; -import javax.annotation.Nonnull; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.List; -import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; -import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; +import javax.annotation.Nonnull; public final class YoutubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory { @@ -44,24 +45,28 @@ public final class YoutubeSearchQueryHandlerFactory extends SearchQueryHandlerFa default: break; case VIDEOS: - return SEARCH_URL + URLEncoder.encode(searchString, UTF_8) + return SEARCH_URL + URLEncoder.encode(searchString, + StandardCharsets.UTF_8.name()) + "&sp=EgIQAQ%253D%253D"; case CHANNELS: - return SEARCH_URL + URLEncoder.encode(searchString, UTF_8) + return SEARCH_URL + URLEncoder.encode(searchString, + StandardCharsets.UTF_8.name()) + "&sp=EgIQAg%253D%253D"; case PLAYLISTS: - return SEARCH_URL + URLEncoder.encode(searchString, UTF_8) + return SEARCH_URL + URLEncoder.encode(searchString, + StandardCharsets.UTF_8.name()) + "&sp=EgIQAw%253D%253D"; case MUSIC_SONGS: case MUSIC_VIDEOS: case MUSIC_ALBUMS: case MUSIC_PLAYLISTS: case MUSIC_ARTISTS: - return MUSIC_SEARCH_URL + URLEncoder.encode(searchString, UTF_8); + return MUSIC_SEARCH_URL + URLEncoder.encode(searchString, + StandardCharsets.UTF_8.name()); } } - return SEARCH_URL + URLEncoder.encode(searchString, UTF_8); + return SEARCH_URL + URLEncoder.encode(searchString, StandardCharsets.UTF_8.name()); } catch (final UnsupportedEncodingException e) { throw new ParsingException("Could not encode query", e); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Parser.java b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Parser.java index 64707cd3a..03e2c67cd 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Parser.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Parser.java @@ -26,6 +26,9 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.EnumSet; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; @@ -99,7 +102,7 @@ public final class Parser { for (final String arg : input.split("&")) { final String[] splitArg = arg.split("="); if (splitArg.length > 1) { - map.put(splitArg[0], URLDecoder.decode(splitArg[1], UTF_8)); + map.put(splitArg[0], URLDecoder.decode(splitArg[1], StandardCharsets.UTF_8.name())); } else { map.put(splitArg[0], ""); } 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 47b24cb3d..a9cd7229d 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,6 +6,7 @@ import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collection; import java.util.Map; @@ -17,14 +18,8 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; public final class Utils { - public static final String HTTP = "http://"; public static final String HTTPS = "https://"; - /** - * @deprecated Use {@link java.nio.charset.StandardCharsets#UTF_8} - */ - @Deprecated - public static final String UTF_8 = "UTF-8"; private static final Pattern M_PATTERN = Pattern.compile("(https?)?://m\\."); private static final Pattern WWW_PATTERN = Pattern.compile("(https?)?://www\\."); @@ -139,7 +134,7 @@ public final class Utils { String query; try { - query = URLDecoder.decode(params[0], UTF_8); + query = URLDecoder.decode(params[0], StandardCharsets.UTF_8.name()); } catch (final UnsupportedEncodingException e) { // Cannot decode string with UTF-8, using the string without decoding query = params[0]; @@ -147,7 +142,7 @@ public final class Utils { if (query.equals(parameterName)) { try { - return URLDecoder.decode(params[1], UTF_8); + return URLDecoder.decode(params[1], StandardCharsets.UTF_8.name()); } catch (final UnsupportedEncodingException e) { // Cannot decode string with UTF-8, using the string without decoding return params[1]; @@ -246,7 +241,8 @@ public final class Utils { try { final URL decoded = Utils.stringToURL(url); if (decoded.getHost().contains("google") && decoded.getPath().equals("/url")) { - return URLDecoder.decode(Parser.matchGroup1("&url=([^&]+)(?:&|$)", url), UTF_8); + return URLDecoder.decode(Parser.matchGroup1("&url=([^&]+)(?:&|$)", url), + StandardCharsets.UTF_8.name()); } } catch (final Exception ignored) { } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorTest.java index eeeb896de..bb53146c1 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorTest.java @@ -1,5 +1,13 @@ package org.schabi.newpipe.extractor.services.soundcloud.search; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; +import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoDuplicatedItems; +import static org.schabi.newpipe.extractor.services.soundcloud.linkHandler.SoundcloudSearchQueryHandlerFactory.PLAYLISTS; +import static org.schabi.newpipe.extractor.services.soundcloud.linkHandler.SoundcloudSearchQueryHandlerFactory.TRACKS; +import static org.schabi.newpipe.extractor.services.soundcloud.linkHandler.SoundcloudSearchQueryHandlerFactory.USERS; +import static java.util.Collections.singletonList; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.schabi.newpipe.downloader.DownloaderTestImpl; @@ -12,18 +20,13 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.search.SearchExtractor; import org.schabi.newpipe.extractor.services.DefaultSearchExtractorTest; -import javax.annotation.Nullable; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.List; -import static java.util.Collections.singletonList; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; -import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoDuplicatedItems; -import static org.schabi.newpipe.extractor.services.soundcloud.linkHandler.SoundcloudSearchQueryHandlerFactory.*; -import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; +import javax.annotation.Nullable; public class SoundcloudSearchExtractorTest { @@ -138,7 +141,7 @@ public class SoundcloudSearchExtractorTest { private static String urlEncode(String value) { try { - return URLEncoder.encode(value, UTF_8); + return URLEncoder.encode(value, StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSubscriptionExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSubscriptionExtractorTest.java index f5003383c..8224f991f 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSubscriptionExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSubscriptionExtractorTest.java @@ -1,5 +1,11 @@ package org.schabi.newpipe.extractor.services.youtube; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; +import static org.schabi.newpipe.FileUtils.resolveTestResource; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.schabi.newpipe.downloader.DownloaderTestImpl; @@ -13,13 +19,10 @@ import org.schabi.newpipe.extractor.subscription.SubscriptionItem; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; -import static org.junit.jupiter.api.Assertions.*; -import static org.schabi.newpipe.FileUtils.resolveTestResource; -import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; - /** * Test for {@link YoutubeSubscriptionExtractor} */ @@ -54,7 +57,7 @@ public class YoutubeSubscriptionExtractorTest { @Test public void testEmptySourceException() throws Exception { final List items = subscriptionExtractor.fromInputStream( - new ByteArrayInputStream("[]".getBytes(UTF_8))); + new ByteArrayInputStream("[]".getBytes(StandardCharsets.UTF_8))); assertTrue(items.isEmpty()); } @@ -62,7 +65,7 @@ public class YoutubeSubscriptionExtractorTest { public void testSubscriptionWithEmptyTitleInSource() throws Exception { final String source = "[{\"snippet\":{\"resourceId\":{\"channelId\":\"UCEOXxzW2vU0P-0THehuIIeg\"}}}]"; final List items = subscriptionExtractor.fromInputStream( - new ByteArrayInputStream(source.getBytes(UTF_8))); + new ByteArrayInputStream(source.getBytes(StandardCharsets.UTF_8))); assertEquals(1, items.size()); assertEquals(ServiceList.YouTube.getServiceId(), items.get(0).getServiceId()); @@ -75,7 +78,7 @@ public class YoutubeSubscriptionExtractorTest { final String source = "[{\"snippet\":{\"resourceId\":{\"channelId\":\"gibberish\"},\"title\":\"name1\"}}," + "{\"snippet\":{\"resourceId\":{\"channelId\":\"UCEOXxzW2vU0P-0THehuIIeg\"},\"title\":\"name2\"}}]"; final List items = subscriptionExtractor.fromInputStream( - new ByteArrayInputStream(source.getBytes(UTF_8))); + new ByteArrayInputStream(source.getBytes(StandardCharsets.UTF_8))); assertEquals(1, items.size()); assertEquals(ServiceList.YouTube.getServiceId(), items.get(0).getServiceId()); @@ -99,7 +102,7 @@ public class YoutubeSubscriptionExtractorTest { for (String invalidContent : invalidList) { try { - byte[] bytes = invalidContent.getBytes(UTF_8); + byte[] bytes = invalidContent.getBytes(StandardCharsets.UTF_8); subscriptionExtractor.fromInputStream(new ByteArrayInputStream(bytes)); fail("Extracting from \"" + invalidContent + "\" didn't throw an exception"); } catch (final Exception e) {