🏡 index : github.com/captn3m0/youtube-cue.git

author Nemo <commits@captnemo.in> 2022-08-26 18:33:00.0 +05:30:00
committer Nemo <commits@captnemo.in> 2022-08-26 18:33:06.0 +05:30:00
commit
5ba24e95db29fe6f55a9832f9efcbaf94b9f5c92 [patch]
tree
0e47d9047d84086351259c9f4828c9808d786039
parent
91242ce61f5032f14631e0736f455508a61b9f84
download
5ba24e95db29fe6f55a9832f9efcbaf94b9f5c92.tar.gz

Fixes #75

Drops any tracks that start after the track length (as per YouTube).
We can add a flag for making this optional in case it is needed

Diff

 index.js      | 2 +-
 src/parser.js | 8 ++++++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/index.js b/index.js
index 6a13e67..e94fe72 100755
--- a/index.js
+++ a/index.js
@@ -49,7 +49,6 @@
  let url = argv._[0];

  ytdl.getInfo(url).then((info) => {
    console.log(info);
    let audioFile = argv["audio-file"]
      ? argv["audio-file"]
      : `${info.videoDetails.title}.m4a`;
@@ -75,6 +74,7 @@
      artist,
      forceTimestamps,
      forceDurations,
      length: Number(info.videoDetails.lengthSeconds)
    });
    generate({ tracks, artist, audioFile, album }, output_file);
    console.log(`"${output_file}" saved`);
diff --git a/src/parser.js b/src/parser.js
index ad966d3..ea0d421 100644
--- a/src/parser.js
+++ a/src/parser.js
@@ -153,6 +153,12 @@
  }
};

var dropInvalid = function(e) {
  // All tracks should start before the closing time
  if (_options.length) return (e.start.calc < _options.length);
  return true;
}

export function parse(
  text,
  options = { artist: "Unknown", forceTimestamps: false, forceDurations: false }
@@ -184,5 +190,5 @@
    }
  }

  return result.map(parseTitle).map(parseArtist).map(addTrack).map(addEnd);
  return result.map(parseTitle).map(parseArtist).map(addTrack).map(addEnd).filter(dropInvalid);
}