Skip to content

Commit 9ca52ca

Browse files
committed
use only one constant UTF-8
1 parent 50e5718 commit 9ca52ca

17 files changed

Lines changed: 100 additions & 116 deletions

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.net.URLEncoder;
88
import java.util.List;
99

10+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
11+
1012
public class MediaCCCSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
1113
public static final String ALL = "all";
1214
public static final String CONFERENCES = "conferences";
@@ -31,7 +33,7 @@ public String getUrl(final String query, final List<String> contentFilter,
3133
final String sortFilter) throws ParsingException {
3234
try {
3335
return "https://media.ccc.de/public/events/search?q="
34-
+ URLEncoder.encode(query, "UTF-8");
36+
+ URLEncoder.encode(query, UTF_8);
3537
} catch (UnsupportedEncodingException e) {
3638
throw new ParsingException("Could not create search string with query: " + query, e);
3739
}

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,7 @@
1818
import org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper;
1919
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeSearchQueryHandlerFactory;
2020
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeStreamLinkHandlerFactory;
21-
import org.schabi.newpipe.extractor.stream.AudioStream;
22-
import org.schabi.newpipe.extractor.stream.Description;
23-
import org.schabi.newpipe.extractor.stream.Stream;
24-
import org.schabi.newpipe.extractor.stream.StreamExtractor;
25-
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
26-
import org.schabi.newpipe.extractor.stream.StreamSegment;
27-
import org.schabi.newpipe.extractor.stream.StreamType;
28-
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
29-
import org.schabi.newpipe.extractor.stream.VideoStream;
21+
import org.schabi.newpipe.extractor.stream.*;
3022
import org.schabi.newpipe.extractor.utils.JsonUtils;
3123
import org.schabi.newpipe.extractor.utils.Utils;
3224

@@ -40,6 +32,8 @@
4032
import java.util.List;
4133
import java.util.Locale;
4234

35+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
36+
4337
public class PeertubeStreamExtractor extends StreamExtractor {
4438
private final String baseUrl;
4539
private JsonObject json;
@@ -322,7 +316,7 @@ private String getRelatedStreamsUrl(final List<String> tags) throws UnsupportedE
322316
params.append("start=0&count=8&sort=-createdAt");
323317
for (final String tag : tags) {
324318
params.append("&tagsOneOf=");
325-
params.append(URLEncoder.encode(tag, "UTF-8"));
319+
params.append(URLEncoder.encode(tag, UTF_8));
326320
}
327321
return url + "?" + params.toString();
328322
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
import java.net.URLEncoder;
99
import java.util.List;
1010

11+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
12+
1113
public class PeertubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
1214

13-
public static final String CHARSET_UTF_8 = "UTF-8";
1415
public static final String VIDEOS = "videos";
1516
public static final String SEPIA_VIDEOS = "sepia_videos"; // sepia is the global index
1617
public static final String SEPIA_BASE_URL = "https://sepiasearch.org";
@@ -35,7 +36,7 @@ public String getUrl(String searchString, List<String> contentFilters, String so
3536
public String getUrl(String searchString, List<String> contentFilters, String sortFilter, String baseUrl) throws ParsingException {
3637
try {
3738
final String url = baseUrl + SEARCH_ENDPOINT
38-
+ "?search=" + URLEncoder.encode(searchString, CHARSET_UTF_8);
39+
+ "?search=" + URLEncoder.encode(searchString, UTF_8);
3940

4041
return url;
4142
} catch (UnsupportedEncodingException e) {

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
import static java.util.Collections.singletonList;
3939
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
4040
import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING;
41-
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
42-
import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps;
41+
import static org.schabi.newpipe.extractor.utils.Utils.*;
4342

4443
public class SoundcloudParsingHelper {
4544
private static final String HARDCODED_CLIENT_ID = "H2c34Q0E7hftqnuDHGsk88DbNqhYpgMm"; // Updated on 24/06/20
@@ -117,7 +116,7 @@ public static OffsetDateTime parseDateFrom(String textualUploadDate) throws Pars
117116
*/
118117
public static JsonObject resolveFor(Downloader downloader, String url) throws IOException, ExtractionException {
119118
String apiUrl = "https://api-v2.soundcloud.com/resolve"
120-
+ "?url=" + URLEncoder.encode(url, "UTF-8")
119+
+ "?url=" + URLEncoder.encode(url, UTF_8)
121120
+ "&client_id=" + clientId();
122121

123122
try {
@@ -136,7 +135,7 @@ public static JsonObject resolveFor(Downloader downloader, String url) throws IO
136135
public static String resolveUrlWithEmbedPlayer(String apiUrl) throws IOException, ReCaptchaException, ParsingException {
137136

138137
String response = NewPipe.getDownloader().get("https://w.soundcloud.com/player/?url="
139-
+ URLEncoder.encode(apiUrl, "UTF-8"), SoundCloud.getLocalization()).responseBody();
138+
+ URLEncoder.encode(apiUrl, UTF_8), SoundCloud.getLocalization()).responseBody();
140139

141140
return Jsoup.parse(response).select("link[rel=\"canonical\"]").first().attr("abs:href");
142141
}
@@ -158,7 +157,7 @@ public static String resolveIdWithEmbedPlayer(String urlString) throws IOExcepti
158157
}
159158

160159
String response = NewPipe.getDownloader().get("https://w.soundcloud.com/player/?url="
161-
+ URLEncoder.encode(url.toString(), "UTF-8"), SoundCloud.getLocalization()).responseBody();
160+
+ URLEncoder.encode(url.toString(), UTF_8), SoundCloud.getLocalization()).responseBody();
162161
// handle playlists / sets different and get playlist id via uir field in JSON
163162
if (url.getPath().contains("/sets/") && !url.getPath().endsWith("/sets"))
164163
return Parser.matchGroup1("\"uri\":\\s*\"https:\\/\\/api\\.soundcloud\\.com\\/playlists\\/((\\d)*?)\"", response);

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.grack.nanojson.JsonObject;
55
import com.grack.nanojson.JsonParser;
66
import com.grack.nanojson.JsonParserException;
7-
87
import org.schabi.newpipe.extractor.MediaFormat;
98
import org.schabi.newpipe.extractor.MetaInfo;
109
import org.schabi.newpipe.extractor.NewPipe;
@@ -17,15 +16,10 @@
1716
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
1817
import org.schabi.newpipe.extractor.localization.DateWrapper;
1918
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
20-
import org.schabi.newpipe.extractor.stream.AudioStream;
21-
import org.schabi.newpipe.extractor.stream.Description;
22-
import org.schabi.newpipe.extractor.stream.StreamExtractor;
23-
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
24-
import org.schabi.newpipe.extractor.stream.StreamSegment;
25-
import org.schabi.newpipe.extractor.stream.StreamType;
26-
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
27-
import org.schabi.newpipe.extractor.stream.VideoStream;
19+
import org.schabi.newpipe.extractor.stream.*;
2820

21+
import javax.annotation.Nonnull;
22+
import javax.annotation.Nullable;
2923
import java.io.IOException;
3024
import java.io.UnsupportedEncodingException;
3125
import java.net.URLEncoder;
@@ -34,10 +28,8 @@
3428
import java.util.List;
3529
import java.util.Locale;
3630

37-
import javax.annotation.Nonnull;
38-
import javax.annotation.Nullable;
39-
4031
import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING;
32+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
4133
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
4234

4335
public class SoundcloudStreamExtractor extends StreamExtractor {
@@ -73,7 +65,7 @@ public String getName() {
7365
@Override
7466
public String getTextualUploadDate() {
7567
return track.getString("created_at")
76-
.replace("T"," ")
68+
.replace("T", " ")
7769
.replace("Z", "");
7870
}
7971

@@ -232,7 +224,7 @@ public List<AudioStream> getAudioStreams() throws IOException, ExtractionExcepti
232224

233225
private static String urlEncode(String value) {
234226
try {
235-
return URLEncoder.encode(value, "UTF-8");
227+
return URLEncoder.encode(value, UTF_8);
236228
} catch (UnsupportedEncodingException e) {
237229
throw new IllegalStateException(e);
238230
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
import java.util.ArrayList;
1818
import java.util.List;
1919

20-
public class SoundcloudSuggestionExtractor extends SuggestionExtractor {
20+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
2121

22-
public static final String CHARSET_UTF_8 = "UTF-8";
22+
public class SoundcloudSuggestionExtractor extends SuggestionExtractor {
2323

2424
public SoundcloudSuggestionExtractor(StreamingService service) {
2525
super(service);
@@ -32,7 +32,7 @@ public List<String> suggestionList(String query) throws IOException, ExtractionE
3232
Downloader dl = NewPipe.getDownloader();
3333

3434
String url = "https://api-v2.soundcloud.com/search/queries"
35-
+ "?q=" + URLEncoder.encode(query, CHARSET_UTF_8)
35+
+ "?q=" + URLEncoder.encode(query, UTF_8)
3636
+ "&client_id=" + SoundcloudParsingHelper.clientId()
3737
+ "&limit=10";
3838

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
import java.net.URLEncoder;
1212
import java.util.List;
1313

14+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
15+
1416
public class SoundcloudSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
15-
public static final String CHARSET_UTF_8 = "UTF-8";
1617

1718
public static final String TRACKS = "tracks";
1819
public static final String USERS = "users";
@@ -43,7 +44,7 @@ public String getUrl(String id, List<String> contentFilter, String sortFilter) t
4344
}
4445
}
4546

46-
return url + "?q=" + URLEncoder.encode(id, CHARSET_UTF_8)
47+
return url + "?q=" + URLEncoder.encode(id, UTF_8)
4748
+ "&client_id=" + SoundcloudParsingHelper.clientId()
4849
+ "&limit=" + ITEMS_PER_PAGE
4950
+ "&offset=0";

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public static boolean isInvidioURL(final URL url) {
124124

125125
/**
126126
* Parses the duration string of the video expecting ":" or "." as separators
127+
*
127128
* @return the duration in seconds
128129
* @throws ParsingException when more than 3 separators are found
129130
*/
@@ -193,6 +194,7 @@ public static OffsetDateTime parseDateFrom(final String textualUploadDate) throw
193194
/**
194195
* Checks if the given playlist id is a YouTube Mix (auto-generated playlist)
195196
* Ids from a YouTube Mix start with "RD"
197+
*
196198
* @param playlistId
197199
* @return Whether given id belongs to a YouTube Mix
198200
*/
@@ -203,15 +205,18 @@ public static boolean isYoutubeMixId(final String playlistId) {
203205
/**
204206
* Checks if the given playlist id is a YouTube Music Mix (auto-generated playlist)
205207
* Ids from a YouTube Music Mix start with "RDAMVM" or "RDCLAK"
208+
*
206209
* @param playlistId
207210
* @return Whether given id belongs to a YouTube Music Mix
208211
*/
209212
public static boolean isYoutubeMusicMixId(final String playlistId) {
210213
return playlistId.startsWith("RDAMVM") || playlistId.startsWith("RDCLAK");
211214
}
215+
212216
/**
213217
* Checks if the given playlist id is a YouTube Channel Mix (auto-generated playlist)
214218
* Ids from a YouTube channel Mix start with "RDCM"
219+
*
215220
* @return Whether given id belongs to a YouTube Channel Mix
216221
*/
217222
public static boolean isYoutubeChannelMixId(final String playlistId) {
@@ -220,6 +225,7 @@ public static boolean isYoutubeChannelMixId(final String playlistId) {
220225

221226
/**
222227
* Extracts the video id from the playlist id for Mixes.
228+
*
223229
* @throws ParsingException If the playlistId is a Channel Mix or not a mix.
224230
*/
225231
public static String extractVideoIdFromMixId(final String playlistId) throws ParsingException {
@@ -311,7 +317,8 @@ private static void extractClientVersionAndKey() throws IOException, ExtractionE
311317
clientVersion = contextClientVersion;
312318
break;
313319
}
314-
} catch (Parser.RegexException ignored) { }
320+
} catch (Parser.RegexException ignored) {
321+
}
315322
}
316323

317324
if (!isNullOrEmpty(clientVersion) && !isNullOrEmpty(shortClientVersion)) {
@@ -323,7 +330,8 @@ private static void extractClientVersionAndKey() throws IOException, ExtractionE
323330
} catch (Parser.RegexException e) {
324331
try {
325332
key = Parser.matchGroup1("innertubeApiKey\":\"([0-9a-zA-Z_-]+?)\"", html);
326-
} catch (Parser.RegexException ignored) { }
333+
} catch (Parser.RegexException ignored) {
334+
}
327335
}
328336
}
329337

@@ -390,7 +398,7 @@ public static boolean areHardcodedYoutubeMusicKeysValid() throws IOException, Re
390398
.end()
391399
.value("query", "test")
392400
.value("params", "Eg-KAQwIARAAGAAgACgAMABqChAEEAUQAxAKEAk%3D")
393-
.end().done().getBytes("UTF-8");
401+
.end().done().getBytes(UTF_8);
394402
// @formatter:on
395403

396404
final Map<String, List<String>> headers = new HashMap<>();
@@ -454,7 +462,7 @@ public static String getUrlFromNavigationEndpoint(JsonObject navigationEndpoint)
454462
if (param.split("=")[0].equals("q")) {
455463
String url;
456464
try {
457-
url = URLDecoder.decode(param.split("=")[1], "UTF-8");
465+
url = URLDecoder.decode(param.split("=")[1], UTF_8);
458466
} catch (UnsupportedEncodingException e) {
459467
return null;
460468
}
@@ -502,6 +510,7 @@ public static String getUrlFromNavigationEndpoint(JsonObject navigationEndpoint)
502510

503511
/**
504512
* Get the text from a JSON object that has either a simpleText or a runs array.
513+
*
505514
* @param textObject JSON object to get the text from
506515
* @param html whether to return HTML, by parsing the navigationEndpoint
507516
* @return text in the JSON object or {@code null}
@@ -729,7 +738,7 @@ private static MetaInfo getClarificationRendererContent(final JsonObject clarifi
729738

730739
final String title = YoutubeParsingHelper.getTextFromObject(clarificationRenderer.getObject("contentTitle"));
731740
final String text = YoutubeParsingHelper.getTextFromObject(clarificationRenderer.getObject("text"));
732-
if (title == null || text == null) {
741+
if (title == null || text == null) {
733742
throw new ParsingException("Could not extract clarification renderer content");
734743
}
735744
metaInfo.setTitle(title);
@@ -773,6 +782,7 @@ private static MetaInfo getClarificationRendererContent(final JsonObject clarifi
773782
/**
774783
* Sometimes, YouTube provides URLs which use Google's cache. They look like
775784
* {@code https://webcache.googleusercontent.com/search?q=cache:CACHED_URL}
785+
*
776786
* @param url the URL which might refer to the Google's webcache
777787
* @return the URL which is referring to the original site
778788
*/

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.grack.nanojson.JsonArray;
44
import com.grack.nanojson.JsonObject;
55
import com.grack.nanojson.JsonParser;
6-
76
import org.schabi.newpipe.extractor.Page;
87
import org.schabi.newpipe.extractor.StreamingService;
98
import org.schabi.newpipe.extractor.comments.CommentsExtractor;
@@ -19,6 +18,7 @@
1918
import org.schabi.newpipe.extractor.utils.JsonUtils;
2019
import org.schabi.newpipe.extractor.utils.Parser;
2120

21+
import javax.annotation.Nonnull;
2222
import java.io.IOException;
2323
import java.io.UnsupportedEncodingException;
2424
import java.net.URLEncoder;
@@ -27,9 +27,8 @@
2727
import java.util.Map;
2828
import java.util.regex.Pattern;
2929

30-
import javax.annotation.Nonnull;
31-
3230
import static java.util.Collections.singletonList;
31+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
3332
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
3433

3534
public class YoutubeCommentsExtractor extends CommentsExtractor {
@@ -152,9 +151,9 @@ private String getDataString(Map<String, String> params) throws UnsupportedEncod
152151
first = false;
153152
else
154153
result.append("&");
155-
result.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
154+
result.append(URLEncoder.encode(entry.getKey(), UTF_8));
156155
result.append("=");
157-
result.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
156+
result.append(URLEncoder.encode(entry.getValue(), UTF_8));
158157
}
159158
return result.toString();
160159
}

0 commit comments

Comments
 (0)