Skip to content

Commit 09d1d7c

Browse files
Copilotpaul-1
andcommitted
Remove block data functions and track timing internally for metadata timer calculation
Co-authored-by: paul-1 <6473457+paul-1@users.noreply.github.com>
1 parent 699446c commit 09d1d7c

File tree

1 file changed

+17
-48
lines changed

1 file changed

+17
-48
lines changed

Plugins/SiriusXM/ProtocolHandler.pm

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -519,26 +519,7 @@ sub getMetadataFor {
519519
Slim::Music::Info::setDuration($song->track, $meta->{duration}) if $song;
520520
}
521521

522-
# Store track timing info for metadata refresh calculations only
523-
if ($xmplaylist_meta->{track_timestamp}) {
524-
# Store track start time info in block data for timer calculations
525-
my $blockData = __PACKAGE__->getBlockData($song) || {};
526-
527-
# Parse timestamp and set start time
528-
eval {
529-
my $track_start_time = str2time($xmplaylist_meta->{track_timestamp});
530-
if (defined $track_start_time) {
531-
$blockData->{track_start_time} = $track_start_time;
532-
$blockData->{xmplaylist_id} = $xmplaylist_meta->{xmplaylist_id} if $xmplaylist_meta->{xmplaylist_id};
533-
534-
__PACKAGE__->setBlockData($song, $blockData);
535-
}
536-
};
537-
538-
if ($@) {
539-
$log->warn("Failed to parse track timestamp: $@");
540-
}
541-
}
522+
542523

543524
# Really noisy log message when using a LMS web.
544525
# $log->debug("Using xmplaylist metadata: " . ($meta->{title} || 'Unknown') .
@@ -626,28 +607,7 @@ sub requestString {
626607
return $class->SUPER::requestString($client, $url, $maxRedirects);
627608
}
628609

629-
# Block data management (following RadioParadise pattern)
630-
sub getBlockData {
631-
my ($class, $song) = @_;
632-
return unless $song;
633-
634-
my $url = $song->streamUrl() || return;
635-
return $playerStates{_cleanupBlockURL($url)};
636-
}
637-
638-
sub setBlockData {
639-
my ($class, $song, $data) = @_;
640-
return unless $song && $data;
641-
642-
my $url = $song->streamUrl() || return;
643-
$playerStates{_cleanupBlockURL($url)} = $data;
644-
}
645610

646-
sub _cleanupBlockURL {
647-
my $url = shift || '';
648-
$url =~ s/\?.*//;
649-
return $url;
650-
}
651611

652612
# Calculate elapsed time for a track based on its start timestamp
653613
sub _calculateTrackElapsed {
@@ -688,17 +648,26 @@ sub _calculateNextUpdateInterval {
688648
my $xmplaylist_meta = $song->pluginData('xmplaylist_meta');
689649
return METADATA_UPDATE_INTERVAL unless $xmplaylist_meta;
690650

691-
# Get block data to check track timing
692-
my $blockData = __PACKAGE__->getBlockData($song);
693-
return METADATA_UPDATE_INTERVAL unless $blockData && $blockData->{track_start_time};
694-
695-
# Get track duration if available
651+
# Get track duration and timestamp if available
696652
my $duration = $xmplaylist_meta->{duration};
697-
return METADATA_UPDATE_INTERVAL unless defined $duration && $duration > 0;
653+
my $timestamp = $xmplaylist_meta->{track_timestamp};
654+
655+
return METADATA_UPDATE_INTERVAL unless defined $duration && $duration > 0 && $timestamp;
656+
657+
# Parse the track start time from xmplaylist timestamp
658+
my $track_start_time;
659+
eval {
660+
$track_start_time = str2time($timestamp);
661+
};
662+
663+
if ($@ || !defined $track_start_time) {
664+
$log->debug("Failed to parse track timestamp '$timestamp', using default interval");
665+
return METADATA_UPDATE_INTERVAL;
666+
}
698667

699668
# Calculate using formula: Duration - (Current Time - Start Time) - 30
700669
my $current_time = time();
701-
my $elapsed = $current_time - $blockData->{track_start_time};
670+
my $elapsed = $current_time - $track_start_time;
702671
my $remaining = $duration - $elapsed;
703672
my $nextInterval = $remaining - 30;
704673

0 commit comments

Comments
 (0)