Skip to content

feat: fix and improve auto-selection for default dubbed audio language#3748

Merged
ImprovedTube merged 1 commit intocode-charity:masterfrom
Pieko16:master
Apr 2, 2026
Merged

feat: fix and improve auto-selection for default dubbed audio language#3748
ImprovedTube merged 1 commit intocode-charity:masterfrom
Pieko16:master

Conversation

@Pieko16
Copy link
Copy Markdown
Contributor

@Pieko16 Pieko16 commented Apr 1, 2026

Description

This PR fixes the issue where the "Default Dubbed Language" setting failed to automatically switch the video's audio track.

Technical Root Cause

The previous implementation was attempting to read languageCode from the getLanguageInfo() object. Through debugging, it was discovered that YouTube's Player API does not provide languageCode for audio tracks (it is only available for text/caption tracks). Audio tracks store their language identifiers in the id property (e.g., "en.1", "tr"). Because the code was looking for a non-existent property, the matching logic always failed.

Changes & Improvements

  • Property Fix: Switched from info.languageCode to info.id to correctly identify the track language.
  • Enhanced Matching: Updated the logic to handle various ID formats (e.g., exact matches like en or prefixed IDs like en.1 and en-US).
  • Reliable Timing (Polling): Replaced static setTimeout calls with a setInterval polling mechanism. It now attempts to switch the track every 300ms (up to 10 tries) to ensure the player is fully initialized and tracks are loaded.
  • Efficiency: Added an early exit check if only one audio track is available (meaning no dubbing is present for the video).
  • Code Cleanup: Refactored the trySelectTrack function for better stability and error handling.

Linked Issue

Fixes #3747

@ImprovedTube
Copy link
Copy Markdown
Member

hi and thank you so much! @Pieko16


Sorry using our menu was or appeared comparably complicated here
https://github.com/code-charity/youtube/wiki/Contributing#adding-a-feature

We should document what is 'player_' for or don't need it.

'disabled' can automatically remove the variable from storage

(Please consider to come back in future, a follow up PR or so.)

@ImprovedTube ImprovedTube merged commit 865bc3a into code-charity:master Apr 2, 2026
@ImprovedTube ImprovedTube added the untested please test. (also applies to proactively merged pull requests.) label Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

untested please test. (also applies to proactively merged pull requests.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💡Add dubbing auto-choose

2 participants