Brion VIBBER has uploaded a new change for review. https://gerrit.wikimedia.org/r/310594
Change subject: New requeueTranscodes.php maint script for TMH ...................................................................... New requeueTranscodes.php maint script for TMH Maint script to clear old transcodes and batch-queue the new ones. Supplements/replaces old resetTranscodes.php and retryTranscodes.php... Can be used to batch-queue all files of a given format/resolution key, or all resolutions for a given filename, or just those that were errored out or stalled. Uses the image table as a source of files to list, so can reach *all* video files, even those that have not been properly recorded in the transcode table, and can reach transcodes that have not been listed. Limitations: * potentially slow when dealing with all files! * very verbose output Todo: * support audio transcodes * add a queue-state throttle option for major bulk updates Examples: ``` mwscript \ extensions/TimedMediaHandler/maintenance/requeueTranscodes.php \ --key=1080p.ogv mwscript \ extensions/TimedMediaHandler/maintenance/requeueTranscodes.php \ --key=1080p.ogv \ --error mwscript \ extensions/TimedMediaHandler/maintenance/requeueTranscodes.php \ --file=Folgers.ogv mwscript \ extensions/TimedMediaHandler/maintenance/requeueTranscodes.php \ --stalled ``` Bug: T102096 Change-Id: I0dbd701f86dfd42db8016df1883705ea209a85c4 --- A maintenance/requeueTranscodes.php 1 file changed, 104 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TimedMediaHandler refs/changes/94/310594/1 diff --git a/maintenance/requeueTranscodes.php b/maintenance/requeueTranscodes.php new file mode 100644 index 0000000..601bb35 --- /dev/null +++ b/maintenance/requeueTranscodes.php @@ -0,0 +1,104 @@ +<?php +/** + * Re-queue selected, or all, transcodes + */ +$IP = getenv( 'MW_INSTALL_PATH' ); +if ( $IP === false ) { + $IP = __DIR__ . '/../../..'; +} +require_once "$IP/maintenance/Maintenance.php"; + +class RequeueTranscodes extends Maintenance { + + public function __construct() { + parent::__construct(); + $this->addOption( "file", "re-queue selected formats only for the given file", false, true ); + $this->addOption( "key", "re-queue for given format key", false, true ); + $this->addOption( "error", "re-queue formats that previously failed", false, false ); + $this->addOption( "stalled", "re-queue formats that were started but not finished", false, false ); + $this->addOption( "all", "re-queue all output formats", false, false ); + $this->mDescription = "re-queue existing and missing media transcodes."; + } + + public function execute() { + $this->output( "Cleanup transcodes:\n" ); + $dbr = wfGetDB( DB_SLAVE ); + $where = [ 'img_media_type' => 'VIDEO' ]; + if ( $this->hasOption( 'file' ) ) { + $title = Title::newFromText( $this->getOption( 'file' ), NS_FILE ); + if ( !$title ) { + $this->output( "Invalid --file option provided" ); + return; + } + $where['img_name'] = $title->getDBkey(); + } + $res = $dbr->select( 'image', ['img_name'], $where, __METHOD__ ); + foreach ( $res as $row ) { + $title = Title::newFromText( $row->img_name, NS_FILE ); + $file = wfLocalFile( $title ); + $handler = $file ? $file->getHandler() : null; + if ( $file && $handler && $handler instanceof TimedMediaHandler ) { + $this->output( $file->getName() . "\n" ); + $this->processFile( $file ); + } + } + $this->output( "Finished!\n" ); + } + + public function processFile( File $file ) { + global $wgEnabledTranscodeSet, $wgEnabledAudioTranscodeSet; + $transcodeSet = array_merge( $wgEnabledTranscodeSet, $wgEnabledAudioTranscodeSet ); + $dbw = wfGetDB( DB_MASTER ); + + if ( $this->hasOption( "all" ) ) { + $toAdd = $toRemove = $transcodeSet; + } elseif ( $this->hasOption( "key" ) ) { + $toAdd = $toRemove = [ $this->getOption( 'key' ) ]; + } else { + $toAdd = $transcodeSet; + $toRemove = []; + $state = WebVideoTranscode::getTranscodeState( $file, $dbw ); + foreach ( $state as $key => $item ) { + if ( $this->hasOption( 'error' ) && ( $item['time_error'] || !$item['time_addjob'] ) ) { + $toRemove[] = $key; + continue; + } + if ( $this->hasOption( 'stalled' ) && ( $item['time_addjob'] && !$item['time_success'] && !$item['time_error'] ) ) { + $toRemove[] = $key; + continue; + } + } + } + + $state = WebVideoTranscode::cleanupTranscodes( $file ); + + if ( $toRemove ) { + $state = WebVideoTranscode::getTranscodeState( $file, $dbw ); + $keys = array_intersect( $toRemove, array_keys( $state ) ); + natsort( $keys ); + foreach( $keys as $key ) { + $this->output(".. removing $key\n"); + WebVideoTranscode::removeTranscodes( $file, $key ); + } + } + + if ( $toAdd ) { + $keys = $toAdd; + $state = WebVideoTranscode::getTranscodeState( $file, $dbw ); + natsort( $keys ); + foreach ( $keys as $key ) { + if ( !WebVideoTranscode::isTranscodeEnabled( $file, $key ) ) { + // don't enqueue too-big files + continue; + } + if ( !array_key_exists( $key, $state ) || !$state[$key]['time_addjob'] ) { + $this->output(".. queueing $key\n"); + WebVideoTranscode::updateJobQueue( $file, $key ); + } + } + } + } +} + +$maintClass = 'RequeueTranscodes'; // Tells it to run the class +require_once RUN_MAINTENANCE_IF_MAIN; -- To view, visit https://gerrit.wikimedia.org/r/310594 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0dbd701f86dfd42db8016df1883705ea209a85c4 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/TimedMediaHandler Gerrit-Branch: master Gerrit-Owner: Brion VIBBER <br...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits