mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2025-04-29 08:20:34 +05:30
[YouTube] Fix detection of ended livestreams and parse livestream upload date
This commit is contained in:
parent
827f7bd137
commit
89a77ae74a
@ -137,18 +137,27 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getTextualUploadDate() throws ParsingException {
|
public String getTextualUploadDate() throws ParsingException {
|
||||||
if (getStreamType().equals(StreamType.LIVE_STREAM)) {
|
final JsonObject micro =
|
||||||
return null;
|
playerResponse.getObject("microformat").getObject("playerMicroformatRenderer");
|
||||||
}
|
if (!micro.getString("uploadDate", EMPTY_STRING).isEmpty()) {
|
||||||
|
|
||||||
JsonObject micro = playerResponse.getObject("microformat").getObject("playerMicroformatRenderer");
|
|
||||||
if (micro.isString("uploadDate") && !micro.getString("uploadDate").isEmpty()) {
|
|
||||||
return micro.getString("uploadDate");
|
return micro.getString("uploadDate");
|
||||||
}
|
} else if (!micro.getString("publishDate", EMPTY_STRING).isEmpty()) {
|
||||||
if (micro.isString("publishDate") && !micro.getString("publishDate").isEmpty()) {
|
|
||||||
return micro.getString("publishDate");
|
return micro.getString("publishDate");
|
||||||
|
} else {
|
||||||
|
final JsonObject liveDetails = micro.getObject("liveBroadcastDetails");
|
||||||
|
if (!liveDetails.getString("endTimestamp", EMPTY_STRING).isEmpty()) {
|
||||||
|
// an ended live stream
|
||||||
|
return liveDetails.getString("endTimestamp");
|
||||||
|
} else if (!liveDetails.getString("startTimestamp", EMPTY_STRING).isEmpty()) {
|
||||||
|
// a running live stream
|
||||||
|
return liveDetails.getString("startTimestamp");
|
||||||
|
} else if (getStreamType() == StreamType.LIVE_STREAM) {
|
||||||
|
// this should never be reached, but a live stream without upload date is valid
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getTextFromObject(getVideoPrimaryInfoRenderer().getObject("dateText")).startsWith("Premiered")) {
|
if (getTextFromObject(getVideoPrimaryInfoRenderer().getObject("dateText")).startsWith("Premiered")) {
|
||||||
@ -176,6 +185,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
return DateTimeFormatter.ISO_LOCAL_DATE.format(localDate);
|
return DateTimeFormatter.ISO_LOCAL_DATE.format(localDate);
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ParsingException("Could not get upload date");
|
throw new ParsingException("Could not get upload date");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -597,16 +607,13 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StreamType getStreamType() throws ParsingException {
|
public StreamType getStreamType() {
|
||||||
assertPageFetched();
|
assertPageFetched();
|
||||||
try {
|
return playerResponse.getObject("streamingData").has(FORMATS)
|
||||||
return playerResponse.getObject("videoDetails").getBoolean("isLiveContent")
|
? StreamType.VIDEO_STREAM : StreamType.LIVE_STREAM;
|
||||||
? StreamType.LIVE_STREAM : StreamType.VIDEO_STREAM;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new ParsingException("Could not get stream type", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private StreamInfoItemExtractor getNextStream() throws ExtractionException {
|
private StreamInfoItemExtractor getNextStream() throws ExtractionException {
|
||||||
try {
|
try {
|
||||||
final JsonObject firstWatchNextItem = initialData.getObject("contents")
|
final JsonObject firstWatchNextItem = initialData.getObject("contents")
|
||||||
|
@ -45,8 +45,8 @@ public class YoutubeStreamExtractorLivestreamTest extends DefaultStreamExtractor
|
|||||||
@Override public long expectedLength() { return 0; }
|
@Override public long expectedLength() { return 0; }
|
||||||
@Override public long expectedTimestamp() { return TIMESTAMP; }
|
@Override public long expectedTimestamp() { return TIMESTAMP; }
|
||||||
@Override public long expectedViewCountAtLeast() { return 0; }
|
@Override public long expectedViewCountAtLeast() { return 0; }
|
||||||
@Nullable @Override public String expectedUploadDate() { return null; }
|
@Nullable @Override public String expectedUploadDate() { return "2020-02-22 00:00:00.000"; }
|
||||||
@Nullable @Override public String expectedTextualUploadDate() { return null; }
|
@Nullable @Override public String expectedTextualUploadDate() { return "2020-02-22"; }
|
||||||
@Override public long expectedLikeCountAtLeast() { return 825000; }
|
@Override public long expectedLikeCountAtLeast() { return 825000; }
|
||||||
@Override public long expectedDislikeCountAtLeast() { return 15600; }
|
@Override public long expectedDislikeCountAtLeast() { return 15600; }
|
||||||
@Override public boolean expectedHasSubtitles() { return false; }
|
@Override public boolean expectedHasSubtitles() { return false; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user