From ecc20adaa93018a4d32d24431cd04e9db2d0f5af Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Mon, 16 May 2016 04:16:40 -0400 Subject: [PATCH] Add lbry.getMediaType() --- js/lbry.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/js/lbry.js b/js/lbry.js index 7db326935..16b8f5ef8 100644 --- a/js/lbry.js +++ b/js/lbry.js @@ -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); }; + +