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) { if (!self::$AllowProtocolYT && !\OC_User::isAdminUser(self::$CurrentUID)) { return array('ERROR' => true, 'MESSAGE' => 'Notallowedtouseprotocolyt'); } $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 { if (!self::$AllowProtocolHTTP && !\OC_User::isAdminUser(self::$CurrentUID) && Tools::StartsWith(strtolower($URL), 'http')) { return array('ERROR' => true, 'MESSAGE' => 'Notallowedtouseprotocolhttp'); } elseif (!self::$AllowProtocolFTP && !\OC_User::isAdminUser(self::$CurrentUID) && Tools::StartsWith(strtolower($URL), 'ftp')) { return array('ERROR' => true, 'MESSAGE' => 'Notallowedtouseprotocolftp'); } $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'], 'follow-torrent' => false); 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 = self::$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`, `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'); } }