aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/static/js/watch.hls.js
diff options
context:
space:
mode:
authorAstounds <kirito@disroot.org>2026-04-05 18:31:35 -0500
committerAstounds <kirito@disroot.org>2026-04-05 18:31:35 -0500
commit13a0e6ceeddc99a895c36f597ae6b388caebfce4 (patch)
tree657e86cf8282ab50188c0eebbad6709b50b54305 /youtube/static/js/watch.hls.js
parente8e2aa93d621b3f2ffe9c8f7b06d381012f6bff8 (diff)
downloadyt-local-13a0e6ceeddc99a895c36f597ae6b388caebfce4.tar.lz
yt-local-13a0e6ceeddc99a895c36f597ae6b388caebfce4.tar.xz
yt-local-13a0e6ceeddc99a895c36f597ae6b388caebfce4.zip
fix(hls): improve audio track selection and auto-detect "Original"
- Auto-select "Original" audio track by default in both native and Plyr HLS players - Fix native HLS audio selector to use numeric indices instead of string matching - Robustly detect "original" track by checking both `name` and `lang` attributes - Fix audio track change handler to correctly switch between available tracks
Diffstat (limited to 'youtube/static/js/watch.hls.js')
-rw-r--r--youtube/static/js/watch.hls.js32
1 files changed, 19 insertions, 13 deletions
diff --git a/youtube/static/js/watch.hls.js b/youtube/static/js/watch.hls.js
index cedfbf3..a924fdb 100644
--- a/youtube/static/js/watch.hls.js
+++ b/youtube/static/js/watch.hls.js
@@ -149,17 +149,11 @@ document.addEventListener('DOMContentLoaded', function() {
if (audioTrackSelect) {
audioTrackSelect.addEventListener('change', function() {
- const trackId = this.value;
+ const trackIdx = parseInt(this.value);
- if (hls && hls.audioTracks) {
- const index = hls.audioTracks.findIndex(t =>
- t.lang === trackId || t.name === trackId
- );
-
- if (index !== -1) {
- hls.audioTrack = index;
- console.log('Audio track changed to:', index);
- }
+ if (!isNaN(trackIdx) && hls && hls.audioTracks && trackIdx >= 0 && trackIdx < hls.audioTracks.length) {
+ hls.audioTrack = trackIdx;
+ console.log('Audio track changed to:', hls.audioTracks[trackIdx].name || trackIdx);
}
});
}
@@ -171,13 +165,25 @@ document.addEventListener('DOMContentLoaded', function() {
// Populate audio track select if needed
if (audioTrackSelect && data.audioTracks.length > 0) {
audioTrackSelect.innerHTML = '<option value="">Select audio track</option>';
- data.audioTracks.forEach(track => {
+ let originalIdx = -1;
+ data.audioTracks.forEach((track, idx) => {
+ // Find "original" track
+ if (originalIdx === -1 && (track.name || '').toLowerCase().includes('original')) {
+ originalIdx = idx;
+ }
const option = document.createElement('option');
- option.value = track.lang || track.name;
- option.textContent = track.name || track.lang || `Track ${track.id}`;
+ option.value = String(idx);
+ option.textContent = track.name || track.lang || `Track ${idx}`;
audioTrackSelect.appendChild(option);
});
audioTrackSelect.disabled = false;
+
+ // Auto-select "original" audio track
+ if (originalIdx !== -1) {
+ hls.audioTrack = originalIdx;
+ audioTrackSelect.value = String(originalIdx);
+ console.log('Auto-selected original audio track:', data.audioTracks[originalIdx].name);
+ }
}
});
}