TheDJ has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/286760

Change subject: [WIP] Log and report the file size of derivatives
......................................................................

[WIP] Log and report the file size of derivatives

Untested code. Might continue with this later. Or abandon.. you never
know.

Bug: T57942
Change-Id: Ib483d8ed1b7f3e24b69b62f2dd5b0bc2cb677c7f
---
M TimedMediaHandler.hooks.php
M TimedMediaHandler.sql
M TranscodeStatusTable.php
M WebVideoTranscode/WebVideoTranscode.php
M WebVideoTranscode/WebVideoTranscodeJob.php
A archives/transcode_size.sql
6 files changed, 34 insertions(+), 4 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TimedMediaHandler 
refs/changes/60/286760/1

diff --git a/TimedMediaHandler.hooks.php b/TimedMediaHandler.hooks.php
index 81fdc3a..da301ed 100644
--- a/TimedMediaHandler.hooks.php
+++ b/TimedMediaHandler.hooks.php
@@ -674,6 +674,7 @@
                        $updater->addExtensionTable( 'transcode', 
"$base/TimedMediaHandler.sql" );
                        $updater->addExtensionUpdate( [ 'addIndex', 
'transcode', 'transcode_name_key',
                                "$base/archives/transcode_name_key.sql", true ] 
);
+                       $updater->addExtensionField( 'transcode', 
'transcode_size', "$base/archives/transcode_size.sql" );
                        break;
                case 'postgres':
                        // TODO
diff --git a/TimedMediaHandler.sql b/TimedMediaHandler.sql
index 7bafe67..e58b8fe 100644
--- a/TimedMediaHandler.sql
+++ b/TimedMediaHandler.sql
@@ -10,7 +10,8 @@
        transcode_time_startwork VARCHAR(14) NULL,
        transcode_time_success VARCHAR(14) NULL,
        transcode_time_error VARCHAR(14) NULL,
-       transcode_final_bitrate INT NOT NULL
+       transcode_final_bitrate INT NOT NULL,
+       transcode_size INT unsigned NOT NULL default 0
 ) /*$wgDBTableOptions*/;
 
 CREATE INDEX /*i*/transcode_time_inx ON /*_*/transcode( transcode_time_addjob 
,transcode_time_startwork , transcode_time_success, transcode_time_error );
diff --git a/TranscodeStatusTable.php b/TranscodeStatusTable.php
index 37fef9d..ff48b1d 100644
--- a/TranscodeStatusTable.php
+++ b/TranscodeStatusTable.php
@@ -102,6 +102,7 @@
 
                $o .= '<th>' . wfMessage( 'timedmedia-status' )->escaped() . 
'</th>';
                $o .= '<th>' . wfMessage( 'timedmedia-transcodeduration' 
)->escaped() . '</th>';
+               $o .= '<th>' . wfMessage( 'timedmedia-transcodesize' 
)->escaped() . '</th>';
                $o .= "</tr>\n";
 
                foreach ( $transcodeRows as $transcodeKey => $state ) {
@@ -130,6 +131,7 @@
                        // Status:
                        $o .= '<td>' . self::getStatusMsg( $file, $state ) . 
'</td>';
                        $o .= '<td>' . self::getTranscodeDuration( $file, 
$state ) . '</td>';
+                       $o .= '<td>' . self::getTranscodeFilesize( $file, 
$state ) . '</td>';
 
                        $o .= '</tr>';
                }
@@ -184,6 +186,24 @@
         * @param $state
         * @return string
         */
+       public static function getTranscodeFilesize( $file, $state ) {
+               global $wgLang;
+               if ( !is_null( $state['success'] ) {
+                       if ( $state['size'] == 0 ) {
+                               return $wgLang->formatSize( $state['size'] );
+                       } else {
+                               return $wgLang->formatSize( filesize( 
$this->getTargetEncodePath() );
+                       }
+               } else {
+                       return '';
+               }
+       }
+
+       /**
+        * @param $file File
+        * @param $state
+        * @return string
+        */
        public static function getStatusMsg( $file, $state ) {
                global $wgContLang;
                // Check for success:
diff --git a/WebVideoTranscode/WebVideoTranscode.php 
b/WebVideoTranscode/WebVideoTranscode.php
index 010e21c..ff7d002 100644
--- a/WebVideoTranscode/WebVideoTranscode.php
+++ b/WebVideoTranscode/WebVideoTranscode.php
@@ -1046,6 +1046,9 @@
                        $fields["bandwidth"] = intval(
                                self::$transcodeState[$fileName][ $transcodeKey 
]['final_bitrate']
                        );
+                       $fields["size"] = intval(
+                               self::$transcodeState[$fileName][ $transcodeKey 
]['size']
+                       );
                }
 
                if ( !$file->getHandler()->isAudio( $file ) ) {
@@ -1103,7 +1106,8 @@
                                                'transcode_key' => 
$transcodeKey,
                                                'transcode_time_addjob' => null,
                                                'transcode_error' => "",
-                                               'transcode_final_bitrate' => 0
+                                               'transcode_final_bitrate' => 0,
+                                               'transcode_size' => 0
                                        ],
                                        __METHOD__,
                                        [ 'IGNORE' ]
@@ -1172,7 +1176,8 @@
                                        'transcode_key' => $transcodeKey,
                                        'transcode_time_addjob' => 
$db->timestamp(),
                                        'transcode_error' => "",
-                                       'transcode_final_bitrate' => 0
+                                       'transcode_final_bitrate' => 0,
+                                       'transcode_size' => 0
                                ],
                                __METHOD__,
                                [ 'IGNORE' ]
diff --git a/WebVideoTranscode/WebVideoTranscodeJob.php 
b/WebVideoTranscode/WebVideoTranscodeJob.php
index 78ae728..ae16018 100644
--- a/WebVideoTranscode/WebVideoTranscodeJob.php
+++ b/WebVideoTranscode/WebVideoTranscodeJob.php
@@ -268,6 +268,7 @@
                                $this->setTranscodeError( $transcodeKey, 
$result->getWikiText() );
                                $status = false;
                        } else {
+                               $fileSize = filesize( 
$this->getTargetEncodePath();
                                $bitrate = round(
                                        intval( filesize( 
$this->getTargetEncodePath() ) /  $file->getLength() ) * 8
                                );
@@ -278,7 +279,8 @@
                                        [
                                                'transcode_error' => '',
                                                'transcode_time_success' => 
$dbw->timestamp(),
-                                               'transcode_final_bitrate' => 
$bitrate
+                                               'transcode_final_bitrate' => 
$bitrate,
+                                               'transcode_size' => $fileSize
                                        ],
                                        [
                                                'transcode_image_name' => 
$this->getFile()->getName(),
diff --git a/archives/transcode_size.sql b/archives/transcode_size.sql
new file mode 100644
index 0000000..e7cb9e9
--- /dev/null
+++ b/archives/transcode_size.sql
@@ -0,0 +1 @@
+ALTER TABLE /*_*/transcode ADD transcode_size int unsigned NOT NULL default 0

-- 
To view, visit https://gerrit.wikimedia.org/r/286760
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib483d8ed1b7f3e24b69b62f2dd5b0bc2cb677c7f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TimedMediaHandler
Gerrit-Branch: master
Gerrit-Owner: TheDJ <hartman.w...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to