Exemple #1
0
 /**
  * Test the getInstance function with the CONVERT environment variable.
  *
  * @return void
  */
 public function testGetInstanceWithEnv()
 {
     putenv('CONVERT=1');
     Config::destroyInstance();
     $config = Config::getInstance('config_test.yml');
     $this->assertEquals($config->convert, true);
 }
Exemple #2
0
 /**
  * VideoDownload constructor.
  */
 public function __construct(Config $config = null)
 {
     if (isset($config)) {
         $this->config = $config;
     } else {
         $this->config = Config::getInstance();
     }
     $this->procBuilder = new ProcessBuilder();
     if (!is_file($this->config->youtubedl)) {
         throw new \Exception("Can't find youtube-dl at " . $this->config->youtubedl);
     } elseif (!is_file($this->config->python)) {
         throw new \Exception("Can't find Python at " . $this->config->python);
     }
     $this->procBuilder->setPrefix(array_merge([$this->config->python, $this->config->youtubedl], $this->config->params));
 }
Exemple #3
0
 /**
  * Dislay information about the video
  * @return void
  */
 static function video()
 {
     global $app;
     $config = Config::getInstance();
     if (isset($_GET["url"])) {
         if (isset($_GET['audio'])) {
             try {
                 $video = VideoDownload::getJSON($_GET["url"]);
                 //Vimeo needs a correct user-agent
                 $UA = VideoDownload::getUA();
                 ini_set('user_agent', $UA);
                 $url_info = parse_url($video->url);
                 if ($url_info['scheme'] == 'rtmp') {
                     ob_end_flush();
                     header('Content-Disposition: attachment; filename="' . html_entity_decode(pathinfo(VideoDownload::getFilename($video->webpage_url), PATHINFO_FILENAME) . '.mp3', ENT_COMPAT, 'ISO-8859-1') . '"');
                     header("Content-Type: audio/mpeg");
                     passthru('/usr/bin/rtmpdump -q -r ' . escapeshellarg($video->url) . '   |  ' . $config->avconv . ' -v quiet -i - -f mp3 -vn pipe:1');
                     exit;
                 } else {
                     ob_end_flush();
                     header('Content-Disposition: attachment; filename="' . html_entity_decode(pathinfo(VideoDownload::getFilename($video->webpage_url), PATHINFO_FILENAME) . '.mp3', ENT_COMPAT, 'ISO-8859-1') . '"');
                     header("Content-Type: audio/mpeg");
                     passthru('curl  --user-agent ' . escapeshellarg($UA) . ' ' . escapeshellarg($video->url) . '   |  ' . $config->avconv . ' -v quiet -i - -f mp3 -vn pipe:1');
                     exit;
                 }
             } catch (\Exception $e) {
                 $error = $e->getMessage();
             }
         } else {
             try {
                 $video = VideoDownload::getJSON($_GET["url"]);
                 $app->render('head.tpl', array('class' => 'video'));
                 $app->render('video.tpl', array('video' => $video));
                 $app->render('footer.tpl');
             } catch (\Exception $e) {
                 $error = $e->getMessage();
             }
         }
     }
     if (isset($error)) {
         $app->render('head.tpl', array('class' => 'video'));
         $app->render('error.tpl', array('errors' => $error));
         $app->render('footer.tpl');
     }
 }
 /**
  * Test getAudioStream function without curl or rtmpdump.
  *
  * @param string $url    URL
  * @param string $format Format
  *
  * @return void
  * @expectedException Exception
  * @dataProvider      urlProvider
  */
 public function testGetAudioStreamCurlError($url, $format)
 {
     $config = \Alltube\Config::getInstance();
     $config->curl = 'foobar';
     $config->rtmpdump = 'foobar';
     $this->download->getAudioStream($url, $format);
 }
Exemple #5
0
 /**
  * Dislay information about the video.
  *
  * @param Request  $request  PSR-7 request
  * @param Response $response PSR-7 response
  *
  * @return Response HTTP response
  */
 public function video(Request $request, Response $response)
 {
     $params = $request->getQueryParams();
     $this->config = Config::getInstance();
     if (isset($params['url'])) {
         if (isset($params['audio'])) {
             try {
                 $url = $this->download->getURL($params['url'], 'mp3[protocol^=http]');
                 return $response->withRedirect($url);
             } catch (\Exception $e) {
                 $response = $response->withHeader('Content-Disposition', 'attachment; filename="' . $this->download->getAudioFilename($params['url'], 'bestaudio/best') . '"');
                 $response = $response->withHeader('Content-Type', 'audio/mpeg');
                 if ($request->isGet()) {
                     $process = $this->download->getAudioStream($params['url'], 'bestaudio/best');
                     $response = $response->withBody(new Stream($process));
                 }
                 return $response;
             }
         } else {
             $video = $this->download->getJSON($params['url']);
             if ($this->container instanceof Container) {
                 $this->container->view->render($response, 'video.tpl', ['video' => $video, 'class' => 'video', 'title' => $video->title, 'description' => 'Download "' . $video->title . '" from ' . $video->extractor_key]);
             }
         }
     } else {
         return $response->withRedirect($this->container->get('router')->pathFor('index'));
     }
 }
Exemple #6
0
 /**
  * Test the getInstance function
  * @return void
  */
 public function testGetInstance()
 {
     putenv('CONVERT=1');
     $config = Config::getInstance();
     $this->assertEquals($config->convert, true);
 }