2
0
mirror of https://github.com/TeamNewPipe/NewPipeExtractor synced 2025-08-30 22:05:18 +00:00

Small live stream improvements and cleanup

Thanks to Stypox review

* Improved live stream related code
* Fixed Javadoc

Co-Authored-By: Stypox <stypox@pm.me>
This commit is contained in:
litetex
2025-07-15 22:26:01 +02:00
parent 64e4bafee1
commit b6b395061c
2 changed files with 18 additions and 4 deletions

View File

@@ -136,8 +136,8 @@ public class YoutubeStreamInfoItemLockupExtractor implements StreamInfoItemExtra
@Override
public long getDuration() throws ParsingException {
// Duration can only be extracted for normal videos, not live streams
if (getStreamType() != StreamType.VIDEO_STREAM) {
// Duration can not be extract from live streams, only from normal videos
if (isLive()) {
return -1;
}
@@ -220,6 +220,12 @@ public class YoutubeStreamInfoItemLockupExtractor implements StreamInfoItemExtra
return cachedTextualUploadDate.orElse(null);
}
// Live streams have no upload date
if (isLive()) {
cachedTextualUploadDate = Optional.empty();
return null;
}
// This might be null e.g. for live streams
this.cachedTextualUploadDate = metadataPart(1, 1)
.map(this::getTextContentFromMetadataPart);
@@ -249,7 +255,11 @@ public class YoutubeStreamInfoItemLockupExtractor implements StreamInfoItemExtra
if (optTextContent.isPresent()) {
return getViewCountFromViewCountText(optTextContent.get());
}
return -1;
return !isLive()
? -1
// Live streams don't have the metadata row present if there are 0 viewers
// https://github.com/TeamNewPipe/NewPipeExtractor/pull/1320#discussion_r2205837528
: 0;
}
private long getViewCountFromViewCountText(@Nonnull final String viewCountText)
@@ -322,6 +332,10 @@ public class YoutubeStreamInfoItemLockupExtractor implements StreamInfoItemExtra
return metadataPart.getObject("text").getString("content");
}
private boolean isLive() throws ParsingException {
return getStreamType() != StreamType.VIDEO_STREAM;
}
abstract static class ChannelImageViewModel {
protected JsonObject viewModel;

View File

@@ -58,7 +58,7 @@ public interface StreamInfoItemExtractor extends InfoItemExtractor {
/**
* Parses the number of views
*
* @return the number of views or -1 for live streams
* @return the number of views or -1 if not available
* @throws ParsingException if there is an error in the extraction
*/
long getViewCount() throws ParsingException;