mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 02:01:33 +00:00
update Yenc
This commit is contained in:
@@ -24,31 +24,24 @@ use Illuminate\Support\ServiceProvider;
|
||||
class Yenc extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
* @var string
|
||||
*/
|
||||
protected static $_adapters = [];
|
||||
protected static $_adapter = 'app\extensions\util\yenc\adapter\\';
|
||||
|
||||
/**
|
||||
* Contains adapter configurations for `yEnc` adapter.
|
||||
*
|
||||
* @var array
|
||||
* @param string $adapter
|
||||
*/
|
||||
protected static $_configurations = [];
|
||||
|
||||
/**
|
||||
* @param array $adapters
|
||||
*/
|
||||
public static function setAdapters($adapters)
|
||||
public static function setAdapter(string $adapter)
|
||||
{
|
||||
self::$_adapters[] = $adapters;
|
||||
self::$_adapter = self::$_adapter .= $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @return string
|
||||
*/
|
||||
public static function getAdapters(): array
|
||||
public static function getAdapter(): string
|
||||
{
|
||||
return self::$_adapters;
|
||||
return self::$_adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,9 +58,9 @@ class Yenc extends ServiceProvider
|
||||
'name' => 'default',
|
||||
'file' => true,
|
||||
];
|
||||
$_adapters = self::getAdapters();
|
||||
$_adapters = self::getAdapter();
|
||||
|
||||
return $_adapters($options['name'])->decode($text);
|
||||
return $_adapters . $options['name']->decode($text);
|
||||
}
|
||||
|
||||
public static function decodeIgnore(&$text, array $options = [])
|
||||
@@ -76,9 +69,8 @@ class Yenc extends ServiceProvider
|
||||
'name' => 'default',
|
||||
'file' => true,
|
||||
];
|
||||
$_adapters = self::getAdapters();
|
||||
|
||||
return $_adapters($options['name'])->decodeIgnore($text);
|
||||
return (\app\extensions\util\yenc\adapter\$options['name'])->decodeIgnore($text);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,8 +87,8 @@ class Yenc extends ServiceProvider
|
||||
{
|
||||
$options += ['name' => 'default'];
|
||||
|
||||
$_adapters = self::getAdapters();
|
||||
$_adapters = self::getAdapter();
|
||||
|
||||
return $_adapters($options['name'])->encode($data, $filename, $line, $crc32);
|
||||
return $_adapters . $options['name']->encode($data, $filename, $line, $crc32);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,11 @@
|
||||
|
||||
namespace app\extensions\util\yenc\adapter;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use yenc\yenc;
|
||||
|
||||
|
||||
class NzedbYenc extends \lithium\core\Object
|
||||
class NzedbYenc extends ServiceProvider
|
||||
{
|
||||
public static function decode(&$text, $ignore = false, array $options = [])
|
||||
{
|
||||
@@ -48,11 +49,6 @@ class NzedbYenc extends \lithium\core\Object
|
||||
{
|
||||
return (new yenc())->encode($data, $filename, $lineLength);
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
parent::_init();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -19,13 +19,16 @@
|
||||
|
||||
namespace app\extensions\util\yenc\adapter;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use nntmux\Logger;
|
||||
|
||||
|
||||
/**
|
||||
* Class Php
|
||||
*
|
||||
* @package app\extensions\util\yenc\adapter
|
||||
*/
|
||||
class Php extends \lithium\core\Object
|
||||
class Php extends ServiceProvider
|
||||
{
|
||||
public static function decode(&$text, $ignore = false)
|
||||
{
|
||||
@@ -52,8 +55,7 @@ class Php extends \lithium\core\Object
|
||||
if ($headerSize != $trailerSize) {
|
||||
$message = 'Header and trailer file sizes do not match. This is a violation of the yEnc specification.';
|
||||
if (NN_LOGGING || NN_DEBUG) {
|
||||
//TODO replace with lithium logger.
|
||||
// $this->_debugging->log(get_class(), __FUNCTION__, $message, Logger::LOG_NOTICE);
|
||||
$_debugging->log(__CLASS__, __FUNCTION__, $message, Logger::LOG_NOTICE);
|
||||
}
|
||||
|
||||
throw new \RuntimeException($message);
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program (see LICENSE.txt in the base directory. If
|
||||
* not, see:
|
||||
*
|
||||
* @link <http://www.gnu.org/licenses/>.
|
||||
* @author niel
|
||||
* @copyright 2016 nZEDb
|
||||
*/
|
||||
|
||||
namespace app\extensions\util\yenc\adapter;
|
||||
|
||||
use app\extensions\util\Yenc;
|
||||
|
||||
|
||||
class SimplePhpYencDecode extends \lithium\core\Object
|
||||
{
|
||||
public static function decode(&$text, $ignore = false)
|
||||
{
|
||||
return \simple_yenc_decode($text);
|
||||
}
|
||||
|
||||
public static function decodeIgnore(&$text)
|
||||
{
|
||||
return Yenc::decodeIgnore($text, ['name' => 'php']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if this adapter is enabled by checking if the `nzedb_yenc` extension is loaded.
|
||||
*
|
||||
* @return boolean Returns `true` if enabled, otherwise `false`.
|
||||
*/
|
||||
public static function enabled()
|
||||
{
|
||||
return extension_loaded('simple_php_yenc_decode');
|
||||
}
|
||||
|
||||
public static function encode(&$data, $filename, $lineLength, $crc32)
|
||||
{
|
||||
return Yenc::encode($data, $filename, $lineLength, $crc32, ['name' => 'php']);
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
parent::_init();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,96 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program (see LICENSE.txt in the base directory. If
|
||||
* not, see:
|
||||
*
|
||||
* @link <http://www.gnu.org/licenses/>.
|
||||
* @author niel
|
||||
* @copyright 2016 nZEDb
|
||||
*/
|
||||
|
||||
namespace app\extensions\util\yenc\adapter;
|
||||
|
||||
use app\models\Settings;
|
||||
use nntmux\utility\Utility;
|
||||
|
||||
class Ydecode extends \lithium\core\Object
|
||||
{
|
||||
/**
|
||||
* Path to yyDecoder binary.
|
||||
*
|
||||
* @var bool|string
|
||||
* @access protected
|
||||
*/
|
||||
protected static $pathBin;
|
||||
|
||||
/**
|
||||
* If on unix, hide yydecode CLI output.
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected static $silent;
|
||||
|
||||
public static function decode(&$text, $ignore = false)
|
||||
{
|
||||
if (!preg_match('/^(=yBegin.*=yEnd[^$]*)$/ims', $text, $input)) {
|
||||
throw new \UnexpectedValueException('Text does not look like yEnc.');
|
||||
}
|
||||
$data = shell_exec(
|
||||
"echo '{$input[1]}' | '" . self::$pathBin . "' -o - " . ($ignore ? "-b " : " ") . self::$silent
|
||||
);
|
||||
if ($data === null) {
|
||||
throw new \LengthException('Error getting data from yydecode.');
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function decodeIgnore(&$text)
|
||||
{
|
||||
self::decode($text, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if this adapter is enabled by checking if the `yydecode` path is enabled.
|
||||
*
|
||||
* @return boolean Returns `true` if enabled, otherwise `false`.
|
||||
*/
|
||||
public static function enabled()
|
||||
{
|
||||
return !empty(self::$pathBin);
|
||||
}
|
||||
|
||||
public static function encode($data, $filename, $lineLength, $crc32)
|
||||
{
|
||||
return Yenc::encode($data, $filename, $lineLength, $crc32, ['name' => 'Php']);
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
parent::_init();
|
||||
|
||||
$path = Settings::value('apps..yydecoderpath', true);
|
||||
if (!empty($path) && strpos($path, 'simple_php_yenc_decode') === false) {
|
||||
if (file_exists($path) && is_executable($path)) {
|
||||
self::$silent = (Utility::isWin() ? '' : ' > /dev/null 2>&1');
|
||||
self::$pathBin = $path;
|
||||
} else {
|
||||
self::$pathBin = false;
|
||||
}
|
||||
} else {
|
||||
self::$pathBin = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
+1
-15
@@ -41,18 +41,4 @@ if (defined('NN_INSTALLER') && NN_INSTALLER !== false) {
|
||||
}
|
||||
}
|
||||
|
||||
Yenc::setAdapters(
|
||||
[
|
||||
'default' => [
|
||||
'adapter' => $adapter
|
||||
],
|
||||
|
||||
'nzedb' => [
|
||||
'adapter' => 'NzedbYenc'
|
||||
],
|
||||
|
||||
'php' => [
|
||||
'adapter' => 'Php'
|
||||
],
|
||||
]
|
||||
);
|
||||
Yenc::setAdapter($adapter);
|
||||
|
||||
Reference in New Issue
Block a user