mirror of
https://github.com/TeamNewPipe/NewPipeExtractor
synced 2025-09-02 15:25:32 +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:
@@ -136,8 +136,8 @@ public class YoutubeStreamInfoItemLockupExtractor implements StreamInfoItemExtra
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getDuration() throws ParsingException {
|
public long getDuration() throws ParsingException {
|
||||||
// Duration can only be extracted for normal videos, not live streams
|
// Duration can not be extract from live streams, only from normal videos
|
||||||
if (getStreamType() != StreamType.VIDEO_STREAM) {
|
if (isLive()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,6 +220,12 @@ public class YoutubeStreamInfoItemLockupExtractor implements StreamInfoItemExtra
|
|||||||
return cachedTextualUploadDate.orElse(null);
|
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 might be null e.g. for live streams
|
||||||
this.cachedTextualUploadDate = metadataPart(1, 1)
|
this.cachedTextualUploadDate = metadataPart(1, 1)
|
||||||
.map(this::getTextContentFromMetadataPart);
|
.map(this::getTextContentFromMetadataPart);
|
||||||
@@ -249,7 +255,11 @@ public class YoutubeStreamInfoItemLockupExtractor implements StreamInfoItemExtra
|
|||||||
if (optTextContent.isPresent()) {
|
if (optTextContent.isPresent()) {
|
||||||
return getViewCountFromViewCountText(optTextContent.get());
|
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)
|
private long getViewCountFromViewCountText(@Nonnull final String viewCountText)
|
||||||
@@ -322,6 +332,10 @@ public class YoutubeStreamInfoItemLockupExtractor implements StreamInfoItemExtra
|
|||||||
return metadataPart.getObject("text").getString("content");
|
return metadataPart.getObject("text").getString("content");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isLive() throws ParsingException {
|
||||||
|
return getStreamType() != StreamType.VIDEO_STREAM;
|
||||||
|
}
|
||||||
|
|
||||||
abstract static class ChannelImageViewModel {
|
abstract static class ChannelImageViewModel {
|
||||||
protected JsonObject viewModel;
|
protected JsonObject viewModel;
|
||||||
|
|
||||||
|
@@ -58,7 +58,7 @@ public interface StreamInfoItemExtractor extends InfoItemExtractor {
|
|||||||
/**
|
/**
|
||||||
* Parses the number of views
|
* 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
|
* @throws ParsingException if there is an error in the extraction
|
||||||
*/
|
*/
|
||||||
long getViewCount() throws ParsingException;
|
long getViewCount() throws ParsingException;
|
||||||
|
Reference in New Issue
Block a user