Skip to content

Commit 2938067

Browse files
committed
[YouTube] Shorts don't provide a duration anymore
1 parent 91419ec commit 2938067

File tree

4 files changed

+16
-40
lines changed

4 files changed

+16
-40
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ private Optional<JsonObject> collectItem(@Nonnull final MultiInfoItemsCollector
300300
getCommitVideoConsumer(collector, timeAgoParser, channelIds,
301301
richItem.getObject("videoRenderer"));
302302
} else if (richItem.has("reelItemRenderer")) {
303-
getCommitReelItemConsumer(collector, timeAgoParser, channelIds,
303+
getCommitReelItemConsumer(collector, channelIds,
304304
richItem.getObject("reelItemRenderer"));
305305
} else if (richItem.has("playlistRenderer")) {
306306
getCommitPlaylistConsumer(collector, channelIds,
@@ -356,11 +356,10 @@ public String getUploaderUrl() throws ParsingException {
356356
}
357357

358358
private void getCommitReelItemConsumer(@Nonnull final MultiInfoItemsCollector collector,
359-
@Nonnull final TimeAgoParser timeAgoParser,
360359
@Nonnull final List<String> channelIds,
361360
@Nonnull final JsonObject jsonObject) {
362361
collector.commit(
363-
new YoutubeReelInfoItemExtractor(jsonObject, timeAgoParser) {
362+
new YoutubeReelInfoItemExtractor(jsonObject) {
364363
@Override
365364
public String getUploaderName() throws ParsingException {
366365
if (channelIds.size() >= 2) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,7 @@ private void collectStreamsFrom(@Nonnull final StreamInfoItemsCollector collecto
411411
richItemRenderer.getObject("content");
412412
if (richItemRendererContent.has(REEL_ITEM_RENDERER)) {
413413
collector.commit(new YoutubeReelInfoItemExtractor(
414-
richItemRendererContent.getObject(REEL_ITEM_RENDERER),
415-
timeAgoParser));
414+
richItemRendererContent.getObject(REEL_ITEM_RENDERER)));
416415
}
417416
}
418417
}

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

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
package org.schabi.newpipe.extractor.services.youtube.extractors;
22

3+
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
4+
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getThumbnailsFromInfoItem;
5+
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
6+
37
import com.grack.nanojson.JsonObject;
48

59
import org.schabi.newpipe.extractor.Image;
610
import org.schabi.newpipe.extractor.exceptions.ParsingException;
711
import org.schabi.newpipe.extractor.localization.DateWrapper;
8-
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
912
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory;
1013
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
1114
import org.schabi.newpipe.extractor.stream.StreamType;
1215
import org.schabi.newpipe.extractor.utils.Utils;
1316

17+
import java.util.List;
18+
1419
import javax.annotation.Nonnull;
1520
import javax.annotation.Nullable;
1621

17-
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
18-
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getThumbnailsFromInfoItem;
19-
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
20-
21-
import java.util.List;
22-
2322
/**
2423
* A {@link StreamInfoItemExtractor} for YouTube's {@code reelItemRenderers}.
2524
*
@@ -33,13 +32,9 @@ public class YoutubeReelInfoItemExtractor implements StreamInfoItemExtractor {
3332

3433
@Nonnull
3534
private final JsonObject reelInfo;
36-
@Nullable
37-
private final TimeAgoParser timeAgoParser;
3835

39-
public YoutubeReelInfoItemExtractor(@Nonnull final JsonObject reelInfo,
40-
@Nullable final TimeAgoParser timeAgoParser) {
36+
public YoutubeReelInfoItemExtractor(@Nonnull final JsonObject reelInfo) {
4137
this.reelInfo = reelInfo;
42-
this.timeAgoParser = timeAgoParser;
4338
}
4439

4540
@Override
@@ -68,28 +63,6 @@ public StreamType getStreamType() throws ParsingException {
6863
return StreamType.VIDEO_STREAM;
6964
}
7065

71-
@Override
72-
public long getDuration() throws ParsingException {
73-
// Duration of reelItems is only provided in the accessibility data
74-
// example: "VIDEO TITLE - 49 seconds - play video"
75-
// "VIDEO TITLE - 1 minute, 1 second - play video"
76-
final String accessibilityLabel = reelInfo.getObject("accessibility")
77-
.getObject("accessibilityData").getString("label");
78-
if (accessibilityLabel == null || timeAgoParser == null) {
79-
return 0;
80-
}
81-
82-
// This approach may be language dependent
83-
final String[] labelParts = accessibilityLabel.split(" [\u2013-] ");
84-
85-
if (labelParts.length > 2) {
86-
final String textualDuration = labelParts[labelParts.length - 2];
87-
return timeAgoParser.parseDuration(textualDuration);
88-
}
89-
90-
return -1;
91-
}
92-
9366
@Override
9467
public long getViewCount() throws ParsingException {
9568
final String viewCountText = getTextFromObject(reelInfo.getObject("viewCountText"));
@@ -117,6 +90,11 @@ public boolean isAd() throws ParsingException {
11790
return false;
11891
}
11992

93+
@Override
94+
public long getDuration() throws ParsingException {
95+
return -1;
96+
}
97+
12098
@Override
12199
public String getUploaderName() throws ParsingException {
122100
return null;

extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfoItemExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public interface StreamInfoItemExtractor extends InfoItemExtractor {
5050
/**
5151
* Get the stream duration in seconds
5252
*
53-
* @return the stream duration in seconds
53+
* @return the stream duration in seconds or -1 if no duration is available
5454
* @throws ParsingException if there is an error in the extraction
5555
*/
5656
long getDuration() throws ParsingException;

0 commit comments

Comments
 (0)