Skip to content

Commit 366f5c1

Browse files
Use StandardCharsets.UTF_8.
1 parent 0ea16c0 commit 366f5c1

18 files changed

Lines changed: 94 additions & 84 deletions

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCSearchQueryHandlerFactory.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55

66
import java.io.UnsupportedEncodingException;
77
import java.net.URLEncoder;
8+
import java.nio.charset.StandardCharsets;
89
import java.util.List;
910

10-
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
11-
1211
public class MediaCCCSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
1312
public static final String ALL = "all";
1413
public static final String CONFERENCES = "conferences";
@@ -33,7 +32,7 @@ public String getUrl(final String query, final List<String> contentFilter,
3332
final String sortFilter) throws ParsingException {
3433
try {
3534
return "https://media.ccc.de/public/events/search?q="
36-
+ URLEncoder.encode(query, UTF_8);
35+
+ URLEncoder.encode(query, StandardCharsets.UTF_8.name());
3736
} catch (final UnsupportedEncodingException e) {
3837
throw new ParsingException("Could not create search string with query: " + query, e);
3938
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.schabi.newpipe.extractor.services.peertube.extractors;
22

33
import static org.schabi.newpipe.extractor.stream.AudioStream.UNKNOWN_BITRATE;
4-
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
54
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
65

76
import com.grack.nanojson.JsonArray;
@@ -37,6 +36,7 @@
3736
import java.io.IOException;
3837
import java.io.UnsupportedEncodingException;
3938
import java.net.URLEncoder;
39+
import java.nio.charset.StandardCharsets;
4040
import java.util.ArrayList;
4141
import java.util.Collections;
4242
import java.util.List;
@@ -328,7 +328,7 @@ private String getRelatedItemsUrl(@Nonnull final List<String> tags)
328328
params.append("start=0&count=8&sort=-createdAt");
329329
for (final String tag : tags) {
330330
params.append("&tagsOneOf=");
331-
params.append(URLEncoder.encode(tag, UTF_8));
331+
params.append(URLEncoder.encode(tag, StandardCharsets.UTF_8.name()));
332332
}
333333
return url + "?" + params;
334334
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeSearchQueryHandlerFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66

77
import java.io.UnsupportedEncodingException;
88
import java.net.URLEncoder;
9+
import java.nio.charset.StandardCharsets;
910
import java.util.List;
1011

11-
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
12-
1312
public final class PeertubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
1413

1514
public static final String VIDEOS = "videos";
@@ -43,7 +42,8 @@ public String getUrl(final String searchString,
4342
final String sortFilter,
4443
final String baseUrl) throws ParsingException {
4544
try {
46-
return baseUrl + SEARCH_ENDPOINT + "?search=" + URLEncoder.encode(searchString, UTF_8);
45+
return baseUrl + SEARCH_ENDPOINT + "?search=" + URLEncoder.encode(searchString,
46+
StandardCharsets.UTF_8.name());
4747
} catch (final UnsupportedEncodingException e) {
4848
throw new ParsingException("Could not encode query", e);
4949
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.schabi.newpipe.extractor.services.soundcloud;
22

33
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
4-
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
54
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
65
import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps;
76

@@ -33,6 +32,7 @@
3332
import java.net.MalformedURLException;
3433
import java.net.URL;
3534
import java.net.URLEncoder;
35+
import java.nio.charset.StandardCharsets;
3636
import java.time.OffsetDateTime;
3737
import java.time.format.DateTimeFormatter;
3838
import java.time.format.DateTimeParseException;
@@ -109,7 +109,7 @@ public static OffsetDateTime parseDateFrom(final String textualUploadDate)
109109
public static JsonObject resolveFor(@Nonnull final Downloader downloader, final String url)
110110
throws IOException, ExtractionException {
111111
final String apiUrl = SOUNDCLOUD_API_V2_URL + "resolve"
112-
+ "?url=" + URLEncoder.encode(url, UTF_8)
112+
+ "?url=" + URLEncoder.encode(url, StandardCharsets.UTF_8.name())
113113
+ "&client_id=" + clientId();
114114

115115
try {
@@ -131,7 +131,8 @@ public static String resolveUrlWithEmbedPlayer(final String apiUrl) throws IOExc
131131
ReCaptchaException {
132132

133133
final String response = NewPipe.getDownloader().get("https://w.soundcloud.com/player/?url="
134-
+ URLEncoder.encode(apiUrl, UTF_8), SoundCloud.getLocalization()).responseBody();
134+
+ URLEncoder.encode(apiUrl, StandardCharsets.UTF_8.name()),
135+
SoundCloud.getLocalization()).responseBody();
135136

136137
return Jsoup.parse(response).select("link[rel=\"canonical\"]").first()
137138
.attr("abs:href");
@@ -162,7 +163,7 @@ public static String resolveIdWithWidgetApi(final String urlString) throws IOExc
162163

163164
try {
164165
final String widgetUrl = "https://api-widget.soundcloud.com/resolve?url="
165-
+ URLEncoder.encode(url.toString(), UTF_8)
166+
+ URLEncoder.encode(url.toString(), StandardCharsets.UTF_8.name())
166167
+ "&format=json&client_id=" + SoundcloudParsingHelper.clientId();
167168
final String response = NewPipe.getDownloader().get(widgetUrl,
168169
SoundCloud.getLocalization()).responseBody();

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.clientId;
55
import static org.schabi.newpipe.extractor.stream.AudioStream.UNKNOWN_BITRATE;
66
import static org.schabi.newpipe.extractor.stream.Stream.ID_UNKNOWN;
7-
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
87
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
98

109
import com.grack.nanojson.JsonArray;
@@ -36,6 +35,7 @@
3635
import java.io.IOException;
3736
import java.io.UnsupportedEncodingException;
3837
import java.net.URLEncoder;
38+
import java.nio.charset.StandardCharsets;
3939
import java.util.ArrayList;
4040
import java.util.Collections;
4141
import java.util.List;
@@ -320,7 +320,7 @@ public void extractDownloadableFileIfAvailable(final List<AudioStream> audioStre
320320

321321
private static String urlEncode(final String value) {
322322
try {
323-
return URLEncoder.encode(value, UTF_8);
323+
return URLEncoder.encode(value, StandardCharsets.UTF_8.name());
324324
} catch (final UnsupportedEncodingException e) {
325325
throw new IllegalStateException(e);
326326
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudSuggestionExtractor.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package org.schabi.newpipe.extractor.services.soundcloud.extractors;
22

3+
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
4+
35
import com.grack.nanojson.JsonArray;
46
import com.grack.nanojson.JsonObject;
57
import com.grack.nanojson.JsonParser;
68
import com.grack.nanojson.JsonParserException;
9+
710
import org.schabi.newpipe.extractor.NewPipe;
811
import org.schabi.newpipe.extractor.StreamingService;
912
import org.schabi.newpipe.extractor.downloader.Downloader;
@@ -14,12 +17,10 @@
1417

1518
import java.io.IOException;
1619
import java.net.URLEncoder;
20+
import java.nio.charset.StandardCharsets;
1721
import java.util.ArrayList;
1822
import java.util.List;
1923

20-
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
21-
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
22-
2324
public class SoundcloudSuggestionExtractor extends SuggestionExtractor {
2425

2526
public SoundcloudSuggestionExtractor(final StreamingService service) {
@@ -32,7 +33,7 @@ public List<String> suggestionList(final String query) throws IOException,
3233
final List<String> suggestions = new ArrayList<>();
3334
final Downloader dl = NewPipe.getDownloader();
3435
final String url = SOUNDCLOUD_API_V2_URL + "search/queries" + "?q="
35-
+ URLEncoder.encode(query, UTF_8) + "&client_id="
36+
+ URLEncoder.encode(query, StandardCharsets.UTF_8.name()) + "&client_id="
3637
+ SoundcloudParsingHelper.clientId() + "&limit=10";
3738
final String response = dl.get(url, getExtractorLocalization()).responseBody();
3839

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/linkHandler/SoundcloudSearchQueryHandlerFactory.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.schabi.newpipe.extractor.services.soundcloud.linkHandler;
22

3+
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
4+
35
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
46
import org.schabi.newpipe.extractor.exceptions.ParsingException;
57
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
@@ -9,11 +11,9 @@
911
import java.io.IOException;
1012
import java.io.UnsupportedEncodingException;
1113
import java.net.URLEncoder;
14+
import java.nio.charset.StandardCharsets;
1215
import java.util.List;
1316

14-
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
15-
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
16-
1717
public class SoundcloudSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
1818

1919
public static final String TRACKS = "tracks";
@@ -48,9 +48,9 @@ public String getUrl(final String id,
4848
}
4949
}
5050

51-
return url + "?q=" + URLEncoder.encode(id, UTF_8) + "&client_id="
52-
+ SoundcloudParsingHelper.clientId() + "&limit=" + ITEMS_PER_PAGE
53-
+ "&offset=0";
51+
return url + "?q=" + URLEncoder.encode(id, StandardCharsets.UTF_8.name())
52+
+ "&client_id=" + SoundcloudParsingHelper.clientId()
53+
+ "&limit=" + ITEMS_PER_PAGE + "&offset=0";
5454

5555
} catch (final UnsupportedEncodingException e) {
5656
throw new ParsingException("Could not encode query", e);

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import static org.schabi.newpipe.extractor.NewPipe.getDownloader;
2424
import static org.schabi.newpipe.extractor.utils.Utils.HTTP;
2525
import static org.schabi.newpipe.extractor.utils.Utils.HTTPS;
26-
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
2726
import static org.schabi.newpipe.extractor.utils.Utils.getStringResultFromRegexArray;
2827
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
2928
import static java.util.Collections.singletonList;
@@ -575,7 +574,7 @@ public static boolean areHardcodedClientVersionAndKeyValid()
575574
.end()
576575
.value("fetchLiveState", true)
577576
.end()
578-
.end().done().getBytes(UTF_8);
577+
.end().done().getBytes(StandardCharsets.UTF_8);
579578
// @formatter:on
580579

581580
final Map<String, List<String>> headers = new HashMap<>();
@@ -820,7 +819,7 @@ public static boolean isHardcodedYoutubeMusicKeyValid() throws IOException,
820819
.end()
821820
.end()
822821
.value("input", "")
823-
.end().done().getBytes(UTF_8);
822+
.end().done().getBytes(StandardCharsets.UTF_8);
824823
// @formatter:on
825824

826825
final Map<String, List<String>> headers = new HashMap<>();
@@ -892,7 +891,8 @@ public static String getUrlFromNavigationEndpoint(@Nonnull final JsonObject navi
892891
for (final String param : params) {
893892
if (param.split("=")[0].equals("q")) {
894893
try {
895-
return URLDecoder.decode(param.split("=")[1], UTF_8);
894+
return URLDecoder.decode(param.split("=")[1],
895+
StandardCharsets.UTF_8.name());
896896
} catch (final UnsupportedEncodingException e) {
897897
return null;
898898
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
1010
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getValidJsonResponseBody;
1111
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder;
12-
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
1312
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
1413

1514
import com.grack.nanojson.JsonArray;
@@ -35,6 +34,7 @@
3534
import org.schabi.newpipe.extractor.utils.Utils;
3635

3736
import java.io.IOException;
37+
import java.nio.charset.StandardCharsets;
3838
import java.util.ArrayList;
3939
import java.util.HashMap;
4040
import java.util.List;
@@ -98,7 +98,7 @@ public void onFetchPage(@Nonnull final Downloader downloader) throws IOException
9898
getExtractorLocalization(), getExtractorContentCountry())
9999
.value("url", "https://www.youtube.com/" + channelPath)
100100
.done())
101-
.getBytes(UTF_8);
101+
.getBytes(StandardCharsets.UTF_8);
102102

103103
final JsonObject jsonResponse = getJsonPostResponse("navigation/resolve_url",
104104
body, getExtractorLocalization());
@@ -146,7 +146,7 @@ public void onFetchPage(@Nonnull final Downloader downloader) throws IOException
146146
.value("browseId", id)
147147
.value("params", "EgZ2aWRlb3M%3D") // Equal to videos
148148
.done())
149-
.getBytes(UTF_8);
149+
.getBytes(StandardCharsets.UTF_8);
150150

151151
final JsonObject jsonResponse = getJsonPostResponse("browse", body,
152152
getExtractorLocalization());
@@ -397,7 +397,7 @@ private Page getNextPageFrom(final JsonObject continuations,
397397
getExtractorContentCountry())
398398
.value("continuation", continuation)
399399
.done())
400-
.getBytes(UTF_8);
400+
.getBytes(StandardCharsets.UTF_8);
401401

402402
return new Page(YOUTUBEI_V1_URL + "browse?key=" + getKey()
403403
+ DISABLE_PRETTY_PRINT_PARAMETER, null, channelIds, null, body);

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_PLAYLISTS;
1111
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_SONGS;
1212
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_VIDEOS;
13-
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
1413
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
1514

1615
import com.grack.nanojson.JsonArray;
@@ -38,6 +37,7 @@
3837
import org.schabi.newpipe.extractor.utils.Utils;
3938

4039
import java.io.IOException;
40+
import java.nio.charset.StandardCharsets;
4141
import java.util.Collections;
4242
import java.util.HashMap;
4343
import java.util.List;
@@ -113,7 +113,7 @@ public void onFetchPage(@Nonnull final Downloader downloader)
113113
.end()
114114
.value("query", getSearchString())
115115
.value("params", params)
116-
.end().done().getBytes(UTF_8);
116+
.end().done().getBytes(StandardCharsets.UTF_8);
117117
// @formatter:on
118118

119119
final Map<String, List<String>> headers = new HashMap<>();
@@ -248,7 +248,7 @@ public InfoItemsPage<InfoItem> getPage(final Page page)
248248
.value("enableSafetyMode", false)
249249
.end()
250250
.end()
251-
.end().done().getBytes(UTF_8);
251+
.end().done().getBytes(StandardCharsets.UTF_8);
252252
// @formatter:on
253253

254254
final Map<String, List<String>> headers = new HashMap<>();

0 commit comments

Comments
 (0)