Skip to content

Commit 8e07a76

Browse files
committed
Do not parse duration when live stream
Also cache the streamtype
1 parent b15c0dc commit 8e07a76

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class YoutubeStreamInfoItemLockupExtractor implements StreamInfoItemExtra
4141
private final JsonObject lockupViewModel;
4242
private final TimeAgoParser timeAgoParser;
4343

44+
private StreamType cachedStreamType;
4445
private String cachedName;
4546
private Optional<String> cachedTextualUploadDate;
4647

@@ -61,6 +62,13 @@ public YoutubeStreamInfoItemLockupExtractor(final JsonObject lockupViewModel,
6162

6263
@Override
6364
public StreamType getStreamType() throws ParsingException {
65+
if (cachedStreamType == null) {
66+
cachedStreamType = determineStreamType();
67+
}
68+
return cachedStreamType;
69+
}
70+
71+
private StreamType determineStreamType() throws ParsingException {
6472
if (JsonUtils.getArray(lockupViewModel, "contentImage.thumbnailViewModel.overlays")
6573
.streamAsJsonObjects()
6674
.flatMap(overlay -> overlay
@@ -128,6 +136,11 @@ public String getName() throws ParsingException {
128136

129137
@Override
130138
public long getDuration() throws ParsingException {
139+
// Duration can only be extracted for normal videos, not live streams
140+
if (getStreamType() != StreamType.VIDEO_STREAM) {
141+
return -1;
142+
}
143+
131144
final List<String> potentialDurations = JsonUtils.getArray(lockupViewModel,
132145
"contentImage.thumbnailViewModel.overlays")
133146
.streamAsJsonObjects()

0 commit comments

Comments
 (0)