Skip to content

Commit 818745b

Browse files
committed
Make it really old Android compatible
1 parent e920ab3 commit 818745b

File tree

7 files changed

+24
-23
lines changed

7 files changed

+24
-23
lines changed

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
@@ -25,6 +25,7 @@
2525
import static org.schabi.newpipe.extractor.utils.Utils.HTTPS;
2626
import static org.schabi.newpipe.extractor.utils.Utils.getStringResultFromRegexArray;
2727
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
28+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
2829

2930
import com.grack.nanojson.JsonArray;
3031
import com.grack.nanojson.JsonBuilder;
@@ -53,7 +54,6 @@
5354
import java.io.UnsupportedEncodingException;
5455
import java.net.MalformedURLException;
5556
import java.net.URL;
56-
import java.nio.charset.StandardCharsets;
5757
import java.security.SecureRandom;
5858
import java.time.LocalDate;
5959
import java.time.OffsetDateTime;
@@ -553,7 +553,7 @@ public static boolean areHardcodedClientVersionAndKeyValid()
553553
.end()
554554
.value("fetchLiveState", true)
555555
.end()
556-
.end().done().getBytes(StandardCharsets.UTF_8);
556+
.end().done().getBytes(UTF_8);
557557
// @formatter:on
558558

559559
final var headers = getClientHeaders("1", HARDCODED_CLIENT_VERSION);
@@ -794,7 +794,7 @@ public static boolean isHardcodedYoutubeMusicKeyValid() throws IOException,
794794
.end()
795795
.end()
796796
.value("input", "")
797-
.end().done().getBytes(StandardCharsets.UTF_8);
797+
.end().done().getBytes(UTF_8);
798798
// @formatter:on
799799

800800
final var headers = new HashMap<>(getOriginReferrerHeaders(YOUTUBE_MUSIC_URL));
@@ -1376,7 +1376,7 @@ public static byte[] createDesktopPlayerBody(
13761376
.value(CONTENT_CHECK_OK, true)
13771377
.value(RACY_CHECK_OK, true)
13781378
.done())
1379-
.getBytes(StandardCharsets.UTF_8);
1379+
.getBytes(UTF_8);
13801380
// @formatter:on
13811381
}
13821382

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/dashmanifestcreators/YoutubeDashManifestCreatorsUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isTvHtml5SimplyEmbeddedPlayerStreamingUrl;
99
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isWebStreamingUrl;
1010
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
11+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
1112

1213
import org.schabi.newpipe.extractor.MediaFormat;
1314
import org.schabi.newpipe.extractor.NewPipe;
@@ -24,7 +25,6 @@
2425

2526
import java.io.IOException;
2627
import java.io.StringWriter;
27-
import java.nio.charset.StandardCharsets;
2828
import java.util.List;
2929
import java.util.Locale;
3030
import java.util.Map;
@@ -585,7 +585,7 @@ public static Response getInitializationResponse(@Nonnull String baseStreamingUr
585585
final var headers = Map.of("User-Agent",
586586
List.of(isAndroidStreamingUrl ? getAndroidUserAgent(null)
587587
: getIosUserAgent(null)));
588-
final byte[] emptyBody = "".getBytes(StandardCharsets.UTF_8);
588+
final byte[] emptyBody = "".getBytes(UTF_8);
589589
return downloader.post(baseStreamingUrl, headers, emptyBody);
590590
} catch (final IOException | ExtractionException e) {
591591
throw new CreationException("Could not get the "

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.grack.nanojson.JsonArray;
44
import com.grack.nanojson.JsonObject;
55
import com.grack.nanojson.JsonWriter;
6+
67
import org.schabi.newpipe.extractor.Page;
78
import org.schabi.newpipe.extractor.StreamingService;
89
import org.schabi.newpipe.extractor.comments.CommentsExtractor;
@@ -19,13 +20,13 @@
1920
import javax.annotation.Nonnull;
2021
import javax.annotation.Nullable;
2122
import java.io.IOException;
22-
import java.nio.charset.StandardCharsets;
2323
import java.util.Collections;
2424
import java.util.List;
2525

2626
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonPostResponse;
2727
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
2828
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder;
29+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
2930
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
3031

3132
public class YoutubeCommentsExtractor extends CommentsExtractor {
@@ -176,7 +177,7 @@ public InfoItemsPage<CommentsInfoItem> getPage(final Page page)
176177
prepareDesktopJsonBuilder(localization, getExtractorContentCountry())
177178
.value("continuation", page.getId())
178179
.done())
179-
.getBytes(StandardCharsets.UTF_8);
180+
.getBytes(UTF_8);
180181
// @formatter:on
181182

182183
final JsonObject jsonObject = getJsonPostResponse("next", body, localization);
@@ -257,7 +258,7 @@ public void onFetchPage(@Nonnull final Downloader downloader)
257258
prepareDesktopJsonBuilder(localization, getExtractorContentCountry())
258259
.value("videoId", getId())
259260
.done())
260-
.getBytes(StandardCharsets.UTF_8);
261+
.getBytes(UTF_8);
261262
// @formatter:on
262263

263264
final String initialToken =
@@ -272,7 +273,7 @@ public void onFetchPage(@Nonnull final Downloader downloader)
272273
prepareDesktopJsonBuilder(localization, getExtractorContentCountry())
273274
.value("continuation", initialToken)
274275
.done())
275-
.getBytes(StandardCharsets.UTF_8);
276+
.getBytes(UTF_8);
276277
// @formatter:on
277278

278279
ajaxJson = getJsonPostResponse("next", ajaxBody, localization);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import static org.schabi.newpipe.extractor.utils.Utils.getQueryValue;
1212
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
1313
import static org.schabi.newpipe.extractor.utils.Utils.stringToURL;
14+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
1415

1516
import com.grack.nanojson.JsonArray;
1617
import com.grack.nanojson.JsonBuilder;
@@ -37,7 +38,6 @@
3738

3839
import java.io.IOException;
3940
import java.net.URL;
40-
import java.nio.charset.StandardCharsets;
4141
import java.util.HashMap;
4242
import java.util.List;
4343
import java.util.Map;
@@ -86,7 +86,7 @@ public void onFetchPage(@Nonnull final Downloader downloader)
8686
jsonBody.value("playlistIndex", Integer.parseInt(playlistIndexString));
8787
}
8888

89-
final byte[] body = JsonWriter.string(jsonBody.done()).getBytes(StandardCharsets.UTF_8);
89+
final byte[] body = JsonWriter.string(jsonBody.done()).getBytes(UTF_8);
9090

9191
// Cookie is required due to consent
9292
final var headers = getYouTubeHeaders();
@@ -205,7 +205,7 @@ private Page getNextPageFrom(@Nonnull final JsonObject playlistJson,
205205
.value("playlistIndex", index)
206206
.value("params", params)
207207
.done())
208-
.getBytes(StandardCharsets.UTF_8);
208+
.getBytes(UTF_8);
209209

210210
return new Page(YOUTUBEI_V1_URL + "next?key=" + getKey(), null, null, cookies, body);
211211
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getUrlFromNavigationEndpoint;
1111
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder;
1212
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
13+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
1314

1415
import com.grack.nanojson.JsonArray;
1516
import com.grack.nanojson.JsonObject;
@@ -31,7 +32,6 @@
3132
import org.schabi.newpipe.extractor.utils.Utils;
3233

3334
import java.io.IOException;
34-
import java.nio.charset.StandardCharsets;
3535

3636
import javax.annotation.Nonnull;
3737
import javax.annotation.Nullable;
@@ -65,7 +65,7 @@ public void onFetchPage(@Nonnull final Downloader downloader) throws IOException
6565
.value("browseId", "VL" + getId())
6666
.value("params", "wgYCCAA%3D") // Show unavailable videos
6767
.done())
68-
.getBytes(StandardCharsets.UTF_8);
68+
.getBytes(UTF_8);
6969

7070
browseResponse = getJsonPostResponse("browse", body, localization);
7171
YoutubeParsingHelper.defaultAlertsCheck(browseResponse);
@@ -375,7 +375,7 @@ private Page getNextPageFrom(final JsonArray contents)
375375
getExtractorLocalization(), getExtractorContentCountry())
376376
.value("continuation", continuation)
377377
.done())
378-
.getBytes(StandardCharsets.UTF_8);
378+
.getBytes(UTF_8);
379379

380380
return new Page(YOUTUBEI_V1_URL + "browse?key=" + getKey()
381381
+ DISABLE_PRETTY_PRINT_PARAMETER, body);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder;
4040
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareIosMobileJsonBuilder;
4141
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
42+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
4243

4344
import com.grack.nanojson.JsonArray;
4445
import com.grack.nanojson.JsonObject;
@@ -87,7 +88,6 @@
8788
import org.schabi.newpipe.extractor.utils.Utils;
8889

8990
import java.io.IOException;
90-
import java.nio.charset.StandardCharsets;
9191
import java.time.LocalDate;
9292
import java.time.OffsetDateTime;
9393
import java.time.format.DateTimeFormatter;
@@ -887,7 +887,7 @@ public void onFetchPage(@Nonnull final Downloader downloader)
887887
.value(CONTENT_CHECK_OK, true)
888888
.value(RACY_CHECK_OK, true)
889889
.done())
890-
.getBytes(StandardCharsets.UTF_8);
890+
.getBytes(UTF_8);
891891
nextResponse = getJsonPostResponse(NEXT, body, localization);
892892

893893
// streamType can only have LIVE_STREAM, POST_LIVE_STREAM and VIDEO_STREAM values (see
@@ -996,7 +996,7 @@ private void fetchAndroidMobileJsonPlayer(@Nonnull final ContentCountry contentC
996996
// 10.29.2022
997997
.value("params", "8AEB")
998998
.done())
999-
.getBytes(StandardCharsets.UTF_8);
999+
.getBytes(UTF_8);
10001000

10011001
final JsonObject androidPlayerResponse = getJsonAndroidPostResponse(PLAYER,
10021002
mobileBody, localization, "&t=" + generateTParameter()
@@ -1031,7 +1031,7 @@ private void fetchIosMobileJsonPlayer(@Nonnull final ContentCountry contentCount
10311031
.value(CONTENT_CHECK_OK, true)
10321032
.value(RACY_CHECK_OK, true)
10331033
.done())
1034-
.getBytes(StandardCharsets.UTF_8);
1034+
.getBytes(UTF_8);
10351035

10361036
final JsonObject iosPlayerResponse = getJsonIosPostResponse(PLAYER,
10371037
mobileBody, localization, "&t=" + generateTParameter()

extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.net.URL;
88
import java.net.URLDecoder;
99
import java.net.URLEncoder;
10-
import java.nio.charset.StandardCharsets;
1110
import java.util.Arrays;
1211
import java.util.Collection;
1312
import java.util.Map;
@@ -23,6 +22,7 @@ public final class Utils {
2322
public static final String HTTPS = "https://";
2423
private static final Pattern M_PATTERN = Pattern.compile("(https?)?://m\\.");
2524
private static final Pattern WWW_PATTERN = Pattern.compile("(https?)?://www\\.");
25+
public static final String UTF_8 = "UTF-8";
2626

2727
private Utils() {
2828
// no instance
@@ -37,7 +37,7 @@ private Utils() {
3737
*/
3838
public static String encodeUrlUtf8(final String string) throws UnsupportedEncodingException {
3939
// TODO: Switch to URLEncoder.encode(String, Charset) in Java 10.
40-
return URLEncoder.encode(string, StandardCharsets.UTF_8.name());
40+
return URLEncoder.encode(string, UTF_8);
4141
}
4242

4343
/**
@@ -48,7 +48,7 @@ public static String encodeUrlUtf8(final String string) throws UnsupportedEncodi
4848
*/
4949
public static String decodeUrlUtf8(final String url) throws UnsupportedEncodingException {
5050
// TODO: Switch to URLDecoder.decode(String, Charset) in Java 10.
51-
return URLDecoder.decode(url, StandardCharsets.UTF_8.name());
51+
return URLDecoder.decode(url, UTF_8);
5252
}
5353

5454
/**

0 commit comments

Comments
 (0)