Add lbry.getMediaType()

This commit is contained in:
Alex Liebowitz 2016-05-16 04:16:40 -04:00
parent 2824447c6c
commit ecc20adaa9

View file

@ -170,6 +170,26 @@ lbry.imagePath = function(file)
return lbry.rootPath + '/img/' + file;
}
lbry.getMediaType = function(filename) {
var dotIndex = filename.lastIndexOf('.');
if (dotIndex == -1) {
return 'unknown';
}
var ext = filename.substr(dotIndex + 1);
if (/^mp4|mov|m4v|flv|f4v$/i.test(ext)) {
return 'video';
} else if (/^mp3|m4a|aac|wav|flac|ogg$/i.test(ext)) {
return 'audio';
} else if (/^html|htm|pdf|odf|doc|docx|md|markdown|txt$/i.test(ext)) {
return 'document';
} else {
return 'unknown';
}
}
lbry.stop = function(callback) {
lbry.call('stop', {}, callback);
};