Force timestamps using --timestamps-only
This commit is contained in:
parent
b0fd29cbdb
commit
10981c62ce
6
index.js
6
index.js
|
@ -22,6 +22,8 @@ if (argv._.length <1 || argv.help ){
|
||||||
|
|
||||||
where $VIDEOTITLE is the title of the YouTube video.
|
where $VIDEOTITLE is the title of the YouTube video.
|
||||||
|
|
||||||
|
--timestamps-only Do not try to parse the timestamps as track durations
|
||||||
|
|
||||||
Examples
|
Examples
|
||||||
$ youtube-cue --audio-file audio.m4a "https://www.youtube.com/watch?v=THzUassmQwE"
|
$ youtube-cue --audio-file audio.m4a "https://www.youtube.com/watch?v=THzUassmQwE"
|
||||||
"T A Y L O R S W I F T – Folklore [Full album].cue" saved
|
"T A Y L O R S W I F T – Folklore [Full album].cue" saved
|
||||||
|
@ -35,13 +37,15 @@ if (argv._.length <1 || argv.help ){
|
||||||
|
|
||||||
let output_file = argv._[1]? argv._[1] : `${info.videoDetails.title}.cue`
|
let output_file = argv._[1]? argv._[1] : `${info.videoDetails.title}.cue`
|
||||||
|
|
||||||
|
let timestampsOnly = argv['timestamps-only']? argv['timestamps-only'] : false;
|
||||||
|
|
||||||
let res = getArtistTitle(info.videoDetails.title,{
|
let res = getArtistTitle(info.videoDetails.title,{
|
||||||
defaultArtist: "Unknown Artist",
|
defaultArtist: "Unknown Artist",
|
||||||
defaultTitle: info.videoDetails.title
|
defaultTitle: info.videoDetails.title
|
||||||
});
|
});
|
||||||
let [artist, album] = res
|
let [artist, album] = res
|
||||||
artist = (info.videoDetails.media ? info.videoDetails.media.artist : artist)
|
artist = (info.videoDetails.media ? info.videoDetails.media.artist : artist)
|
||||||
let tracks = parse(info.videoDetails.description, {artist})
|
let tracks = parse(info.videoDetails.description, {artist,timestampsOnly})
|
||||||
generate({tracks, artist, audioFile, album}, output_file)
|
generate({tracks, artist, audioFile, album}, output_file)
|
||||||
console.log(`"${output_file}" saved`)
|
console.log(`"${output_file}" saved`)
|
||||||
})
|
})
|
||||||
|
|
|
@ -128,6 +128,9 @@ var timeToObject = function(obj) {
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Instead of timestamps, some tracklists use durations
|
||||||
|
// If durations are provided, use them to re-calculate
|
||||||
|
// the starting and ending timestamps
|
||||||
var fixDurations = function(list) {
|
var fixDurations = function(list) {
|
||||||
for (let i in list) {
|
for (let i in list) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
|
@ -149,7 +152,7 @@ var fixDurations = function(list) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export function parse(text, options = { artist: "Unknown" }) {
|
export function parse(text, options = { artist: "Unknown", timestampsOnly : false }) {
|
||||||
_options = options;
|
_options = options;
|
||||||
let durations = false;
|
let durations = false;
|
||||||
let result = text
|
let result = text
|
||||||
|
@ -158,18 +161,21 @@ export function parse(text, options = { artist: "Unknown" }) {
|
||||||
.map(firstPass)
|
.map(firstPass)
|
||||||
.map(calcTimestamp);
|
.map(calcTimestamp);
|
||||||
|
|
||||||
result.forEach((current, index, list) => {
|
if (options.timestampsOnly == false) {
|
||||||
if (index > 0) {
|
// If our timestamps are not in increasing order
|
||||||
let previous = list[index - 1];
|
// Assume that we've been given a duration list instead
|
||||||
if (current.start.calc < previous.start.calc) {
|
result.forEach((current, index, list) => {
|
||||||
durations = true;
|
if (index > 0) {
|
||||||
|
let previous = list[index - 1];
|
||||||
|
if (current.start.calc < previous.start.calc) {
|
||||||
|
durations = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
if (durations) {
|
if (durations) {
|
||||||
// console.error("Detected durations instead of timestamps. \nIf this is incorrect, pass the --timestamps-only flag and create an issue at \nhttps://github.com/captn3m0/youtube-cue/issues/new/choose")
|
fixDurations(result);
|
||||||
fixDurations(result);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -65,46 +65,74 @@ describe("Parser", function() {
|
||||||
|
|
||||||
it("should parse timestamps with square brackets", function() {
|
it("should parse timestamps with square brackets", function() {
|
||||||
let result = parse(`[00:00:00] 1. Steve Kroeger x Skye Holland - Through The Dark
|
let result = parse(`[00:00:00] 1. Steve Kroeger x Skye Holland - Through The Dark
|
||||||
[00:02:53] 2. Gabri Ponte x Jerome - Lonely `)
|
[00:02:53] 2. Gabri Ponte x Jerome - Lonely `);
|
||||||
assert.deepEqual(result[0], {
|
assert.deepEqual(result[0], {
|
||||||
artist: "Steve Kroeger x Skye Holland",
|
artist: "Steve Kroeger x Skye Holland",
|
||||||
title: "Through The Dark",
|
title: "Through The Dark",
|
||||||
track: 1,
|
track: 1,
|
||||||
start: { ts: "00:00:00", hh: 0, mm: 0, ss: 0, calc: 0 },
|
start: { ts: "00:00:00", hh: 0, mm: 0, ss: 0, calc: 0 },
|
||||||
end: { ts: "00:02:53", hh: 0, mm: 2, ss: 53, calc: 173 },
|
end: { ts: "00:02:53", hh: 0, mm: 2, ss: 53, calc: 173 },
|
||||||
_: { left_text: "", right_text: "Steve Kroeger x Skye Holland - Through The Dark" },
|
_: {
|
||||||
})
|
left_text: "",
|
||||||
|
right_text: "Steve Kroeger x Skye Holland - Through The Dark",
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should parse durations when given", function() {
|
it("should parse durations when given", function() {
|
||||||
let result = parse(`1. Artist - Title 6:19
|
let result = parse(`1. Artist - Title 6:19
|
||||||
2. Another Artist - Another Title 6:59
|
2. Another Artist - Another Title 6:59
|
||||||
3. Yet Another Artist - Yet another title 5:12`)
|
3. Yet Another Artist - Yet another title 5:12`);
|
||||||
assert.deepEqual(result[0], {
|
assert.deepEqual(result[0], {
|
||||||
artist: "Artist",
|
artist: "Artist",
|
||||||
title: "Title",
|
title: "Title",
|
||||||
track: 1,
|
track: 1,
|
||||||
start: { ts: "00:00:00", hh: 0, mm: 0, ss: 0, calc: 0 },
|
start: { ts: "00:00:00", hh: 0, mm: 0, ss: 0, calc: 0 },
|
||||||
end: { ts: "00:06:19", hh: 0, mm: 6, ss: 19, calc: 379 },
|
end: { ts: "00:06:19", hh: 0, mm: 6, ss: 19, calc: 379 },
|
||||||
_: { left_text: "Artist - Title", right_text: "" },
|
_: { left_text: "Artist - Title", right_text: "" },
|
||||||
})
|
});
|
||||||
|
|
||||||
assert.deepEqual(result[1], {
|
assert.deepEqual(result[1], {
|
||||||
artist: "Another Artist",
|
artist: "Another Artist",
|
||||||
title: "Another Title",
|
title: "Another Title",
|
||||||
track: 2,
|
track: 2,
|
||||||
start: { ts: "00:06:19", hh: 0, mm: 6, ss: 19, calc: 379 },
|
start: { ts: "00:06:19", hh: 0, mm: 6, ss: 19, calc: 379 },
|
||||||
end: { ts: "00:13:18", hh: 0, mm: 13, ss: 18, calc: 798 },
|
end: { ts: "00:13:18", hh: 0, mm: 13, ss: 18, calc: 798 },
|
||||||
_: { left_text: "Another Artist - Another Title", right_text: "" },
|
_: { left_text: "Another Artist - Another Title", right_text: "" },
|
||||||
})
|
});
|
||||||
assert.deepEqual(result[2], {
|
assert.deepEqual(result[2], {
|
||||||
artist: "Yet Another Artist",
|
artist: "Yet Another Artist",
|
||||||
title: "Yet another title",
|
title: "Yet another title",
|
||||||
track: 3,
|
track: 3,
|
||||||
start: { ts: "00:13:18", hh: 0, mm: 13, ss: 18, calc: 798 },
|
start: { ts: "00:13:18", hh: 0, mm: 13, ss: 18, calc: 798 },
|
||||||
end: { ts: "00:18:30", hh: 0, mm: 18, ss: 30, calc: 1110 },
|
end: { ts: "00:18:30", hh: 0, mm: 18, ss: 30, calc: 1110 },
|
||||||
_: { left_text: "Yet Another Artist - Yet another title", right_text: "" },
|
_: {
|
||||||
})
|
left_text: "Yet Another Artist - Yet another title",
|
||||||
|
right_text: "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should parse durations as timestamps when forced", function() {
|
||||||
|
let result = parse(
|
||||||
|
`1. Artist - Title 5:00
|
||||||
|
2. Another Artist - Another Title 4:20`,
|
||||||
|
{ timestampsOnly: true }
|
||||||
|
);
|
||||||
|
assert.deepEqual(result[0].end, {
|
||||||
|
ts: "00:4:20",
|
||||||
|
hh: 0,
|
||||||
|
mm: 4,
|
||||||
|
ss: 20,
|
||||||
|
calc: 260,
|
||||||
|
});
|
||||||
|
assert.deepEqual(result[1].start, {
|
||||||
|
ts: "00:4:20",
|
||||||
|
hh: 0,
|
||||||
|
mm: 4,
|
||||||
|
ss: 20,
|
||||||
|
calc: 260,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should parse taylor swift", function() {
|
it("should parse taylor swift", function() {
|
||||||
|
|
Loading…
Reference in New Issue