Example #1
0
 public function testWrappedConstructor()
 {
     $fileString = 'phar://' . ($pf = \Psc\PSC::getEnvironment()->isWindows() ? 'D:/' : '/') . 'does/not/matter/my.phar.gz/i/am/wrapped/class.php';
     $file = new File($fileString);
     $this->assertEquals('php', $file->getExtension());
     $this->assertEquals('class.php', $file->getName());
     $this->assertEquals('phar://' . $pf . 'does/not/matter/my.phar.gz/i/am/wrapped/', (string) $file->getDirectory());
     $this->assertEquals($fileString, (string) $file);
 }
 public function tryUnpack(File $archiveFile)
 {
     try {
         // wir suchen das srt im archive
         if ($archiveFile->getExtension() === 'rar') {
             // vll geht hier sogar zip?
             $archive = new \Psc\System\SimpleRarArchive($archiveFile);
             $files = $archive->listFiles();
             $srt = NULL;
             $this->logger->writeln('Files im Archiv: ' . implode("\n", $files));
             foreach ($files as $file) {
                 if (\Psc\String::endsWith($file, '.srt')) {
                     $srt = $file;
                     break;
                 }
             }
             if ($srt === NULL) {
                 throw new Exception('Keine .srt Datei im Archiv: ' . $archiveFile . ' gefunden');
             }
             $destination = clone $archiveFile;
             $destination->setExtension('srt');
             $archive->extractFile($srt, $destination);
             if ($destination->exists()) {
                 $archiveFile->delete();
                 return $destination;
                 // alles supi
             }
         }
     } catch (\Exception $e) {
         $this->logger->writeln('Fehler beim Versuch zu entpacken: ' . $e->getMessage());
     }
     return $archiveFile;
 }
 protected function moveEpisodeVideo($episode, File $video, $packageDir)
 {
     $targetFile = $this->getTargetFile($episode);
     if (!$video->isWriteable() || !$video->isReadable()) {
         // klappt leider nicht
         $this->log('  Datei wird vermutlich gerade entpackt');
         return;
     }
     $this->log('  Verschiebe: ' . $video . ' nach ' . $targetFile . '..');
     /* Ziel erstellen */
     $targetFile->getDirectory()->make(Dir::PARENT | DIR::ASSERT_EXISTS);
     if ($video->move($targetFile)) {
         $this->log('  verschoben.');
         $episode->setExtension($video->getExtension());
         $episode->setStatus(Status::MOVED);
         $this->cleanup($packageDir);
     }
     return $episode;
 }