Ejemplo n.º 1
0
 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');
     }
 }
Ejemplo n.º 2
0
 /**
  * @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')));
     }
 }
Ejemplo n.º 3
0
 public static function ResetAria2($DbType)
 {
     $SQL = 'SELECT * FROM `*PREFIX*ocdownloader_queue`';
     if ($DbType == 1) {
         $SQL = 'SELECT * FROM *PREFIX*ocdownloader_queue';
     }
     $Query = \OCP\DB::prepare($SQL);
     $Request = $Query->execute();
     while ($Row = $Request->fetchRow()) {
         $Status = Aria2::TellStatus($GID);
         if (!isset($Status['error']) && strcmp($Status['result']['status'], 'error') != 0 && strcmp($Status['result']['status'], 'complete') != 0) {
             Aria2::Remove($GID);
         }
     }
     $Purge = Aria2::PurgeDownloadResult();
     if (isset($Purge['result']) && strcmp($Purge['result'], 'OK') == 0) {
         $SQL = 'TRUNCATE TABLE `*PREFIX*ocdownloader_queue`';
         if ($DbType == 1) {
             $SQL = 'TRUNCATE TABLE *PREFIX*ocdownloader_queue';
         }
         $Query = \OCP\DB::prepare($SQL);
         $Request = $Query->execute();
     }
 }
Ejemplo n.º 4
0
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function CompletelyRemoveAll()
 {
     \OCP\JSON::setContentTypeHeader('application/json');
     try {
         if (isset($_POST['GIDS']) && count($_POST['GIDS']) > 0) {
             $GIDS = array();
             foreach ($_POST['GIDS'] as $GID) {
                 $Status = $this->WhichDownloader == 0 ? Aria2::TellStatus($GID) : CURL::TellStatus($GID);
                 if (!isset($Status['error']) && strcmp($Status['result']['status'], 'removed') == 0) {
                     $Remove = $this->WhichDownloader == 0 ? Aria2::RemoveDownloadResult($GID) : CURL::RemoveDownloadResult($GID);
                 }
                 $SQL = 'DELETE FROM `*PREFIX*ocdownloader_queue` WHERE `UID` = ? AND `GID` = ?';
                 if ($this->DbType == 1) {
                     $SQL = 'DELETE FROM *PREFIX*ocdownloader_queue WHERE "UID" = ? AND "GID" = ?';
                 }
                 $Query = \OCP\DB::prepare($SQL);
                 $Result = $Query->execute(array($this->CurrentUID, $GID));
                 $GIDS[] = $GID;
             }
             return new JSONResponse(array('ERROR' => false, 'MESSAGE' => (string) $this->L10N->t('The download has been totally removed'), 'GIDS' => $GIDS));
         } else {
             return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Bad GID')));
         }
     } catch (Exception $E) {
         return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage()));
     }
 }
Ejemplo n.º 5
0
 /**
  * @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')));
     }
 }
Ejemplo n.º 6
0
 /**
  * @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')));
     }
 }
Ejemplo n.º 7
0
 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);
     }
 }