2015-08-29 21:46:57 +02:00
|
|
|
<?php
|
2019-10-03 21:24:12 +02:00
|
|
|
|
2015-08-29 21:46:57 +02:00
|
|
|
/**
|
2019-04-21 18:30:02 +02:00
|
|
|
* VideoTest class.
|
2016-08-01 13:29:13 +02:00
|
|
|
*/
|
2016-12-05 13:12:27 +01:00
|
|
|
|
2016-03-30 01:49:08 +02:00
|
|
|
namespace Alltube\Test;
|
|
|
|
|
2016-10-18 10:45:16 +02:00
|
|
|
use Alltube\Config;
|
2020-06-21 01:44:20 +02:00
|
|
|
use Alltube\Exception\ConfigException;
|
2020-10-22 22:39:09 +02:00
|
|
|
use Alltube\Exception\DependencyException;
|
2020-06-21 01:44:20 +02:00
|
|
|
use Alltube\Library\Downloader;
|
|
|
|
use Alltube\Library\Exception\AlltubeLibraryException;
|
|
|
|
use Alltube\Library\Exception\AvconvException;
|
|
|
|
use Alltube\Library\Exception\InvalidProtocolConversionException;
|
|
|
|
use Alltube\Library\Exception\PasswordException;
|
|
|
|
use Alltube\Library\Exception\PlaylistConversionException;
|
|
|
|
use Alltube\Library\Exception\RemuxException;
|
|
|
|
use Alltube\Library\Exception\WrongPasswordException;
|
|
|
|
use Alltube\Library\Exception\YoutubedlException;
|
|
|
|
use Alltube\Library\Video;
|
2020-10-22 22:39:09 +02:00
|
|
|
use SmartyException;
|
2015-08-29 21:46:57 +02:00
|
|
|
|
|
|
|
/**
|
2019-04-21 18:30:02 +02:00
|
|
|
* Unit tests for the Video class.
|
2019-10-26 16:13:08 +02:00
|
|
|
* @requires download
|
2020-06-21 01:44:20 +02:00
|
|
|
* @todo Split Downloader and Video tests.
|
2016-08-01 13:29:13 +02:00
|
|
|
*/
|
2020-10-22 22:39:09 +02:00
|
|
|
class VideoTest extends ContainerTest
|
2015-08-29 21:46:57 +02:00
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
/**
|
|
|
|
* Downloader instance used in tests.
|
|
|
|
*
|
|
|
|
* @var Downloader
|
|
|
|
*/
|
|
|
|
private $downloader;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Video format used in tests.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $format;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare tests.
|
2020-10-22 22:39:09 +02:00
|
|
|
*
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws ConfigException
|
2020-10-22 22:39:09 +02:00
|
|
|
* @throws DependencyException
|
|
|
|
* @throws SmartyException
|
2020-06-21 01:44:20 +02:00
|
|
|
*/
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2020-10-22 22:39:09 +02:00
|
|
|
$this->downloader = $this->container->get('config')->getDownloader();
|
2020-06-21 01:44:20 +02:00
|
|
|
$this->format = 'best';
|
|
|
|
}
|
|
|
|
|
2017-11-11 13:58:55 +01:00
|
|
|
/**
|
2019-04-21 18:30:02 +02:00
|
|
|
* Test getExtractors function.
|
2016-10-18 10:45:16 +02:00
|
|
|
*
|
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws AlltubeLibraryException
|
2016-10-18 10:45:16 +02:00
|
|
|
*/
|
2019-04-21 18:30:02 +02:00
|
|
|
public function testGetExtractors()
|
2016-10-18 10:45:16 +02:00
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$this->assertContains('youtube', $this->downloader->getExtractors());
|
2016-10-18 10:45:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-21 18:30:02 +02:00
|
|
|
* Test getUrl function.
|
2015-10-29 18:40:22 +01:00
|
|
|
*
|
2020-05-13 21:33:05 +02:00
|
|
|
* @param string $url URL
|
|
|
|
* @param string $format Format
|
|
|
|
* @param string $filename Filename
|
2017-01-02 23:08:51 +01:00
|
|
|
* @param string $extension File extension
|
2020-05-13 21:33:05 +02:00
|
|
|
* @param string $domain Domain
|
2015-10-29 18:40:22 +01:00
|
|
|
*
|
2016-09-07 22:28:28 +00:00
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws AlltubeLibraryException
|
2015-10-29 18:40:22 +01:00
|
|
|
* @dataProvider urlProvider
|
2017-04-25 00:48:10 +02:00
|
|
|
* @dataProvider m3uUrlProvider
|
|
|
|
* @dataProvider remuxUrlProvider
|
2015-09-04 22:45:55 +02:00
|
|
|
*/
|
2019-04-21 18:30:02 +02:00
|
|
|
public function testgetUrl(
|
2020-10-17 22:22:17 +02:00
|
|
|
string $url,
|
|
|
|
string $format,
|
|
|
|
string $filename,
|
|
|
|
string $extension,
|
|
|
|
string $domain
|
2017-12-05 14:52:20 +01:00
|
|
|
) {
|
2020-06-21 01:44:20 +02:00
|
|
|
$video = new Video($this->downloader, $url, $format);
|
2019-04-21 18:30:02 +02:00
|
|
|
foreach ($video->getUrl() as $videoURL) {
|
2019-11-30 14:08:18 +01:00
|
|
|
$this->assertStringContainsString($domain, $videoURL);
|
2019-04-21 18:30:02 +02:00
|
|
|
}
|
2015-09-04 22:45:55 +02:00
|
|
|
}
|
|
|
|
|
2016-10-20 23:01:31 +02:00
|
|
|
/**
|
2019-04-21 18:30:02 +02:00
|
|
|
* Test getUrl function with a protected video.
|
2016-10-20 23:01:31 +02:00
|
|
|
*
|
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws AlltubeLibraryException
|
2016-10-20 23:01:31 +02:00
|
|
|
*/
|
2019-04-21 18:30:02 +02:00
|
|
|
public function testgetUrlWithPassword()
|
2016-10-20 23:01:31 +02:00
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$video = new Video($this->downloader, 'http://vimeo.com/68375962', 'best', 'youtube-dl');
|
2019-04-21 18:30:02 +02:00
|
|
|
foreach ($video->getUrl() as $videoURL) {
|
2019-11-30 14:08:18 +01:00
|
|
|
$this->assertStringContainsString('vimeocdn.com', $videoURL);
|
2019-04-21 18:30:02 +02:00
|
|
|
}
|
2016-10-20 23:01:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-21 18:30:02 +02:00
|
|
|
* Test getUrl function with a protected video and no password.
|
2016-10-20 23:01:31 +02:00
|
|
|
*
|
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws AlltubeLibraryException
|
2016-10-20 23:01:31 +02:00
|
|
|
*/
|
2019-04-21 18:30:02 +02:00
|
|
|
public function testgetUrlWithMissingPassword()
|
2016-10-20 23:01:31 +02:00
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$this->expectException(PasswordException::class);
|
|
|
|
$video = new Video($this->downloader, 'http://vimeo.com/68375962', $this->format);
|
2019-04-21 18:30:02 +02:00
|
|
|
$video->getUrl();
|
2016-10-20 23:01:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-21 18:30:02 +02:00
|
|
|
* Test getUrl function with a protected video and a wrong password.
|
2016-10-20 23:01:31 +02:00
|
|
|
*
|
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws AlltubeLibraryException
|
2016-10-20 23:01:31 +02:00
|
|
|
*/
|
2019-04-21 18:30:02 +02:00
|
|
|
public function testgetUrlWithWrongPassword()
|
2016-10-20 23:01:31 +02:00
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$this->expectException(WrongPasswordException::class);
|
|
|
|
$video = new Video($this->downloader, 'http://vimeo.com/68375962', 'best', 'foo');
|
2019-04-21 18:30:02 +02:00
|
|
|
$video->getUrl();
|
2016-10-20 23:01:31 +02:00
|
|
|
}
|
|
|
|
|
2015-09-04 22:45:55 +02:00
|
|
|
/**
|
2019-04-21 18:30:02 +02:00
|
|
|
* Test getUrl function errors.
|
2015-10-29 18:40:22 +01:00
|
|
|
*
|
2015-09-04 22:45:55 +02:00
|
|
|
* @param string $url URL
|
2015-10-29 18:40:22 +01:00
|
|
|
*
|
2016-09-07 22:28:28 +00:00
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws AlltubeLibraryException
|
|
|
|
* @dataProvider ErrorUrlProvider
|
2015-09-04 22:45:55 +02:00
|
|
|
*/
|
2020-09-27 19:56:19 +02:00
|
|
|
public function testgetUrlError(string $url)
|
2015-09-04 22:45:55 +02:00
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$this->expectException(YoutubedlException::class);
|
|
|
|
$video = new Video($this->downloader, $url, $this->format);
|
2019-04-21 18:30:02 +02:00
|
|
|
$video->getUrl();
|
2015-09-04 22:45:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Provides URLs for tests.
|
2015-10-29 18:40:22 +01:00
|
|
|
*
|
2016-08-01 13:29:13 +02:00
|
|
|
* @return array[]
|
2015-09-04 22:45:55 +02:00
|
|
|
*/
|
2020-12-17 22:43:05 +01:00
|
|
|
public function urlProvider(): array
|
2015-09-04 22:45:55 +02:00
|
|
|
{
|
2020-05-13 21:33:05 +02:00
|
|
|
return [
|
2016-09-07 22:28:28 +00:00
|
|
|
[
|
2017-01-16 11:29:56 +01:00
|
|
|
'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'best[protocol^=http]',
|
2017-05-31 00:57:39 +02:00
|
|
|
'It_s_Not_Me_It_s_You_-_Hearts_Under_Fire-M7IpKCZ47pU',
|
2017-01-02 23:08:51 +01:00
|
|
|
'mp4',
|
2016-07-30 00:47:46 +02:00
|
|
|
'googlevideo.com',
|
2016-09-07 22:28:28 +00:00
|
|
|
],
|
|
|
|
[
|
2020-10-17 22:09:01 +02:00
|
|
|
'https://www.youtube.com/watch?v=RJJ6FCAXvKg', '18',
|
2019-10-03 21:24:12 +02:00
|
|
|
'Heart_Attack_-_Demi_Lovato_' .
|
2017-05-31 00:48:50 +02:00
|
|
|
'Sam_Tsui_Against_The_Current-RJJ6FCAXvKg',
|
2017-01-02 23:08:51 +01:00
|
|
|
'mp4',
|
2016-07-30 00:47:46 +02:00
|
|
|
'googlevideo.com',
|
2016-09-07 22:28:28 +00:00
|
|
|
],
|
|
|
|
[
|
2016-07-30 14:01:00 +02:00
|
|
|
'http://www.bbc.co.uk/programmes/b039g8p7', 'bestaudio/best',
|
2018-09-03 10:42:20 +02:00
|
|
|
'Kaleidoscope_Leonard_Cohen-b039d07m',
|
2017-01-02 23:08:51 +01:00
|
|
|
'flv',
|
2016-07-30 14:01:00 +02:00
|
|
|
'bbcodspdns.fcod.llnwd.net',
|
2016-09-07 22:28:28 +00:00
|
|
|
],
|
2018-01-25 15:10:11 +01:00
|
|
|
[
|
2019-11-30 14:08:18 +01:00
|
|
|
'https://vimeo.com/24195442', 'http-720p',
|
2019-04-19 23:26:03 +02:00
|
|
|
'Carving_the_Mountains-24195442',
|
|
|
|
'mp4',
|
2020-05-14 11:15:44 +02:00
|
|
|
'akamaized.net',
|
2019-10-26 16:13:08 +02:00
|
|
|
]
|
|
|
|
];
|
2016-12-27 00:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-05-08 19:46:37 +02:00
|
|
|
* Provides URLs for remux tests.
|
2016-12-27 00:10:18 +01:00
|
|
|
*
|
|
|
|
* @return array[]
|
|
|
|
*/
|
2020-12-17 22:43:05 +01:00
|
|
|
public function remuxUrlProvider(): array
|
2017-04-25 00:40:24 +02:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'bestvideo+bestaudio',
|
2017-05-31 00:57:39 +02:00
|
|
|
'It_s_Not_Me_It_s_You_-_Hearts_Under_Fire-M7IpKCZ47pU',
|
2017-04-25 00:40:24 +02:00
|
|
|
'mp4',
|
|
|
|
'googlevideo.com',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-05-08 19:46:37 +02:00
|
|
|
* Provides M3U8 URLs for tests.
|
2017-04-25 00:40:24 +02:00
|
|
|
*
|
|
|
|
* @return array[]
|
|
|
|
*/
|
2020-12-17 22:43:05 +01:00
|
|
|
public function m3uUrlProvider(): array
|
2016-12-27 00:10:18 +01:00
|
|
|
{
|
2020-05-13 21:33:05 +02:00
|
|
|
return [
|
2019-10-26 16:13:08 +02:00
|
|
|
[
|
2017-12-10 18:47:42 +01:00
|
|
|
'https://twitter.com/verge/status/813055465324056576/video/1', 'hls-2176',
|
2017-05-31 00:48:50 +02:00
|
|
|
'The_Verge_-_This_tiny_origami_robot_can_self-fold_and_complete_tasks-813055465324056576',
|
2017-01-16 11:23:47 +01:00
|
|
|
'mp4',
|
2016-12-26 15:50:26 +01:00
|
|
|
'video.twimg.com',
|
2019-10-26 16:13:08 +02:00
|
|
|
]
|
|
|
|
];
|
2015-09-04 22:45:55 +02:00
|
|
|
}
|
|
|
|
|
2017-04-24 18:31:14 +02:00
|
|
|
/**
|
|
|
|
* Provides RTMP URLs for tests.
|
|
|
|
*
|
|
|
|
* @return array[]
|
|
|
|
*/
|
2020-12-17 22:43:05 +01:00
|
|
|
public function rtmpUrlProvider(): array
|
2017-04-24 18:31:14 +02:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
2018-03-20 11:37:47 +01:00
|
|
|
'http://www.rtvnh.nl/video/131946', 'rtmp-264',
|
|
|
|
'Ketting_van_strandgasten-131946',
|
2017-05-04 23:28:29 +02:00
|
|
|
'flv',
|
2018-03-20 11:37:47 +01:00
|
|
|
'lb-nh-vod.cdn.streamgate.nl',
|
2017-04-24 18:31:14 +02:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2015-09-04 22:45:55 +02:00
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Provides incorrect URLs for tests.
|
2015-10-29 18:40:22 +01:00
|
|
|
*
|
2016-08-01 13:29:13 +02:00
|
|
|
* @return array[]
|
2015-09-04 22:45:55 +02:00
|
|
|
*/
|
2020-12-17 22:43:05 +01:00
|
|
|
public function errorUrlProvider(): array
|
2015-09-04 22:45:55 +02:00
|
|
|
{
|
2016-09-07 22:28:28 +00:00
|
|
|
return [
|
|
|
|
['http://example.com/video'],
|
|
|
|
];
|
2015-09-04 22:45:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Test getJSON function.
|
2015-10-29 18:40:22 +01:00
|
|
|
*
|
2020-05-13 21:33:05 +02:00
|
|
|
* @param string $url URL
|
2015-09-04 22:45:55 +02:00
|
|
|
* @param string $format Format
|
2015-10-29 18:40:22 +01:00
|
|
|
*
|
2016-09-07 22:28:28 +00:00
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws AlltubeLibraryException
|
2017-04-25 00:48:10 +02:00
|
|
|
* @dataProvider urlProvider
|
2017-01-16 13:47:29 +01:00
|
|
|
* @dataProvider m3uUrlProvider
|
2015-09-04 22:45:55 +02:00
|
|
|
*/
|
2020-09-27 19:56:19 +02:00
|
|
|
public function testGetJson(string $url, string $format)
|
2015-09-04 22:45:55 +02:00
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$video = new Video($this->downloader, $url, $format);
|
2019-04-21 18:30:02 +02:00
|
|
|
$info = $video->getJson();
|
2015-09-04 22:45:55 +02:00
|
|
|
$this->assertObjectHasAttribute('webpage_url', $info);
|
|
|
|
$this->assertObjectHasAttribute('url', $info);
|
|
|
|
$this->assertObjectHasAttribute('ext', $info);
|
|
|
|
$this->assertObjectHasAttribute('title', $info);
|
2017-01-16 11:29:56 +01:00
|
|
|
$this->assertObjectHasAttribute('extractor_key', $info);
|
2018-01-25 15:10:11 +01:00
|
|
|
$this->assertObjectHasAttribute('format', $info);
|
2015-09-04 22:45:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Test getJSON function errors.
|
2015-10-29 18:40:22 +01:00
|
|
|
*
|
2015-09-04 22:45:55 +02:00
|
|
|
* @param string $url URL
|
2015-10-29 18:40:22 +01:00
|
|
|
*
|
2016-09-07 22:28:28 +00:00
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws AlltubeLibraryException
|
|
|
|
* @dataProvider ErrorURLProvider
|
2015-08-29 21:46:57 +02:00
|
|
|
*/
|
2020-09-27 19:56:19 +02:00
|
|
|
public function testGetJsonError(string $url)
|
2015-08-29 21:46:57 +02:00
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$this->expectException(YoutubedlException::class);
|
|
|
|
$video = new Video($this->downloader, $url, $this->format);
|
2019-04-21 18:30:02 +02:00
|
|
|
$video->getJson();
|
2015-08-29 21:46:57 +02:00
|
|
|
}
|
2016-07-30 00:47:46 +02:00
|
|
|
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Test getFilename function.
|
2016-07-30 00:47:46 +02:00
|
|
|
*
|
2020-05-13 21:33:05 +02:00
|
|
|
* @param string $url URL
|
|
|
|
* @param string $format Format
|
|
|
|
* @param string $filename Filename
|
2017-01-02 23:08:51 +01:00
|
|
|
* @param string $extension File extension
|
2016-07-30 00:47:46 +02:00
|
|
|
*
|
2016-09-07 22:28:28 +00:00
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws AlltubeLibraryException
|
2016-07-30 00:47:46 +02:00
|
|
|
* @dataProvider urlProvider
|
2017-01-16 13:47:29 +01:00
|
|
|
* @dataProvider m3uUrlProvider
|
2017-04-25 00:48:10 +02:00
|
|
|
* @dataProvider remuxUrlProvider
|
2016-07-30 00:47:46 +02:00
|
|
|
*/
|
2020-09-27 19:56:19 +02:00
|
|
|
public function testGetFilename(string $url, string $format, string $filename, string $extension)
|
2016-07-30 00:47:46 +02:00
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$video = new Video($this->downloader, $url, $format);
|
2019-10-03 21:24:12 +02:00
|
|
|
$this->assertEquals($video->getFilename(), $filename . '.' . $extension);
|
2016-07-30 00:47:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Test getFilename function errors.
|
2016-07-30 00:47:46 +02:00
|
|
|
*
|
|
|
|
* @param string $url URL
|
|
|
|
*
|
2016-09-07 22:28:28 +00:00
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws AlltubeLibraryException
|
|
|
|
* @dataProvider ErrorUrlProvider
|
2016-07-30 00:47:46 +02:00
|
|
|
*/
|
2020-09-27 19:56:19 +02:00
|
|
|
public function testGetFilenameError(string $url)
|
2016-07-30 00:47:46 +02:00
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$this->expectException(YoutubedlException::class);
|
|
|
|
$video = new Video($this->downloader, $url, $this->format);
|
2019-04-21 18:30:02 +02:00
|
|
|
$video->getFilename();
|
2016-07-30 00:47:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Test getAudioStream function.
|
2016-07-30 00:47:46 +02:00
|
|
|
*
|
2020-05-13 21:33:05 +02:00
|
|
|
* @param string $url URL
|
2016-07-30 00:47:46 +02:00
|
|
|
* @param string $format Format
|
|
|
|
*
|
2016-09-07 22:28:28 +00:00
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws AlltubeLibraryException
|
2020-09-27 19:56:19 +02:00
|
|
|
* @dataProvider urlProvider
|
2016-07-30 00:47:46 +02:00
|
|
|
*/
|
2020-09-27 19:56:19 +02:00
|
|
|
public function testGetAudioStream(string $url, string $format)
|
2016-07-30 00:47:46 +02:00
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$video = new Video($this->downloader, $url, $format);
|
|
|
|
$this->assertStream($this->downloader->getAudioStream($video));
|
2016-07-30 00:47:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-06-22 23:26:47 +02:00
|
|
|
* Test getAudioStream function without ffmpeg.
|
2016-07-30 00:47:46 +02:00
|
|
|
*
|
2020-06-21 01:44:20 +02:00
|
|
|
* @param string $url URL
|
2016-07-30 00:47:46 +02:00
|
|
|
* @param string $format Format
|
|
|
|
*
|
2016-09-07 22:28:28 +00:00
|
|
|
* @return void
|
2020-09-27 19:56:19 +02:00
|
|
|
* @throws AlltubeLibraryException
|
|
|
|
* @throws ConfigException
|
2020-06-21 01:44:20 +02:00
|
|
|
* @dataProvider urlProvider
|
2016-07-30 00:47:46 +02:00
|
|
|
*/
|
2020-09-27 19:56:19 +02:00
|
|
|
public function testGetAudioStreamFfmpegError(string $url, string $format)
|
2016-07-30 00:47:46 +02:00
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$this->expectException(AvconvException::class);
|
2020-10-17 22:07:07 +02:00
|
|
|
$config = new Config(['ffmpeg' => 'foobar']);
|
2020-06-21 01:44:20 +02:00
|
|
|
$downloader = $config->getDownloader();
|
2019-04-21 18:30:02 +02:00
|
|
|
|
2020-06-21 01:44:20 +02:00
|
|
|
$video = new Video($this->downloader, $url, $format, $this->format);
|
|
|
|
$downloader->getAudioStream($video);
|
2016-07-30 00:47:46 +02:00
|
|
|
}
|
2016-07-30 14:01:00 +02:00
|
|
|
|
2016-12-27 00:01:42 +01:00
|
|
|
/**
|
|
|
|
* Test getAudioStream function with a M3U8 file.
|
|
|
|
*
|
2020-06-21 01:44:20 +02:00
|
|
|
* @param string $url URL
|
2016-12-27 00:36:30 +01:00
|
|
|
* @param string $format Format
|
|
|
|
*
|
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws AlltubeLibraryException
|
2017-01-16 13:47:29 +01:00
|
|
|
* @dataProvider m3uUrlProvider
|
2016-12-27 00:36:30 +01:00
|
|
|
*/
|
2020-09-27 19:56:19 +02:00
|
|
|
public function testGetAudioStreamM3uError(string $url, string $format)
|
2016-12-27 00:36:30 +01:00
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$this->expectException(InvalidProtocolConversionException::class);
|
|
|
|
$video = new Video($this->downloader, $url, $format);
|
|
|
|
$this->downloader->getAudioStream($video);
|
2016-12-27 00:36:30 +01:00
|
|
|
}
|
|
|
|
|
2018-05-01 16:28:33 +02:00
|
|
|
/**
|
|
|
|
* Test getAudioStream function with a DASH URL.
|
|
|
|
*
|
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws AlltubeLibraryException
|
2018-05-01 16:28:33 +02:00
|
|
|
*/
|
|
|
|
public function testGetAudioStreamDashError()
|
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$this->expectException(InvalidProtocolConversionException::class);
|
|
|
|
$video = new Video($this->downloader, 'https://vimeo.com/251997032', 'bestaudio/best');
|
|
|
|
$this->downloader->getAudioStream($video);
|
2018-05-01 16:28:33 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 22:52:15 +02:00
|
|
|
/**
|
|
|
|
* Test getAudioStream function with a playlist.
|
|
|
|
*
|
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws AlltubeLibraryException
|
2018-05-23 22:52:15 +02:00
|
|
|
*/
|
|
|
|
public function testGetAudioStreamPlaylistError()
|
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$this->expectException(PlaylistConversionException::class);
|
2019-04-21 18:30:02 +02:00
|
|
|
$video = new Video(
|
2020-06-21 01:44:20 +02:00
|
|
|
$this->downloader,
|
2018-05-26 14:38:42 +02:00
|
|
|
'https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC',
|
|
|
|
'best'
|
|
|
|
);
|
2020-06-21 01:44:20 +02:00
|
|
|
$this->downloader->getAudioStream($video);
|
2018-05-23 22:52:15 +02:00
|
|
|
}
|
|
|
|
|
2017-04-26 00:08:35 +02:00
|
|
|
/**
|
2017-04-26 00:10:00 +02:00
|
|
|
* Assert that a stream is valid.
|
2017-04-26 00:08:35 +02:00
|
|
|
*
|
|
|
|
* @param resource $stream Stream
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function assertStream($stream)
|
|
|
|
{
|
2019-11-30 14:08:18 +01:00
|
|
|
$this->assertIsResource($stream);
|
2017-04-26 00:08:35 +02:00
|
|
|
$this->assertFalse(feof($stream));
|
|
|
|
}
|
|
|
|
|
2016-12-27 00:36:30 +01:00
|
|
|
/**
|
|
|
|
* Test getM3uStream function.
|
|
|
|
*
|
2020-05-13 21:33:05 +02:00
|
|
|
* @param string $url URL
|
2016-12-27 00:36:30 +01:00
|
|
|
* @param string $format Format
|
|
|
|
*
|
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws AlltubeLibraryException
|
2020-09-27 19:56:19 +02:00
|
|
|
* @dataProvider m3uUrlProvider
|
2016-12-27 00:36:30 +01:00
|
|
|
*/
|
2020-09-27 19:56:19 +02:00
|
|
|
public function testGetM3uStream(string $url, string $format)
|
2016-12-27 00:36:30 +01:00
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$video = new Video($this->downloader, $url, $format);
|
|
|
|
$this->assertStream($this->downloader->getM3uStream($video));
|
2016-12-27 00:36:30 +01:00
|
|
|
}
|
|
|
|
|
2017-04-25 00:40:24 +02:00
|
|
|
/**
|
|
|
|
* Test getRemuxStream function.
|
|
|
|
*
|
2020-05-13 21:33:05 +02:00
|
|
|
* @param string $url URL
|
2017-04-25 00:40:24 +02:00
|
|
|
* @param string $format Format
|
|
|
|
*
|
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws AlltubeLibraryException
|
2020-09-27 19:56:19 +02:00
|
|
|
* @dataProvider remuxUrlProvider
|
2017-04-25 00:40:24 +02:00
|
|
|
*/
|
2020-09-27 19:56:19 +02:00
|
|
|
public function testGetRemuxStream(string $url, string $format)
|
2017-04-25 00:40:24 +02:00
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$video = new Video($this->downloader, $url, $format);
|
|
|
|
$this->assertStream($this->downloader->getRemuxStream($video));
|
2019-04-21 18:30:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test getRemuxStream function with a video with only one URL.
|
|
|
|
*
|
2020-06-21 01:44:20 +02:00
|
|
|
* @param string $url URL
|
2019-04-21 18:30:02 +02:00
|
|
|
* @param string $format Format
|
|
|
|
*
|
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws AlltubeLibraryException
|
2019-04-21 18:30:02 +02:00
|
|
|
* @dataProvider urlProvider
|
|
|
|
*/
|
2020-09-27 19:56:19 +02:00
|
|
|
public function testGetRemuxStreamWithWrongVideo(string $url, string $format)
|
2019-04-21 18:30:02 +02:00
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$this->expectException(RemuxException::class);
|
|
|
|
$video = new Video($this->downloader, $url, $format);
|
|
|
|
$this->downloader->getRemuxStream($video);
|
2017-04-25 00:40:24 +02:00
|
|
|
}
|
|
|
|
|
2017-04-24 18:31:14 +02:00
|
|
|
/**
|
|
|
|
* Test getRtmpStream function.
|
|
|
|
*
|
2020-05-13 21:33:05 +02:00
|
|
|
* @param string $url URL
|
2017-04-24 18:31:14 +02:00
|
|
|
* @param string $format Format
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @dataProvider rtmpUrlProvider
|
|
|
|
*/
|
2020-09-27 19:56:19 +02:00
|
|
|
public function testGetRtmpStream(string $url, string $format)
|
2017-04-24 18:31:14 +02:00
|
|
|
{
|
2019-01-15 11:25:49 +01:00
|
|
|
$this->markTestIncomplete('We need to find another RTMP video.');
|
2017-04-24 18:31:14 +02:00
|
|
|
}
|
|
|
|
|
2016-12-27 00:36:30 +01:00
|
|
|
/**
|
2020-06-22 23:26:47 +02:00
|
|
|
* Test getM3uStream function without ffmpeg.
|
2016-12-27 00:36:30 +01:00
|
|
|
*
|
2020-06-21 01:44:20 +02:00
|
|
|
* @param string $url URL
|
2016-12-27 00:36:30 +01:00
|
|
|
* @param string $format Format
|
|
|
|
*
|
2016-12-27 00:01:42 +01:00
|
|
|
* @return void
|
2020-09-27 19:56:19 +02:00
|
|
|
* @throws AlltubeLibraryException
|
|
|
|
* @throws ConfigException
|
2017-01-16 13:47:29 +01:00
|
|
|
* @dataProvider m3uUrlProvider
|
2016-12-27 00:01:42 +01:00
|
|
|
*/
|
2020-09-27 19:56:19 +02:00
|
|
|
public function testGetM3uStreamFfmpegError(string $url, string $format)
|
2016-12-27 00:01:42 +01:00
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$this->expectException(AvconvException::class);
|
2020-10-17 22:07:07 +02:00
|
|
|
$config = new Config(['ffmpeg' => 'foobar']);
|
2020-06-21 01:44:20 +02:00
|
|
|
$downloader = $config->getDownloader();
|
2019-04-21 18:30:02 +02:00
|
|
|
|
2020-06-21 01:44:20 +02:00
|
|
|
$video = new Video($downloader, $url, $format);
|
|
|
|
$downloader->getM3uStream($video);
|
2016-12-27 00:01:42 +01:00
|
|
|
}
|
2017-05-02 17:04:55 +02:00
|
|
|
|
2018-01-24 23:30:24 +01:00
|
|
|
/**
|
2020-06-22 23:26:47 +02:00
|
|
|
* Test getConvertedStream function without ffmpeg.
|
2018-01-24 23:30:24 +01:00
|
|
|
*
|
2020-05-13 21:33:05 +02:00
|
|
|
* @param string $url URL
|
2018-01-24 23:30:24 +01:00
|
|
|
* @param string $format Format
|
|
|
|
*
|
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws AlltubeLibraryException
|
2020-09-27 19:56:19 +02:00
|
|
|
* @dataProvider urlProvider
|
2018-01-24 23:30:24 +01:00
|
|
|
*/
|
2020-09-27 19:56:19 +02:00
|
|
|
public function testGetConvertedStream(string $url, string $format)
|
2018-01-24 23:30:24 +01:00
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$video = new Video($this->downloader, $url, $format);
|
|
|
|
$this->assertStream($this->downloader->getConvertedStream($video, 32, 'flv'));
|
2018-01-24 23:30:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test getConvertedStream function with a M3U8 file.
|
|
|
|
*
|
2020-06-21 01:44:20 +02:00
|
|
|
* @param string $url URL
|
2018-01-24 23:30:24 +01:00
|
|
|
* @param string $format Format
|
|
|
|
*
|
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws AlltubeLibraryException
|
2018-01-24 23:30:24 +01:00
|
|
|
* @dataProvider m3uUrlProvider
|
|
|
|
*/
|
2020-09-27 19:56:19 +02:00
|
|
|
public function testGetConvertedStreamM3uError(string $url, string $format)
|
2018-01-24 23:30:24 +01:00
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$this->expectException(InvalidProtocolConversionException::class);
|
|
|
|
$video = new Video($this->downloader, $url, $format);
|
|
|
|
$this->downloader->getConvertedStream($video, 32, 'flv');
|
2018-01-24 23:30:24 +01:00
|
|
|
}
|
2015-08-29 21:46:57 +02:00
|
|
|
}
|