common.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. Common.js
  3. This file includes all the common functions required by other script files
  4. To use this, include this script file at the top of the other script file
  5. e.g.
  6. var succ = includes("common.js");
  7. */
  8. //Check if the given extension is supported in AirMusic
  9. function IsSupportExt(ext){
  10. var supportExtList = [".mp3",".flac",".wav",".ogg",".aac",".webm"];
  11. ext = "." + ext;
  12. for (var i = 0; i < supportExtList.length; i++){
  13. var thisExt = supportExtList[i];
  14. if (ext == thisExt){
  15. return true
  16. }
  17. }
  18. return false
  19. }
  20. //Check if the file is a hidden or meta file
  21. function IsMetaFile(filepath){
  22. var filename = filepath.split("/").pop();
  23. if (filename.substr(0,2) == "._"){
  24. return true;
  25. }
  26. return false;
  27. }
  28. //Convert filesize from bytes to human readable format
  29. function bytesToSize(bytes) {
  30. var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
  31. if (bytes == 0) return '0 Byte';
  32. var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
  33. return (bytes / Math.pow(1024, i)).toFixed(2) + ' ' + sizes[i];
  34. }