Exemplo n.º 1
0
 /**
  * Decode a string of text encoded with yEnc. Ignores all errors.
  *
  * @param  string $data The encoded text to decode.
  *
  * @return string The decoded yEnc string, or the input string, if it's not yEnc.
  *
  * @access protected
  */
 protected function _decodeIgnoreYEnc(&$data)
 {
     if (preg_match('/^(=yBegin.*=yEnd[^$]*)$/ims', $data, $input)) {
         // If there user has no yyDecode path set, use PHP to decode yEnc.
         if ($this->_yyDecoderPath === false) {
             $data = '';
             $input = trim(preg_replace('/\\r\\n/im', '', preg_replace('/(^=yEnd.*)/im', '', preg_replace('/(^=yPart.*\\r\\n)/im', '', preg_replace('/(^=yBegin.*\\r\\n)/im', '', $input[1], 1), 1), 1)));
             $length = strlen($input);
             for ($chr = 0; $chr < $length; $chr++) {
                 $data .= $input[$chr] !== '=' ? chr(ord($input[$chr]) - 42) : chr(ord($input[++$chr]) - 64 - 42);
             }
         } else {
             if ($this->_yEncExtension) {
                 $data = simple_yenc_decode($input[1]);
             } else {
                 $inFile = $this->_yEncTempInput . mt_rand(0, 999999);
                 $ouFile = $this->_yEncTempOutput . mt_rand(0, 999999);
                 file_put_contents($inFile, $input[1]);
                 file_put_contents($ouFile, '');
                 \newznab\utility\Utility::runCmd("'" . $this->_yyDecoderPath . "' '" . $inFile . "' -o '" . $ouFile . "' -f -b" . $this->_yEncSilence);
                 $data = file_get_contents($ouFile);
                 if ($data === false) {
                     $data = $this->throwError('Error getting data from yydecode.');
                 }
                 unlink($inFile);
                 unlink($ouFile);
             }
         }
     }
     return $data;
 }
Exemplo n.º 2
0
 /**
  * Return file type/info using magic numbers.
  * Try using `file` program where available, fallback to using PHP's finfo class.
  *
  * @param string $path Path to the file / folder to check.
  *
  * @return string File info. Empty string on failure.
  */
 public static function fileInfo($path)
 {
     $output = '';
     $magicPath = (new Settings())->getSetting('magic_file_path');
     if (self::hasCommand('file') && (!self::isWin() || !empty($magicPath))) {
         $magicSwitch = empty($magicPath) ? '' : " -m {$magicPath}";
         $output = Utility::runCmd('file' . $magicSwitch . ' -b "' . $path . '"');
         if (is_array($output)) {
             switch (count($output)) {
                 case 0:
                     $output = '';
                     break;
                 case 1:
                     $output = $output[0];
                     break;
                 default:
                     $output = implode(' ', $output);
                     break;
             }
         } else {
             $output = '';
         }
     } else {
         $fileInfo = empty($magicPath) ? new \finfo(FILEINFO_RAW) : new \finfo(FILEINFO_RAW, $magicPath);
         $output = $fileInfo->file($path);
         if (empty($output)) {
             $output = '';
         }
         $fileInfo->close();
     }
     return $output;
 }
Exemplo n.º 3
0
 /**
  * Try to get media info xml from a video file.
  *
  * @param string $fileLocation
  *
  * @return bool
  */
 protected function _getMediaInfo($fileLocation)
 {
     if (!$this->_processMediaInfo) {
         return false;
     }
     // Look for the video file.
     if (is_file($fileLocation)) {
         // Run media info on it.
         $xmlArray = Utility::runCmd($this->_killString . $this->pdo->getSetting('mediainfopath') . '" --Output=XML "' . $fileLocation . '"');
         // Check if we got it.
         if (is_array($xmlArray)) {
             // Convert it to string.
             $xmlArray = implode("\n", $xmlArray);
             if (!preg_match('/<track type="(Audio|Video)">/i', $xmlArray)) {
                 return false;
             }
             // Insert it into the DB.
             $this->_releaseExtra->addFull($this->_release['id'], $xmlArray);
             $this->_releaseExtra->addFromXml($this->_release['id'], $xmlArray);
             if ($this->_echoCLI) {
                 $this->_echo('m', 'primaryOver', false);
             }
             return true;
         }
     }
     return false;
 }
Exemplo n.º 4
0
 /**
  * Has to be performed after mediainfo, as lame strips id3 tags.
  */
 public function lameAudioSample($lameinfo, $releaseguid)
 {
     $returnval = false;
     $minacceptableencodefilesize = 10000;
     $samplefile = $this->mp3SavePath . $releaseguid . '.mp3';
     $samplefileogg = $this->mp3SavePath . $releaseguid . '.ogg';
     $ffmpeginfo = $this->pdo->getSetting('ffmpegpath');
     if (file_exists($samplefile)) {
         $outfile = $this->mp3SavePath . $releaseguid . '_l.mp3';
         $outfileogg = $this->mp3SavePath . $releaseguid . '_l.ogg';
         //
         // lame the sample down to 96kb and replace it. alternatives could be
         // V8 for low quality variable.
         //
         $execstring = '"' . $lameinfo . '" -b 96 "' . $samplefile . '" "' . $outfile . '"';
         $execstringogg = '"' . $ffmpeginfo . '" -i "' . $samplefile . '" -acodec libvorbis "' . $outfileogg . '"';
         $output = Utility::runCmd($execstring, false, true);
         $output = Utility::runCmd($execstringogg, false, true);
         //
         // lame can create bad/small files if the source was corrupt
         // if it creates a file thats surprisingly small, then ignore it and retain
         // original
         //
         if (file_exists($outfile)) {
             if (filesize($outfile) < $minacceptableencodefilesize) {
                 unlink($outfile);
             } else {
                 unlink($samplefile);
                 rename($outfile, $samplefile);
                 $returnval = true;
             }
         }
         if (file_exists($outfileogg)) {
             if (filesize($outfileogg) < $minacceptableencodefilesize) {
                 unlink($outfileogg);
             } else {
                 rename($outfileogg, $samplefileogg);
                 $returnval = true;
             }
         }
     }
     return $returnval;
 }