Skip to content

Commit b1ecb68

Browse files
authored
Merge pull request #1277 from litetex/fix-tests
Fix tests and cleanup other stuff
2 parents e506ad3 + e408124 commit b1ecb68

278 files changed

Lines changed: 60503 additions & 17237 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

extractor/build.gradle

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ dependencies {
2929
implementation 'org.jsoup:jsoup:1.17.2'
3030
implementation "com.google.code.findbugs:jsr305:$jsr305Version"
3131

32-
// do not upgrade to 1.7.14, since in 1.7.14 Rhino uses the `SourceVersion` class, which is not
33-
// available on Android (even when using desugaring), and `NoClassDefFoundError` is thrown
3432
implementation 'org.mozilla:rhino:1.7.15'
3533

3634
checkstyle "com.puppycrawl.tools:checkstyle:$checkstyleVersion"
@@ -40,6 +38,6 @@ dependencies {
4038
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
4139
testImplementation 'org.junit.jupiter:junit-jupiter-params'
4240

43-
testImplementation "com.squareup.okhttp3:okhttp:3.12.13"
44-
testImplementation 'com.google.code.gson:gson:2.11.0'
41+
testImplementation "com.squareup.okhttp3:okhttp:4.12.0"
42+
testImplementation 'com.google.code.gson:gson:2.12.1'
4543
}

extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
1414
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
1515

16-
import javax.annotation.Nonnull;
1716
import java.io.IOException;
1817
import java.util.ArrayList;
1918
import java.util.List;
2019

20+
import javax.annotation.Nonnull;
21+
2122
public final class PlaylistInfo extends ListInfo<StreamInfoItem> {
2223

2324
/**
@@ -45,7 +46,11 @@ public enum PlaylistType {
4546
/**
4647
* A mix made only of streams from (or related to) the same channel, for example YouTube
4748
* channel mixes
49+
*
50+
* @deprecated There is currently no service that implements this.
51+
* YouTube removed all playlists with this type around 2024-06
4852
*/
53+
@Deprecated
4954
MIX_CHANNEL,
5055

5156
/**

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public List<MetaInfo> getMetaInfo() throws ParsingException {
4848
return Collections.emptyList();
4949
}
5050

51+
@Override
5152
public InfoItemsPage<InfoItem> getPage(final Page page)
5253
throws IOException, ExtractionException {
5354
final MultiInfoItemsCollector collector = new MultiInfoItemsCollector(getServiceId());
@@ -97,16 +98,12 @@ public InfoItemsPage<InfoItem> getPage(final Page page)
9798
}
9899
}
99100

100-
// Search results appear to be capped at six pages
101-
assert pages.size() < 10;
102-
103101
String nextUrl = null;
104102
if (currentPage < pages.size()) {
105103
nextUrl = page.getUrl().substring(0, page.getUrl().length() - 1) + (currentPage + 1);
106104
}
107105

108106
return new InfoItemsPage<>(collector, new Page(nextUrl));
109-
110107
}
111108

112109
@Nonnull

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,24 @@
77
import com.grack.nanojson.JsonObject;
88
import com.grack.nanojson.JsonParser;
99
import com.grack.nanojson.JsonParserException;
10+
import com.grack.nanojson.JsonWriter;
1011

1112
import org.schabi.newpipe.extractor.NewPipe;
1213
import org.schabi.newpipe.extractor.StreamingService;
1314
import org.schabi.newpipe.extractor.downloader.Downloader;
1415
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
1516
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
16-
import org.schabi.newpipe.extractor.utils.Utils;
1717

1818
import java.io.IOException;
19+
import java.nio.charset.StandardCharsets;
1920
import java.util.Collections;
2021
import java.util.List;
2122
import java.util.stream.Collectors;
2223

2324
public class BandcampSuggestionExtractor extends SuggestionExtractor {
2425

25-
private static final String AUTOCOMPLETE_URL = BASE_API_URL + "/fuzzysearch/1/autocomplete?q=";
26+
private static final String AUTOCOMPLETE_URL = BASE_API_URL
27+
+ "/bcsearch_public_api/1/autocomplete_elastic";
2628
public BandcampSuggestionExtractor(final StreamingService service) {
2729
super(service);
2830
}
@@ -33,7 +35,18 @@ public List<String> suggestionList(final String query) throws IOException, Extra
3335

3436
try {
3537
final JsonObject fuzzyResults = JsonParser.object().from(downloader
36-
.get(AUTOCOMPLETE_URL + Utils.encodeUrlUtf8(query)).responseBody());
38+
.postWithContentTypeJson(
39+
AUTOCOMPLETE_URL,
40+
Collections.emptyMap(),
41+
JsonWriter.string()
42+
.object()
43+
.value("fan_id", (String) null)
44+
.value("full_page", false)
45+
.value("search_filter", "")
46+
.value("search_text", query)
47+
.end()
48+
.done()
49+
.getBytes(StandardCharsets.UTF_8)).responseBody());
3750

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

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

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
import org.schabi.newpipe.extractor.stream.AudioTrackType;
6161
import org.schabi.newpipe.extractor.utils.JsonUtils;
6262
import org.schabi.newpipe.extractor.utils.Parser;
63-
import org.schabi.newpipe.extractor.utils.ProtoBuilder;
6463
import org.schabi.newpipe.extractor.utils.RandomStringFromAlphabetGenerator;
6564
import org.schabi.newpipe.extractor.utils.Utils;
6665

@@ -235,23 +234,6 @@ public static boolean isY2ubeURL(@Nonnull final URL url) {
235234
return url.getHost().equalsIgnoreCase("y2u.be");
236235
}
237236

238-
public static String randomVisitorData(final ContentCountry country) {
239-
final ProtoBuilder pbE2 = new ProtoBuilder();
240-
pbE2.string(2, "");
241-
pbE2.varint(4, numberGenerator.nextInt(255) + 1);
242-
243-
final ProtoBuilder pbE = new ProtoBuilder();
244-
pbE.string(1, country.getCountryCode());
245-
pbE.bytes(2, pbE2.toBytes());
246-
247-
final ProtoBuilder pb = new ProtoBuilder();
248-
pb.string(1, RandomStringFromAlphabetGenerator.generate(
249-
CONTENT_PLAYBACK_NONCE_ALPHABET, 11, numberGenerator));
250-
pb.varint(5, System.currentTimeMillis() / 1000 - numberGenerator.nextInt(600000));
251-
pb.bytes(6, pbE.toBytes());
252-
return pb.toUrlencodedBase64();
253-
}
254-
255237
/**
256238
* Parses the duration string of the video expecting ":" or "." as separators
257239
*
@@ -359,16 +341,6 @@ public static boolean isYoutubeMusicMixId(@Nonnull final String playlistId) {
359341
return playlistId.startsWith("RDAMVM") || playlistId.startsWith("RDCLAK");
360342
}
361343

362-
/**
363-
* Checks if the given playlist id is a YouTube Channel Mix (auto-generated playlist)
364-
* Ids from a YouTube channel Mix start with "RDCM"
365-
*
366-
* @return Whether given id belongs to a YouTube Channel Mix
367-
*/
368-
public static boolean isYoutubeChannelMixId(@Nonnull final String playlistId) {
369-
return playlistId.startsWith("RDCM");
370-
}
371-
372344
/**
373345
* Checks if the given playlist id is a YouTube Genre Mix (auto-generated playlist)
374346
* Ids from a YouTube Genre Mix start with "RDGMEM"
@@ -399,11 +371,6 @@ public static String extractVideoIdFromMixId(final String playlistId)
399371
} else if (isYoutubeMusicMixId(playlistId)) {
400372
return playlistId.substring(6);
401373

402-
} else if (isYoutubeChannelMixId(playlistId)) {
403-
// Channel mixes are of the form RMCM{channelId}, so videoId can't be determined
404-
throw new ParsingException("Video id could not be determined from channel mix id: "
405-
+ playlistId);
406-
407374
} else if (isYoutubeGenreMixId(playlistId)) {
408375
// Genre mixes are of the form RDGMEM{garbage}, so videoId can't be determined
409376
throw new ParsingException("Video id could not be determined from genre mix id: "
@@ -438,8 +405,6 @@ public static PlaylistInfo.PlaylistType extractPlaylistTypeFromPlaylistId(
438405
throw new ParsingException("Could not extract playlist type from empty playlist id");
439406
} else if (isYoutubeMusicMixId(playlistId)) {
440407
return PlaylistInfo.PlaylistType.MIX_MUSIC;
441-
} else if (isYoutubeChannelMixId(playlistId)) {
442-
return PlaylistInfo.PlaylistType.MIX_CHANNEL;
443408
} else if (isYoutubeGenreMixId(playlistId)) {
444409
return PlaylistInfo.PlaylistType.MIX_GENRE;
445410
} else if (isYoutubeMixId(playlistId)) { // normal mix

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

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

3+
import com.grack.nanojson.JsonArray;
34
import com.grack.nanojson.JsonObject;
45
import org.schabi.newpipe.extractor.Image;
56
import org.schabi.newpipe.extractor.channel.ChannelInfoItemExtractor;
@@ -61,10 +62,16 @@ public String getUrl() throws ParsingException {
6162

6263
@Override
6364
public long getSubscriberCount() throws ParsingException {
64-
final String subscriberCount = getTextFromObject(artistInfoItem.getArray("flexColumns")
65-
.getObject(2)
65+
final JsonArray flexColumns = artistInfoItem.getArray("flexColumns");
66+
final JsonArray runs = flexColumns
67+
.getObject(flexColumns.size() - 1)
6668
.getObject("musicResponsiveListItemFlexColumnRenderer")
67-
.getObject("text"));
69+
.getObject("text")
70+
.getArray("runs");
71+
// NOTE: YoutubeParsingHelper#getTextFromObject would use all entries from the run array,
72+
// which is not wanted as only the last entry contains the actual subscriberCount
73+
final String subscriberCount = runs.getObject(runs.size() - 1)
74+
.getString("text");
6875
if (!isNullOrEmpty(subscriberCount)) {
6976
try {
7077
return Utils.mixedNumberWordToLong(subscriberCount);

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubePlaylistLinkHandlerFactory.java

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

3-
import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException;
43
import org.schabi.newpipe.extractor.exceptions.ParsingException;
54
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
65
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
@@ -57,14 +56,6 @@ public String getId(final String url) throws ParsingException, UnsupportedOperat
5756
"the list-ID given in the URL does not match the list pattern");
5857
}
5958

60-
if (YoutubeParsingHelper.isYoutubeChannelMixId(listID)
61-
&& Utils.getQueryValue(urlObj, "v") == null) {
62-
// Video id can't be determined from the channel mix id.
63-
// See YoutubeParsingHelper#extractVideoIdFromMixId
64-
throw new ContentNotSupportedException(
65-
"Channel Mix without a video id are not supported");
66-
}
67-
6859
return listID;
6960
} catch (final Exception exception) {
7061
throw new ParsingException("Error could not parse URL: " + exception.getMessage(),

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeStreamLinkHandlerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public String getId(final String theUrlString)
114114
try {
115115
url = Utils.stringToURL(urlString);
116116
} catch (final MalformedURLException e) {
117-
throw new IllegalArgumentException("The given URL is not valid");
117+
throw new ParsingException("The given URL is not valid", e);
118118
}
119119

120120
final String host = url.getHost();

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

Lines changed: 0 additions & 73 deletions
This file was deleted.

extractor/src/test/java/org/schabi/newpipe/downloader/DownloaderFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static DownloaderType getDownloaderType() {
3636
* @param path The path to the folder where mocks are saved/retrieved.
3737
* Preferably starting with {@link DownloaderFactory#RESOURCE_PATH}
3838
*/
39-
public static Downloader getDownloader(final String path) throws IOException {
39+
public static Downloader getDownloader(final String path) {
4040
final DownloaderType type = getDownloaderType();
4141
switch (type) {
4242
case REAL:

0 commit comments

Comments
 (0)