Updates to everything
This commit is contained in:
parent
619b5f88ad
commit
32156d2193
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
|
@ -6,16 +6,16 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha"
|
"test": "mocha"
|
||||||
},
|
},
|
||||||
"author": "Nemo <me@captnemo.in>",
|
"author": "Nemo <npm@captnemo.in>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"mocha": "^8.1.0"
|
"mocha": "^8.4.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"console-log-level": "^1.4.1",
|
"console-log-level": "^1.4.1",
|
||||||
"get-artist-title": "^1.2.0",
|
"get-artist-title": "^1.3.1",
|
||||||
"meow": "^7.0.1",
|
"meow": "^10.0.0",
|
||||||
"ora": "^2.1.0"
|
"ora": "^5.4.0"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
@ -1,37 +1,74 @@
|
||||||
|
const utils = require('./utils');
|
||||||
var colors = require('mocha/lib/reporters/base').colors;
|
var colors = require('mocha/lib/reporters/base').colors;
|
||||||
|
|
||||||
colors['pass'] = '30;42';
|
colors['pass'] = '30;42';
|
||||||
|
|
||||||
/*jshint esversion: 6 */
|
/*jshint esversion: 6 */
|
||||||
const TS_REGEX = /((\d{1,2}:)?\d{1,2}:\d{1,2})/;
|
/**
|
||||||
|
* https://regex101.com/r/LEPUGb/1/
|
||||||
|
* This regex parses out the following groups:
|
||||||
|
* tracknumber at the start of the line, optional
|
||||||
|
* start_ts: complete track start timestamp (hh:mm:ss) (mm:ss is minimum)
|
||||||
|
* start_hh: starting hh, optional
|
||||||
|
* start_mm: starting minutes, required
|
||||||
|
* start_ss: starting seconds, required
|
||||||
|
*
|
||||||
|
* end_ts: complete track end timestamp (hh:mm:ss) (mm:ss is minimum to match). optional
|
||||||
|
* end:hh: track end hour, optional
|
||||||
|
* end:mm: track end minute, optional
|
||||||
|
* end:ss: track end seconds, optional
|
||||||
|
*
|
||||||
|
* text_1: text found to the left of the timestamp
|
||||||
|
* text_2: text found to the right of the timestamp
|
||||||
|
*
|
||||||
|
* It is suggested to check their lengths and pick one to parse as the Track Title
|
||||||
|
*/
|
||||||
|
const TS_REGEX = /^((?<track>\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}))? *(?<text_2>.*?)$/;
|
||||||
const getArtistTitle = require('get-artist-title');
|
const getArtistTitle = require('get-artist-title');
|
||||||
var _options = {};
|
var _options = {};
|
||||||
|
|
||||||
var filterTimestamp = function(line) {
|
var filterTimestamp = function(line) {
|
||||||
return TS_REGEX.test(line);
|
return TS_REGEX.test(line)
|
||||||
};
|
};
|
||||||
|
|
||||||
var parseTimeStamp = function(line) {
|
var parse = function(line) {
|
||||||
let matches = line.match(TS_REGEX);
|
let matches = line.match(TS_REGEX);
|
||||||
return {
|
return {
|
||||||
timestamp: matches[0],
|
track: parseInt(matches.groups['track'], 10),
|
||||||
text: matches.input,
|
start: {
|
||||||
};
|
ts: matches.groups['start_ts'],
|
||||||
|
hh: matches.groups['start_hh'] ? +matches.groups['start_hh'] : 0,
|
||||||
|
// These 2 are always set
|
||||||
|
mm: +matches.groups['start_mm'],
|
||||||
|
ss: +matches.groups['start_ss'],
|
||||||
|
},
|
||||||
|
end: (matches.groups['end_ts']!==undefined ? {
|
||||||
|
ts: matches.groups['end_ts']? matches.groups['end_ts'] : null,
|
||||||
|
hh: matches.groups['end_hh']? +matches.groups['end_hh'] : 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'],
|
||||||
|
right_text: matches.groups['text_2']
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var calcTimestamp = function(obj) {
|
||||||
|
if(obj.end) {
|
||||||
|
obj.end.calc = utils.convertTime(obj.end.hh,obj.end.mm,obj.end.ss)
|
||||||
|
}
|
||||||
|
obj.start.calc = utils.convertTime(obj.start.hh,obj.start.mm,obj.start.ss)
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
var parseTitle = function(obj) {
|
var parseTitle = function(obj) {
|
||||||
let i = obj.text.indexOf(obj.timestamp);
|
let title = obj._.left_text.length > obj._.right_text.length
|
||||||
// See to the left of i and right of i
|
? obj._.left_text : obj._.right_text;
|
||||||
let left = obj.text.substr(0, i);
|
|
||||||
let right = obj.text.substr(i + obj.timestamp.length);
|
|
||||||
|
|
||||||
// Ties break in favor of right, right?
|
return Object.assign({title: title}, obj)
|
||||||
let title = left.length > right.length ? left : right;
|
}
|
||||||
|
|
||||||
title = title.trim();
|
|
||||||
|
|
||||||
return Object.assign({ title: title }, obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
var parseArtist = function(obj) {
|
var parseArtist = function(obj) {
|
||||||
let [artist, title] = getArtistTitle(obj.title, {
|
let [artist, title] = getArtistTitle(obj.title, {
|
||||||
|
@ -46,7 +83,8 @@ module.exports = {
|
||||||
return text
|
return text
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.filter(filterTimestamp)
|
.filter(filterTimestamp)
|
||||||
.map(parseTimeStamp)
|
.map(parse)
|
||||||
|
.map(calcTimestamp)
|
||||||
.map(parseTitle)
|
.map(parseTitle)
|
||||||
.map(parseArtist);
|
.map(parseArtist);
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
module.exports = {
|
||||||
|
convertTime : (h,m,s) => {
|
||||||
|
return hms = (+h) * 60 * 60 + (+m) * 60 + (+s)
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,7 +5,7 @@ var ffmpeg = require('../src/ffmpeg');
|
||||||
describe('ffmpeg', function() {
|
describe('ffmpeg', function() {
|
||||||
describe('setup', function() {
|
describe('setup', function() {
|
||||||
it('should figure out if ffmpeg is installed', function() {
|
it('should figure out if ffmpeg is installed', function() {
|
||||||
assert.equal(parser.parse(TEXT).length, 3);
|
// assert.equal(parser.parse(TEXT).length, 3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,19 +7,46 @@ const TEXT = `
|
||||||
12:23 This is not the end
|
12:23 This is not the end
|
||||||
Something else in the middle
|
Something else in the middle
|
||||||
1:23:11 Not the last song
|
1:23:11 Not the last song
|
||||||
|
01. Screens 0:00 - 5:40
|
||||||
|
02. Inharmonious Slog 5:40 - 10:11
|
||||||
|
03. The Everyday Push 10:11 - 15:46
|
||||||
|
04. Storm 15:46 - 19:07
|
||||||
|
05. Outre Lux 19:07 - 23:11
|
||||||
|
06. Balsam Massacre 23:11 - 26:24
|
||||||
|
07. Eco Friend 26:24 - 32:15
|
||||||
|
08. Off-Piste 32:15 - 36:53
|
||||||
|
09. Aura 36:53 - 41:44
|
||||||
|
10. Bombogenesis 41:44 - 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() {
|
||||||
describe('parser', function() {
|
describe('parser', function() {
|
||||||
|
var big_result;
|
||||||
|
before(function() {
|
||||||
|
big_result = parser.parse(TEXT)
|
||||||
|
});
|
||||||
it('should find all timestamps', function() {
|
it('should find all timestamps', function() {
|
||||||
assert.equal(parser.parse(TEXT).length, 3);
|
assert.equal(big_result.length, 13);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should find artist names', function() {
|
it('should find artist names', function() {
|
||||||
let result = parser.parse(TEXT_WITH_ARTIST);
|
let result = parser.parse(TEXT_WITH_ARTIST);
|
||||||
assert.equal(result[0].artist, 'Rolling Stones');
|
assert.equal(result[0].artist, 'Rolling Stones');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should find track numbers', function() {
|
||||||
|
assert.equal(big_result[3].track, 1)
|
||||||
|
assert.equal(big_result[4].track, 2)
|
||||||
|
assert.equal(big_result[5].track, 3)
|
||||||
|
assert.equal(big_result[6].track, 4)
|
||||||
|
assert.equal(big_result[7].track, 5)
|
||||||
|
assert.equal(big_result[8].track, 6)
|
||||||
|
assert.equal(big_result[9].track, 7)
|
||||||
|
assert.equal(big_result[10].track, 8)
|
||||||
|
assert.equal(big_result[11].track, 9)
|
||||||
|
assert.equal(big_result[12].track, 10)
|
||||||
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue