[style] Run everything through prettier
This commit is contained in:
parent
bcae4ebeb1
commit
9cc3cd4228
50
index.js
50
index.js
|
@ -1,13 +1,13 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
import ytdl from 'ytdl-core';
|
import ytdl from "ytdl-core";
|
||||||
import getArtistTitle from 'get-artist-title'
|
import getArtistTitle from "get-artist-title";
|
||||||
import {parse} from './src/parser.js'
|
import { parse } from "./src/parser.js";
|
||||||
import {generate} from './src/cue.js'
|
import { generate } from "./src/cue.js";
|
||||||
import minimist from 'minimist'
|
import minimist from "minimist";
|
||||||
import exit from 'process'
|
import exit from "process";
|
||||||
|
|
||||||
let argv = minimist(process.argv.slice(2), {
|
let argv = minimist(process.argv.slice(2), {
|
||||||
string: 'audio-file'
|
string: "audio-file",
|
||||||
});
|
});
|
||||||
|
|
||||||
if (argv._.length < 1 || argv.help) {
|
if (argv._.length < 1 || argv.help) {
|
||||||
|
@ -36,32 +36,38 @@ if (argv._.length <1 || argv.help ){
|
||||||
$ 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
|
||||||
$ youtube-cue "https://youtu.be/THzUassmQwE" folklore.cue
|
$ youtube-cue "https://youtu.be/THzUassmQwE" folklore.cue
|
||||||
folklore.cue saved`)
|
folklore.cue saved`);
|
||||||
} else {
|
} else {
|
||||||
let url = argv._[0]
|
let url = argv._[0];
|
||||||
|
|
||||||
ytdl.getInfo(url).then(info=>{
|
ytdl.getInfo(url).then((info) => {
|
||||||
let audioFile = argv['audio-file']? argv['audio-file'] : `${info.videoDetails.title}.m4a`
|
let audioFile = argv["audio-file"]
|
||||||
|
? argv["audio-file"]
|
||||||
|
: `${info.videoDetails.title}.m4a`;
|
||||||
|
|
||||||
let output_file = argv._[1]? argv._[1] : `${info.videoDetails.title}.cue`
|
let output_file = argv._[1] ? argv._[1] : `${info.videoDetails.title}.cue`;
|
||||||
|
|
||||||
let forceTimestamps = argv['timestamps']? argv['timestamps'] : false;
|
let forceTimestamps = argv["timestamps"] ? argv["timestamps"] : false;
|
||||||
|
|
||||||
let forceDurations = argv['durations']? argv['durations'] : false;
|
let forceDurations = argv["durations"] ? argv["durations"] : false;
|
||||||
|
|
||||||
if (forceTimestamps && forceDurations) {
|
if (forceTimestamps && forceDurations) {
|
||||||
console.error("You can't pass both --timestamps and durations");
|
console.error("You can't pass both --timestamps and durations");
|
||||||
exit(1)
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
artist = info.videoDetails.media ? info.videoDetails.media.artist : artist;
|
||||||
|
let tracks = parse(info.videoDetails.description, {
|
||||||
|
artist,
|
||||||
|
forceTimestamps,
|
||||||
|
forceDurations,
|
||||||
|
});
|
||||||
|
generate({ tracks, artist, audioFile, album }, output_file);
|
||||||
|
console.log(`"${output_file}" saved`);
|
||||||
});
|
});
|
||||||
let [artist, album] = res
|
|
||||||
artist = (info.videoDetails.media ? info.videoDetails.media.artist : artist)
|
|
||||||
let tracks = parse(info.videoDetails.description, {artist, forceTimestamps, forceDurations})
|
|
||||||
generate({tracks, artist, audioFile, album}, output_file)
|
|
||||||
console.log(`"${output_file}" saved`)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
11
src/cue.js
11
src/cue.js
|
@ -1,9 +1,9 @@
|
||||||
import fs from 'fs';
|
import fs from "fs";
|
||||||
|
|
||||||
// https://en.wikipedia.org/wiki/Cue_sheet_(computing)
|
// https://en.wikipedia.org/wiki/Cue_sheet_(computing)
|
||||||
export function generate(data, outputFile) {
|
export function generate(data, outputFile) {
|
||||||
try {
|
try {
|
||||||
fs.truncateSync(outputFile)
|
fs.truncateSync(outputFile);
|
||||||
} catch {}
|
} catch {}
|
||||||
fs.appendFileSync(outputFile, `REM Generated using youtube-cue\n`);
|
fs.appendFileSync(outputFile, `REM Generated using youtube-cue\n`);
|
||||||
fs.appendFileSync(outputFile, `PERFORMER "${data.artist}"\n`);
|
fs.appendFileSync(outputFile, `PERFORMER "${data.artist}"\n`);
|
||||||
|
@ -11,11 +11,14 @@ export function generate(data, outputFile) {
|
||||||
fs.appendFileSync(outputFile, `FILE "${data.audioFile}" M4A\n`);
|
fs.appendFileSync(outputFile, `FILE "${data.audioFile}" M4A\n`);
|
||||||
for (var i in data.tracks) {
|
for (var i in data.tracks) {
|
||||||
let song = data.tracks[i];
|
let song = data.tracks[i];
|
||||||
let minutes = (song.start.hh * 60) + (song.start.mm)
|
let minutes = song.start.hh * 60 + song.start.mm;
|
||||||
fs.appendFileSync(outputFile, ` TRACK ${song.track} AUDIO\n`);
|
fs.appendFileSync(outputFile, ` TRACK ${song.track} AUDIO\n`);
|
||||||
fs.appendFileSync(outputFile, ` TITLE "${song.title}"\n`);
|
fs.appendFileSync(outputFile, ` TITLE "${song.title}"\n`);
|
||||||
fs.appendFileSync(outputFile, ` PERFORMER "${song.artist}"\n`);
|
fs.appendFileSync(outputFile, ` PERFORMER "${song.artist}"\n`);
|
||||||
// Cue File is always MINUTES:SECONDS:FRAME, where FRAME is 00
|
// Cue File is always MINUTES:SECONDS:FRAME, where FRAME is 00
|
||||||
fs.appendFileSync(outputFile, ` INDEX 01 ${minutes}:${song.start.ss}:00\n`);
|
fs.appendFileSync(
|
||||||
|
outputFile,
|
||||||
|
` INDEX 01 ${minutes}:${song.start.ss}:00\n`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,8 @@
|
||||||
*
|
*
|
||||||
* It is suggested to check their lengths and pick one to parse as the Track Title
|
* It is suggested to check their lengths and pick one to parse as the Track Title
|
||||||
*/
|
*/
|
||||||
const TS_REGEX = /^((?<trackl>\d{1,3})\.)? *(?<text_1>.*?) *[\(\[]?(?<start_ts>((?<start_hh>\d{1,2}):)?(?<start_mm>\d{1,2}):(?<start_ss>\d{1,2})) *-? *[\)\]]?(?<end_ts>(?<end_hh>\d{1,2}:)?(?<end_mm>\d{1,2}):(?<end_ss>\d{1,2}))? *((?<trackr>\d{1,3})\.)? *(?<text_2>.*?)$/;
|
const TS_REGEX =
|
||||||
|
/^((?<trackl>\d{1,3})\.)? *(?<text_1>.*?) *[\(\[]?(?<start_ts>((?<start_hh>\d{1,2}):)?(?<start_mm>\d{1,2}):(?<start_ss>\d{1,2})) *-? *[\)\]]?(?<end_ts>(?<end_hh>\d{1,2}:)?(?<end_mm>\d{1,2}):(?<end_ss>\d{1,2}))? *((?<trackr>\d{1,3})\.)? *(?<text_2>.*?)$/;
|
||||||
import getArtistTitle from "get-artist-title";
|
import getArtistTitle from "get-artist-title";
|
||||||
var _options = {};
|
var _options = {};
|
||||||
|
|
||||||
|
@ -183,9 +184,5 @@ export function parse(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result.map(parseTitle).map(parseArtist).map(addTrack).map(addEnd);
|
||||||
.map(parseTitle)
|
|
||||||
.map(parseArtist)
|
|
||||||
.map(addTrack)
|
|
||||||
.map(addEnd);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,8 @@ 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",
|
||||||
|
@ -140,7 +141,10 @@ describe("Parser", function() {
|
||||||
track: 3,
|
track: 3,
|
||||||
end: null,
|
end: null,
|
||||||
start: { ts: "00:02:00", hh: 0, mm: 2, ss: 0, calc: 120 },
|
start: { ts: "00:02:00", hh: 0, mm: 2, ss: 0, calc: 120 },
|
||||||
_: { left_text: "Yet Another Artist - Yet another title", right_text: "" },
|
_: {
|
||||||
|
left_text: "Yet Another Artist - Yet another title",
|
||||||
|
right_text: "",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue