Skip to content

Commit 85af0e4

Browse files
author
ImprovedTube
authored
Disabling AI auto-dub feature and forcing the original audio track
please test
2 parents 0038a2f + 8001f59 commit 85af0e4

5 files changed

Lines changed: 66 additions & 3 deletions

File tree

_locales/en/messages.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,5 +1448,8 @@
14481448
},
14491449
"disableLikesAnimation": {
14501450
"message": "Disable likes animation"
1451+
},
1452+
"disableAutoDubbing": {
1453+
"message": "Disable auto dubbing"
14511454
}
14521455
}

js&css/web-accessible/core.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,14 @@ document.addEventListener('it-message-from-extension', function () {
204204
ImprovedTube.init();
205205
ImprovedTube.blocklistInit();
206206

207-
// REACTION OR VISUAL FEEDBACK WHEN THE USER CHANGES A SETTING (already automated for our CSS features):
207+
/*--------------------------------------------------------------
208+
# Immediate reaction to any change of our extension storage (settings)
209+
While most of our features are chosen permanently (set and forget) and need to run with YouTube,
210+
we only started this section for feedback and reducing new user's misunderstandings.
211+
(For our simple CSS-only features this isn't necessary, since a loop is doing it and there could be a shared loop for many JS feature too)
212+
Yet doing this, it could also be used for big extra visual feedback pointing at or highlighing the immediate change on youtube.
213+
(to make it most intutive to the many new or visual users, bringing changes with simple css-transations or animation. Like an interactive tutorial.)
214+
--------------------------------------------------------------*/
208215
} else if (message.action === 'storage-changed') {
209216
let camelized_key = message.camelizedKey;
210217

@@ -451,6 +458,11 @@ document.addEventListener('it-message-from-extension', function () {
451458
ImprovedTube.playlistCopyVideoIdButton();
452459
}
453460
break
461+
case 'disableAutoDubbing':
462+
if (ImprovedTube.storage.disable_auto_dubbing === true) {
463+
ImprovedTube.disableAutoDubbing();
464+
}
465+
break
454466
}
455467

456468
// dont trigger shortcuts on config change, reinitialize handler instead

js&css/web-accessible/functions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ ImprovedTube.initPlayer = function () {
358358
ImprovedTube.playerQuality();
359359
ImprovedTube.batteryFeatures();
360360
ImprovedTube.playerVolume();
361-
if (this.storage.player_always_repeat === true) { ImprovedTube.playerRepeat(); }
361+
if (this.storage.player_always_repeat === true) { ImprovedTube.playerRepeat(); }
362362

363363
ImprovedTube.playerScreenshotButton();
364364
ImprovedTube.playerRepeatButton();
@@ -372,6 +372,7 @@ ImprovedTube.initPlayer = function () {
372372
ImprovedTube.expandDescription();
373373
setTimeout(function () {ImprovedTube.forcedTheaterMode(); }, 150);
374374
if (location.href.indexOf('/embed/') === -1) { ImprovedTube.miniPlayer(); }
375+
if (ImprovedTube.storage.disable_auto_dubbing === true) { ImprovedTube.disableAutoDubbing(); }
375376
}
376377
};
377378

js&css/web-accessible/www.youtube.com/player.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1595,4 +1595,47 @@ ImprovedTube.playerRewindAndForwardButtons = function(){
15951595

15961596

15971597
}
1598-
}
1598+
}
1599+
/*------------------------------------------------------------------------------
1600+
# DISABLE AUTO DUBBING
1601+
------------------------------------------------------------------------------*/
1602+
ImprovedTube.disableAutoDubbing = function () {
1603+
const player = this.elements.player;
1604+
const tracks = player.getAvailableAudioTracks();
1605+
const originalTrack = findOriginalAudioTrack(tracks);
1606+
1607+
if (originalTrack) {
1608+
player.setAudioTrack(originalTrack);
1609+
}
1610+
1611+
function findOriginalAudioTrack(audioTracks) {
1612+
// Score tracks based on likely original source
1613+
for (const track of audioTracks) {
1614+
if (hasOriginalKeyword(track)) {
1615+
return track;
1616+
}
1617+
}
1618+
1619+
for (const track of audioTracks) {
1620+
if (hasASR(track)) {
1621+
return track;
1622+
}
1623+
}
1624+
1625+
function hasASR(track) {
1626+
return Array.isArray(track.captionTracks) &&
1627+
track.captionTracks.some(ct => ct.kind === 'asr');
1628+
}
1629+
1630+
function hasOriginalKeyword(track) {
1631+
const name = track?.HB?.name?.toLowerCase() || '';
1632+
const localizedOriginalWords = ['original', 'originale', 'originalny', 'originalaudio', 'origineel', 'orijinal']; // Add more if needed
1633+
return localizedOriginalWords.some(word => name.includes(word));
1634+
}
1635+
1636+
// As a fallback: default or first item
1637+
const fallback = audioTracks.find(t => t?.HB?.isDefault) || audioTracks[0];
1638+
console.log(fallback);
1639+
return fallback;
1640+
}
1641+
}

menu/skeleton-parts/player.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,5 +1199,9 @@ extension.skeleton.main.layers.section.player.on.click = {
11991199
click: 'main.layers.section.appearance.on.click.player.on.click.player_hide_controls_options.on.click'
12001200
}
12011201
},
1202+
disable_auto_dubbing: {
1203+
component: 'switch',
1204+
text: 'disableAutoDubbing'
1205+
}
12021206
}
12031207
};

0 commit comments

Comments
 (0)