-
Notifications
You must be signed in to change notification settings - Fork 7
/
progress.php
38 lines (33 loc) · 1.12 KB
/
progress.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
/*
* By Pedroxam
*/
// If the log can't be displayed in the index, change $root value to: dirname(__FILE__)
$root = '.';
$getContent = file_get_contents($root . '/log.txt');
preg_match("/Duration: (.*?), start:/ms", $getContent, $matches);
if(!empty($rawDuration = $matches[1]))
$ar = array_reverse(explode(":", $rawDuration));
$duration = floatval($ar[0]);
if (!empty($ar[1])) $duration += intval($ar[1]) * 60;
if (!empty($ar[2])) $duration += intval($ar[2]) * 60 * 60;
preg_match_all("/time=(.*?) bitrate/", $getContent, $matches);
$rawTime = array_pop($matches);
if (is_array($rawTime)){$rawTime = array_pop($rawTime);}
$ar = array_reverse(explode(":", $rawTime));
$time = floatval($ar[0]);
if (!empty($ar[1])) $time += intval($ar[1]) * 60;
if (!empty($ar[2])) $time += intval($ar[2]) * 60 * 60;
//progress prec..
$progress = round(($time/$duration) * 100);
if(
$progress > 98 or
strpos($getContent, 'Qavg') !== false or
strpos($getContent, 'kb/s:') !== false
){
$results = 'done';
}
else {
$results = $progress;
}
exit(json_encode([ 'progress' => $results, 'log' => $getContent ]));