Skip to content

Commit e4ec766

Browse files
committed
Possibly fix misdetections as livestreams
1 parent b3fde19 commit e4ec766

File tree

4 files changed

+14
-19
lines changed

4 files changed

+14
-19
lines changed

common/src/main/java/dev/lavalink/youtube/clients/skeleton/NonMusicClient.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,7 @@ public AudioItem loadVideo(@NotNull YoutubeAudioSourceManager source,
350350
author = "Unknown artist";
351351
}
352352

353-
TemporalInfo temporalInfo = TemporalInfo.fromRawData(
354-
!playabilityStatus.get("liveStreamability").isNull(),
355-
videoDetails.get("lengthSeconds"),
356-
videoDetails.get("isLive").asBoolean(false)
357-
);
358-
353+
TemporalInfo temporalInfo = TemporalInfo.fromRawData(playabilityStatus, videoDetails);
359354
return buildAudioTrack(source, videoDetails, title, author, temporalInfo.durationMillis, videoId, temporalInfo.isActiveStream);
360355
}
361356

common/src/main/java/dev/lavalink/youtube/track/TemporalInfo.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,26 @@ private TemporalInfo(boolean isActiveStream, long durationMillis) {
1515
this.durationMillis = durationMillis;
1616
}
1717

18+
// normal video? but has liveStreamability: PRRBJOn_n-Y
19+
// livestream: jfKfPfyJRdk
20+
1821
@NotNull
19-
public static TemporalInfo fromRawData(boolean hasLivestreamability, JsonBrowser durationSecondsField, boolean isLive) {
20-
long durationValue = durationSecondsField.asLong(0L);
22+
public static TemporalInfo fromRawData(JsonBrowser playabilityStatus, JsonBrowser videoDetails) {
23+
JsonBrowser durationField = videoDetails.get("lengthSeconds");
24+
long durationValue = durationField.asLong(0L);
25+
26+
boolean hasLivestreamability = !playabilityStatus.get("liveStreamability").isNull();
27+
boolean isLive = videoDetails.get("isLive").asBoolean(false)
28+
|| videoDetails.get("isLiveContent").asBoolean(false);
2129

2230
if (hasLivestreamability) {
2331
// Premieres have duration information, but act as a normal stream. When we play it, we don't know the
2432
// current position of it since YouTube doesn't provide such information, so assume duration is unknown.
2533
durationValue = 0;
2634
}
2735

28-
// VODs are not really live streams, even though the response JSON indicates that it is.
29-
// If it is actually live, then duration is also missing or 0.
30-
boolean isActiveStream = hasLivestreamability || isLive;
31-
3236
return new TemporalInfo(
33-
isActiveStream,
37+
(isLive || hasLivestreamability) && durationValue == 0,
3438
durationValue == 0 ? DURATION_MS_UNKNOWN : Units.secondsToMillis(durationValue)
3539
);
3640
}

v2/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ base {
1414
dependencies {
1515
api(projects.common)
1616
compileOnly(libs.lavaplayer.v2)
17+
1718
implementation(libs.rhino.engine)
1819
implementation(libs.nanojson)
1920
compileOnly(libs.slf4j)

v2/src/main/java/dev/lavalink/youtube/clients/skeleton/ThumbnailNonMusicClient.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,7 @@ public AudioItem loadVideo(@NotNull YoutubeAudioSourceManager source,
101101
author = "Unknown artist";
102102
}
103103

104-
TemporalInfo temporalInfo = TemporalInfo.fromRawData(
105-
!playabilityStatus.get("liveStreamability").isNull(),
106-
videoDetails.get("lengthSeconds"),
107-
false
108-
);
109-
104+
TemporalInfo temporalInfo = TemporalInfo.fromRawData(playabilityStatus, videoDetails);
110105
String thumbnailUrl = ThumbnailTools.getYouTubeThumbnail(videoDetails, videoId);
111106

112107
AudioTrackInfo info = new AudioTrackInfo(title, author, temporalInfo.durationMillis, videoId, temporalInfo.isActiveStream, WATCH_URL + videoId, thumbnailUrl, null);

0 commit comments

Comments
 (0)