Skip to content

Commit f4084ed

Browse files
Merge branch 'dev' into Refactor-date-parsing
# Conflicts: # extractor/src/main/java/org/schabi/newpipe/extractor/localization/DateWrapper.java
2 parents 8997187 + 8dfb0d3 commit f4084ed

39 files changed

Lines changed: 2326 additions & 136 deletions

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ If you're using Gradle, you could add NewPipe Extractor as a dependency with the
2020
-dontwarn org.mozilla.javascript.tools.**
2121
```
2222

23-
**Note:** To use NewPipe Extractor in Android projects with a `minSdk` below 33, [core library desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) with the `desugar_jdk_libs_nio` artifact is required.
23+
> [!NOTE]
24+
> To use NewPipe Extractor in Android projects with a `minSdk` below 33, [core library desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) with the `desugar_jdk_libs_nio` artifact is required.
2425
2526
### Testing changes
2627

@@ -41,6 +42,8 @@ Another approach would be to use the local Maven repository, here's a gist of ho
4142
3. Run gradle's `ìnstall` task to deploy this library to your local repository (using the wrapper, present in the root of this project: `./gradlew install`)
4243
4. Change the dependency version used in your project to match the one you chose in step 2 (`implementation 'com.github.teamnewpipe:NewPipeExtractor:LOCAL_SNAPSHOT'`)
4344

45+
46+
> [!TIP]
4447
> Tip for Android Studio users: After you make changes and run the `install` task, use the menu option `File → "Sync with File System"` to refresh the library in your project.
4548
4649
## Supported sites

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ allprojects {
2929
ext {
3030
nanojsonVersion = "e9d656ddb49a412a5a0a5d5ef20ca7ef09549996"
3131
jsr305Version = "3.0.2"
32-
junitVersion = "5.13.4"
33-
checkstyleVersion = "10.4"
32+
junitVersion = "5.14.0"
33+
checkstyleVersion = "10.26.1"
3434
}
3535
}
3636

extractor/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ checkstyleTest {
2828

2929
ext {
3030
rhinoVersion = '1.8.0'
31-
protobufVersion = '4.32.0'
31+
protobufVersion = '4.32.1'
3232
}
3333

3434
dependencies {
@@ -51,7 +51,7 @@ dependencies {
5151
testImplementation 'org.junit.jupiter:junit-jupiter-params'
5252

5353
testImplementation "com.squareup.okhttp3:okhttp:4.12.0"
54-
testImplementation 'com.google.code.gson:gson:2.13.1'
54+
testImplementation 'com.google.code.gson:gson:2.13.2'
5555
}
5656

5757
protobuf {

extractor/src/main/java/org/schabi/newpipe/extractor/localization/DateWrapper.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ public boolean isApproximation() {
8282
return isApproximation;
8383
}
8484

85+
@Override
86+
public String toString() {
87+
return "DateWrapper{"
88+
+ "instant=" + instant
89+
+ ", isApproximation=" + isApproximation
90+
+ '}';
91+
}
92+
8593
public static DateWrapper fromOffsetDateTime(final String date) throws ParsingException {
8694
if (date == null) {
8795
return null;

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.schabi.newpipe.extractor.stream.StreamExtractor;
2727
import org.schabi.newpipe.extractor.stream.StreamType;
2828
import org.schabi.newpipe.extractor.stream.VideoStream;
29-
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
3029
import org.schabi.newpipe.extractor.utils.JsonUtils;
3130
import org.schabi.newpipe.extractor.utils.LocaleCompat;
3231

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/infoItems/MediaCCCStreamInfoItemExtractor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.schabi.newpipe.extractor.localization.DateWrapper;
77
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
88
import org.schabi.newpipe.extractor.stream.StreamType;
9-
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
109

1110
import javax.annotation.Nonnull;
1211
import javax.annotation.Nullable;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ public long getLength() {
119119

120120
@Override
121121
public long getTimeStamp() throws ParsingException {
122-
return getTimestampSeconds("(#t=\\d{0,3}h?\\d{0,3}m?\\d{1,3}s?)");
122+
final var timestamp = getTimestampSeconds("(#t=\\d{0,3}h?\\d{0,3}m?\\d{1,3}s?)");
123+
return timestamp == -2 ? 0 : timestamp;
123124
}
124125

125126
@Override
@@ -168,7 +169,7 @@ public List<AudioStream> getAudioStreams() throws ExtractionException {
168169

169170
try {
170171
final JsonArray transcodings = track.getObject("media")
171-
.getArray("transcodings");
172+
.getArray("transcodings");
172173
if (!isNullOrEmpty(transcodings)) {
173174
// Get information about what stream formats are available
174175
extractAudioStreams(transcodings, audioStreams);

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

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

3+
import java.util.regex.Pattern;
4+
35
import org.schabi.newpipe.extractor.exceptions.ParsingException;
46
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
57
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
@@ -9,11 +11,18 @@
911
public final class SoundcloudStreamLinkHandlerFactory extends LinkHandlerFactory {
1012
private static final SoundcloudStreamLinkHandlerFactory INSTANCE
1113
= new SoundcloudStreamLinkHandlerFactory();
12-
private static final String URL_PATTERN = "^https?://(www\\.|m\\.|on\\.)?"
13-
+ "soundcloud.com/[0-9a-z_-]+"
14-
+ "/(?!(tracks|albums|sets|reposts|followers|following)/?$)[0-9a-z_-]+/?([#?].*)?$";
15-
private static final String API_URL_PATTERN = "^https?://api-v2\\.soundcloud.com"
16-
+ "/(tracks|albums|sets|reposts|followers|following)/([0-9a-z_-]+)/";
14+
15+
private static final Pattern URL_PATTERN = Pattern.compile(
16+
"^https?://(?:www\\.|m\\.|on\\.)?"
17+
+ "soundcloud.com/[0-9a-z_-]+"
18+
+ "/(?!(?:tracks|albums|sets|reposts|followers|following)/?$)[0-9a-z_-]+/?(?:[#?].*)?$"
19+
);
20+
21+
private static final Pattern API_URL_PATTERN = Pattern.compile(
22+
"^https?://api-v2\\.soundcloud.com"
23+
+ "/(tracks|albums|sets|reposts|followers|following)/([0-9a-z_-]+)/"
24+
);
25+
1726
private SoundcloudStreamLinkHandlerFactory() {
1827
}
1928

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import org.schabi.newpipe.extractor.localization.DateWrapper;
88
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
99
import org.schabi.newpipe.extractor.stream.StreamType;
10-
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
1110

1211
import javax.annotation.Nonnull;
1312
import javax.annotation.Nullable;

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory;
3636
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
3737
import org.schabi.newpipe.extractor.stream.StreamType;
38+
import org.schabi.newpipe.extractor.stream.ContentAvailability;
3839
import org.schabi.newpipe.extractor.utils.JsonUtils;
3940
import org.schabi.newpipe.extractor.utils.Parser;
4041
import org.schabi.newpipe.extractor.utils.Utils;
@@ -472,4 +473,33 @@ public boolean isShortFormContent() throws ParsingException {
472473
throw new ParsingException("Could not determine if this is short-form content", e);
473474
}
474475
}
476+
477+
private boolean isMembersOnly() throws ParsingException {
478+
return videoInfo.getArray("badges")
479+
.stream()
480+
.filter(JsonObject.class::isInstance)
481+
.map(JsonObject.class::cast)
482+
.map(badge -> badge.getObject("metadataBadgeRenderer").getString("style"))
483+
.anyMatch("BADGE_STYLE_TYPE_MEMBERS_ONLY"::equals);
484+
}
485+
486+
487+
@Nonnull
488+
@Override
489+
public ContentAvailability getContentAvailability() throws ParsingException {
490+
if (isPremiere()) {
491+
return ContentAvailability.UPCOMING;
492+
}
493+
494+
if (isMembersOnly()) {
495+
return ContentAvailability.MEMBERSHIP;
496+
}
497+
498+
if (isPremium()) {
499+
return ContentAvailability.PAID;
500+
}
501+
502+
return ContentAvailability.AVAILABLE;
503+
}
504+
475505
}

0 commit comments

Comments
 (0)