]> _ Git - cubeextranet.git/commitdiff
done #2302 @1
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 2 Jul 2019 17:01:07 +0000 (17:01 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 2 Jul 2019 17:01:07 +0000 (17:01 +0000)
inc/commons/class.common.tools.php

index 65448876ad7c5effcef205d0e4b8495f730fb039..332589ed7ace1fabf4a7281cb56ae8093b0f1503 100644 (file)
@@ -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 .= '<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;
+    }
+
 }