@@ -368,6 +368,7 @@ sub new {
368368 last_segment => {}, # Track last requested segment per channel_id
369369 playlist_cache => {}, # Store cached m3u8 content per channel_id
370370 playlist_next_update => {}, # Track next scheduled update time per channel_id
371+ playlist_first_load => {}, # Track if this is the first playlist load per channel_id
371372
372373 ua => undef ,
373374 json => JSON::XS-> new-> utf8-> canonical,
@@ -1042,21 +1043,31 @@ sub get_playlist {
10421043 # Cache the playlist content
10431044 $self -> {playlist_cache }-> {$channel_id } = $content ;
10441045
1045- # Schedule next playlist update based on new segment count
1046- if ($new_segment_count > 0) {
1047- my $delay = $self -> calculate_playlist_update_delay($content , $new_segment_count );
1048- my $next_update = time () + $delay ;
1049- $self -> {playlist_next_update }-> {$channel_id } = $next_update ;
1050-
1051- my $update_time = strftime(' %Y-%m-%d %H:%M:%S' , localtime ($next_update ));
1052- main::log_info(sprintf (" Cached playlist for channel %s , next update scheduled in %.1f seconds at %s (%d new segments)" ,
1053- $channel_id , $delay , $update_time , $new_segment_count ));
1046+ # Check if this is the first playlist load for this channel
1047+ my $is_first_load = !exists $self -> {playlist_first_load }-> {$channel_id };
1048+
1049+ if ($is_first_load ) {
1050+ # Mark that we've loaded this channel's playlist at least once
1051+ $self -> {playlist_first_load }-> {$channel_id } = 1;
1052+ main::log_info(" First playlist load for channel $channel_id - skipping scheduling (may be caching many segments)" );
1053+ # Don't schedule next update on first load
10541054 } else {
1055- # No new segments, schedule a default update in 30 seconds
1056- my $delay = 30;
1057- my $next_update = time () + $delay ;
1058- $self -> {playlist_next_update }-> {$channel_id } = $next_update ;
1059- main::log_debug(" No new segments in playlist for channel $channel_id , scheduling default update in $delay seconds" );
1055+ # Schedule next playlist update based on new segment count (second load and beyond)
1056+ if ($new_segment_count > 0) {
1057+ my $delay = $self -> calculate_playlist_update_delay($content , $new_segment_count );
1058+ my $next_update = time () + $delay ;
1059+ $self -> {playlist_next_update }-> {$channel_id } = $next_update ;
1060+
1061+ my $update_time = strftime(' %Y-%m-%d %H:%M:%S' , localtime ($next_update ));
1062+ main::log_info(sprintf (" Cached playlist for channel %s , next update scheduled in %.1f seconds at %s (%d new segments)" ,
1063+ $channel_id , $delay , $update_time , $new_segment_count ));
1064+ } else {
1065+ # No new segments, schedule a default update in 30 seconds
1066+ my $delay = 30;
1067+ my $next_update = time () + $delay ;
1068+ $self -> {playlist_next_update }-> {$channel_id } = $next_update ;
1069+ main::log_debug(" No new segments in playlist for channel $channel_id , scheduling default update in $delay seconds" );
1070+ }
10601071 }
10611072
10621073 return $content ;
0 commit comments