Skip to content

Commit fc54fb2

Browse files
authored
Merge pull request #1140 from Stypox/yt-shorts-no-duration
[YouTube] Always return -1 as duration of Shorts returned inside reel items
2 parents 0518487 + 83c1737 commit fc54fb2

File tree

8 files changed

+122
-140
lines changed

8 files changed

+122
-140
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;

extractor/src/test/resources/org/schabi/newpipe/extractor/services/youtube/extractor/channelTabs/shorts/generated_mock_0.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@
4141
"same-origin; report-to\u003d\"youtube_main\""
4242
],
4343
"date": [
44-
"Fri, 08 Dec 2023 19:38:04 GMT"
44+
"Thu, 21 Dec 2023 19:53:52 GMT"
4545
],
4646
"expires": [
47-
"Fri, 08 Dec 2023 19:38:04 GMT"
47+
"Thu, 21 Dec 2023 19:53:52 GMT"
4848
],
4949
"origin-trial": [
5050
"AvC9UlR6RDk2crliDsFl66RWLnTbHrDbp+DiY6AYz/PNQ4G4tdUTjrHYr2sghbkhGQAVxb7jaPTHpEVBz0uzQwkAAAB4eyJvcmlnaW4iOiJodHRwczovL3lvdXR1YmUuY29tOjQ0MyIsImZlYXR1cmUiOiJXZWJWaWV3WFJlcXVlc3RlZFdpdGhEZXByZWNhdGlvbiIsImV4cGlyeSI6MTcxOTUzMjc5OSwiaXNTdWJkb21haW4iOnRydWV9"
@@ -62,9 +62,9 @@
6262
"ESF"
6363
],
6464
"set-cookie": [
65-
"YSC\u003dXVJaGz18ttE; Domain\u003d.youtube.com; Path\u003d/; Secure; HttpOnly; SameSite\u003dnone",
66-
"VISITOR_INFO1_LIVE\u003d; Domain\u003d.youtube.com; Expires\u003dSat, 13-Mar-2021 19:38:04 GMT; Path\u003d/; Secure; HttpOnly; SameSite\u003dnone",
67-
"CONSENT\u003dPENDING+916; expires\u003dSun, 07-Dec-2025 19:38:04 GMT; path\u003d/; domain\u003d.youtube.com; Secure"
65+
"YSC\u003d52XN8PrKcOs; Domain\u003d.youtube.com; Path\u003d/; Secure; HttpOnly; SameSite\u003dnone",
66+
"VISITOR_INFO1_LIVE\u003d; Domain\u003d.youtube.com; Expires\u003dFri, 26-Mar-2021 19:53:52 GMT; Path\u003d/; Secure; HttpOnly; SameSite\u003dnone",
67+
"CONSENT\u003dPENDING+032; expires\u003dSat, 20-Dec-2025 19:53:52 GMT; path\u003d/; domain\u003d.youtube.com; Secure"
6868
],
6969
"strict-transport-security": [
7070
"max-age\u003d31536000"

extractor/src/test/resources/org/schabi/newpipe/extractor/services/youtube/extractor/channelTabs/shorts/generated_mock_1.json

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

extractor/src/test/resources/org/schabi/newpipe/extractor/services/youtube/extractor/channelTabs/shorts/generated_mock_2.json

Lines changed: 8 additions & 8 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)