Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.81 KB | None | 0 0
  1. function durationYT2($str) {
  2.     $m = preg_split('#PT|H|M|S#', $str, -1, PREG_SPLIT_NO_EMPTY);
  3.     array_walk($m, function(&$v){$v = substr('0'.$v, -2); return $v;});
  4.     return /*(count($m)==1) ? join(':', (array('00')+$m)) :*/ join(':', $m);
  5. }
  6. function durationYT($str) {
  7.     preg_match('#PT(([0-9]{1,2})H)?(([0-9]{1,2})M)?(([0-9]{1,2})S)?#i', $str, $match);
  8.     return join(':', array_filter(array((isset($match[2])?$match[2]:null), substr('00'.(isset($match[4])?$match[4]:''), -2), substr('00'.(isset($match[6])?$match[6]:''), -2))));
  9. }
  10. function duration2second($str) {
  11.     preg_match('#PT(([0-9]{1,2})H)?(([0-9]{1,2})M)?(([0-9]{1,2})S)?#i', $str, $match);
  12.     return array_sum(array(3600*(isset($match[2])?$match[2]:0), 60*(isset($match[4])?$match[4]:0), (isset($match[6])?$match[6]:0)));
  13. }
  14. function mp3Size($str) {
  15.     preg_match('#PT(([0-9]{1,2})H)?(([0-9]{1,2})M)?(([0-9]{1,2})S)?#i', $str, $match);
  16.     $byte['s'] = 1024*1024*(isset($match[6])?(int)$match[6]:0)/60;
  17.     $byte['m'] = 1024*1024*(isset($match[4])?(int)$match[4]:0);
  18.     $byte['h'] = 1024*1024*60*(isset($match[2])?(int)$match[2]:0);
  19.     $size = array_sum($byte);
  20.     if($size==0) return '0 KB';
  21.     $base = log($size, 1024);
  22.     $suffixes = array(' Bytes', ' KB', ' MB', ' GB', ' TB');
  23.     return round(pow(1024, $base - floor($base)), 2).$suffixes[floor($base)];
  24. }
  25. function videoSize($str) {
  26.     preg_match('#PT(([0-9]{1,2})H)?(([0-9]{1,2})M)?(([0-9]{1,2})S)?#i', $str, $match);
  27.     $byte['s'] = 1024*1024*(isset($match[6])?(int)$match[6]:0)/60;
  28.     $byte['m'] = 1024*1024*(isset($match[4])?(int)$match[4]:0);
  29.     $byte['h'] = 1024*1024*60*(isset($match[2])?(int)$match[2]:0);
  30.     $size = 2.3648243*array_sum($byte);
  31.     if($size==0) return '0 KB';
  32.     $base = log($size, 1024);
  33.     $suffixes = array(' Bytes', ' KB', ' MB', ' GB', ' TB');
  34.     return round(pow(1024, $base - floor($base)), 2).$suffixes[floor($base)];
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement