From: vincent@cubedesigners.com Date: Tue, 2 Jul 2019 17:01:07 +0000 (+0000) Subject: done #2302 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=4cf358e8574d97a09de64656083bc619697a7c22;p=cubeextranet.git done #2302 @1 --- diff --git a/inc/commons/class.common.tools.php b/inc/commons/class.common.tools.php index 65448876a..332589ed7 100644 --- a/inc/commons/class.common.tools.php +++ b/inc/commons/class.common.tools.php @@ -1274,17 +1274,88 @@ class commonTools public static function youtubedl() { - $url = $_GET['url']; + + if (isset($_GET['url'])) { + self::youtubedlo(); + return; + } + if (isset($_POST['list'])) { + self::youtubedll(); + return; + } + + + //commonDroits::min(5); + + global $core; + + + $res = commonPage::barre(); + $res .= commonPage::tMain(); + $res .= commonPage::bh(); + $res .= '
'; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= '
' . __('Récupérer des webvideos (youtube, vimeo, etc.)') . '
' . __("Liste") . '
' . $core->typo->BoutonOK(__('Télécharger')) . '
'; + $res .= '
'; + $res .= commonPage::bf(); + + $res .= commonPage::bMain(); + + return $res; + } + + public static function youtubedll() + { + $e = explode("\r", $_POST['list']); $dir = '/data/extranet/www/cache/youtubedl'; - `cd $dir;youtube-dl $url`; - $fname = trim(`youtube-dl --get-filename $url`); - $path = $dir . '/' . $fname; + $paths = []; + foreach ($e as $item) { + $item = trim($item); + if ($item === '') { + continue; + } + $paths[] = $dir . '/' . self::_youtubedl($item); + } + + $zipPath = '/data/extranet/www/cache/youtubedl/batch-' . rand(1, 10000000000) . '.zip'; + CubeIT_Util_Zip::archive($paths, $zipPath); + + header('Content-Type: application/zip'); + header('Content-Disposition: attachment; filename="youtubedl.zip"'); + header('X-SendFile: ' . $zipPath); + ob_end_clean(); + exit; + } + + public static function youtubedlo() + { + $url = $_GET['url']; + $path = self::_youtubedl($url); header('Content-Type: application/octet-stream'); - header('Content-Disposition: attachment; filename="' . $fname . '"'); - header('X-SendFile: ' . $path); + header('Content-Disposition: attachment; filename="' . $path . '"'); + header('X-SendFile: ' . '/data/extranet/www/cache/youtubedl' . $path); ob_end_clean(); exit; } + public static function _youtubedl($url) + { + set_time_limit(0); + $dir = '/data/extranet/www/cache/youtubedl'; + $opts = ' -f \'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4\' -o \'%(id)s-%(title)s.%(ext)s\' --restrict-filenames '; + $fname = trim(`youtube-dl --get-filename $opts $url`); + + $final = $dir . $fname; + + if (!file_exists($final) || filesize($final) == 0) { + `cd $dir;youtube-dl $opts $url`; + } + + return $fname; + } + }