public function run() { $this->output->writeln("Downloading video: " . $this->video->getId()); $this->logger->addInfo("START Downloading video: " . $this->video->getId()); if ($this->video->getDownloaded()) { $this->output->writeln("<info>Video already downloaded... Continue...</info>"); $this->logger->addInfo("END Skipping video: " . $this->video->getId() . " -> Already exists!"); return; } $builder = new ProcessBuilder(array('youtube-dl', '-x', '--audio-format', 'mp3', '--output', $this->webDir . "/media/" . "%(id)s.%(ext)s", '--cache-dir', $this->appDir . "/ytdl_cache/", 'https://youtube.com/watch?v=' . $this->video->getId())); $process = $builder->getProcess(); $process->setTimeout(0); $logger = $this->logger; $output = $this->output; $process->run(function ($type, $buffer) use($logger, $output) { if (Process::ERR === $type) { $output->writeln("<error>{$buffer}</error>"); $logger->addError("YOUTUBE-DL: " . $buffer); } else { $logger->addDebug("YOUTUBE-DL: " . $buffer); } }); $this->logger->addDebug("Video " . $this->video->getId() . ": Exitcode " . $process->getExitCode()); if ($process->getExitCode() === 0) { $this->video->setDownloaded(true); $output->writeln("<info>Video successfully downloaded!</info>"); $this->logger->addInfo("Video " . $this->video->getId() . ": Downloaded successfull"); } elseif ($process->getExitCode() === 127) { $this->video->setDownloaded(false); $output->writeln("<error>youtube-dl isn't installed!</error>"); $this->logger->addError("youtube-dl isn't available!"); } else { $this->video->setDownloaded(false); $output->writeln("<error>Video downloading error! See logs.</error>"); $this->logger->addError("Video " . $this->video->getId() . ": Unknown error!"); } $this->videoWrapper->saveVideo($this->video); }
public function deleteVideo(Video $video) { $stmt = $this->db->prepare("DELETE FROM videos WHERE id IS :id"); $stmt->bindParam("id", $video->getId()); $stmt->execute(); $this->db->commit(); }