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 .= '<form action="" method="post" class="notajax">';
+ $res .= '<table class="liste">';
+ $res .= '<tr><th colspan="2"><strong>' . __('Récupérer des webvideos (youtube, vimeo, etc.)') . '</strong></th></tr>';
+ $res .= '<tr><td>' . __("Liste") . '</td><td><textarea cols="80" rows="20" name="list"></textarea></td></tr>';
+ $res .= '<tr><td class="right" colspan="2"><a href="#" class="submit">' . $core->typo->BoutonOK(__('Télécharger')) . '</a></td></td>';
+ $res .= '</table>';
+ $res .= '</form>';
+ $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;
+ }
+
}