Skip to content

Commit

Permalink
Fix livestream detection (+ playback)
Browse files Browse the repository at this point in the history
  • Loading branch information
devoxin committed Aug 23, 2024
1 parent 3746930 commit f74d499
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public AudioItem loadVideo(@NotNull YoutubeAudioSourceManager source,
TemporalInfo temporalInfo = TemporalInfo.fromRawData(
!playabilityStatus.get("liveStreamability").isNull(),
videoDetails.get("lengthSeconds"),
false
videoDetails.get("isLive").asBoolean(false)
);

return buildAudioTrack(source, videoDetails, title, author, temporalInfo.durationMillis, videoId, temporalInfo.isActiveStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ private TemporalInfo(boolean isActiveStream, long durationMillis) {
}

@NotNull
public static TemporalInfo fromRawData(boolean wasLiveStream, JsonBrowser durationSecondsField, boolean legacy) {
public static TemporalInfo fromRawData(boolean hasLivestreamability, JsonBrowser durationSecondsField, boolean isLive) {
long durationValue = durationSecondsField.asLong(0L);

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

// VODs are not really live streams, even though the response JSON indicates that it is.
// If it is actually live, then duration is also missing or 0.
boolean isActiveStream = wasLiveStream && durationValue == 0;
boolean isActiveStream = hasLivestreamability || isLive;

return new TemporalInfo(
isActiveStream,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@
* responds to a segment request with 204.
*/
public class YoutubeMpegStreamAudioTrack extends MpegAudioTrack {
private static final Logger log = LoggerFactory.getLogger(com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeMpegStreamAudioTrack.class);
private static final RequestConfig streamingRequestConfig = RequestConfig.custom().setSocketTimeout(3000).setConnectionRequestTimeout(3000).setConnectTimeout(3000).build();
private static final Logger log = LoggerFactory.getLogger(YoutubeMpegStreamAudioTrack.class);
private static final RequestConfig streamingRequestConfig = RequestConfig.custom()
.setSocketTimeout(3000)
.setConnectionRequestTimeout(3000)
.setConnectTimeout(3000)
.build();
private static final long EMPTY_RETRY_THRESHOLD_MS = 400;
private static final long EMPTY_RETRY_INTERVAL_MS = 50;
private static final long MAX_REWIND_TIME = 43200; // Seconds
Expand Down

0 comments on commit f74d499

Please sign in to comment.