1010
1111namespace nystudio107 \transcoder \controllers ;
1212
13- use nystudio107 \transcoder \Transcoder ;
14-
1513use Craft ;
1614use craft \web \Controller ;
1715use craft \helpers \Json ;
@@ -51,7 +49,7 @@ class DefaultController extends Controller
5149 public function actionDownloadFile ($ url )
5250 {
5351 $ filePath = parse_url ($ url , PHP_URL_PATH );
54- $ filePath = $ _SERVER ['DOCUMENT_ROOT ' ] . $ filePath ;
52+ $ filePath = $ _SERVER ['DOCUMENT_ROOT ' ]. $ filePath ;
5553 Craft::$ app ->getResponse ()->sendFile (
5654 $ filePath ,
5755 null ,
@@ -75,74 +73,71 @@ public function actionDownloadFile($url)
7573 public function actionProgress ($ filename )
7674 {
7775 $ result = [];
78- $ progressFile = sys_get_temp_dir () . DIRECTORY_SEPARATOR . $ filename . " .progress " ;
76+ $ progressFile = sys_get_temp_dir (). DIRECTORY_SEPARATOR . $ filename. ' .progress ' ;
7977 if (file_exists ($ progressFile )) {
8078 $ content = @file_get_contents ($ progressFile );
8179 if ($ content ) {
82-
8380 // get duration of source
84- preg_match ("/Duration: (.*?), start:/ " , $ content , $ matches );
85-
86- if (count ($ matches ) > 0 ) {
87-
88- $ rawDuration = $ matches [1 ];
89-
90- // rawDuration is in 00:00:00.00 format. This converts it to seconds.
91- $ ar = array_reverse (explode (": " , $ rawDuration ));
92- $ duration = floatval ($ ar [0 ]);
93- if (!empty ($ ar [1 ])) {
94- $ duration += intval ($ ar [1 ]) * 60 ;
95- }
96- if (!empty ($ ar [2 ])) {
97- $ duration += intval ($ ar [2 ]) * 60 * 60 ;
98- }
99- } else {
100- $ duration = 'unknown ' ; // with GIF as input, duration is unknown
101- }
81+ preg_match ('/Duration: (.*?), start:/ ' , $ content , $ matches );
82+ if (\count ($ matches ) > 0 ) {
83+ $ rawDuration = $ matches [1 ];
84+
85+ // rawDuration is in 00:00:00.00 format. This converts it to seconds.
86+ $ ar = array_reverse (explode (': ' , $ rawDuration ));
87+ $ duration = (float )$ ar [0 ];
88+ if (!empty ($ ar [1 ])) {
89+ $ duration += (int )$ ar [1 ] * 60 ;
90+ }
91+ if (!empty ($ ar [2 ])) {
92+ $ duration += (int )$ ar [2 ] * 60 * 60 ;
93+ }
94+ } else {
95+ $ duration = 'unknown ' ; // with GIF as input, duration is unknown
96+ }
10297
10398 // Get the time in the file that is already encoded
104- preg_match_all (" /time=(.*?) bitrate/ " , $ content , $ matches );
99+ preg_match_all (' /time=(.*?) bitrate/ ' , $ content , $ matches );
105100 $ rawTime = array_pop ($ matches );
106101
107102 // this is needed if there is more than one match
108- if (is_array ($ rawTime )) {
103+ if (\ is_array ($ rawTime )) {
109104 $ rawTime = array_pop ($ rawTime );
110105 }
111106
112107 //rawTime is in 00:00:00.00 format. This converts it to seconds.
113- $ ar = array_reverse (explode (" : " , $ rawTime ));
114- $ time = floatval ( $ ar [0 ]) ;
108+ $ ar = array_reverse (explode (' : ' , $ rawTime ));
109+ $ time = ( float ) $ ar [0 ];
115110 if (!empty ($ ar [1 ])) {
116- $ time += intval ( $ ar [1 ]) * 60 ;
111+ $ time += ( int ) $ ar [1 ] * 60 ;
117112 }
118113 if (!empty ($ ar [2 ])) {
119- $ time += intval ( $ ar [2 ]) * 60 * 60 ;
114+ $ time += ( int ) $ ar [2 ] * 60 * 60 ;
120115 }
121116
122117 //calculate the progress
123- if ($ duration != 'unknown ' ) {
124- $ progress = round (($ time / $ duration ) * 100 );
118+ if ($ duration != = 'unknown ' ) {
119+ $ progress = round (($ time / $ duration ) * 100 );
125120 } else {
126- $ progress = 'unknown ' ;
121+ $ progress = 'unknown ' ;
122+ }
123+
124+ // return results
125+ if ($ progress !== 'unknown ' && $ progress < 100 ) {
126+ $ result = [
127+ 'filename ' => $ filename ,
128+ 'duration ' => $ duration ,
129+ 'time ' => $ time ,
130+ 'progress ' => $ progress ,
131+ ];
132+ } elseif ($ progress === 'unknown ' ) {
133+ $ result = [
134+ 'filename ' => $ filename ,
135+ 'duration ' => 'unknown ' ,
136+ 'time ' => $ time ,
137+ 'progress ' => 'unknown ' ,
138+ 'message ' => 'encoding GIF, can \'t determine duration ' ,
139+ ];
127140 }
128-
129- // return results
130- if ($ progress != "unknown " && $ progress < 100 ) {
131- $ result = [
132- 'filename ' => $ filename ,
133- 'duration ' => $ duration ,
134- 'time ' => $ time ,
135- 'progress ' => $ progress ,
136- ];
137- } elseif ($ progress == "unknown " ) {
138- $ result = [
139- 'filename ' => $ filename ,
140- 'duration ' => 'unknown ' ,
141- 'time ' => $ time ,
142- 'progress ' => 'unknown ' ,
143- 'message ' => 'encoding GIF, can \'t determine duration '
144- ];
145- }
146141 }
147142 }
148143
0 commit comments