Add rtmp tests

This commit is contained in:
Pierre Rudloff 2016-07-30 14:01:00 +02:00
parent ef65cb502b
commit 37c223638d
4 changed files with 53 additions and 8 deletions

View file

@ -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();
/**

View file

@ -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'},

View file

@ -10,3 +10,4 @@ curl_params:
convert: false
avconv: vendor/bin/ffmpeg
rtmpdump: vendor/bin/rtmpdump
curl: /usr/bin/curl

View file

@ -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);
}
}