Skip to content

Commit 0c8d773

Browse files
committed
Make it really old Android compatible
1 parent eac850c commit 0c8d773

12 files changed

+37
-36
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
import javax.annotation.Nonnull;
1111
import java.io.IOException;
12-
import java.nio.charset.StandardCharsets;
1312
import java.util.Optional;
1413

1514
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.defaultAlertsCheck;
1615
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonPostResponse;
1716
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder;
1817
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
18+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
1919

2020
/**
2121
* Shared functions for extracting YouTube channel pages and tabs.
@@ -51,7 +51,7 @@ public static String resolveChannelId(@Nonnull final String idOrPath)
5151
prepareDesktopJsonBuilder(Localization.DEFAULT, ContentCountry.DEFAULT)
5252
.value("url", "https://www.youtube.com/" + idOrPath)
5353
.done())
54-
.getBytes(StandardCharsets.UTF_8);
54+
.getBytes(UTF_8);
5555

5656
final JsonObject jsonResponse = getJsonPostResponse(
5757
"navigation/resolve_url", body, Localization.DEFAULT);
@@ -143,7 +143,7 @@ public static ChannelResponseData getChannelResponse(@Nonnull final String chann
143143
.value("browseId", id)
144144
.value("params", parameters)
145145
.done())
146-
.getBytes(StandardCharsets.UTF_8);
146+
.getBytes(UTF_8);
147147

148148
final JsonObject jsonResponse = getJsonPostResponse(
149149
"browse", body, localization);

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;
@@ -57,7 +58,6 @@
5758
import java.io.UnsupportedEncodingException;
5859
import java.net.MalformedURLException;
5960
import java.net.URL;
60-
import java.nio.charset.StandardCharsets;
6161
import java.time.LocalDate;
6262
import java.time.OffsetDateTime;
6363
import java.time.ZoneOffset;
@@ -557,7 +557,7 @@ public static boolean areHardcodedClientVersionAndKeyValid()
557557
.end()
558558
.value("fetchLiveState", true)
559559
.end()
560-
.end().done().getBytes(StandardCharsets.UTF_8);
560+
.end().done().getBytes(UTF_8);
561561
// @formatter:on
562562

563563
final var headers = getClientHeaders("1", HARDCODED_CLIENT_VERSION);
@@ -798,7 +798,7 @@ public static boolean isHardcodedYoutubeMusicKeyValid() throws IOException,
798798
.end()
799799
.end()
800800
.value("input", "")
801-
.end().done().getBytes(StandardCharsets.UTF_8);
801+
.end().done().getBytes(UTF_8);
802802
// @formatter:on
803803

804804
final var headers = new HashMap<>(getOriginReferrerHeaders(YOUTUBE_MUSIC_URL));
@@ -1439,7 +1439,7 @@ public static byte[] createDesktopPlayerBody(
14391439
.value(CONTENT_CHECK_OK, true)
14401440
.value(RACY_CHECK_OK, true)
14411441
.done())
1442-
.getBytes(StandardCharsets.UTF_8);
1442+
.getBytes(UTF_8);
14431443
// @formatter:on
14441444
}
14451445

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;
@@ -25,7 +26,6 @@
2526

2627
import java.io.IOException;
2728
import java.io.StringWriter;
28-
import java.nio.charset.StandardCharsets;
2929
import java.util.List;
3030
import java.util.Locale;
3131
import java.util.Map;
@@ -623,7 +623,7 @@ public static Response getInitializationResponse(@Nonnull String baseStreamingUr
623623
final var headers = Map.of("User-Agent",
624624
List.of(isAndroidStreamingUrl ? getAndroidUserAgent(null)
625625
: getIosUserAgent(null)));
626-
final byte[] emptyBody = "".getBytes(StandardCharsets.UTF_8);
626+
final byte[] emptyBody = "".getBytes(UTF_8);
627627
return downloader.post(baseStreamingUrl, headers, emptyBody);
628628
} catch (final IOException | ExtractionException e) {
629629
throw new CreationException("Could not get the "

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import javax.annotation.Nonnull;
2121
import javax.annotation.Nullable;
2222
import java.io.IOException;
23-
import java.nio.charset.StandardCharsets;
2423
import java.util.List;
2524
import java.util.Optional;
2625

@@ -33,6 +32,7 @@
3332
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
3433
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder;
3534
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
35+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
3636

3737
/**
3838
* A {@link ChannelTabExtractor} implementation for the YouTube service.
@@ -423,7 +423,7 @@ private Page getNextPageFrom(final JsonObject continuations,
423423
useVisitorData && channelIds.size() >= 3 ? channelIds.get(2) : null)
424424
.value("continuation", continuation)
425425
.done())
426-
.getBytes(StandardCharsets.UTF_8);
426+
.getBytes(UTF_8);
427427

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

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 {
@@ -191,7 +192,7 @@ public InfoItemsPage<CommentsInfoItem> getPage(final Page page)
191192
prepareDesktopJsonBuilder(localization, getExtractorContentCountry())
192193
.value("continuation", page.getId())
193194
.done())
194-
.getBytes(StandardCharsets.UTF_8);
195+
.getBytes(UTF_8);
195196
// @formatter:on
196197

197198
final JsonObject jsonObject = getJsonPostResponse("next", body, localization);
@@ -272,7 +273,7 @@ public void onFetchPage(@Nonnull final Downloader downloader)
272273
prepareDesktopJsonBuilder(localization, getExtractorContentCountry())
273274
.value("videoId", getId())
274275
.done())
275-
.getBytes(StandardCharsets.UTF_8);
276+
.getBytes(UTF_8);
276277
// @formatter:on
277278

278279
final String initialToken =
@@ -287,7 +288,7 @@ public void onFetchPage(@Nonnull final Downloader downloader)
287288
prepareDesktopJsonBuilder(localization, getExtractorContentCountry())
288289
.value("continuation", initialToken)
289290
.done())
290-
.getBytes(StandardCharsets.UTF_8);
291+
.getBytes(UTF_8);
291292
// @formatter:on
292293

293294
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;
@@ -41,7 +42,6 @@
4142

4243
import java.io.IOException;
4344
import java.net.URL;
44-
import java.nio.charset.StandardCharsets;
4545
import java.util.HashMap;
4646
import java.util.List;
4747
import java.util.Map;
@@ -97,7 +97,7 @@ public void onFetchPage(@Nonnull final Downloader downloader)
9797
jsonBody.value("playlistIndex", Integer.parseInt(playlistIndexString));
9898
}
9999

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

102102
// Cookie is required due to consent
103103
final var headers = getYouTubeHeaders();
@@ -223,7 +223,7 @@ private Page getNextPageFrom(@Nonnull final JsonObject playlistJson,
223223
.value("playlistIndex", index)
224224
.value("params", params)
225225
.done())
226-
.getBytes(StandardCharsets.UTF_8);
226+
.getBytes(UTF_8);
227227

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

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,6 +10,7 @@
1010
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_SONGS;
1111
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_VIDEOS;
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;
@@ -32,7 +33,6 @@
3233
import org.schabi.newpipe.extractor.utils.JsonUtils;
3334

3435
import java.io.IOException;
35-
import java.nio.charset.StandardCharsets;
3636
import java.util.Collections;
3737
import java.util.List;
3838
import java.util.stream.Collectors;
@@ -107,7 +107,7 @@ public void onFetchPage(@Nonnull final Downloader downloader)
107107
.end()
108108
.value("query", getSearchString())
109109
.value("params", params)
110-
.end().done().getBytes(StandardCharsets.UTF_8);
110+
.end().done().getBytes(UTF_8);
111111
// @formatter:on
112112

113113
final String responseBody = getValidJsonResponseBody(
@@ -235,7 +235,7 @@ public InfoItemsPage<InfoItem> getPage(final Page page)
235235
.value("enableSafetyMode", false)
236236
.end()
237237
.end()
238-
.end().done().getBytes(StandardCharsets.UTF_8);
238+
.end().done().getBytes(UTF_8);
239239
// @formatter:on
240240

241241
final String responseBody = getValidJsonResponseBody(

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;
@@ -33,7 +34,6 @@
3334
import org.schabi.newpipe.extractor.utils.Utils;
3435

3536
import java.io.IOException;
36-
import java.nio.charset.StandardCharsets;
3737
import java.util.List;
3838

3939
import javax.annotation.Nonnull;
@@ -71,7 +71,7 @@ public void onFetchPage(@Nonnull final Downloader downloader) throws IOException
7171
.value("browseId", "VL" + getId())
7272
.value("params", "wgYCCAA%3D") // Show unavailable videos
7373
.done())
74-
.getBytes(StandardCharsets.UTF_8);
74+
.getBytes(UTF_8);
7575

7676
browseResponse = getJsonPostResponse("browse", body, localization);
7777
YoutubeParsingHelper.defaultAlertsCheck(browseResponse);
@@ -385,7 +385,7 @@ private Page getNextPageFrom(final JsonArray contents)
385385
getExtractorLocalization(), getExtractorContentCountry())
386386
.value("continuation", continuation)
387387
.done())
388-
.getBytes(StandardCharsets.UTF_8);
388+
.getBytes(UTF_8);
389389

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

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

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

1213
import com.grack.nanojson.JsonArray;
1314
import com.grack.nanojson.JsonBuilder;
@@ -30,7 +31,6 @@
3031
import org.schabi.newpipe.extractor.utils.JsonUtils;
3132

3233
import java.io.IOException;
33-
import java.nio.charset.StandardCharsets;
3434
import java.util.List;
3535

3636
import javax.annotation.Nonnull;
@@ -87,7 +87,7 @@ public void onFetchPage(@Nonnull final Downloader downloader) throws IOException
8787
jsonBody.value("params", params);
8888
}
8989

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

9292
initialData = getJsonPostResponse("search", body, localization);
9393
}
@@ -190,7 +190,7 @@ public InfoItemsPage<InfoItem> getPage(final Page page) throws IOException,
190190
getExtractorContentCountry())
191191
.value("continuation", page.getId())
192192
.done())
193-
.getBytes(StandardCharsets.UTF_8);
193+
.getBytes(UTF_8);
194194
// @formatter:on
195195

196196
final JsonObject ajaxJson = getJsonPostResponse("search", json, localization);

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
@@ -40,6 +40,7 @@
4040
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder;
4141
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareIosMobileJsonBuilder;
4242
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
43+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
4344

4445
import com.grack.nanojson.JsonArray;
4546
import com.grack.nanojson.JsonObject;
@@ -86,7 +87,6 @@
8687
import org.schabi.newpipe.extractor.utils.Utils;
8788

8889
import java.io.IOException;
89-
import java.nio.charset.StandardCharsets;
9090
import java.time.LocalDate;
9191
import java.time.OffsetDateTime;
9292
import java.time.format.DateTimeFormatter;
@@ -838,7 +838,7 @@ public void onFetchPage(@Nonnull final Downloader downloader)
838838
.value(CONTENT_CHECK_OK, true)
839839
.value(RACY_CHECK_OK, true)
840840
.done())
841-
.getBytes(StandardCharsets.UTF_8);
841+
.getBytes(UTF_8);
842842
nextResponse = getJsonPostResponse(NEXT, body, localization);
843843

844844
// streamType can only have LIVE_STREAM, POST_LIVE_STREAM and VIDEO_STREAM values (see
@@ -945,7 +945,7 @@ private void fetchAndroidMobileJsonPlayer(@Nonnull final ContentCountry contentC
945945
// using some parameters for Android client requests
946946
.value("params", "CgIQBg")
947947
.done())
948-
.getBytes(StandardCharsets.UTF_8);
948+
.getBytes(UTF_8);
949949

950950
final JsonObject androidPlayerResponse = getJsonAndroidPostResponse(PLAYER,
951951
mobileBody, localization, "&t=" + generateTParameter()
@@ -980,7 +980,7 @@ private void fetchIosMobileJsonPlayer(@Nonnull final ContentCountry contentCount
980980
.value(CONTENT_CHECK_OK, true)
981981
.value(RACY_CHECK_OK, true)
982982
.done())
983-
.getBytes(StandardCharsets.UTF_8);
983+
.getBytes(UTF_8);
984984

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

0 commit comments

Comments
 (0)