mirror of
https://github.com/sigmasternchen/MyTube
synced 2025-03-15 04:48:55 +00:00
added re-encode command
This commit is contained in:
parent
1cb640f2b9
commit
1f6a0f7adc
1 changed files with 95 additions and 0 deletions
95
src/Command/ReencodeCommand.php
Normal file
95
src/Command/ReencodeCommand.php
Normal file
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Controller\WatchController;
|
||||
use App\Entity\Video;
|
||||
use App\Mapper\CustomUuidMapper;
|
||||
use App\Service\VideoService;
|
||||
use Exception;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class ReencodeCommand extends Command
|
||||
{
|
||||
protected static $defaultName = "app:reencode";
|
||||
|
||||
private const ARGUMENT_NAME = "video_id";
|
||||
|
||||
private $videoService;
|
||||
private $uuidMapper;
|
||||
|
||||
public function __construct(
|
||||
VideoService $videoService,
|
||||
CustomUuidMapper $uuidMapper,
|
||||
string $name = null
|
||||
)
|
||||
{
|
||||
parent::__construct($name);
|
||||
$this->videoService = $videoService;
|
||||
$this->uuidMapper = $uuidMapper;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setDescription("flags video for re-encoding");
|
||||
$this->addArgument(self::ARGUMENT_NAME, InputArgument::REQUIRED, "The video to be flagged for re-encode.");
|
||||
}
|
||||
|
||||
private function recursiveDelete($dir)
|
||||
{
|
||||
if (is_dir($dir)) {
|
||||
$objects = scandir($dir);
|
||||
foreach ($objects as $object) {
|
||||
if ($object != "." && $object != "..") {
|
||||
if (is_dir($dir . DIRECTORY_SEPARATOR . $object) && !is_link($dir . "/" . $object))
|
||||
$this->recursiveDelete($dir . DIRECTORY_SEPARATOR . $object);
|
||||
else
|
||||
unlink($dir . DIRECTORY_SEPARATOR . $object);
|
||||
}
|
||||
}
|
||||
rmdir($dir);
|
||||
}
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$id = $input->getArgument(self::ARGUMENT_NAME);
|
||||
|
||||
try {
|
||||
$id = $this->uuidMapper->fromString($id);
|
||||
} catch (Exception $e) {
|
||||
try {
|
||||
$id = str_replace("-", "", $id);
|
||||
$id = Uuid::fromBytes(hex2bin($id));
|
||||
} catch (Exception $e) {
|
||||
$output->writeln("Can't parse video id.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
$video = $this->videoService->get($id);
|
||||
|
||||
if (!$video) {
|
||||
$output->
|
||||
$output->writeln("Can't find video.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$video->setTranscodingProgress(0);
|
||||
$video->setState(Video::PROCESSING_META);
|
||||
$this->videoService->update($video);
|
||||
|
||||
$this->recursiveDelete(WatchController::CONTENT_DIRECTORY . $video->getId() . "/");
|
||||
|
||||
$video->setState(Video::QUEUED);
|
||||
$this->videoService->update($video);
|
||||
|
||||
$output->writeln("Done");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue