public function __construct($AppName, IRequest $Request, $CurrentUID, IL10N $L10N) { parent::__construct($AppName, $Request); $this->CurrentUID = $CurrentUID; $this->L10N = $L10N; if (strcmp(Config::getSystemValue('dbtype'), 'pgsql') == 0) { $this->DbType = 1; } $this->CanCheckForUpdate = Tools::CanCheckForUpdate(); $this->Settings = new Settings(); $this->Settings->SetKey('WhichDownloader'); $this->WhichDownloader = $this->Settings->GetValue(); $this->WhichDownloader = is_null($this->WhichDownloader) ? 'ARIA2' : $this->WhichDownloader; $this->Settings->SetKey('AllowProtocolHTTP'); $this->AllowProtocolHTTP = $this->Settings->GetValue(); $this->AllowProtocolHTTP = is_null($this->AllowProtocolHTTP) || \OC_User::isAdminUser($this->CurrentUID) ? true : strcmp($this->AllowProtocolHTTP, 'Y') == 0; $this->Settings->SetKey('AllowProtocolFTP'); $this->AllowProtocolFTP = $this->Settings->GetValue(); $this->AllowProtocolFTP = is_null($this->AllowProtocolFTP) || \OC_User::isAdminUser($this->CurrentUID) ? true : strcmp($this->AllowProtocolFTP, 'Y') == 0; $this->Settings->SetKey('AllowProtocolYT'); $this->AllowProtocolYT = $this->Settings->GetValue(); $this->AllowProtocolYT = is_null($this->AllowProtocolYT) || \OC_User::isAdminUser($this->CurrentUID) ? true : strcmp($this->AllowProtocolYT, 'Y') == 0; $this->Settings->SetKey('AllowProtocolBT'); $this->AllowProtocolBT = $this->Settings->GetValue(); $this->AllowProtocolBT = is_null($this->AllowProtocolBT) || \OC_User::isAdminUser($this->CurrentUID) ? true : strcmp($this->AllowProtocolBT, 'Y') == 0; }
public function __construct($AppName, IRequest $Request, $CurrentUID, IL10N $L10N) { parent::__construct($AppName, $Request); $this->CurrentUID = $CurrentUID; $this->L10N = $L10N; if (strcmp(Config::getSystemValue('dbtype'), 'pgsql') == 0) { $this->DbType = 1; } $this->CanCheckForUpdate = Tools::CanCheckForUpdate(); $this->Settings = new Settings(); $this->Settings->SetKey('WhichDownloader'); $this->WhichDownloader = $this->Settings->GetValue(); $this->WhichDownloader = is_null($this->WhichDownloader) ? 'ARIA2' : $this->WhichDownloader; }
/** * @AdminRequired * @NoCSRFRequired */ public function Check() { \OCP\JSON::setContentTypeHeader('application/json'); if ($this->Allow) { try { $LastVersionNumber = Tools::GetLastVersionNumber(); $AppVersion = \OCP\App::getAppVersion('ocdownloader'); $Response = array('ERROR' => false, 'RESULT' => version_compare($AppVersion, $LastVersionNumber, '<')); } catch (Exception $E) { $Response = array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Error while checking application version on GitHub')); } } else { $Response = array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('You are not allowed to check for application updates')); } return new JSONResponse($Response); }
public static function Add($URL) { try { self::Load(); $URL = urldecode($URL); if (Tools::CheckURL($URL)) { if (preg_match('/^https{0,1}:\\/\\/www\\.youtube\\.com\\/watch\\?v=.*$/', $URL) == 1) { $YouTube = new YouTube(self::$YTDLBinary, $URL); if (!is_null(self::$ProxyAddress) && self::$ProxyPort > 0 && self::$ProxyPort <= 65536) { $YouTube->SetProxy(self::$ProxyAddress, self::$ProxyPort); } $VideoData = $YouTube->GetVideoData(); if (!isset($VideoData['VIDEO']) || !isset($VideoData['FULLNAME'])) { return array('ERROR' => true, 'MESSAGE' => 'UnabletoretrievetrueYouTubevideoURL'); } $DL = array('URL' => $VideoData['VIDEO'], 'FILENAME' => Tools::CleanString($VideoData['FULLNAME']), 'PROTO' => 'Video'); } else { $DL = array('URL' => $URL, 'FILENAME' => Tools::CleanString(substr($URL, strrpos($URL, '/') + 1)), 'PROTO' => strtoupper(substr($URL, 0, strpos($URL, ':')))); } $OPTIONS = array('dir' => self::$AbsoluteDownloadsFolder, 'out' => $DL['FILENAME']); if (!is_null(self::$ProxyAddress) && self::$ProxyPort > 0 && self::$ProxyPort <= 65536) { $OPTIONS['all-proxy'] = rtrim(self::$ProxyAddress, '/') . ':' . self::$ProxyPort; if (!is_null(self::$ProxyUser) && !is_null(self::$ProxyPasswd)) { $OPTIONS['all-proxy-user'] = self::$ProxyUser; $OPTIONS['all-proxy-passwd'] = self::$ProxyPasswd; } } $AddURI = Aria2::AddUri(array($DL['URL']), $OPTIONS); if (isset($AddURI['result']) && !is_null($AddURI['result'])) { $SQL = 'INSERT INTO `*PREFIX*ocdownloader_queue` (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `IS_CLEANED`, `STATUS`, `TIMESTAMP`) VALUES (?, ?, ?, ?, ?, ?, ?)'; if (self::$DbType == 1) { $SQL = 'INSERT INTO *PREFIX*ocdownloader_queue ("UID", "GID", "FILENAME", "PROTOCOL", "IS_CLEANED", "STATUS", "TIMESTAMP") VALUES (?, ?, ?, ?, ?, ?, ?)'; } $Query = \OCP\DB::prepare($SQL); $Result = $Query->execute(array(self::$CurrentUID, $AddURI['result'], $DL['FILENAME'], strcmp($DL['PROTO'], 'Video') == 0 ? 'YT ' . (string) self::$L10N->t('Video') : $DL['PROTO'], 1, 1, time())); return array('ERROR' => false, 'FILENAME' => $DL['FILENAME']); } else { return array('ERROR' => true, 'MESSAGE' => 'ReturnedGIDisnullIsAria2crunningasadaemon'); } } else { return array('ERROR' => true, 'MESSAGE' => 'InvalidURL'); } } catch (Exception $E) { return array('ERROR' => true, 'MESSAGE' => 'Unabletolaunchthedownload'); } }
/** * @NoAdminRequired * @NoCSRFRequired */ public function Add() { \OCP\JSON::setContentTypeHeader('application/json'); if (isset($_POST['FILE']) && strlen($_POST['FILE']) > 0 && Tools::CheckURL($_POST['FILE']) && isset($_POST['OPTIONS'])) { try { if (!$this->AllowProtocolYT && !\OC_User::isAdminUser($this->CurrentUID)) { throw new \Exception((string) $this->L10N->t('You are not allowed to use the YouTube protocol')); } $YouTube = new YouTube($this->YTDLBinary, $_POST['FILE']); if (!is_null($this->ProxyAddress) && $this->ProxyPort > 0 && $this->ProxyPort <= 65536) { $YouTube->SetProxy($this->ProxyAddress, $this->ProxyPort); } if (isset($_POST['OPTIONS']['YTForceIPv4']) && strcmp($_POST['OPTIONS']['YTForceIPv4'], 'false') == 0) { $YouTube->SetForceIPv4(false); } // Extract Audio YES if (isset($_POST['OPTIONS']['YTExtractAudio']) && strcmp($_POST['OPTIONS']['YTExtractAudio'], 'true') == 0) { $VideoData = $YouTube->GetVideoData(true); if (!isset($VideoData['AUDIO']) || !isset($VideoData['FULLNAME'])) { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Unable to retrieve true YouTube audio URL'))); } $DL = array('URL' => $VideoData['AUDIO'], 'FILENAME' => Tools::CleanString($VideoData['FULLNAME']), 'TYPE' => 'YT Audio'); } else { $VideoData = $YouTube->GetVideoData(); if (!isset($VideoData['VIDEO']) || !isset($VideoData['FULLNAME'])) { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Unable to retrieve true YouTube video URL'))); } $DL = array('URL' => $VideoData['VIDEO'], 'FILENAME' => Tools::CleanString($VideoData['FULLNAME']), 'TYPE' => 'YT Video'); } // If target file exists, create a new one if (\OC\Files\Filesystem::file_exists($this->DownloadsFolder . '/' . $DL['FILENAME'])) { $DL['FILENAME'] = time() . '_' . $DL['FILENAME']; } // Create the target file if the downloader is ARIA2 if ($this->WhichDownloader == 0) { \OC\Files\Filesystem::touch($this->DownloadsFolder . '/' . $DL['FILENAME']); } else { if (!\OC\Files\Filesystem::is_dir($this->DownloadsFolder)) { \OC\Files\Filesystem::mkdir($this->DownloadsFolder); } } $OPTIONS = array('dir' => $this->AbsoluteDownloadsFolder, 'out' => $DL['FILENAME']); if (!is_null($this->ProxyAddress) && $this->ProxyPort > 0 && $this->ProxyPort <= 65536) { $OPTIONS['all-proxy'] = rtrim($this->ProxyAddress, '/') . ':' . $this->ProxyPort; if (!is_null($this->ProxyUser) && !is_null($this->ProxyPasswd)) { $OPTIONS['all-proxy-user'] = $this->ProxyUser; $OPTIONS['all-proxy-passwd'] = $this->ProxyPasswd; } } if (!is_null($this->MaxDownloadSpeed) && $this->MaxDownloadSpeed > 0) { $OPTIONS['max-download-limit'] = $this->MaxDownloadSpeed . 'K'; } $AddURI = $this->WhichDownloader == 0 ? Aria2::AddUri(array($DL['URL']), array('Params' => $OPTIONS)) : CURL::AddUri($DL['URL'], $OPTIONS); if (isset($AddURI['result']) && !is_null($AddURI['result'])) { $SQL = 'INSERT INTO `*PREFIX*ocdownloader_queue` (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES (?, ?, ?, ?, ?, ?)'; if ($this->DbType == 1) { $SQL = 'INSERT INTO *PREFIX*ocdownloader_queue ("UID", "GID", "FILENAME", "PROTOCOL", "STATUS", "TIMESTAMP") VALUES (?, ?, ?, ?, ?, ?)'; } $Query = \OCP\DB::prepare($SQL); $Result = $Query->execute(array($this->CurrentUID, $AddURI['result'], $DL['FILENAME'], $DL['TYPE'], 1, time())); sleep(1); $Status = Aria2::TellStatus($AddURI['result']); $Progress = 0; if ($Status['result']['totalLength'] > 0) { $Progress = $Status['result']['completedLength'] / $Status['result']['totalLength']; } $ProgressString = Tools::GetProgressString($Status['result']['completedLength'], $Status['result']['totalLength'], $Progress); return new JSONResponse(array('ERROR' => false, 'MESSAGE' => (string) $this->L10N->t('Download started'), 'GID' => $AddURI['result'], 'PROGRESSVAL' => round($Progress * 100, 2) . '%', 'PROGRESS' => is_null($ProgressString) ? (string) $this->L10N->t('N/A') : $ProgressString, 'STATUS' => isset($Status['result']['status']) ? (string) $this->L10N->t(ucfirst($Status['result']['status'])) : (string) $this->L10N->t('N/A'), 'STATUSID' => Tools::GetDownloadStatusID($Status['result']['status']), 'SPEED' => isset($Status['result']['downloadSpeed']) ? Tools::FormatSizeUnits($Status['result']['downloadSpeed']) . '/s' : (string) $this->L10N->t('N/A'), 'FILENAME' => strlen($DL['FILENAME']) > 40 ? substr($DL['FILENAME'], 0, 40) . '...' : $DL['FILENAME'], 'PROTO' => $DL['TYPE'], 'ISTORRENT' => false)); } else { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Returned GID is null ! Is Aria2c running as a daemon ?'))); } } catch (Exception $E) { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage())); } } else { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Please check the URL you\'ve just provided'))); } }
/** * @NoAdminRequired * @NoCSRFRequired */ public function Count() { \OCP\JSON::setContentTypeHeader('application/json'); try { return new JSONResponse(array('ERROR' => false, 'COUNTER' => Tools::GetCounters($this->DbType, $this->CurrentUID))); } catch (Exception $E) { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage())); } }
/** * @NoAdminRequired * @NoCSRFRequired */ public function add() { \OCP\JSON::setContentTypeHeader('application/json'); if (isset($_POST['FILE']) && strlen(trim($_POST['FILE'])) > 0 && (Tools::CheckURL($_POST['FILE']) || Tools::CheckFilepath($this->TorrentsFolder . '/' . $_POST['FILE'])) && isset($_POST['OPTIONS'])) { try { if (!$this->AllowProtocolBT && !\OC_User::isAdminUser($this->CurrentUID)) { throw new \Exception((string) $this->L10N->t('You are not allowed to use the BitTorrent protocol')); } $Target = Tools::CleanString(str_replace('.torrent', '', $_POST['FILE'])); $OPTIONS = array('dir' => rtrim($this->AbsoluteDownloadsFolder, '/') . '/' . $Target, 'seed-ratio' => $this->BTRatioToReach, 'seed-time' => $this->SeedTime); // If target file exists, create a new one if (!\OC\Files\Filesystem::is_dir(rtrim($this->DownloadsFolder, '/') . '/' . $Target)) { // Create the target file \OC\Files\Filesystem::mkdir(rtrim($this->DownloadsFolder, '/') . '/' . $Target); } else { $OPTIONS['bt-hash-check-seed'] = true; $OPTIONS['check-integrity'] = true; } if (!is_null($this->MaxDownloadSpeed) && $this->MaxDownloadSpeed > 0) { $OPTIONS['max-download-limit'] = $this->MaxDownloadSpeed . 'K'; } if (!is_null($this->BTMaxUploadSpeed) && $this->BTMaxUploadSpeed > 0) { $OPTIONS['max-upload-limit'] = $this->BTMaxUploadSpeed . 'K'; } if (!$this->ProxyOnlyWithYTDL && !is_null($this->ProxyAddress) && $this->ProxyPort > 0 && $this->ProxyPort <= 65536) { $OPTIONS['all-proxy'] = rtrim($this->ProxyAddress, '/') . ':' . $this->ProxyPort; if (!is_null($this->ProxyUser) && !is_null($this->ProxyPasswd)) { $OPTIONS['all-proxy-user'] = $this->ProxyUser; $OPTIONS['all-proxy-passwd'] = $this->ProxyPasswd; } } $AddTorrent = Aria2::AddTorrent(base64_encode(file_get_contents(rtrim($this->AbsoluteTorrentsFolder, '/') . '/' . $_POST['FILE'])), array(), array('Params' => $OPTIONS)); if (isset($AddTorrent['result']) && !is_null($AddTorrent['result'])) { $SQL = 'INSERT INTO `*PREFIX*ocdownloader_queue` (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES (?, ?, ?, ?, ?, ?)'; if ($this->DbType == 1) { $SQL = 'INSERT INTO *PREFIX*ocdownloader_queue ("UID", "GID", "FILENAME", "PROTOCOL", "STATUS", "TIMESTAMP") VALUES (?, ?, ?, ?, ?, ?)'; } $Query = \OCP\DB::prepare($SQL); $Result = $Query->execute(array($this->CurrentUID, $AddTorrent['result'], $Target, 'BitTorrent', 1, time())); if (isset($_POST['OPTIONS']['BTRMTorrent']) && strcmp($_POST['OPTIONS']['BTRMTorrent'], "true") == 0) { \OC\Files\Filesystem::unlink($this->TorrentsFolder . '/' . $_POST['FILE']); } sleep(1); $Status = Aria2::TellStatus($AddTorrent['result']); $Progress = $Status['result']['completedLength'] / $Status['result']['totalLength']; return new JSONResponse(array('ERROR' => false, 'MESSAGE' => (string) $this->L10N->t('Download started'), 'GID' => $AddTorrent['result'], 'PROGRESSVAL' => round($Progress * 100, 2) . '%', 'PROGRESS' => Tools::GetProgressString($Status['result']['completedLength'], $Status['result']['totalLength'], $Progress) . ' - ' . $this->L10N->t('Seeders') . ': ' . $Status['result']['numSeeders'], 'STATUS' => isset($Status['result']['status']) ? (string) $this->L10N->t(ucfirst($Status['result']['status'])) : (string) $this->L10N->t('N/A'), 'STATUSID' => Tools::GetDownloadStatusID($Status['result']['status']), 'SPEED' => isset($Status['result']['downloadSpeed']) ? Tools::FormatSizeUnits($Status['result']['downloadSpeed']) . '/s' : (string) $this->L10N->t('N/A'), 'FILENAME' => strlen($Target) > 40 ? substr($Target, 0, 40) . '...' : $Target, 'PROTO' => 'BitTorrent', 'ISTORRENT' => true)); } else { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Returned GID is null ! Is Aria2c running as a daemon ?'))); } } catch (Exception $E) { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage())); } } else { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Please check the URL or filepath you\'ve just provided'))); } }
/** * @NoAdminRequired * @NoCSRFRequired */ public function Add() { \OCP\JSON::setContentTypeHeader('application/json'); if (isset($_POST['FILE']) && strlen($_POST['FILE']) > 0 && Tools::CheckURL($_POST['FILE']) && isset($_POST['OPTIONS'])) { try { $Target = Tools::CleanString(substr($_POST['FILE'], strrpos($_POST['FILE'], '/') + 1)); // If target file exists, create a new one if (\OC\Files\Filesystem::file_exists($this->DownloadsFolder . '/' . $Target)) { $Target = time() . '_' . $Target; } // Create the target file if the downloader is Aria2 if ($this->WhichDownloader == 0) { \OC\Files\Filesystem::touch($this->DownloadsFolder . '/' . $Target); } else { if (!\OC\Files\Filesystem::is_dir($this->DownloadsFolder)) { \OC\Files\Filesystem::mkdir($this->DownloadsFolder); } } // Build OPTIONS array $OPTIONS = array('dir' => $this->AbsoluteDownloadsFolder, 'out' => $Target, 'follow-torrent' => false); if (isset($_POST['OPTIONS']['FTPUser']) && strlen(trim($_POST['OPTIONS']['FTPUser'])) > 0 && isset($_POST['OPTIONS']['FTPPasswd']) && strlen(trim($_POST['OPTIONS']['FTPPasswd'])) > 0) { $OPTIONS['ftp-user'] = $_POST['OPTIONS']['FTPUser']; $OPTIONS['ftp-passwd'] = $_POST['OPTIONS']['FTPPasswd']; } if (isset($_POST['OPTIONS']['FTPPasv']) && strlen(trim($_POST['OPTIONS']['FTPPasv'])) > 0) { $OPTIONS['ftp-pasv'] = strcmp($_POST['OPTIONS']['FTPPasv'], "true") == 0 ? true : false; } if (!$this->ProxyOnlyWithYTDL && !is_null($this->ProxyAddress) && $this->ProxyPort > 0 && $this->ProxyPort <= 65536) { $OPTIONS['all-proxy'] = rtrim($this->ProxyAddress, '/') . ':' . $this->ProxyPort; if (!is_null($this->ProxyUser) && !is_null($this->ProxyPasswd)) { $OPTIONS['all-proxy-user'] = $this->ProxyUser; $OPTIONS['all-proxy-passwd'] = $this->ProxyPasswd; } } $AddURI = $this->WhichDownloader == 0 ? Aria2::AddUri(array($_POST['FILE']), array('Params' => $OPTIONS)) : CURL::AddUri($_POST['FILE'], $OPTIONS); if (isset($AddURI['result']) && !is_null($AddURI['result'])) { $SQL = 'INSERT INTO `*PREFIX*ocdownloader_queue` (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES (?, ?, ?, ?, ?, ?)'; if ($this->DbType == 1) { $SQL = 'INSERT INTO *PREFIX*ocdownloader_queue ("UID", "GID", "FILENAME", "PROTOCOL", "STATUS", "TIMESTAMP") VALUES (?, ?, ?, ?, ?, ?)'; } $Query = \OCP\DB::prepare($SQL); $Result = $Query->execute(array($this->CurrentUID, $AddURI['result'], $Target, strtoupper(substr($_POST['FILE'], 0, strpos($_POST['FILE'], ':'))), 1, time())); sleep(1); $Status = $this->WhichDownloader == 0 ? Aria2::TellStatus($AddURI['result']) : CURL::TellStatus($AddURI['result']); $Progress = 0; if ($Status['result']['totalLength'] > 0) { $Progress = $Status['result']['completedLength'] / $Status['result']['totalLength']; } $ProgressString = Tools::GetProgressString($Status['result']['completedLength'], $Status['result']['totalLength'], $Progress); return new JSONResponse(array('ERROR' => false, 'MESSAGE' => (string) $this->L10N->t('Download started'), 'GID' => $AddURI['result'], 'PROGRESSVAL' => round($Progress * 100, 2) . '%', 'PROGRESS' => is_null($ProgressString) ? (string) $this->L10N->t('N/A') : $ProgressString, 'STATUS' => isset($Status['result']['status']) ? (string) $this->L10N->t(ucfirst($Status['result']['status'])) : (string) $this->L10N->t('N/A'), 'STATUSID' => Tools::GetDownloadStatusID($Status['result']['status']), 'SPEED' => isset($Status['result']['downloadSpeed']) ? Tools::FormatSizeUnits($Status['result']['downloadSpeed']) . '/s' : (string) $this->L10N->t('N/A'), 'FILENAME' => strlen($Target) > 40 ? substr($Target, 0, 40) . '...' : $Target, 'PROTO' => strtoupper(substr($_POST['FILE'], 0, strpos($_POST['FILE'], ':'))), 'ISTORRENT' => false)); } else { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t($this->WhichDownloader == 0 ? 'Returned GID is null ! Is Aria2c running as a daemon ?' : 'An error occurred while running the CURL download'))); } } catch (Exception $E) { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage())); } } else { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Please check the URL you\'ve just provided'))); } }
/** * @AdminRequired * @NoCSRFRequired */ public function Save() { \OCP\JSON::setContentTypeHeader('application/json'); $Error = false; $Message = null; if (isset($_POST['KEY']) && strlen(trim($_POST['KEY'])) > 0 && isset($_POST['VAL']) && strlen(trim($_POST['VAL'])) >= 0) { $PostKey = $_POST['KEY']; $PostValue = $_POST['VAL']; if (in_array($PostKey, $this->OCDSettingKeys)) { $this->Settings->SetKey($PostKey); if (strcmp($PostKey, 'YTDLBinary') == 0) { $PostValue = trim(str_replace(' ', '\\ ', $PostValue)); if (!file_exists($PostValue)) { $PostValue = null; $Error = true; $Message = (string) $this->L10N->t('Unable to find YouTube-DL binary'); } } elseif (strcmp($PostKey, 'ProxyAddress') == 0) { if (!Tools::CheckURL($PostValue) && strlen(trim($PostValue)) > 0) { $PostValue = null; $Error = true; $Message = (string) $this->L10N->t('Invalid proxy address URL'); } } elseif (strcmp($PostKey, 'ProxyPort') == 0) { if (!is_numeric($PostValue)) { $PostValue = null; $Error = true; $Message = (string) $this->L10N->t('Proxy port should be a numeric value'); } elseif ($PostValue <= 0 || $PostValue > 65536) { $PostValue = null; $Error = true; $Message = (string) $this->L10N->t('Proxy port should be a value from 1 to 65536'); } } elseif (strcmp($PostKey, 'CheckForUpdates') == 0) { if (!in_array($PostValue, array('Y', 'N'))) { $PostValue = 'Y'; } } elseif (strcmp($PostKey, 'WhichDownloader') == 0) { if (!in_array($PostValue, array('ARIA2', 'CURL'))) { $PostValue = 'ARIA2'; } elseif (strcmp($PostValue, 'ARIA2') != 0) { Tools::ResetAria2($this->DbType); } } elseif (strcmp($PostKey, 'ProxyOnlyWithYTDL') == 0) { if (!in_array($PostValue, array('Y', 'N'))) { $PostValue = 'N'; } } else { $PostValue = null; $Error = true; } if (strlen(trim($PostValue)) <= 0) { $PostValue = null; } if ($this->Settings->CheckIfKeyExists()) { $this->Settings->UpdateValue($PostValue); } else { $this->Settings->InsertValue($PostValue); } } } return new JSONResponse(array('ERROR' => $Error, 'MESSAGE' => is_null($Message) ? (string) $this->L10N->t('Saved') : $Message)); }
public static function GetQueue() { self::Load(); try { $Params = array(self::$CurrentUID); $StatusReq = '(?, ?, ?, ?, ?)'; $Params[] = 0; $Params[] = 1; $Params[] = 2; $Params[] = 3; $Params[] = 4; $IsCleanedReq = '(?, ?)'; $Params[] = 0; $Params[] = 1; $SQL = 'SELECT * FROM `*PREFIX*ocdownloader_queue` WHERE `UID` = ? AND `STATUS` IN ' . $StatusReq . ' AND `IS_CLEANED` IN ' . $IsCleanedReq . ' ORDER BY `TIMESTAMP` ASC'; if (self::$DbType == 1) { $SQL = 'SELECT * FROM *PREFIX*ocdownloader_queue WHERE "UID" = ? AND "STATUS" IN ' . $StatusReq . ' AND "IS_CLEANED" IN ' . $IsCleanedReq . ' ORDER BY "TIMESTAMP" ASC'; } $Query = \OCP\DB::prepare($SQL); $Request = $Query->execute($Params); $Queue = []; while ($Row = $Request->fetchRow()) { $Status = self::$WhichDownloader == 0 ? Aria2::TellStatus($Row['GID']) : CURL::TellStatus($Row['GID']); $DLStatus = 5; // Error if (!is_null($Status)) { if (!isset($Status['error'])) { $Progress = 0; if ($Status['result']['totalLength'] > 0) { $Progress = $Status['result']['completedLength'] / $Status['result']['totalLength']; } $DLStatus = Tools::GetDownloadStatusID($Status['result']['status']); $ProgressString = Tools::GetProgressString($Status['result']['completedLength'], $Status['result']['totalLength'], $Progress); $Queue[] = array('GID' => $Row['GID'], 'PROGRESSVAL' => round($Progress * 100, 2), 'PROGRESS' => array('Message' => null, 'ProgressString' => is_null($ProgressString) ? 'N_A' : $ProgressString, 'NumSeeders' => isset($Status['result']['bittorrent']) && $Progress < 1 ? $Status['result']['numSeeders'] : null, 'UploadLength' => isset($Status['result']['bittorrent']) && $Progress == 1 ? Tools::FormatSizeUnits($Status['result']['uploadLength']) : null, 'Ratio' => isset($Status['result']['bittorrent']) ? round($Status['result']['uploadLength'] / $Status['result']['completedLength'], 2) : null), 'STATUS' => array('Value' => isset($Status['result']['status']) ? $Row['STATUS'] == 4 ? 'Removed' : ucfirst($Status['result']['status']) : 'N_A', 'Seeding' => isset($Status['result']['bittorrent']) && $Progress == 1 && $DLStatus != 3 ? true : false), 'STATUSID' => $Row['STATUS'] == 4 ? 4 : $DLStatus, 'SPEED' => isset($Status['result']['downloadSpeed']) ? $Progress == 1 ? isset($Status['result']['bittorrent']) ? $Status['result']['uploadSpeed'] == 0 ? '--' : Tools::FormatSizeUnits($Status['result']['uploadSpeed']) . '/s' : '--' : ($DLStatus == 4 ? '--' : Tools::FormatSizeUnits($Status['result']['downloadSpeed']) . '/s') : 'N_A', 'FILENAME' => $Row['FILENAME'], 'PROTO' => $Row['PROTOCOL'], 'ISTORRENT' => isset($Status['result']['bittorrent'])); if ($Row['STATUS'] != $DLStatus) { $SQL = 'UPDATE `*PREFIX*ocdownloader_queue` SET `STATUS` = ? WHERE `UID` = ? AND `GID` = ? AND `STATUS` != ?'; if (self::$DbType == 1) { $SQL = 'UPDATE *PREFIX*ocdownloader_queue SET "STATUS" = ? WHERE "UID" = ? AND "GID" = ? AND "STATUS" != ?'; } $Query = \OCP\DB::prepare($SQL); $Result = $Query->execute(array($DLStatus, self::$CurrentUID, $Row['GID'], 4)); } } else { $Queue[] = array('GID' => $Row['GID'], 'PROGRESSVAL' => 0, 'PROGRESS' => array('Message' => 'ErrorGIDnotfound', 'ProgressString' => null, 'NumSeeders' => null, 'UploadLength' => null, 'Ratio' => null), 'STATUS' => array('Value' => 'N_A', 'Seeding' => null), 'STATUSID' => $DLStatus, 'SPEED' => 'N_A', 'FILENAME' => $Row['FILENAME'], 'PROTO' => $Row['PROTOCOL'], 'ISTORRENT' => isset($Status['result']['bittorrent'])); } } else { $Queue[] = array('GID' => $Row['GID'], 'PROGRESSVAL' => 0, 'PROGRESS' => array('Message' => self::$WhichDownloader == 0 ? 'ReturnedstatusisnullIsAria2crunningasadaemon' : 'Unabletofinddownloadstatusfile', 'ProgressString' => null, 'NumSeeders' => null, 'UploadLength' => null, 'Ratio' => null), 'STATUS' => array('Value' => 'N_A', 'Seeding' => null), 'STATUSID' => $DLStatus, 'SPEED' => 'N_A', 'FILENAME' => $Row['FILENAME'], 'PROTO' => $Row['PROTOCOL'], 'ISTORRENT' => isset($Status['result']['bittorrent'])); } } return array('ERROR' => false, 'MESSAGE' => null, 'QUEUE' => $Queue, 'COUNTER' => Tools::GetCounters(self::$DbType, self::$CurrentUID)); } catch (Exception $E) { return array('ERROR' => true, 'MESSAGE' => $E->getMessage(), 'QUEUE' => null, 'COUNTER' => null); } }