72 lines
2.1 KiB
JavaScript
72 lines
2.1 KiB
JavaScript
|
var fs = require("fs")
|
||
|
var id3r = require('id3js');
|
||
|
var id3 = require('id3-writer');
|
||
|
|
||
|
var forEach = require('async-foreach').forEach;
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// just use this in the browser with the provided bundle
|
||
|
var sqlite3 = require('sqlite3').verbose();
|
||
|
var db = new sqlite3.Database('/Users/pg/code/tb/mydb.sqlite');
|
||
|
|
||
|
var create_db = function(){
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
var fix_tag = function(filename, tags){
|
||
|
var writer = new id3.Writer();
|
||
|
var file = new id3.File(filename);
|
||
|
|
||
|
var mytitle= filename.split("/").pop().split("-")[1]
|
||
|
console.log(mytitle)
|
||
|
var meta = new id3.Meta({title: mytitle, artist:tags.artist.replace("\u0000",""), album: tags.album.replace("\u0000",""), year:'2015'})
|
||
|
tags=meta
|
||
|
writer.setFile(file).write(meta, function(err) {
|
||
|
if (err)
|
||
|
console.log("writer.setFile " + err )
|
||
|
|
||
|
|
||
|
})
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
var process_files = function(files){
|
||
|
var myfile = "./assets/emissions/unknown-ALLO-128kbps.mp3"
|
||
|
var myjson = []
|
||
|
db.serialize(function(){
|
||
|
db.run("CREATE TABLE emissions (title TEXT, artist TEXT, album TEXT, genre TEXT, year TEXT , href TEXT)");
|
||
|
db.run("BEGIN TRANSACTION");
|
||
|
var stmt = db.prepare("INSERT INTO emissions ( title, artist, album, genre, year, href) VALUES ( ?, ?, ?, ?, ?, ? )");
|
||
|
forEach(files, function(item, index, arr) {
|
||
|
id3r({ file: item, type: id3r.OPEN_LOCAL }, function(err, tags) {
|
||
|
|
||
|
if (err)
|
||
|
console.log(err)
|
||
|
// if (tags.year===null){
|
||
|
// fix_tag(item, tags)
|
||
|
//}
|
||
|
//
|
||
|
db.run("INSERT INTO emissions ( title, artist, album, genre, year, href) VALUES ( ?, ?, ?, ?, ?, ? )",
|
||
|
[tags.title, tags.artist, tags.album, "Emission", tags.v2['release-time'], "/audio_files/"+item]);
|
||
|
|
||
|
})
|
||
|
|
||
|
},function (notAborted, arr){
|
||
|
console.log("");
|
||
|
db.run("END");})
|
||
|
})
|
||
|
}
|
||
|
|
||
|
process.chdir("assets/audio_files")
|
||
|
fs.readdir('.', function (err, files){
|
||
|
|
||
|
|
||
|
if (!err)
|
||
|
process_files(files)
|
||
|
})
|