Compare commits
83 Commits
Author | SHA1 | Date |
---|---|---|
Nemo | 4d1bea0d0f | |
Nemo | a94395ea9d | |
Nemo | 8019310674 | |
Nemo | 1a2d485d10 | |
dependabot[bot] | 7cce1333f1 | |
Nemo | 1b9a02fa20 | |
dependabot[bot] | cbc90f7110 | |
dependabot[bot] | b785434c45 | |
dependabot[bot] | 7c43700c11 | |
dependabot[bot] | 33741a50e7 | |
dependabot[bot] | 3bd269e517 | |
dependabot[bot] | 2a67cc7c0b | |
dependabot[bot] | 51a50b8a11 | |
dependabot[bot] | 7c97cc9bc3 | |
dependabot[bot] | ce3c11a820 | |
dependabot[bot] | d376b3ad3d | |
dependabot[bot] | 6af3c1da60 | |
dependabot[bot] | 68bf09689a | |
dependabot[bot] | 84c23243d3 | |
dependabot[bot] | 1e9bace48d | |
dependabot[bot] | 00af711bf6 | |
dependabot[bot] | 278aebf32f | |
dependabot[bot] | 1743561886 | |
Nemo | f4f0e4db76 | |
Nemo | 8a570f74ad | |
Nemo | 5ba24e95db | |
Nemo | 91242ce61f | |
Nemo | 34acfe769e | |
Nemo | 0012c3b083 | |
Nemo | 93321c6fb9 | |
Nemo | 25e0081c6d | |
Nemo | 9245d84332 | |
Nemo | bb11d6e9a8 | |
Nemo | ce4074f829 | |
dependabot[bot] | 25ff38e93e | |
dependabot[bot] | 343fbda261 | |
dependabot[bot] | f53aed7dec | |
dependabot[bot] | 531ad3de3f | |
dependabot[bot] | c185212b14 | |
dependabot[bot] | 869487e153 | |
Nemo | 98f17e55d3 | |
Nemo | f281a42a2e | |
Nemo | 242e08bc1b | |
dependabot[bot] | e83debe2bf | |
dependabot[bot] | 9925d6e578 | |
Nemo | 0986305a50 | |
Nemo | a08e1cd3b3 | |
dependabot[bot] | 4744bb604f | |
dependabot[bot] | 42a3dfb872 | |
Nemo | 8c3a3a7ec6 | |
dependabot[bot] | 3acd787d0d | |
dependabot[bot] | 4f136dcf42 | |
dependabot[bot] | 5b65a76e6c | |
dependabot[bot] | f6acc1bdd8 | |
dependabot[bot] | 1cb210d64c | |
dependabot[bot] | 666e802cfe | |
dependabot[bot] | 5046823854 | |
dependabot[bot] | 741d74ddf1 | |
dependabot[bot] | 67012ca4ac | |
Nemo | 8724ba85aa | |
Nemo | 68e53896b9 | |
Nemo | 30effce43b | |
Nemo | 2eadb53b8f | |
Nemo | 44e68fc140 | |
Nemo | 9cc3cd4228 | |
Nemo | bcae4ebeb1 | |
Nemo | e0f05fe646 | |
Nemo | 610c13fcef | |
Nemo | 089c46d978 | |
Nemo | 1aa0be59da | |
Nemo | c4b1b42461 | |
dependabot[bot] | a710658b49 | |
Nemo | a737d37105 | |
Nemo | 7247b7be66 | |
Nemo | 10981c62ce | |
Nemo | b0fd29cbdb | |
Nemo | deca378937 | |
Nemo | 3fdb7739ff | |
Nemo | ce845195cf | |
Nemo | d47844fe3b | |
Nemo | 3f9eb44d58 | |
Nemo | 3c916c93ec | |
Nemo | ecd52f60d1 |
|
@ -0,0 +1,3 @@
|
||||||
|
github: captn3m0
|
||||||
|
ko_fi: captn3m0
|
||||||
|
liberapay: captn3m0
|
|
@ -0,0 +1,29 @@
|
||||||
|
---
|
||||||
|
name: 'Bug Report: Incorrect CUE sheet'
|
||||||
|
about: Create a bug report if youtube-cue fails to work on a specific Youtube Video
|
||||||
|
title: "[BUG] Failed on a Youtube link"
|
||||||
|
labels: bug
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Youtube URL**
|
||||||
|
|
||||||
|
Type the Youtube URL you tried here.
|
||||||
|
|
||||||
|
**Command you ran**
|
||||||
|
|
||||||
|
Type the complete command you typed, such as:
|
||||||
|
|
||||||
|
youtube-cue https://www.youtube.com/watch?v=XsRAAp-Ivuc
|
||||||
|
|
||||||
|
**Output**
|
||||||
|
|
||||||
|
Give complete output here, if you got any
|
||||||
|
|
||||||
|
**Version Information**
|
||||||
|
|
||||||
|
Paste the output of `npm list -g --depth=0 youtube-cue` here
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
|
@ -0,0 +1,5 @@
|
||||||
|
blank_issues_enabled: true
|
||||||
|
contact_links:
|
||||||
|
- name: Need support?
|
||||||
|
url: https://github.com/captn3m0/youtube-cue/discussions/new?category=q-a
|
||||||
|
about: Please ask and answer questions here.
|
|
@ -0,0 +1,20 @@
|
||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this project
|
||||||
|
title: ''
|
||||||
|
labels: enhancement
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context or screenshots about the feature request here.
|
|
@ -1,13 +1,17 @@
|
||||||
on: push
|
on: push
|
||||||
name: Main Workflow
|
name: Main Workflow
|
||||||
jobs:
|
jobs:
|
||||||
runNpmStuff:
|
tests:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
node: ["18", "20", "21"]
|
||||||
name: Run NPM Stuff
|
name: Run NPM Stuff
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- uses: actions/setup-node@v2
|
- uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: '16'
|
node-version: ${{matrix.node}}
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm test
|
- run: npm run lint
|
||||||
|
- run: npm run test
|
||||||
|
|
39
CHANGELOG.md
39
CHANGELOG.md
|
@ -1,4 +1,5 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
|
@ -6,21 +7,57 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
## 1.0.4 - 2021-06-28
|
## 1.0.9
|
||||||
|
### Changed
|
||||||
|
- Dependency Updates
|
||||||
|
- Minimum NodeJS version is now v14
|
||||||
|
|
||||||
|
## 1.0.8
|
||||||
### Added
|
### Added
|
||||||
|
- Dependency Updates
|
||||||
|
|
||||||
|
## 1.0.7
|
||||||
|
### Added
|
||||||
|
- `--version` is now supported
|
||||||
|
- An update notification is shown if the package isn't latest.
|
||||||
|
|
||||||
|
## 1.0.6 - 2021-07-29
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Tracklists using duration instead of timestamps are now supported.
|
||||||
|
|
||||||
|
## 1.0.5 - 2021-07-21
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Dependency Updates
|
||||||
|
|
||||||
|
## 1.0.4 - 2021-06-28
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
- Support for timestamps in square brackets (#64)
|
- Support for timestamps in square brackets (#64)
|
||||||
- Improved formatting for helptext
|
- Improved formatting for helptext
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- output filename has a default value, and is now optional
|
- output filename has a default value, and is now optional
|
||||||
|
|
||||||
## 1.0.3 - 2021-06-28
|
## 1.0.3 - 2021-06-28
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Dependency Updates
|
- Dependency Updates
|
||||||
|
|
||||||
## 1.0.2 - 2021-06-10
|
## 1.0.2 - 2021-06-10
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Switches from `mocha` to `minimist` to parse arguments. Now down to 9 total (recursive) dependencies.
|
- Switches from `mocha` to `minimist` to parse arguments. Now down to 9 total (recursive) dependencies.
|
||||||
|
|
||||||
## 1.01 - 2021-06-10
|
## 1.01 - 2021-06-10
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Dependency Updates
|
- Dependency Updates
|
||||||
|
|
32
README.md
32
README.md
|
@ -1,4 +1,4 @@
|
||||||
# youtube-cue
|
# youtube-cue ![npm](https://img.shields.io/npm/v/youtube-cue) ![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/npm/youtube-cue) ![NPM](https://img.shields.io/npm/l/youtube-cue) ![Snyk Vulnerabilities for npm package](https://img.shields.io/snyk/vulnerabilities/npm/youtube-cue) [![Total Dependencies](https://img.shields.io/badge/Total%20Dependencies-4-orange)](https://www.npmjs.com/package/youtube-cue)
|
||||||
|
|
||||||
Generate CUE sheet from timestamps in youtube video description.
|
Generate CUE sheet from timestamps in youtube video description.
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ Generate CUE sheet from timestamps in youtube video description.
|
||||||
2. The video has timestamps in the video description.
|
2. The video has timestamps in the video description.
|
||||||
3. The video is publicly available on Youtube.
|
3. The video is publicly available on Youtube.
|
||||||
|
|
||||||
`youtube-cue` will read the video description, get the timestamps and generate a [CUE sheet][cue] accordingly.
|
`youtube-cue` will read the video description, get the timestamps and generate a [CUE sheet][cue] accordingly. It will also work if track durations are used instead of timestamps.
|
||||||
|
|
||||||
## Anti-features
|
## Anti-features
|
||||||
|
|
||||||
|
@ -31,21 +31,33 @@ For all of the above, there are better tools available, such as [youtube-dl](htt
|
||||||
|
|
||||||
You need to pass 2 parameters, a Youtube URL and a output CUE filename. YouTube short URLs (`youtu.be`) are accepted. You can additionally pass a `audio-file` argument which is used for the [`FILE` specified in the CUE file][cuefile].
|
You need to pass 2 parameters, a Youtube URL and a output CUE filename. YouTube short URLs (`youtu.be`) are accepted. You can additionally pass a `audio-file` argument which is used for the [`FILE` specified in the CUE file][cuefile].
|
||||||
|
|
||||||
$ youtube-cue [--audio-file audio.m4a] <youtube_url> <output.cue>
|
youtube-cue [--audio-file audio.m4a] <youtube_url> [output_file]
|
||||||
|
|
||||||
Options
|
Options
|
||||||
--help, Show help
|
--help, Show help
|
||||||
--audio-file, Input Audio File (optional)
|
--audio-file, Input Audio File (optional) that is written to the CUE sheet
|
||||||
|
|
||||||
|
The default audio file is set to %VIDEOTITLE.m4a
|
||||||
|
The default output file is set to %VIDEOTITLE.cue
|
||||||
|
|
||||||
|
where $VIDEOTITLE is the title of the YouTube video.
|
||||||
|
|
||||||
|
Generally the parser detects whether numbers are positional timestamps or track durations.
|
||||||
|
To enforce a desired interpretation you can use these flags:
|
||||||
|
|
||||||
|
--timestamps Parse as positional timestamps (relative to the start of the playlist)
|
||||||
|
--durations Parse as track durations
|
||||||
|
|
||||||
|
The above 2 are only needed to force behaviour in
|
||||||
|
very specific edge cases, they should not be required for most files.
|
||||||
|
|
||||||
Examples
|
Examples
|
||||||
$ youtube-cue --audio-file audio.m4a "https://www.youtube.com/watch?v=THzUassmQwE" output.cue
|
$ youtube-cue --audio-file audio.m4a "https://www.youtube.com/watch?v=WzpmVxvoBoc" "The Groovy Nobody - Solarium.cue"
|
||||||
output.cue saved
|
"The Groovy Nobody - Solarium.cue" saved
|
||||||
$ youtube-cue "https://youtu.be/THzUassmQwE" folklore.cue
|
|
||||||
folklore.cue saved
|
|
||||||
|
|
||||||
## Personal Usage
|
## Personal Usage
|
||||||
|
|
||||||
I have this in my `.bashrc` to download, split, tag, and import albums:
|
I have this in my `.bashrc` to download, split, tag, and import albums using beet:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
function ytdl.album() {
|
function ytdl.album() {
|
||||||
|
@ -61,7 +73,7 @@ function ytdl.album() {
|
||||||
|
|
||||||
## HACKING
|
## HACKING
|
||||||
|
|
||||||
- If this video does not work on a specific video, please attach the complete output
|
- If it does not work on a specific video, please attach the complete output
|
||||||
- Pull Requests are welcome that add support for a better parser without breaking the existing tests
|
- Pull Requests are welcome that add support for a better parser without breaking the existing tests
|
||||||
- Please add tests for any new functionality
|
- Please add tests for any new functionality
|
||||||
|
|
||||||
|
|
74
index.js
74
index.js
|
@ -1,15 +1,22 @@
|
||||||
#!/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 updateNotifier from "update-notifier";
|
||||||
|
import pkg from "./src/package.js";
|
||||||
|
|
||||||
|
updateNotifier({ pkg }).notify();
|
||||||
|
|
||||||
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.version) {
|
||||||
|
console.log(pkg.version);
|
||||||
|
} else if (argv._.length < 1 || argv.help) {
|
||||||
console.log(`Usage
|
console.log(`Usage
|
||||||
$ youtube-cue [--audio-file audio.m4a] <youtube_url> [output_file]
|
$ youtube-cue [--audio-file audio.m4a] <youtube_url> [output_file]
|
||||||
|
|
||||||
|
@ -22,27 +29,54 @@ if (argv._.length <1 || argv.help ){
|
||||||
|
|
||||||
where $VIDEOTITLE is the title of the YouTube video.
|
where $VIDEOTITLE is the title of the YouTube video.
|
||||||
|
|
||||||
|
Generally the parser detects whether numbers are positional timestamps or track durations.
|
||||||
|
To enforce a desired interpretation you can use these flags:
|
||||||
|
|
||||||
|
--timestamps Parse as positional timestamps (relative to the start of the playlist)
|
||||||
|
--durations Parse as track durations
|
||||||
|
|
||||||
|
The above 2 are only needed to force behaviour in very specific edge cases, they should
|
||||||
|
not be required for most files.
|
||||||
|
|
||||||
|
--version Print version
|
||||||
|
|
||||||
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
|
||||||
$ 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 res = getArtistTitle(info.videoDetails.title,{
|
let forceTimestamps = argv["timestamps"] ? argv["timestamps"] : false;
|
||||||
|
|
||||||
|
let forceDurations = argv["durations"] ? argv["durations"] : false;
|
||||||
|
|
||||||
|
if (forceTimestamps && forceDurations) {
|
||||||
|
console.error("You can't pass both --timestamps and durations");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
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, {
|
||||||
generate({tracks, artist, audioFile, album}, output_file)
|
artist,
|
||||||
console.log(`"${output_file}" saved`)
|
forceTimestamps,
|
||||||
})
|
forceDurations,
|
||||||
|
length: Number(info.videoDetails.lengthSeconds),
|
||||||
|
});
|
||||||
|
generate({ tracks, artist, audioFile, album }, output_file);
|
||||||
|
console.log(`"${output_file}" saved`);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
13
package.json
13
package.json
|
@ -1,22 +1,25 @@
|
||||||
{
|
{
|
||||||
"name": "youtube-cue",
|
"name": "youtube-cue",
|
||||||
"version": "1.0.4",
|
"version": "1.0.10",
|
||||||
"description": "Generates Cue sheet from Youtube URL",
|
"description": "Generates Cue sheet from Youtube URL",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha"
|
"test": "mocha",
|
||||||
|
"lint": "prettier --check *.js src/*.js test/*.js"
|
||||||
},
|
},
|
||||||
"bin": "index.js",
|
"bin": "index.js",
|
||||||
"author": "Nemo <npm@captnemo.in>",
|
"author": "Nemo <npm@captnemo.in>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"mocha": "^9.0.0"
|
"mocha": "^10.0.0",
|
||||||
|
"prettier": "^3.1.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"console-log-level": "^1.4.1",
|
"console-log-level": "^1.4.1",
|
||||||
"get-artist-title": "^1.3.1",
|
"get-artist-title": "^1.3.1",
|
||||||
"minimist": "^1.2.5",
|
"minimist": "^1.2.8",
|
||||||
"ytdl-core": "^4.8.2"
|
"update-notifier": "^7.0.0",
|
||||||
|
"ytdl-core": "^4.11.5"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
16
src/cue.js
16
src/cue.js
|
@ -1,21 +1,27 @@
|
||||||
import fs from 'fs';
|
import fs from "fs";
|
||||||
|
|
||||||
|
/** code to create a new CUE file, as per the standard
|
||||||
|
* with a REM PERFORMER, TITLE, FILE attribute
|
||||||
|
* and a list of tracks provided as input
|
||||||
|
*/
|
||||||
|
|
||||||
// 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`);
|
||||||
fs.appendFileSync(outputFile, `TITLE "${data.album}"\n`);
|
fs.appendFileSync(outputFile, `TITLE "${data.album}"\n`);
|
||||||
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 = String(song.start.hh * 60 + song.start.mm).padStart(2, "0");
|
||||||
|
let seconds = String(song.start.ss).padStart(2, "0");
|
||||||
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}:${seconds}:00\n`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { createRequire } from "module";
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
const data = require("../package.json");
|
||||||
|
|
||||||
|
export default data;
|
198
src/parser.js
198
src/parser.js
|
@ -20,94 +20,184 @@
|
||||||
*
|
*
|
||||||
* 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 =
|
||||||
import getArtistTitle from 'get-artist-title'
|
/^((?<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";
|
||||||
var _options = {};
|
var _options = {};
|
||||||
|
|
||||||
function convertTime(h,m,s) {
|
// Returns number of total seconds
|
||||||
return (+h) * 60 * 60 + (+m) * 60 + (+s)
|
function convertTime(h, m, s) {
|
||||||
|
return +h * 60 * 60 + +m * 60 + +s;
|
||||||
}
|
}
|
||||||
|
|
||||||
var filterTimestamp = function(line) {
|
// Only picks out lines which have a timestamp in them
|
||||||
return TS_REGEX.test(line)
|
var filterTimestamp = function (line) {
|
||||||
|
return TS_REGEX.test(line);
|
||||||
};
|
};
|
||||||
|
|
||||||
var firstPass = function(line) {
|
// Parse each line as per the regex
|
||||||
|
var firstPass = function (line) {
|
||||||
let matches = line.match(TS_REGEX);
|
let matches = line.match(TS_REGEX);
|
||||||
let track = matches.groups['trackl'] ? +matches.groups['trackl'] : (matches.groups['trackr'] ? +matches.groups['trackr'] : null)
|
let track = matches.groups["trackl"]
|
||||||
|
? +matches.groups["trackl"]
|
||||||
|
: matches.groups["trackr"]
|
||||||
|
? +matches.groups["trackr"]
|
||||||
|
: null;
|
||||||
return {
|
return {
|
||||||
track: track,
|
track: track,
|
||||||
start: {
|
start: {
|
||||||
ts: matches.groups['start_ts'].length<6 ? `00:${matches.groups['start_ts']}` : matches.groups['start_ts'],
|
ts:
|
||||||
hh: matches.groups['start_hh'] ? +matches.groups['start_hh'] : 0,
|
matches.groups["start_ts"].length < 6
|
||||||
|
? `00:${matches.groups["start_ts"]}`
|
||||||
|
: matches.groups["start_ts"],
|
||||||
|
hh: matches.groups["start_hh"] ? +matches.groups["start_hh"] : 0,
|
||||||
// These 2 are always set
|
// These 2 are always set
|
||||||
mm: +matches.groups['start_mm'],
|
mm: +matches.groups["start_mm"],
|
||||||
ss: +matches.groups['start_ss'],
|
ss: +matches.groups["start_ss"],
|
||||||
},
|
},
|
||||||
end: (matches.groups['end_ts']!==undefined ? {
|
end:
|
||||||
ts: matches.groups['end_ts']? matches.groups['end_ts'] : null,
|
matches.groups["end_ts"] !== undefined
|
||||||
hh: matches.groups['end_hh']? +matches.groups['end_hh'] : null,
|
? {
|
||||||
mm: matches.groups['end_mm']? +matches.groups['end_mm'] : null,
|
ts: matches.groups["end_ts"] ? matches.groups["end_ts"] : null,
|
||||||
ss: matches.groups['end_ss']? +matches.groups['end_ss'] : null,
|
hh: matches.groups["end_hh"] ? +matches.groups["end_hh"] : null,
|
||||||
} : null),
|
mm: matches.groups["end_mm"] ? +matches.groups["end_mm"] : null,
|
||||||
|
ss: matches.groups["end_ss"] ? +matches.groups["end_ss"] : null,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
_: {
|
_: {
|
||||||
left_text: matches.groups['text_1'],
|
left_text: matches.groups["text_1"],
|
||||||
right_text: matches.groups['text_2']
|
right_text: matches.groups["text_2"],
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var calcTimestamp = function(obj) {
|
// Add a calc attribute with total seconds
|
||||||
if(obj.end) {
|
var calcTimestamp = function (obj) {
|
||||||
obj.end.calc = convertTime(obj.end.hh,obj.end.mm,obj.end.ss)
|
if (obj.end) {
|
||||||
|
obj.end.calc = convertTime(obj.end.hh, obj.end.mm, obj.end.ss);
|
||||||
}
|
}
|
||||||
obj.start.calc = convertTime(obj.start.hh,obj.start.mm,obj.start.ss)
|
obj.start.calc = convertTime(obj.start.hh, obj.start.mm, obj.start.ss);
|
||||||
return obj
|
return obj;
|
||||||
}
|
};
|
||||||
|
|
||||||
var parseTitle = function(obj) {
|
// Pick the longer "text" from left or right side.
|
||||||
obj.title = obj._.left_text.length > obj._.right_text.length
|
var parseTitle = function (obj) {
|
||||||
? obj._.left_text : obj._.right_text;
|
obj.title =
|
||||||
return obj
|
obj._.left_text.length > obj._.right_text.length
|
||||||
}
|
? obj._.left_text
|
||||||
|
: obj._.right_text;
|
||||||
|
return obj;
|
||||||
|
};
|
||||||
|
|
||||||
var parseArtist = function(obj) {
|
// Parse the text as the title/artist
|
||||||
|
var parseArtist = function (obj) {
|
||||||
let [artist, title] = getArtistTitle(obj.title, {
|
let [artist, title] = getArtistTitle(obj.title, {
|
||||||
defaultArtist: _options.artist,
|
defaultArtist: _options.artist,
|
||||||
defaultTitle: obj.title
|
defaultTitle: obj.title,
|
||||||
});
|
});
|
||||||
obj.artist = artist
|
obj.artist = artist;
|
||||||
obj.title = title
|
obj.title = title;
|
||||||
return obj
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
var addTrack = function(obj, index) {
|
// If track numbers are not present, add them accordingly
|
||||||
if (obj.track==null) {
|
var addTrack = function (obj, index) {
|
||||||
obj.track = index+1
|
if (obj.track == null) {
|
||||||
|
obj.track = index + 1;
|
||||||
}
|
}
|
||||||
return obj
|
return obj;
|
||||||
}
|
};
|
||||||
|
|
||||||
var addEnd = function(obj, index, arr) {
|
// Add "end" timestamps as next start timestamps
|
||||||
|
var addEnd = function (obj, index, arr) {
|
||||||
if (!obj.end) {
|
if (!obj.end) {
|
||||||
if(arr.length!=index+1) {
|
if (arr.length != index + 1) {
|
||||||
let next = arr[index+1]
|
let next = arr[index + 1];
|
||||||
obj.end = next.start
|
obj.end = next.start;
|
||||||
return obj
|
return obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return obj
|
return obj;
|
||||||
}
|
};
|
||||||
|
|
||||||
export function parse (text, options = { artist: 'Unknown' }) {
|
var timeToObject = function (obj) {
|
||||||
|
let d = new Date(obj.calc * 1000).toISOString();
|
||||||
|
obj.hh = +d.substr(11, 2);
|
||||||
|
obj.mm = +d.substr(14, 2);
|
||||||
|
obj.ss = +d.substr(17, 2);
|
||||||
|
obj.ts = d.substr(11, 8);
|
||||||
|
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) {
|
||||||
|
for (let i in list) {
|
||||||
|
if (i == 0) {
|
||||||
|
// Set the first one to start of track.
|
||||||
|
list[i].start.hh = list[i].start.mm = list[i].start.ss = 0;
|
||||||
|
// And end at the right time
|
||||||
|
list[i].end = { calc: list[i].start.calc };
|
||||||
|
list[i].start.calc = 0;
|
||||||
|
} else {
|
||||||
|
// All the others tracks start at the end of the previous one
|
||||||
|
// And end at start time + duration
|
||||||
|
let previous = list[i - 1];
|
||||||
|
list[i].end = { calc: previous.end.calc + list[i].start.calc };
|
||||||
|
list[i].start.calc = previous.end.calc;
|
||||||
|
}
|
||||||
|
|
||||||
|
list[i].start = timeToObject(list[i].start);
|
||||||
|
list[i].end = timeToObject(list[i].end);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
) {
|
||||||
_options = options;
|
_options = options;
|
||||||
return text
|
let durations = false;
|
||||||
.split('\n')
|
let result = text
|
||||||
|
.split("\n")
|
||||||
.filter(filterTimestamp)
|
.filter(filterTimestamp)
|
||||||
.map(firstPass)
|
.map(firstPass)
|
||||||
.map(calcTimestamp)
|
.map(calcTimestamp);
|
||||||
|
|
||||||
|
if (!options.forceTimestamps) {
|
||||||
|
// If our timestamps are not in increasing order
|
||||||
|
// Assume that we've been given a duration list instead
|
||||||
|
if (result[0].start.calc != 0) {
|
||||||
|
result.forEach((current, index, list) => {
|
||||||
|
if (index > 0) {
|
||||||
|
let previous = list[index - 1];
|
||||||
|
if (current.start.calc < previous.start.calc) {
|
||||||
|
durations = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (durations || options.forceDurations == true) {
|
||||||
|
fixDurations(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
.map(parseTitle)
|
.map(parseTitle)
|
||||||
.map(parseArtist)
|
.map(parseArtist)
|
||||||
.map(addTrack)
|
.map(addTrack)
|
||||||
.map(addEnd)
|
.map(addEnd)
|
||||||
|
.filter(dropInvalid);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*jshint esversion: 6 */
|
||||||
|
import { strict as assert } from "assert";
|
||||||
|
import { generate } from "../src/cue.js";
|
||||||
|
import fs from "fs";
|
||||||
|
|
||||||
|
const DATA = {
|
||||||
|
artist: "Dumbledore",
|
||||||
|
album: "Curse of the Elder Wand",
|
||||||
|
audioFile: "audio.m4a",
|
||||||
|
tracks: [
|
||||||
|
{
|
||||||
|
artist: "Unknown",
|
||||||
|
title: "the 1",
|
||||||
|
track: 1,
|
||||||
|
start: { ts: "00:00:00", hh: 0, mm: 0, ss: 0, calc: 0 },
|
||||||
|
end: { ts: "00:3:9", hh: 0, mm: 3, ss: 9, calc: 189 },
|
||||||
|
_: { left_text: "", right_text: "the 1" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
artist: "Unknown",
|
||||||
|
title: "cardigan",
|
||||||
|
track: 2,
|
||||||
|
start: { ts: "00:3:09", hh: 0, mm: 3, ss: 9, calc: 189 },
|
||||||
|
end: { ts: "00:9:30", hh: 0, mm: 9, ss: 30, calc: 570 },
|
||||||
|
_: { left_text: "", right_text: "cardigan" },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("CUE", function () {
|
||||||
|
it("should generate with leading zeroes", function () {
|
||||||
|
generate(DATA, "/tmp/test.cue");
|
||||||
|
const CUE_EXPECTED = `REM Generated using youtube-cue
|
||||||
|
PERFORMER "Dumbledore"
|
||||||
|
TITLE "Curse of the Elder Wand"
|
||||||
|
FILE "audio.m4a" M4A
|
||||||
|
TRACK 1 AUDIO
|
||||||
|
TITLE "the 1"
|
||||||
|
PERFORMER "Unknown"
|
||||||
|
INDEX 01 00:00:00
|
||||||
|
TRACK 2 AUDIO
|
||||||
|
TITLE "cardigan"
|
||||||
|
PERFORMER "Unknown"
|
||||||
|
INDEX 01 03:09:00
|
||||||
|
`;
|
||||||
|
assert.equal(CUE_EXPECTED, fs.readFileSync("/tmp/test.cue", "utf-8"));
|
||||||
|
});
|
||||||
|
});
|
|
@ -5,10 +5,10 @@ import { parse } from "../src/parser.js";
|
||||||
|
|
||||||
const TEXT = `
|
const TEXT = `
|
||||||
00:40 The Coders - Hello World
|
00:40 The Coders - Hello World
|
||||||
12:23 This is not the end
|
1:00 This is not the end
|
||||||
Something else in the middle
|
Something else in the middle
|
||||||
1:23:11 Not the last song
|
1:23 Not the last song
|
||||||
01. Screens 0:00 - 5:40
|
01. Screens 1:40 - 5:40
|
||||||
02. Inharmonious Slog 5:40 - 10:11
|
02. Inharmonious Slog 5:40 - 10:11
|
||||||
03. The Everyday Push 10:11 - 15:46
|
03. The Everyday Push 10:11 - 15:46
|
||||||
04. Storm 15:46 - 19:07
|
04. Storm 15:46 - 19:07
|
||||||
|
@ -24,21 +24,21 @@ Hello World 48:20
|
||||||
|
|
||||||
const TEXT_WITH_ARTIST = "12:23 Rolling Stones - Hello World";
|
const TEXT_WITH_ARTIST = "12:23 Rolling Stones - Hello World";
|
||||||
|
|
||||||
describe("Parser", function() {
|
describe("Parser", function () {
|
||||||
var big_result;
|
var big_result;
|
||||||
before(function() {
|
before(function () {
|
||||||
big_result = parse(TEXT);
|
big_result = parse(TEXT);
|
||||||
});
|
});
|
||||||
it("should find all timestamps", function() {
|
it("should find all timestamps", function () {
|
||||||
assert.equal(big_result.length, 15);
|
assert.equal(big_result.length, 15);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should find artist names", function() {
|
it("should find artist names", function () {
|
||||||
let result = parse(TEXT_WITH_ARTIST);
|
let result = parse(TEXT_WITH_ARTIST);
|
||||||
assert.equal(result[0].artist, "Rolling Stones");
|
assert.equal(result[0].artist, "Rolling Stones");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should find track numbers", function() {
|
it("should find track numbers", function () {
|
||||||
assert.equal(big_result[3].track, 1);
|
assert.equal(big_result[3].track, 1);
|
||||||
assert.equal(big_result[4].track, 2);
|
assert.equal(big_result[4].track, 2);
|
||||||
assert.equal(big_result[5].track, 3);
|
assert.equal(big_result[5].track, 3);
|
||||||
|
@ -51,7 +51,7 @@ describe("Parser", function() {
|
||||||
assert.equal(big_result[12].track, 10);
|
assert.equal(big_result[12].track, 10);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should ensure ending timestamps for all", function() {
|
it("should ensure ending timestamps for all", function () {
|
||||||
assert.deepEqual(big_result[13].end, {
|
assert.deepEqual(big_result[13].end, {
|
||||||
calc: 3023,
|
calc: 3023,
|
||||||
hh: 0,
|
hh: 0,
|
||||||
|
@ -63,20 +63,162 @@ describe("Parser", function() {
|
||||||
assert.deepEqual(big_result[14].end, null);
|
assert.deepEqual(big_result[14].end, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
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 =
|
||||||
[00:02:53] 2. Gabri Ponte x Jerome - Lonely `)
|
parse(`[00:00:00] 1. Steve Kroeger x Skye Holland - Through The Dark
|
||||||
|
[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 taylor swift", function() {
|
it("should parse durations when given", function () {
|
||||||
|
let result = parse(`1. Artist - Title 6:19
|
||||||
|
2. Another Artist - Another Title 6:59
|
||||||
|
3. Yet Another Artist - Yet another title 5:12`);
|
||||||
|
assert.deepEqual(result[0], {
|
||||||
|
artist: "Artist",
|
||||||
|
title: "Title",
|
||||||
|
track: 1,
|
||||||
|
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 },
|
||||||
|
_: { left_text: "Artist - Title", right_text: "" },
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(result[1], {
|
||||||
|
artist: "Another Artist",
|
||||||
|
title: "Another Title",
|
||||||
|
track: 2,
|
||||||
|
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 },
|
||||||
|
_: { left_text: "Another Artist - Another Title", right_text: "" },
|
||||||
|
});
|
||||||
|
assert.deepEqual(result[2], {
|
||||||
|
artist: "Yet Another Artist",
|
||||||
|
title: "Yet another title",
|
||||||
|
track: 3,
|
||||||
|
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 },
|
||||||
|
_: {
|
||||||
|
left_text: "Yet Another Artist - Yet another title",
|
||||||
|
right_text: "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should parse as timestamps if first timestamp is 00:00", function () {
|
||||||
|
let result = parse(`1. Artist - Title 00:00
|
||||||
|
2. Another Artist - Another Title 01:00
|
||||||
|
3. Yet Another Artist - Yet another title 02:00`);
|
||||||
|
assert.deepEqual(result[0], {
|
||||||
|
artist: "Artist",
|
||||||
|
title: "Title",
|
||||||
|
track: 1,
|
||||||
|
start: { ts: "00:00:00", hh: 0, mm: 0, ss: 0, calc: 0 },
|
||||||
|
end: { ts: "00:01:00", hh: 0, mm: 1, ss: 0, calc: 60 },
|
||||||
|
_: { left_text: "Artist - Title", right_text: "" },
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(result[1], {
|
||||||
|
artist: "Another Artist",
|
||||||
|
title: "Another Title",
|
||||||
|
track: 2,
|
||||||
|
end: { ts: "00:02:00", hh: 0, mm: 2, ss: 0, calc: 120 },
|
||||||
|
start: { ts: "00:01:00", hh: 0, mm: 1, ss: 0, calc: 60 },
|
||||||
|
_: { left_text: "Another Artist - Another Title", right_text: "" },
|
||||||
|
});
|
||||||
|
assert.deepEqual(result[2], {
|
||||||
|
artist: "Yet Another Artist",
|
||||||
|
title: "Yet another title",
|
||||||
|
track: 3,
|
||||||
|
end: null,
|
||||||
|
start: { ts: "00:02:00", hh: 0, mm: 2, ss: 0, calc: 120 },
|
||||||
|
_: {
|
||||||
|
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`,
|
||||||
|
{ forceTimestamps: 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 timestamps as durations when forced", function () {
|
||||||
|
let result = parse(
|
||||||
|
`1. Artist - Title 1:00
|
||||||
|
2. Another Artist - Another Title 1:15`,
|
||||||
|
{ forceDurations: true },
|
||||||
|
);
|
||||||
|
assert.deepEqual(result[0], {
|
||||||
|
track: 1,
|
||||||
|
_: { left_text: "Artist - Title", right_text: "" },
|
||||||
|
title: "Title",
|
||||||
|
artist: "Artist",
|
||||||
|
end: {
|
||||||
|
ts: "00:01:00",
|
||||||
|
hh: 0,
|
||||||
|
mm: 1,
|
||||||
|
ss: 0,
|
||||||
|
calc: 60,
|
||||||
|
},
|
||||||
|
start: {
|
||||||
|
ts: "00:00:00",
|
||||||
|
hh: 0,
|
||||||
|
mm: 0,
|
||||||
|
ss: 0,
|
||||||
|
calc: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
assert.deepEqual(result[1], {
|
||||||
|
track: 2,
|
||||||
|
_: { left_text: "Another Artist - Another Title", right_text: "" },
|
||||||
|
title: "Another Title",
|
||||||
|
artist: "Another Artist",
|
||||||
|
start: {
|
||||||
|
ts: "00:01:00",
|
||||||
|
hh: 0,
|
||||||
|
mm: 1,
|
||||||
|
ss: 0,
|
||||||
|
calc: 60,
|
||||||
|
},
|
||||||
|
end: {
|
||||||
|
ts: "00:02:15",
|
||||||
|
hh: 0,
|
||||||
|
mm: 2,
|
||||||
|
ss: 15,
|
||||||
|
calc: 135,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should parse taylor swift", function () {
|
||||||
let result = parse(`0:00 the 1
|
let result = parse(`0:00 the 1
|
||||||
3:29 cardigan
|
3:29 cardigan
|
||||||
9:30 the last great american dynasty
|
9:30 the last great american dynasty
|
||||||
|
|
Loading…
Reference in New Issue