Skip to content

Commit d3b4289

Browse files
committed
Make it really old Android compatible - again
Base64 is not available on such Androids too
1 parent 39cb3f7 commit d3b4289

File tree

8 files changed

+29
-20
lines changed

8 files changed

+29
-20
lines changed

checkstyle/checkstyle.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@
100100
<module name="AvoidStarImport"/>
101101
<module name="IllegalImport"> <!-- defaults to sun.* packages -->
102102
<property name="illegalClasses" value="
103+
java.nio.charset.StandardCharsets,
104+
java.util.Base64,
103105
org.jetbrains.annotations.Nullable,
104106
org.jetbrains.annotations.NotNull,
105107
androidx.annotation.Nullable,

extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampCommentsExtractor.java

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

33
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.BASE_API_URL;
4+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
45

56
import com.grack.nanojson.JsonArray;
67
import com.grack.nanojson.JsonObject;
@@ -21,7 +22,6 @@
2122
import org.schabi.newpipe.extractor.utils.JsonUtils;
2223

2324
import java.io.IOException;
24-
import java.nio.charset.StandardCharsets;
2525
import java.util.Collections;
2626
import java.util.List;
2727

@@ -107,7 +107,7 @@ private JsonObject fetchReviewsData(final String trackId, final String token)
107107
.value("token", token)
108108
.value("count", 7)
109109
.array("exclude_fan_ids").end()
110-
.end().done().getBytes(StandardCharsets.UTF_8)).responseBody());
110+
.end().done().getBytes(UTF_8)).responseBody());
111111
} catch (final IOException | ReCaptchaException e) {
112112
throw new ParsingException("Could not fetch reviews", e);
113113
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampExtractorHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.schabi.newpipe.extractor.utils.Utils;
2020

2121
import java.io.IOException;
22-
import java.nio.charset.StandardCharsets;
2322
import java.time.DateTimeException;
2423
import java.time.ZonedDateTime;
2524
import java.time.format.DateTimeFormatter;
@@ -31,6 +30,7 @@
3130
import javax.annotation.Nonnull;
3231
import javax.annotation.Nullable;
3332

33+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
3434
import static org.schabi.newpipe.extractor.Image.HEIGHT_UNKNOWN;
3535
import static org.schabi.newpipe.extractor.Image.WIDTH_UNKNOWN;
3636
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
@@ -125,7 +125,7 @@ public static JsonObject getArtistDetails(final String id) throws ParsingExcepti
125125
.value("band_id", id)
126126
.end()
127127
.done()
128-
.getBytes(StandardCharsets.UTF_8)).responseBody());
128+
.getBytes(UTF_8)).responseBody());
129129
} catch (final IOException | ReCaptchaException | JsonParserException e) {
130130
throw new ParsingException("Could not download band details", e);
131131
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampFeaturedExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
import javax.annotation.Nonnull;
2020
import java.io.IOException;
21-
import java.nio.charset.StandardCharsets;
2221
import java.util.Collections;
2322

23+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
2424
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.BASE_API_URL;
2525

2626
public class BandcampFeaturedExtractor extends KioskExtractor<PlaylistInfoItem> {
@@ -45,7 +45,7 @@ public void onFetchPage(@Nonnull final Downloader downloader)
4545
json = JsonParser.object().from(getDownloader().postWithContentTypeJson(
4646
FEATURED_API_URL,
4747
Collections.emptyMap(),
48-
"{\"platform\":\"\",\"version\":0}".getBytes(StandardCharsets.UTF_8))
48+
"{\"platform\":\"\",\"version\":0}".getBytes(UTF_8))
4949
.responseBody());
5050
} catch (final JsonParserException e) {
5151
throw new ParsingException("Could not parse Bandcamp featured API response", e);

extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampSuggestionExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package org.schabi.newpipe.extractor.services.bandcamp.extractors;
44

55
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.BASE_API_URL;
6+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
67

78
import com.grack.nanojson.JsonObject;
89
import com.grack.nanojson.JsonParser;
@@ -16,7 +17,6 @@
1617
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
1718

1819
import java.io.IOException;
19-
import java.nio.charset.StandardCharsets;
2020
import java.util.Collections;
2121
import java.util.List;
2222
import java.util.stream.Collectors;
@@ -46,7 +46,7 @@ public List<String> suggestionList(final String query) throws IOException, Extra
4646
.value("search_text", query)
4747
.end()
4848
.done()
49-
.getBytes(StandardCharsets.UTF_8)).responseBody());
49+
.getBytes(UTF_8)).responseBody());
5050

5151
return fuzzyResults.getObject("auto").getArray("results").stream()
5252
.filter(JsonObject.class::isInstance)

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
import org.schabi.newpipe.extractor.utils.Utils;
1919

2020
import java.io.IOException;
21-
import java.nio.charset.StandardCharsets;
21+
import java.io.UnsupportedEncodingException;
2222

2323
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.COUNT_KEY;
2424
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.ITEMS_PER_PAGE;
2525
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.START_KEY;
2626
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
27+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
2728

2829
import javax.annotation.Nonnull;
2930

@@ -130,11 +131,11 @@ public InfoItemsPage<CommentsInfoItem> getPage(final Page page)
130131
}
131132
} else {
132133
try {
133-
json = JsonParser.object().from(new String(page.getBody(), StandardCharsets.UTF_8));
134+
json = JsonParser.object().from(new String(page.getBody(), UTF_8));
134135
isReply = true;
135136
total = json.getArray(CHILDREN).size();
136137
collectRepliesFrom(collector, json);
137-
} catch (final JsonParserException e) {
138+
} catch (final JsonParserException | UnsupportedEncodingException e) {
138139
throw new ParsingException(
139140
"Could not parse json data for nested comments info", e);
140141
}

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

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

1818
import javax.annotation.Nonnull;
1919
import javax.annotation.Nullable;
20-
import java.nio.charset.StandardCharsets;
20+
import java.io.UnsupportedEncodingException;
2121
import java.util.List;
2222
import java.util.Objects;
2323

2424
import static org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeCommentsExtractor.CHILDREN;
2525
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.getAvatarsFromOwnerAccountOrVideoChannelObject;
2626
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.parseDateFrom;
27+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
2728

2829
public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtractor {
2930
@Nonnull
@@ -130,8 +131,13 @@ public Page getReplies() throws ParsingException {
130131
// is also structured like a JsonObject.
131132
final JsonObject pageContent = new JsonObject();
132133
pageContent.put(CHILDREN, children);
133-
return new Page(repliesUrl, threadId,
134-
JsonWriter.string(pageContent).getBytes(StandardCharsets.UTF_8));
134+
try {
135+
return new Page(repliesUrl, threadId,
136+
JsonWriter.string(pageContent).getBytes(UTF_8));
137+
} catch (final UnsupportedEncodingException e) {
138+
throw new ParsingException(
139+
"Could not parse data", e);
140+
}
135141
}
136142
return new Page(repliesUrl, threadId);
137143
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import javax.annotation.Nonnull;
1212
import javax.annotation.Nullable;
1313
import java.io.IOException;
14-
import java.nio.charset.StandardCharsets;
1514
import java.util.HashMap;
1615
import java.util.List;
1716
import java.util.Map;
@@ -35,6 +34,7 @@
3534
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getValidJsonResponseBody;
3635
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getYouTubeHeaders;
3736
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareJsonBuilder;
37+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
3838

3939
public final class YoutubeStreamHelper {
4040

@@ -69,7 +69,7 @@ public static JsonObject getWebMetadataPlayerResponse(
6969
addVideoIdCpnAndOkChecks(builder, videoId, null);
7070

7171
final byte[] body = JsonWriter.string(builder.done())
72-
.getBytes(StandardCharsets.UTF_8);
72+
.getBytes(UTF_8);
7373

7474
final String url = YOUTUBEI_V1_URL + PLAYER + "?" + DISABLE_PRETTY_PRINT_PARAMETER
7575
+ "&$fields=microformat,playabilityStatus,storyboards,videoDetails";
@@ -115,7 +115,7 @@ public static JsonObject getWebEmbeddedPlayerResponse(
115115
}
116116

117117
final byte[] body = JsonWriter.string(builder.done())
118-
.getBytes(StandardCharsets.UTF_8);
118+
.getBytes(UTF_8);
119119
final String url = YOUTUBEI_V1_URL + PLAYER + "?" + DISABLE_PRETTY_PRINT_PARAMETER;
120120

121121
return JsonUtils.toJsonObject(getValidJsonResponseBody(
@@ -144,7 +144,7 @@ public static JsonObject getAndroidPlayerResponse(
144144
addPoToken(builder, androidPoTokenResult.playerRequestPoToken);
145145

146146
final byte[] body = JsonWriter.string(builder.done())
147-
.getBytes(StandardCharsets.UTF_8);
147+
.getBytes(UTF_8);
148148

149149
final String url = YOUTUBEI_V1_GAPIS_URL + PLAYER + "?" + DISABLE_PRETTY_PRINT_PARAMETER
150150
+ "&t=" + generateTParameter() + "&id=" + videoId;
@@ -179,7 +179,7 @@ public static JsonObject getAndroidReelPlayerResponse(
179179
.value("disablePlayerResponse", false);
180180

181181
final byte[] body = JsonWriter.string(builder.done())
182-
.getBytes(StandardCharsets.UTF_8);
182+
.getBytes(UTF_8);
183183

184184
final String url = YOUTUBEI_V1_GAPIS_URL + "reel/reel_item_watch" + "?"
185185
+ DISABLE_PRETTY_PRINT_PARAMETER + "&t=" + generateTParameter() + "&id=" + videoId
@@ -219,7 +219,7 @@ public static JsonObject getIosPlayerResponse(@Nonnull final ContentCountry cont
219219
}
220220

221221
final byte[] body = JsonWriter.string(builder.done())
222-
.getBytes(StandardCharsets.UTF_8);
222+
.getBytes(UTF_8);
223223

224224
final String url = YOUTUBEI_V1_GAPIS_URL + PLAYER + "?" + DISABLE_PRETTY_PRINT_PARAMETER
225225
+ "&t=" + generateTParameter() + "&id=" + videoId;

0 commit comments

Comments
 (0)