Make RTMP videos work in stream mode (fixes #104)
This commit is contained in:
parent
d2ad962f6f
commit
fb3834296a
4 changed files with 68 additions and 1 deletions
|
@ -324,4 +324,16 @@ class VideoDownload
|
|||
|
||||
return popen($procBuilder->getProcess()->getCommandLine(), 'r');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get video stream from an RTMP video.
|
||||
*
|
||||
* @param \stdClass $video Video object returned by getJSON
|
||||
*
|
||||
* @return resource popen stream
|
||||
*/
|
||||
public function getRtmpStream(\stdClass $video)
|
||||
{
|
||||
return popen($this->getRtmpProcess($video)->getCommandLine(), 'r');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -305,7 +305,13 @@ class FrontController
|
|||
private function getStream($url, $format, $response, $request, $password = null)
|
||||
{
|
||||
$video = $this->download->getJSON($url, $format, $password);
|
||||
if ($video->protocol == 'm3u8') {
|
||||
if ($video->protocol == 'rtmp') {
|
||||
$stream = $this->download->getRtmpStream($video);
|
||||
$response = $response->withHeader('Content-Type', 'video/'.$video->ext);
|
||||
if ($request->isGet()) {
|
||||
$response = $response->withBody(new Stream($stream));
|
||||
}
|
||||
} elseif ($video->protocol == 'm3u8') {
|
||||
$stream = $this->download->getM3uStream($video);
|
||||
$response = $response->withHeader('Content-Type', 'video/'.$video->ext);
|
||||
if ($request->isGet()) {
|
||||
|
|
|
@ -344,6 +344,21 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertTrue($result->isOk());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the redirect() function with an RTMP stream.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRedirectWithRtmpStream()
|
||||
{
|
||||
$controller = new FrontController($this->container, new Config(['stream'=>true]));
|
||||
$result = $controller->redirect(
|
||||
$this->request->withQueryParams(['url'=>'http://www.rtl2.de/sendung/grip-das-motormagazin/folge/folge-203-0']),
|
||||
$this->response
|
||||
);
|
||||
$this->assertTrue($result->isOk());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the redirect() function with a missing password.
|
||||
*
|
||||
|
|
|
@ -196,6 +196,23 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides RTMP URLs for tests.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function rtmpUrlProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'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',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides incorrect URLs for tests.
|
||||
*
|
||||
|
@ -373,6 +390,23 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertFalse(feof($stream));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getRtmpStream function.
|
||||
*
|
||||
* @param string $url URL
|
||||
* @param string $format Format
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider rtmpUrlProvider
|
||||
*/
|
||||
public function testGetRtmpStream($url, $format)
|
||||
{
|
||||
$video = $this->download->getJSON($url, $format);
|
||||
$stream = $this->download->getRtmpStream($video);
|
||||
$this->assertInternalType('resource', $stream);
|
||||
$this->assertFalse(feof($stream));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getM3uStream function without avconv.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue