-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
look up metadata once then start server Fixes #33
- Loading branch information
Nick Desaulniers
committed
Jan 3, 2014
1 parent
94553d7
commit 51974e8
Showing
3 changed files
with
42 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,47 @@ | ||
var shell = require('shelljs'); | ||
var fs = require('fs'); | ||
var Metalib = require('fluent-ffmpeg').Metadata; | ||
var music_folders = require('../config/config.json').music_folders | ||
.map(escapejson); | ||
var supported_extension_re = /\.(mp3|ogg|wav|m4a|flac)$/; | ||
var file_dict = {}; | ||
var file_metadata = []; | ||
|
||
function escapejson (filename) { | ||
return filename.replace(/\\/g, ''); | ||
}; | ||
function escapejson (filename) { return filename.replace(/\\/g, ''); }; | ||
|
||
var FileMap = { | ||
retrieve: function (id) { | ||
return file_dict[id]; | ||
}, | ||
retrieveAll: function () { | ||
return file_dict; | ||
}, | ||
module.exports = { | ||
retrieve: function (id) { return file_dict[id]; }, | ||
retrieveAll: function () { return file_metadata; }, | ||
previously_transcoded: function (file_path) { | ||
var lib_file_path = 'library/' + file_path; | ||
return fs.existsSync(lib_file_path) ? lib_file_path : ''; | ||
}, | ||
update: function () { | ||
update: function (cb) { | ||
var counter = file_metadata.length = 0; | ||
shell.find(music_folders).filter(function (file_path) { | ||
return supported_extension_re.test(file_path) && fs.existsSync(file_path); | ||
}).forEach(function (file_path) { | ||
file_dict[fs.statSync(file_path).ino] = file_path; | ||
}).forEach(function (file_path, i, all_songs) { | ||
if (i === 0) console.log('Parsing ' + all_songs.length + ' songs.'); | ||
var songID = fs.statSync(file_path).ino; | ||
file_dict[songID] = file_path; | ||
new Metalib(file_path, function (metadata, err) { | ||
if (err) return console.error(err); | ||
file_metadata.push({ | ||
songID: songID, | ||
ext: file_path.replace(/.+\./, ''), | ||
title: metadata.title || file_path.replace(/.+\//, ''), | ||
artist: metadata.artist, | ||
album: metadata.album, | ||
year: metadata.date, | ||
track: metadata.track, | ||
duration: metadata.durationraw, | ||
}); | ||
if (++counter === all_songs.length && typeof cb === 'function') { | ||
console.log('Done parsing.'); | ||
cb(); | ||
} | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
FileMap.update(); | ||
|
||
exports.FileMap = FileMap; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters