-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcli.js
executable file
·151 lines (144 loc) · 5.19 KB
/
cli.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env node
const path = require('path');
const program = require('commander');
const info = require('./package.json');
const Metaflac = require('./index');
let file;
program.version(info.version, '-v, --version');
program.arguments('<FLACfile>').action((FLACfile) => {
file = FLACfile;
});
program.option('--show-md5sum', 'Show the MD5 signature from the STREAMINFO block.');
program.option('--show-min-blocksize', 'Show the minimum block size from the STREAMINFO block.');
program.option('--show-max-blocksize', 'Show the maximum block size from the STREAMINFO block.');
program.option('--show-min-framesize', 'Show the minimum frame size from the STREAMINFO block.');
program.option('--show-max-framesize', 'Show the maximum frame size from the STREAMINFO block.');
program.option('--show-sample-rate', 'Show the sample rate from the STREAMINFO block.');
program.option('--show-channels', 'Show the number of channels from the STREAMINFO block.');
program.option('--show-bps', 'Show the # of bits per sample from the STREAMINFO block.');
program.option('--show-total-samples', 'Show the total # of samples from the STREAMINFO block.');
program.option('--show-vendor-tag', 'Show the vendor string from the VORBIS_COMMENT block.');
program.option('--show-tag <NAME>', 'Show all tags where the the field name matches NAME.');
program.option('--remove-tag <NAME>', 'Remove all tags whose field name is NAME.');
program.option('--remove-first-tag <NAME>', 'Remove first tag whose field name is NAME.');
program.option('--remove-all-tags', 'Remove all tags, leaving only the vendor string.');
program.option(
'--set-tag <FIELD>',
'Add a tag. The FIELD must comply with the Vorbis comment spec, of the form NAME=VALUE. If there is currently no tag block, one will be created.'
);
program.option(
'--set-tag-from-file <FIELD>',
'Like --set-tag, except the VALUE is a filename whose contents will be read verbatim to set the tag value.'
);
program.option('--import-tags-from <FILE>', 'Import tags from a file.');
program.option(
'--export-tags-to <FILE>',
'Export tags to a file. Use - for stdout. Each line will be of the form NAME=VALUE.'
);
program.option('--import-picture-from <FILENAME>', 'Import a picture and store it in a PICTURE metadata block.');
program.option('--export-picture-to <FILE>', 'Export PICTURE block to a file.');
program.option('--list-picture', 'List all picture block info.');
program.parse(process.argv);
if (typeof file === 'undefined') {
console.error('ERROR: you must specify one FLAC file;');
process.exit(1);
}
try {
const flac = new Metaflac(file);
if (program.showMd5sum) {
console.log(flac.getMd5sum());
}
if (program.showMinBlocksize) {
console.log(flac.getMinBlocksize());
}
if (program.showMaxBlocksize) {
console.log(flac.getMaxBlocksize());
}
if (program.showMinFramesize) {
console.log(flac.getMinFramesize());
}
if (program.showMaxFramesize) {
console.log(flac.getMaxFramesize());
}
if (program.showSampleRate) {
console.log(flac.getSampleRate());
}
if (program.showChannels) {
console.log(flac.getChannels());
}
if (program.showBps) {
console.log(flac.getBps());
}
if (program.showTotalSamples) {
console.log(flac.getTotalSamples());
}
if (program.showVendorTag) {
console.log(flac.getVendorTag());
}
if (program.showTag) {
console.log(flac.getTag(program.showTag));
}
if (program.removeTag) {
flac.removeTag(program.removeTag);
console.log(flac.getAllTags().join('\n'));
}
if (program.removeFirstTag) {
flac.removeFirstTag(program.removeFirstTag);
console.log(flac.getAllTags().join('\n'));
}
if (program.removeAllTags) {
flac.removeAllTags();
console.log(flac.getAllTags().join('\n'));
}
if (program.setTag) {
flac.setTag(program.setTag);
console.log(flac.getAllTags().join('\n'));
flac.save();
}
if (program.setTagFromFile) {
flac.setTagFromFile(program.setTagFromFile);
console.log(flac.getAllTags().join('\n'));
}
if (program.importTagsFrom) {
flac.importTagsFrom(program.importTagsFrom);
console.log(flac.getAllTags().join('\n'));
}
if (program.exportTagsTo) {
if (program.exportTagsTo === '-') {
console.log(flac.getAllTags().join('\n'));
} else {
let filepath;
if (!path.isAbsolute(program.exportTagsTo)) {
filepath = path.resolve(process.cwd(), program.exportTagsTo);
} else {
filepath = program.exportTagsTo;
}
flac.exportTagsTo(filepath);
}
}
if (program.importPictureFrom) {
let filepath;
if (!path.isAbsolute(program.importPictureFrom)) {
filepath = path.resolve(process.cwd(), program.importPictureFrom);
} else {
filepath = program.importPictureFrom;
}
flac.importPictureFrom(filepath);
flac.save();
}
if (program.exportPictureTo) {
let filepath;
if (!path.isAbsolute(program.exportPictureTo)) {
filepath = path.resolve(process.cwd(), program.exportPictureTo);
} else {
filepath = program.exportPictureTo;
}
flac.exportPictureTo(filepath);
}
if (program.listPicture) {
flac.getPicturesSpecs().forEach((spec) => console.log(spec));
}
} catch (e) {
console.log(`Error: ${e.message}`);
process.exit(1);
}