Skip to content

Commit

Permalink
Fix: ignore preloaded manifest (not playing) (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
dannvix committed Mar 18, 2018
1 parent e3cce2d commit 42fecfa
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "NflxMultiSubs",
"description": "Bilingual Subtitles & Enhanced Experiences for Netflix",
"author": "Dan Chen",
"version": "1.6.2",
"version": "1.6.3",
"license": "MIT",
"private": true,
"scripts": {
Expand Down
64 changes: 37 additions & 27 deletions src/nflxmultisubs.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,39 +730,49 @@ class NflxMultiSubsManager {
try {
console.log(`Manifest: ${manifest.movieId}`);

const manifestInUrl = /^\/watch\/(\d+)/.exec(window.location.pathname)[1];
const playingManifest = (manifest.movieId.toString() === manifestInUrl);
if (!playingManifest) {
console.log(`Ignored: manifest ${manifest.movieId} not playing`);
return;
}

const movieChanged = (manifest.movieId !== this.lastMovieId);
if (movieChanged) {
this.lastMovieId = manifest.movieId;
gSubtitles = buildSubtitleList(manifest.textTracks);
if (!movieChanged) {
console.log(`Ignored: manifest ${manifest.movieId} loaded yet`);
return;
}

gSubtitleMenu = new SubtitleMenu();
gSubtitleMenu.render();
this.lastMovieId = manifest.movieId;
gSubtitles = buildSubtitleList(manifest.textTracks);

// select subtitle to match the default audio track
try {
const defaultAudioTrack = manifest.audioTracks.find(t => manifest.defaultMedia.indexOf(t.id) >= 0);
if (defaultAudioTrack) {
const bcp47 = defaultAudioTrack.bcp47;
let autoSubtitleId = gSubtitles.findIndex(t => (t.bcp47 === bcp47 && t.isCaption));
autoSubtitleId = (autoSubtitleId < 0) ? gSubtitles.findIndex(t => t.bcp47 === bcp47) : autoSubtitleId;
if (autoSubtitleId >= 0) {
console.log(`Subtitle "${bcp47}" auto-enabled to match audio`);
activateSubtitle(autoSubtitleId);
}
gSubtitleMenu = new SubtitleMenu();
gSubtitleMenu.render();

// select subtitle to match the default audio track
try {
const defaultAudioTrack = manifest.audioTracks.find(t => manifest.defaultMedia.indexOf(t.id) >= 0);
if (defaultAudioTrack) {
const bcp47 = defaultAudioTrack.bcp47;
let autoSubtitleId = gSubtitles.findIndex(t => (t.bcp47 === bcp47 && t.isCaption));
autoSubtitleId = (autoSubtitleId < 0) ? gSubtitles.findIndex(t => t.bcp47 === bcp47) : autoSubtitleId;
if (autoSubtitleId >= 0) {
console.log(`Subtitle "${bcp47}" auto-enabled to match audio`);
activateSubtitle(autoSubtitleId);
}
}
catch (err) {
console.error('Default audio track not found, ', err);
}
}
catch (err) {
console.error('Default audio track not found, ', err);
}

// retrieve video ratio
try {
let { width, height } = manifest.videoTracks[0].downloadables[0];
gVideoRatio = height / width;
}
catch (err) {
console.error('Video ratio not available, ', err);
}
// retrieve video ratio
try {
let { width, height } = manifest.videoTracks[0].downloadables[0];
gVideoRatio = height / width;
}
catch (err) {
console.error('Video ratio not available, ', err);
}
}
catch (err) {
Expand Down

0 comments on commit 42fecfa

Please sign in to comment.