From 37c223638d8bb8875aad0dbb33a8d9feb84fd135 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sat, 30 Jul 2016 14:01:00 +0200 Subject: [PATCH] Add rtmp tests --- classes/Config.php | 1 + classes/VideoDownload.php | 16 +++++++++----- config.example.yml | 1 + tests/VideoDownloadTest.php | 43 ++++++++++++++++++++++++++++++++++--- 4 files changed, 53 insertions(+), 8 deletions(-) diff --git a/classes/Config.php b/classes/Config.php index cc13c3c..96e5ca5 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -35,6 +35,7 @@ class Config public $convert = false; public $avconv = 'vendor/bin/ffmpeg'; public $rtmpdump = 'vendor/bin/rtmpdump'; + public $curl = '/usr/bin/curl'; public $curl_params = array(); /** diff --git a/classes/VideoDownload.php b/classes/VideoDownload.php index c252697..c22733b 100644 --- a/classes/VideoDownload.php +++ b/classes/VideoDownload.php @@ -196,21 +196,27 @@ class VideoDownload $builder->add('--playpath'); $builder->add($video->play_path); } - foreach ($video->rtmp_conn as $conn) { - $builder->add('--conn'); - $builder->add($conn); + if (isset($video->rtmp_conn)) { + foreach ($video->rtmp_conn as $conn) { + $builder->add('--conn'); + $builder->add($conn); + } + } + if (isset($video->app)) { + $builder->add('--app'); + $builder->add($video->app); } $chain = new Chain($builder->getProcess()); $chain->add('|', $avconvProc); } else { - if (!shell_exec('which curl')) { + if (!shell_exec('which '.$this->config->curl)) { throw(new \Exception('Can\'t find curl')); } $chain = new Chain( ProcessBuilder::create( array_merge( array( - 'curl', + $this->config->curl, '--silent', '--location', '--user-agent', $video->http_headers->{'User-Agent'}, diff --git a/config.example.yml b/config.example.yml index 9f66ab7..ca03f0b 100644 --- a/config.example.yml +++ b/config.example.yml @@ -10,3 +10,4 @@ curl_params: convert: false avconv: vendor/bin/ffmpeg rtmpdump: vendor/bin/rtmpdump +curl: /usr/bin/curl diff --git a/tests/VideoDownloadTest.php b/tests/VideoDownloadTest.php index bfe4e4d..7faada5 100644 --- a/tests/VideoDownloadTest.php +++ b/tests/VideoDownloadTest.php @@ -105,6 +105,24 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase 'vimeocdn.com', "Carving the Mountains-24195442.mp3" ), + array( + 'http://www.bbc.co.uk/programmes/b039g8p7', 'bestaudio/best', + "Leonard Cohen, Kaleidoscope - BBC Radio 4-b039d07m.flv", + 'bbcodspdns.fcod.llnwd.net', + "Leonard Cohen, Kaleidoscope - BBC Radio 4-b039d07m.mp3" + ), + array( + 'http://www.arte.tv/guide/de/sendungen/XEN/xenius/?vid=055918-015_PLUS7-D', 'RTMP_MQ_1', + "Xenius-063945-044-A.flv", + 'edgefcs.net', + "Xenius-063945-044-A.mp3" + ), + array( + 'http://www.rtl2.de/sendung/grip-das-motormagazin/folge/folge-203-0', 'bestaudio/best', + "GRIP sucht den Sommerkönig-folge-203-0.f4v", + 'edgefcs.net', + "GRIP sucht den Sommerkönig-folge-203-0.mp3" + ) ); } @@ -209,12 +227,13 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase */ public function testGetAudioStream($url, $format) { - $process = $this->download->getAudioStream($url, $format); - $this->assertInternalType('resource', $process); + $stream = $this->download->getAudioStream($url, $format); + $this->assertInternalType('resource', $stream); + $this->assertNotEmpty(fread($stream, 100)); } /** - * Test getAudioStream function + * Test getAudioStream function without avconv * * @param string $url URL * @param string $format Format @@ -229,4 +248,22 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase $config->avconv = 'foobar'; $this->download->getAudioStream($url, $format); } + + /** + * 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); + } }