-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebvtt.js
60 lines (50 loc) · 1.41 KB
/
webvtt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env node
var parser = require( "../lib/parser" ),
fs = require( "fs" ),
program = require( "commander" );
program
.version( "0.0.1" )
.usage( "[options] <file...>" )
.option( "-s, --silent", "don't print errors messages" )
.parse( process.argv );
var filenames = program.args,
failed = false;
if( filenames.length < 1 ) {
console.log( "Missing input file(s)." );
console.log( "Usage: webvtt " + program.usage() );
process.exit( 1 );
}
filenames.forEach( function( filename ) {
try {
var stats = fs.statSync( filename );
if( !stats.isFile() ) {
console.log( "webvtt: %s: Not a file.", filename );
failed = true;
return;
}
} catch( e ) {
console.log( "webvtt: %s: No such file.", filename );
failed = true;
return;
}
var data = fs.readFileSync( filename, "utf-8" );
if( !data ) {
console.log( "webvtt: %s: Error - %s", filename, err.message );
failed = true;
return;
}
// Strip optional Unicode BOM character
data = data.replace( /^\uFEFF/, '' );
var r = ( new parser.WebVTTParser() ).parse( data ),
errors = r.errors,
error;
for( var i = 0; i < errors.length; i++ ) {
failed = true;
error = errors[ i ];
if( !program.silent ) {
// sourcefile:lineno.column: message
console.log( "%s:%s.%s: %s", filename, error.line, error.col|0, error.message );
}
}
});
process.exit( failed ? 1 : 0 );