Skip to content

Conversation

@suryaprakash0010
Copy link
Contributor

Fix: YouTube Autoplay Fails After Track 400

🎯 Issue Summary

Fixes #3541 - YouTube fails to autoplay next track for all tracks past 400 in large playlists.

🔍 Root Cause

The playlistUpNextAutoplay function was incorrectly setting currentIndex = totalVideos when playlist_up_next_autoplay was disabled, forcing playlists to end and breaking autoplay for large playlists beyond YouTube's ~200 video pagination limit.

🛠️ Solution

Core Fix

  • Before: Forced playlist termination by setting currentIndex = totalVideos
  • After: Proper synchronization between currentIndex and localCurrentIndex to maintain playlist continuity

Enhanced Features

  • Large Playlist Handler: Monitors video changes and ensures proper index synchronization
  • Observer Pattern: Detects playlist data updates when YouTube loads new segments
  • Memory Management: Proper cleanup of observers and event listeners
  • Navigation Support: Handles navigation between playlist and non-playlist pages

📁 Files Changed

📝 js&css\web-accessible\www.youtube.com\playlist.js

  • Fixed playlistUpNextAutoplay() logic
  • Added playlistLargePlaylistHandler() function
  • Added cleanupPlaylistHandlers() function

📝 js&css\web-accessible\functions.js

  • Integrated large playlist handler into videoPageUpdate()
  • Added cleanup logic for non-playlist pages

📝 js&css\web-accessible\init.js

  • Added handler to playlist initialization in yt-page-data-updated
  • Added cleanup in yt-navigate-finish for navigation

🧪 test-large-playlist-fix.js (New)

  • Comprehensive test script for verification
  • Manual testing instructions

🔄 How It Works

  1. YouTube's Limitation: Loads playlists in chunks (~200 videos)
  2. Our Solution: Continuously monitors and synchronizes playlist indices
  3. Result: Seamless autoplay beyond track 400

🧪 Testing

Automated Test

// Run in browser console on any YouTube playlist
testLargePlaylistFix();

Manual Testing

  1. Find a playlist with 400+ videos
  2. Start playing from video 200 or later
  3. Enable/disable autoplay settings
  4. Verify autoplay continues seamlessly

Verification

  • ✅ Fixes autoplay failure after track 400
  • ✅ Maintains backward compatibility
  • ✅ Proper memory management
  • ✅ Handles navigation correctly
  • ✅ Works with existing playlist features

📊 Impact

  • Files Modified: 3 core files + 1 test file
  • Lines Added: ~200 lines
  • Breaking Changes: None
  • Performance: Minimal impact

🎉 Result

Users can now autoplay through large playlists without interruption after track 400, resolving the long-standing issue reported in #3541.

@ImprovedTube ImprovedTube merged commit ff9d942 into code-charity:master Feb 1, 2026
1 check passed
@ImprovedTube
Copy link
Member

thank you so much! @suryaprakash0010

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐞fail after track #400

2 participants