Skip to content

Instantly share code, notes, and snippets.

@maimainoue
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maimainoue/a3725133bf69d3edc5f2 to your computer and use it in GitHub Desktop.
Save maimainoue/a3725133bf69d3edc5f2 to your computer and use it in GitHub Desktop.
Cue作成
Cue.makeCue = function(di) {
var cueFile = '';
// ""で囲う
escapeStr = function(str) {
if( str.match('"') ) {
return str;
} else {
return '"'+str+'"';
}
}
try {
if(di.discId != '' && typeof di.discId !== "undefined")
cueFile += 'REM DISCID ' + di.discId + '\n'
if(di.accurateRipId != '' && typeof di.accurateRipId !== "undefined")
cueFile += 'REM ACCURATERIPID ' + di.accurateRipId + '\n'
if(di.comment != '' && typeof di.comment !== "undefined")
cueFile += 'REM COMMENT "' + di.comment + '"\n'
if(di.date != '' && typeof di.date !== "undefined")
cueFile += 'REM DATE ' + di.date + '\n'
if(di.genre != '' && typeof di.genre !== "undefined")
cueFile += 'REM GENRE ' + di.genre + '\n'
if(di.catalog != '' && typeof di.catalog !== "undefined")
cueFile += 'CATALOG ' + di.catalog + '\n'
if(di.albumArtist != '' && typeof di.albumArtist !== "undefined")
cueFile += 'PERFORMER ' + escapeStr(di.albumArtist) + '\n'
if(di.albumTitle != '' && typeof di.albumTitle !== "undefined")
cueFile += 'TITLE ' + escapeStr(di.albumTitle) + '\n'
if(di.replaygain_album_gain != '' && typeof di.replaygain_album_gain !== "undefined")
cueFile += 'REM REPLAYGAIN_ALBUM_GAIN "' + di.replaygain_album_gain + '"\n'
if(di.replaygain_album_peak != '' && typeof di.replaygain_album_peak !== "undefined")
cueFile += 'REM REPLAYGAIN_ALBUM_PEAK "' + di.replaygain_album_peak + '"\n'
if(di.wavFile != '' && typeof di.wavFile!== "undefined")
cueFile += 'FILE "' + di.wavFile + '" ' + di.wavFileType + '\n'
for(var ii = 0 ; ii < di.trackCount ; ii ++ )
{
cueFile += ' TRACK ' + ('0' + (ii+1)).slice(-2) + ' AUDIO\n'
//if(di.track[ii].title != '' && typeof di.track[ii].title !== "undefined")
cueFile += ' TITLE ' + escapeStr(di.track[ii].title) + '\n'
if(di.track[ii].artist != '' && typeof di.track[ii].artist !== "undefined")
cueFile += ' PERFORMER ' + escapeStr(di.track[ii].artist)+ '\n'
if(di.track[ii].isrc != '' && typeof di.track[ii].isrc !== "undefined")
cueFile += ' ISRC ' + di.track[ii].isrc + '\n'
if(di.track[ii].replaygain_trackgain != '' &&
typeof di.track[ii].replaygain_trackgain !== "undefined")
cueFile += ' REM REPLAYGAIN_TRACK_GAIN '
+ di.track[ii].replaygain_trackgain + ' dB\n'
if(di.track[ii].replaygain_track_peak != '' &&
typeof di.track[ii].replaygain_track_peak !== "undefined")
cueFile += ' REM REPLAYGAIN_TRACK_PEAK '
+ di.track[ii].replaygain_track_peak + '\n'
for(var jj = 0 ; jj < di.track[ii].indexCount ; jj ++ )
{
if(di.track[ii].index[jj].id != '' &&
typeof di.track[ii].index[jj].id !== "undefined") {
cueFile += ' INDEX '
+ di.track[ii].index[jj].id
+ ' '
+ ('0'+di.track[ii].index[jj].min).slice(-2)
+ ':'
+ ('0'+di.track[ii].index[jj].sec).slice(-2)
+ ':'
+ ('0'+di.track[ii].index[jj].flame).slice(-2)
+ '\n';
}
}
}
} catch(e) {
console.log(e);
}
return cueFile;
}
Cue.writeCue = function(di,param,cb) {
try {
if( param.encode == undefined ) {
param.encode = 'utf-8';
}
//console.log(param.encode);
var buf = Cue.makeCue(di);
//console.log(buf);
//if( param.encode == 'CP932' ) {
buf = buf.replace(/\r/g,'').replace(/\n/g,'\r\n');
//}
buf = jconv.encode(buf,param.encode);
//console.log('convert');
fs.writeFile(param.fileName, buf, cb);
} catch(e) {
cb(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment