From fd059258d9d902da5287a65558a46546bf371b95 Mon Sep 17 00:00:00 2001 From: Dandy Chen Date: Fri, 18 Feb 2022 22:51:13 +0800 Subject: [PATCH 1/3] fix: ttDownloadables no height prop cause exception --- src/nflxmultisubs.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/nflxmultisubs.js b/src/nflxmultisubs.js index 293b92d..8491028 100644 --- a/src/nflxmultisubs.js +++ b/src/nflxmultisubs.js @@ -374,8 +374,9 @@ class SubtitleFactory { } static _buildImageBased(track, lang, bcp47) { - const maxHeight = Math.max(...Object.values(track.ttDownloadables).map(d => d.height)); - const d = Object.values(track.ttDownloadables).find(d => d.height === maxHeight); + const maxHeight = Math.max(...Object.values(track.ttDownloadables) + .map(d => Number.isInteger(d.height) ? d.height : 0)); + const d = Object.values(track.ttDownloadables).find(d => maxHeight === 0 || d.height === maxHeight); const urls = Object.values(d.downloadUrls); return new ImageSubtitle(lang, bcp47, urls); } From cba8df8d6dd624ab3db6a4eea43ff4375ab3ffe6 Mon Sep 17 00:00:00 2001 From: Dandy Chen Date: Fri, 18 Feb 2022 22:51:50 +0800 Subject: [PATCH 2/3] fix: prevent observer node don't have querySelector cause exception --- src/nflxmultisubs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nflxmultisubs.js b/src/nflxmultisubs.js index 8491028..9f50bc7 100644 --- a/src/nflxmultisubs.js +++ b/src/nflxmultisubs.js @@ -465,7 +465,7 @@ const bodyObserver = new MutationObserver(mutations => { mutations.forEach(mutation => { mutation.addedNodes.forEach(node => { // FIXME: performance hazard - const subtitleMenuElem = node.querySelector('div[data-uia="selector-audio-subtitle"]'); + const subtitleMenuElem = node && node.querySelector && node.querySelector('div[data-uia="selector-audio-subtitle"]'); if (subtitleMenuElem) { // popup menu attached if (!subtitleMenuElem.getElementsByClassName(SUBTITLE_LIST_CLASSNAME).length) { From b60470543fdf073691129ae9cb213a0d24633c43 Mon Sep 17 00:00:00 2001 From: Dandy Chen Date: Fri, 18 Feb 2022 22:52:13 +0800 Subject: [PATCH 3/3] fix: change get default audio language way --- src/nflxmultisubs.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/nflxmultisubs.js b/src/nflxmultisubs.js index 9f50bc7..f7b460a 100644 --- a/src/nflxmultisubs.js +++ b/src/nflxmultisubs.js @@ -1071,8 +1071,9 @@ class NflxMultiSubsManager { defaultAudioId = manifest.recommendedMedia.audioTrackId; defaultAudioTrack = manifest.audio_tracks.find(t => t.new_track_id == defaultAudioId); } - console.log(`Default audio track language: ${defaultAudioLanguage}`); - const autoSubtitleId = gSubtitles.findIndex(t => t.bcp47 == defaultAudioLanguage); + + console.log(`Default audio track language: ${defaultAudioTrack.language}`); + const autoSubtitleId = gSubtitles.findIndex(t => t.bcp47 == defaultAudioTrack.language); if (autoSubtitleId >= 0) { console.log(`Subtitle #${autoSubtitleId} auto-enabled to match audio`); activateSubtitle(autoSubtitleId);