Move Video class to a separate library
+ improve error handling + youtube-dl update
This commit is contained in:
parent
7d94271a49
commit
5c2823e3f1
30 changed files with 649 additions and 1152 deletions
|
@ -7,7 +7,7 @@
|
|||
namespace Alltube\Test;
|
||||
|
||||
use Alltube\Config;
|
||||
use Exception;
|
||||
use Alltube\Exception\ConfigException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
|
@ -33,7 +33,7 @@ abstract class BaseTest extends TestCase
|
|||
|
||||
/**
|
||||
* Prepare tests.
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
namespace Alltube\Test;
|
||||
|
||||
use Alltube\Config;
|
||||
use Exception;
|
||||
use Alltube\Exception\ConfigException;
|
||||
|
||||
/**
|
||||
* Unit tests for the Config class.
|
||||
|
@ -23,7 +23,7 @@ class ConfigTest extends BaseTest
|
|||
|
||||
/**
|
||||
* Prepare tests.
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
|
@ -82,7 +82,7 @@ class ConfigTest extends BaseTest
|
|||
* Test the setFile function.
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function testSetFile()
|
||||
{
|
||||
|
@ -97,7 +97,7 @@ class ConfigTest extends BaseTest
|
|||
*/
|
||||
public function testSetFileWithMissingFile()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectException(ConfigException::class);
|
||||
Config::setFile('foo');
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ class ConfigTest extends BaseTest
|
|||
* Test the setOptions function.
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function testSetOptions()
|
||||
{
|
||||
|
@ -118,7 +118,7 @@ class ConfigTest extends BaseTest
|
|||
* Test the setOptions function.
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function testSetOptionsWithoutUpdate()
|
||||
{
|
||||
|
@ -134,7 +134,7 @@ class ConfigTest extends BaseTest
|
|||
*/
|
||||
public function testSetOptionsWithBadYoutubedl()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectException(ConfigException::class);
|
||||
Config::setOptions(['youtubedl' => 'foo']);
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ class ConfigTest extends BaseTest
|
|||
*/
|
||||
public function testSetOptionsWithBadPython()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectException(ConfigException::class);
|
||||
Config::setOptions(['python' => 'foo']);
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ class ConfigTest extends BaseTest
|
|||
* Test the getInstance function with the CONVERT and PYTHON environment variables.
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function testGetInstanceWithEnv()
|
||||
{
|
||||
|
|
|
@ -9,13 +9,14 @@ namespace Alltube\Test;
|
|||
use Alltube\Controller\BaseController;
|
||||
use Alltube\Controller\DownloadController;
|
||||
use Alltube\Controller\FrontController;
|
||||
use Alltube\Exception\ConfigException;
|
||||
use Alltube\LocaleManager;
|
||||
use Alltube\ViewFactory;
|
||||
use Exception;
|
||||
use Slim\Container;
|
||||
use Slim\Http\Environment;
|
||||
use Slim\Http\Request;
|
||||
use Slim\Http\Response;
|
||||
use SmartyException;
|
||||
|
||||
/**
|
||||
* Abstract class used by the controller tests.
|
||||
|
@ -51,7 +52,7 @@ abstract class ControllerTest extends BaseTest
|
|||
|
||||
/**
|
||||
* Prepare tests.
|
||||
* @throws Exception
|
||||
* @throws ConfigException|SmartyException
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
namespace Alltube\Test;
|
||||
|
||||
use Alltube\Config;
|
||||
use Alltube\Exception\ConfigException;
|
||||
use Alltube\Stream\ConvertedPlaylistArchiveStream;
|
||||
use Alltube\Video;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Unit tests for the ConvertedPlaylistArchiveStream class.
|
||||
|
@ -18,14 +18,16 @@ class ConvertedPlaylistArchiveStreamTest extends StreamTest
|
|||
{
|
||||
/**
|
||||
* Prepare tests.
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$video = new Video('https://www.youtube.com/playlist?list=PL1j4Ff8cAqPu5iowaeUAY8lRgkfT4RybJ');
|
||||
$config = Config::getInstance();
|
||||
$downloader = $config->getDownloader();
|
||||
$video = $downloader->getVideo('https://www.youtube.com/playlist?list=PL1j4Ff8cAqPu5iowaeUAY8lRgkfT4RybJ');
|
||||
|
||||
$this->stream = new ConvertedPlaylistArchiveStream($video);
|
||||
$this->stream = new ConvertedPlaylistArchiveStream($downloader, $video);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,11 @@ namespace Alltube\Test;
|
|||
|
||||
use Alltube\Config;
|
||||
use Alltube\Controller\DownloadController;
|
||||
use Exception;
|
||||
use Alltube\Exception\ConfigException;
|
||||
use Alltube\Library\Exception\EmptyUrlException;
|
||||
use Alltube\Library\Exception\RemuxException;
|
||||
use Alltube\Library\Exception\YoutubedlException;
|
||||
use SmartyException;
|
||||
|
||||
/**
|
||||
* Unit tests for the FrontController class.
|
||||
|
@ -18,7 +22,7 @@ class DownloadControllerTest extends ControllerTest
|
|||
{
|
||||
/**
|
||||
* Prepare tests.
|
||||
* @throws Exception
|
||||
* @throws ConfigException|SmartyException
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
|
@ -64,7 +68,7 @@ class DownloadControllerTest extends ControllerTest
|
|||
* Test the download() function with streams enabled.
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function testDownloadWithStream()
|
||||
{
|
||||
|
@ -80,7 +84,7 @@ class DownloadControllerTest extends ControllerTest
|
|||
* Test the download() function with an M3U stream.
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function testDownloadWithM3uStream()
|
||||
{
|
||||
|
@ -100,7 +104,7 @@ class DownloadControllerTest extends ControllerTest
|
|||
* Test the download() function with an RTMP stream.
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function testDownloadWithRtmpStream()
|
||||
{
|
||||
|
@ -118,7 +122,7 @@ class DownloadControllerTest extends ControllerTest
|
|||
* Test the download() function with a remuxed video.
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function testDownloadWithRemux()
|
||||
{
|
||||
|
@ -140,7 +144,8 @@ class DownloadControllerTest extends ControllerTest
|
|||
*/
|
||||
public function testDownloadWithRemuxDisabled()
|
||||
{
|
||||
$this->assertRequestIsServerError(
|
||||
$this->expectException(RemuxException::class);
|
||||
$this->getRequestResult(
|
||||
'download',
|
||||
[
|
||||
'url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU',
|
||||
|
@ -166,7 +171,8 @@ class DownloadControllerTest extends ControllerTest
|
|||
*/
|
||||
public function testDownloadWithError()
|
||||
{
|
||||
$this->assertRequestIsServerError('download', ['url' => 'http://example.com/foo']);
|
||||
$this->expectException(YoutubedlException::class);
|
||||
$this->getRequestResult('download', ['url' => 'http://example.com/foo']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -177,7 +183,8 @@ class DownloadControllerTest extends ControllerTest
|
|||
*/
|
||||
public function testDownloadWithEmptyUrl()
|
||||
{
|
||||
$this->assertRequestIsServerError(
|
||||
$this->expectException(EmptyUrlException::class);
|
||||
$this->getRequestResult(
|
||||
'download',
|
||||
['url' => 'https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC']
|
||||
);
|
||||
|
@ -188,7 +195,7 @@ class DownloadControllerTest extends ControllerTest
|
|||
*
|
||||
* @return void
|
||||
* @requires OS Linux
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function testDownloadWithPlaylist()
|
||||
{
|
||||
|
@ -204,7 +211,7 @@ class DownloadControllerTest extends ControllerTest
|
|||
* Test the download() function with an advanced conversion.
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function testDownloadWithAdvancedConversion()
|
||||
{
|
||||
|
|
|
@ -8,9 +8,12 @@ namespace Alltube\Test;
|
|||
|
||||
use Alltube\Config;
|
||||
use Alltube\Controller\FrontController;
|
||||
use Alltube\Exception\ConfigException;
|
||||
use Alltube\Library\Exception\AlltubeLibraryException;
|
||||
use Exception;
|
||||
use Slim\Http\Environment;
|
||||
use Slim\Http\Request;
|
||||
use SmartyException;
|
||||
|
||||
/**
|
||||
* Unit tests for the FrontController class.
|
||||
|
@ -25,7 +28,7 @@ class FrontControllerTest extends ControllerTest
|
|||
|
||||
/**
|
||||
* Prepare tests.
|
||||
* @throws Exception
|
||||
* @throws ConfigException|SmartyException
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
|
@ -48,7 +51,7 @@ class FrontControllerTest extends ControllerTest
|
|||
* Test the constructor with streams enabled.
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function testConstructorWithStream()
|
||||
{
|
||||
|
@ -99,7 +102,7 @@ class FrontControllerTest extends ControllerTest
|
|||
*/
|
||||
public function testPassword()
|
||||
{
|
||||
$this->assertRequestIsOk('password');
|
||||
$this->assertRequestIsClientError('password');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -128,7 +131,7 @@ class FrontControllerTest extends ControllerTest
|
|||
*
|
||||
* @return void
|
||||
* @requires download
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function testInfoWithAudio()
|
||||
{
|
||||
|
@ -145,7 +148,7 @@ class FrontControllerTest extends ControllerTest
|
|||
*
|
||||
* @return void
|
||||
* @requires download
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function testInfoWithVimeoAudio()
|
||||
{
|
||||
|
@ -160,7 +163,7 @@ class FrontControllerTest extends ControllerTest
|
|||
*
|
||||
* @return void
|
||||
* @requires download
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function testInfoWithUnconvertedAudio()
|
||||
{
|
||||
|
@ -180,6 +183,7 @@ class FrontControllerTest extends ControllerTest
|
|||
*
|
||||
* @return void
|
||||
* @requires download
|
||||
* @throws AlltubeLibraryException
|
||||
*/
|
||||
public function testInfoWithPassword()
|
||||
{
|
||||
|
@ -199,8 +203,8 @@ class FrontControllerTest extends ControllerTest
|
|||
*/
|
||||
public function testInfoWithMissingPassword()
|
||||
{
|
||||
$this->assertRequestIsOk('info', ['url' => 'http://vimeo.com/68375962']);
|
||||
$this->assertRequestIsOk('info', ['url' => 'http://vimeo.com/68375962', 'audio' => true]);
|
||||
$this->assertRequestIsClientError('info', ['url' => 'http://vimeo.com/68375962']);
|
||||
$this->assertRequestIsClientError('info', ['url' => 'http://vimeo.com/68375962', 'audio' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -208,7 +212,7 @@ class FrontControllerTest extends ControllerTest
|
|||
*
|
||||
* @return void
|
||||
* @requires download
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function testInfoWithStream()
|
||||
{
|
||||
|
|
|
@ -7,7 +7,9 @@
|
|||
namespace Alltube\Test;
|
||||
|
||||
use Alltube\Controller\JsonController;
|
||||
use Exception;
|
||||
use Alltube\Exception\ConfigException;
|
||||
use Alltube\Library\Exception\YoutubedlException;
|
||||
use SmartyException;
|
||||
|
||||
/**
|
||||
* Unit tests for the FrontController class.
|
||||
|
@ -16,7 +18,7 @@ class JsonControllerTest extends ControllerTest
|
|||
{
|
||||
/**
|
||||
* Prepare tests.
|
||||
* @throws Exception
|
||||
* @throws ConfigException|SmartyException
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
|
@ -44,7 +46,8 @@ class JsonControllerTest extends ControllerTest
|
|||
*/
|
||||
public function testJsonWithError()
|
||||
{
|
||||
$this->assertRequestIsServerError('json', ['url' => 'http://example.com/foo']);
|
||||
$this->expectException(YoutubedlException::class);
|
||||
$this->getRequestResult('json', ['url' => 'http://example.com/foo']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
namespace Alltube\Test;
|
||||
|
||||
use Alltube\Config;
|
||||
use Alltube\Exception\ConfigException;
|
||||
use Alltube\Stream\PlaylistArchiveStream;
|
||||
use Alltube\Video;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Unit tests for the PlaylistArchiveStream class.
|
||||
|
@ -18,14 +18,16 @@ class PlaylistArchiveStreamTest extends StreamTest
|
|||
{
|
||||
/**
|
||||
* Prepare tests.
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$video = new Video('https://www.youtube.com/playlist?list=PL1j4Ff8cAqPu5iowaeUAY8lRgkfT4RybJ');
|
||||
$config = Config::getInstance();
|
||||
$downloader = $config->getDownloader();
|
||||
$video = $downloader->getVideo('https://www.youtube.com/playlist?list=PL1j4Ff8cAqPu5iowaeUAY8lRgkfT4RybJ');
|
||||
|
||||
$this->stream = new PlaylistArchiveStream($video);
|
||||
$this->stream = new PlaylistArchiveStream($downloader, $video);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,36 +6,51 @@
|
|||
|
||||
namespace Alltube\Test;
|
||||
|
||||
use Alltube\Video;
|
||||
use Alltube\Config;
|
||||
use Alltube\Exception\ConfigException;
|
||||
use Alltube\Library\Downloader;
|
||||
use Alltube\Library\Exception\AlltubeLibraryException;
|
||||
use Alltube\Library\Exception\PopenStreamException;
|
||||
use Alltube\Library\Video;
|
||||
use Mockery;
|
||||
use phpmock\mockery\PHPMockery;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Unit tests for the Video class.
|
||||
* They are in a separate file so they can safely replace PHP functions with stubs.
|
||||
*
|
||||
* @requires download
|
||||
*/
|
||||
class VideoStubsTest extends BaseTest
|
||||
{
|
||||
/**
|
||||
* Video URL used in many tests.
|
||||
* Video used in many tests.
|
||||
*
|
||||
* @var Video
|
||||
*/
|
||||
private $video;
|
||||
|
||||
/**
|
||||
* Downloader instance used in tests.
|
||||
*
|
||||
* @var Downloader
|
||||
*/
|
||||
private $downloader;
|
||||
|
||||
/**
|
||||
* Initialize properties used by test.
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
PHPMockery::mock('Alltube', 'popen');
|
||||
PHPMockery::mock('Alltube', 'fopen');
|
||||
PHPMockery::mock('Alltube\Library', 'popen');
|
||||
PHPMockery::mock('Alltube\Library', 'fopen');
|
||||
|
||||
$this->video = new Video('https://www.youtube.com/watch?v=XJC9_JkzugE');
|
||||
$config = Config::getInstance();
|
||||
$this->downloader = $config->getDownloader();
|
||||
$this->video = $this->downloader->getVideo('https://www.youtube.com/watch?v=XJC9_JkzugE');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,55 +67,60 @@ class VideoStubsTest extends BaseTest
|
|||
* Test getAudioStream function with a buggy popen.
|
||||
*
|
||||
* @return void
|
||||
* @throws AlltubeLibraryException
|
||||
*/
|
||||
public function testGetAudioStreamWithPopenError()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$this->video->getAudioStream();
|
||||
$this->expectException(PopenStreamException::class);
|
||||
$this->downloader->getAudioStream($this->video);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getM3uStream function with a buggy popen.
|
||||
*
|
||||
* @return void
|
||||
* @throws AlltubeLibraryException
|
||||
*/
|
||||
public function testGetM3uStreamWithPopenError()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$this->video->getM3uStream();
|
||||
$this->expectException(PopenStreamException::class);
|
||||
$this->downloader->getM3uStream($this->video);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getRtmpStream function with a buggy popen.
|
||||
*
|
||||
* @return void
|
||||
* @throws AlltubeLibraryException
|
||||
*/
|
||||
public function testGetRtmpStreamWithPopenError()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$this->video->getRtmpStream();
|
||||
$this->expectException(PopenStreamException::class);
|
||||
$this->downloader->getRtmpStream($this->video);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getRemuxStream function with a buggy popen.
|
||||
*
|
||||
* @return void
|
||||
* @throws AlltubeLibraryException
|
||||
*/
|
||||
public function testGetRemuxStreamWithPopenError()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectException(PopenStreamException::class);
|
||||
$video = $this->video->withFormat('bestvideo+bestaudio');
|
||||
$video->getRemuxStream();
|
||||
$this->downloader->getRemuxStream($video);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getConvertedStream function with a buggy popen.
|
||||
*
|
||||
* @return void
|
||||
* @throws AlltubeLibraryException
|
||||
*/
|
||||
public function testGetConvertedStreamWithPopenError()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$this->video->getConvertedStream(32, 'flv');
|
||||
$this->expectException(PopenStreamException::class);
|
||||
$this->downloader->getConvertedStream($this->video, 32, 'flv');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,26 +7,61 @@
|
|||
namespace Alltube\Test;
|
||||
|
||||
use Alltube\Config;
|
||||
use Alltube\Exception\EmptyUrlException;
|
||||
use Alltube\Exception\PasswordException;
|
||||
use Alltube\Video;
|
||||
use Exception;
|
||||
use Alltube\Exception\ConfigException;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Unit tests for the Video class.
|
||||
* @requires download
|
||||
* @todo Split Downloader and Video tests.
|
||||
*/
|
||||
class VideoTest extends BaseTest
|
||||
{
|
||||
/**
|
||||
* Downloader instance used in tests.
|
||||
*
|
||||
* @var Downloader
|
||||
*/
|
||||
private $downloader;
|
||||
|
||||
/**
|
||||
* Video format used in tests.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $format;
|
||||
|
||||
/**
|
||||
* Prepare tests.
|
||||
* @throws ConfigException
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$config = Config::getInstance();
|
||||
$this->downloader = $config->getDownloader();
|
||||
$this->format = 'best';
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getExtractors function.
|
||||
*
|
||||
* @return void
|
||||
* @throws PasswordException
|
||||
* @throws AlltubeLibraryException
|
||||
*/
|
||||
public function testGetExtractors()
|
||||
{
|
||||
$this->assertContains('youtube', Video::getExtractors());
|
||||
$this->assertContains('youtube', $this->downloader->getExtractors());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,8 +74,7 @@ class VideoTest extends BaseTest
|
|||
* @param string $domain Domain
|
||||
*
|
||||
* @return void
|
||||
* @throws PasswordException
|
||||
* @throws EmptyUrlException
|
||||
* @throws AlltubeLibraryException
|
||||
* @dataProvider urlProvider
|
||||
* @dataProvider m3uUrlProvider
|
||||
* @dataProvider remuxUrlProvider
|
||||
|
@ -52,7 +86,7 @@ class VideoTest extends BaseTest
|
|||
/* @scrutinizer ignore-unused */ $extension,
|
||||
$domain
|
||||
) {
|
||||
$video = new Video($url, $format);
|
||||
$video = new Video($this->downloader, $url, $format);
|
||||
foreach ($video->getUrl() as $videoURL) {
|
||||
$this->assertStringContainsString($domain, $videoURL);
|
||||
}
|
||||
|
@ -62,12 +96,11 @@ class VideoTest extends BaseTest
|
|||
* Test getUrl function with a protected video.
|
||||
*
|
||||
* @return void
|
||||
* @throws EmptyUrlException
|
||||
* @throws PasswordException
|
||||
* @throws AlltubeLibraryException
|
||||
*/
|
||||
public function testgetUrlWithPassword()
|
||||
{
|
||||
$video = new Video('http://vimeo.com/68375962', 'best', 'youtube-dl');
|
||||
$video = new Video($this->downloader, 'http://vimeo.com/68375962', 'best', 'youtube-dl');
|
||||
foreach ($video->getUrl() as $videoURL) {
|
||||
$this->assertStringContainsString('vimeocdn.com', $videoURL);
|
||||
}
|
||||
|
@ -77,13 +110,12 @@ class VideoTest extends BaseTest
|
|||
* Test getUrl function with a protected video and no password.
|
||||
*
|
||||
* @return void
|
||||
* @throws EmptyUrlException
|
||||
* @throws PasswordException
|
||||
* @throws AlltubeLibraryException
|
||||
*/
|
||||
public function testgetUrlWithMissingPassword()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$video = new Video('http://vimeo.com/68375962');
|
||||
$this->expectException(PasswordException::class);
|
||||
$video = new Video($this->downloader, 'http://vimeo.com/68375962', $this->format);
|
||||
$video->getUrl();
|
||||
}
|
||||
|
||||
|
@ -91,13 +123,12 @@ class VideoTest extends BaseTest
|
|||
* Test getUrl function with a protected video and a wrong password.
|
||||
*
|
||||
* @return void
|
||||
* @throws EmptyUrlException
|
||||
* @throws PasswordException
|
||||
* @throws AlltubeLibraryException
|
||||
*/
|
||||
public function testgetUrlWithWrongPassword()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$video = new Video('http://vimeo.com/68375962', 'best', 'foo');
|
||||
$this->expectException(WrongPasswordException::class);
|
||||
$video = new Video($this->downloader, 'http://vimeo.com/68375962', 'best', 'foo');
|
||||
$video->getUrl();
|
||||
}
|
||||
|
||||
|
@ -107,14 +138,13 @@ class VideoTest extends BaseTest
|
|||
* @param string $url URL
|
||||
*
|
||||
* @return void
|
||||
* @throws EmptyUrlException
|
||||
* @throws PasswordException
|
||||
* @dataProvider ErrorUrlProvider
|
||||
* @throws AlltubeLibraryException
|
||||
* @dataProvider ErrorUrlProvider
|
||||
*/
|
||||
public function testgetUrlError($url)
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$video = new Video($url);
|
||||
$this->expectException(YoutubedlException::class);
|
||||
$video = new Video($this->downloader, $url, $this->format);
|
||||
$video->getUrl();
|
||||
}
|
||||
|
||||
|
@ -224,13 +254,13 @@ class VideoTest extends BaseTest
|
|||
* @param string $format Format
|
||||
*
|
||||
* @return void
|
||||
* @throws AlltubeLibraryException
|
||||
* @dataProvider urlProvider
|
||||
* @dataProvider m3uUrlProvider
|
||||
* @throws PasswordException
|
||||
*/
|
||||
public function testGetJson($url, $format)
|
||||
{
|
||||
$video = new Video($url, $format);
|
||||
$video = new Video($this->downloader, $url, $format);
|
||||
$info = $video->getJson();
|
||||
$this->assertObjectHasAttribute('webpage_url', $info);
|
||||
$this->assertObjectHasAttribute('url', $info);
|
||||
|
@ -246,13 +276,13 @@ class VideoTest extends BaseTest
|
|||
* @param string $url URL
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider ErrorURLProvider
|
||||
* @throws PasswordException
|
||||
* @throws AlltubeLibraryException
|
||||
* @dataProvider ErrorURLProvider
|
||||
*/
|
||||
public function testGetJsonError($url)
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$video = new Video($url);
|
||||
$this->expectException(YoutubedlException::class);
|
||||
$video = new Video($this->downloader, $url, $this->format);
|
||||
$video->getJson();
|
||||
}
|
||||
|
||||
|
@ -265,14 +295,14 @@ class VideoTest extends BaseTest
|
|||
* @param string $extension File extension
|
||||
*
|
||||
* @return void
|
||||
* @throws AlltubeLibraryException
|
||||
* @dataProvider urlProvider
|
||||
* @dataProvider m3uUrlProvider
|
||||
* @dataProvider remuxUrlProvider
|
||||
* @throws PasswordException
|
||||
*/
|
||||
public function testGetFilename($url, $format, $filename, $extension)
|
||||
{
|
||||
$video = new Video($url, $format);
|
||||
$video = new Video($this->downloader, $url, $format);
|
||||
$this->assertEquals($video->getFilename(), $filename . '.' . $extension);
|
||||
}
|
||||
|
||||
|
@ -282,13 +312,13 @@ class VideoTest extends BaseTest
|
|||
* @param string $url URL
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider ErrorUrlProvider
|
||||
* @throws PasswordException
|
||||
* @throws AlltubeLibraryException
|
||||
* @dataProvider ErrorUrlProvider
|
||||
*/
|
||||
public function testGetFilenameError($url)
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$video = new Video($url);
|
||||
$this->expectException(YoutubedlException::class);
|
||||
$video = new Video($this->downloader, $url, $this->format);
|
||||
$video->getFilename();
|
||||
}
|
||||
|
||||
|
@ -300,73 +330,80 @@ class VideoTest extends BaseTest
|
|||
*
|
||||
* @return void
|
||||
* @dataProvider urlProvider
|
||||
* @throws Exception
|
||||
* @throws AlltubeLibraryException
|
||||
*/
|
||||
public function testGetAudioStream($url, $format)
|
||||
{
|
||||
$video = new Video($url, $format);
|
||||
$this->assertStream($video->getAudioStream());
|
||||
$video = new Video($this->downloader, $url, $format);
|
||||
$this->assertStream($this->downloader->getAudioStream($video));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getAudioStream function without avconv.
|
||||
*
|
||||
* @param string $url URL
|
||||
* @param string $url URL
|
||||
* @param string $format Format
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider urlProvider
|
||||
* @throws AlltubeLibraryException|ConfigException
|
||||
* @dataProvider urlProvider
|
||||
*/
|
||||
public function testGetAudioStreamAvconvError($url, $format)
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectException(AvconvException::class);
|
||||
Config::setOptions(['avconv' => 'foobar']);
|
||||
$config = Config::getInstance();
|
||||
$downloader = $config->getDownloader();
|
||||
|
||||
$video = new Video($url, $format);
|
||||
$video->getAudioStream();
|
||||
$video = new Video($this->downloader, $url, $format, $this->format);
|
||||
$downloader->getAudioStream($video);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getAudioStream function with a M3U8 file.
|
||||
*
|
||||
* @param string $url URL
|
||||
* @param string $url URL
|
||||
* @param string $format Format
|
||||
*
|
||||
* @return void
|
||||
* @throws AlltubeLibraryException
|
||||
* @dataProvider m3uUrlProvider
|
||||
*/
|
||||
public function testGetAudioStreamM3uError($url, $format)
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$video = new Video($url, $format);
|
||||
$video->getAudioStream();
|
||||
$this->expectException(InvalidProtocolConversionException::class);
|
||||
$video = new Video($this->downloader, $url, $format);
|
||||
$this->downloader->getAudioStream($video);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getAudioStream function with a DASH URL.
|
||||
*
|
||||
* @return void
|
||||
* @throws AlltubeLibraryException
|
||||
*/
|
||||
public function testGetAudioStreamDashError()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$video = new Video('https://vimeo.com/251997032', 'bestaudio/best');
|
||||
$video->getAudioStream();
|
||||
$this->expectException(InvalidProtocolConversionException::class);
|
||||
$video = new Video($this->downloader, 'https://vimeo.com/251997032', 'bestaudio/best');
|
||||
$this->downloader->getAudioStream($video);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getAudioStream function with a playlist.
|
||||
*
|
||||
* @return void
|
||||
* @throws AlltubeLibraryException
|
||||
*/
|
||||
public function testGetAudioStreamPlaylistError()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectException(PlaylistConversionException::class);
|
||||
$video = new Video(
|
||||
$this->downloader,
|
||||
'https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC',
|
||||
'best'
|
||||
);
|
||||
$video->getAudioStream();
|
||||
$this->downloader->getAudioStream($video);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -390,12 +427,12 @@ class VideoTest extends BaseTest
|
|||
*
|
||||
* @return void
|
||||
* @dataProvider m3uUrlProvider
|
||||
* @throws Exception
|
||||
* @throws AlltubeLibraryException
|
||||
*/
|
||||
public function testGetM3uStream($url, $format)
|
||||
{
|
||||
$video = new Video($url, $format);
|
||||
$this->assertStream($video->getM3uStream());
|
||||
$video = new Video($this->downloader, $url, $format);
|
||||
$this->assertStream($this->downloader->getM3uStream($video));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -406,28 +443,29 @@ class VideoTest extends BaseTest
|
|||
*
|
||||
* @return void
|
||||
* @dataProvider remuxUrlProvider
|
||||
* @throws Exception
|
||||
* @throws AlltubeLibraryException
|
||||
*/
|
||||
public function testGetRemuxStream($url, $format)
|
||||
{
|
||||
$video = new Video($url, $format);
|
||||
$this->assertStream($video->getRemuxStream());
|
||||
$video = new Video($this->downloader, $url, $format);
|
||||
$this->assertStream($this->downloader->getRemuxStream($video));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getRemuxStream function with a video with only one URL.
|
||||
*
|
||||
* @param string $url URL
|
||||
* @param string $url URL
|
||||
* @param string $format Format
|
||||
*
|
||||
* @return void
|
||||
* @throws AlltubeLibraryException
|
||||
* @dataProvider urlProvider
|
||||
*/
|
||||
public function testGetRemuxStreamWithWrongVideo($url, $format)
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$video = new Video($url, $format);
|
||||
$video->getRemuxStream();
|
||||
$this->expectException(RemuxException::class);
|
||||
$video = new Video($this->downloader, $url, $format);
|
||||
$this->downloader->getRemuxStream($video);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -437,34 +475,37 @@ class VideoTest extends BaseTest
|
|||
* @param string $format Format
|
||||
*
|
||||
* @return void
|
||||
* @throws AlltubeLibraryException
|
||||
* @dataProvider rtmpUrlProvider
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testGetRtmpStream($url, $format)
|
||||
{
|
||||
$this->markTestIncomplete('We need to find another RTMP video.');
|
||||
|
||||
$video = new Video($url, $format);
|
||||
$video = new Video($this->downloader, $url, $format);
|
||||
|
||||
$this->assertStream($video->getRtmpStream());
|
||||
$this->assertStream($this->downloader->getRtmpStream($video));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getM3uStream function without avconv.
|
||||
*
|
||||
* @param string $url URL
|
||||
* @param string $url URL
|
||||
* @param string $format Format
|
||||
*
|
||||
* @return void
|
||||
* @throws AlltubeLibraryException|ConfigException
|
||||
* @dataProvider m3uUrlProvider
|
||||
*/
|
||||
public function testGetM3uStreamAvconvError($url, $format)
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectException(AvconvException::class);
|
||||
Config::setOptions(['avconv' => 'foobar']);
|
||||
$config = Config::getInstance();
|
||||
$downloader = $config->getDownloader();
|
||||
|
||||
$video = new Video($url, $format);
|
||||
$video->getM3uStream();
|
||||
$video = new Video($downloader, $url, $format);
|
||||
$downloader->getM3uStream($video);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -475,27 +516,28 @@ class VideoTest extends BaseTest
|
|||
*
|
||||
* @return void
|
||||
* @dataProvider urlProvider
|
||||
* @throws Exception
|
||||
* @throws AlltubeLibraryException
|
||||
*/
|
||||
public function testGetConvertedStream($url, $format)
|
||||
{
|
||||
$video = new Video($url, $format);
|
||||
$this->assertStream($video->getConvertedStream(32, 'flv'));
|
||||
$video = new Video($this->downloader, $url, $format);
|
||||
$this->assertStream($this->downloader->getConvertedStream($video, 32, 'flv'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getConvertedStream function with a M3U8 file.
|
||||
*
|
||||
* @param string $url URL
|
||||
* @param string $url URL
|
||||
* @param string $format Format
|
||||
*
|
||||
* @return void
|
||||
* @throws AlltubeLibraryException
|
||||
* @dataProvider m3uUrlProvider
|
||||
*/
|
||||
public function testGetConvertedStreamM3uError($url, $format)
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$video = new Video($url, $format);
|
||||
$video->getConvertedStream(32, 'flv');
|
||||
$this->expectException(InvalidProtocolConversionException::class);
|
||||
$video = new Video($this->downloader, $url, $format);
|
||||
$this->downloader->getConvertedStream($video, 32, 'flv');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,10 @@
|
|||
|
||||
namespace Alltube\Test;
|
||||
|
||||
use Alltube\Config;
|
||||
use Alltube\Exception\ConfigException;
|
||||
use Alltube\Library\Exception\AlltubeLibraryException;
|
||||
use Alltube\Stream\YoutubeChunkStream;
|
||||
use Alltube\Video;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Unit tests for the YoutubeChunkStream class.
|
||||
|
@ -18,14 +19,17 @@ class YoutubeChunkStreamTest extends StreamTest
|
|||
{
|
||||
/**
|
||||
* Prepare tests.
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
* @throws AlltubeLibraryException
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$video = new Video('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
|
||||
$config = Config::getInstance();
|
||||
$downloader = $config->getDownloader();
|
||||
$video = $downloader->getVideo('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
|
||||
|
||||
$this->stream = new YoutubeChunkStream($video->getHttpResponse());
|
||||
$this->stream = new YoutubeChunkStream($downloader->getHttpResponse($video));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,10 @@
|
|||
|
||||
namespace Alltube\Test;
|
||||
|
||||
use Alltube\Config;
|
||||
use Alltube\Exception\ConfigException;
|
||||
use Alltube\Library\Exception\AlltubeLibraryException;
|
||||
use Alltube\Stream\YoutubeStream;
|
||||
use Alltube\Video;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Unit tests for the YoutubeStream class.
|
||||
|
@ -18,15 +19,17 @@ class YoutubeStreamTest extends StreamTest
|
|||
{
|
||||
/**
|
||||
* Prepare tests.
|
||||
* @throws Exception
|
||||
* @throws ConfigException|AlltubeLibraryException
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$video = new Video('https://www.youtube.com/watch?v=dQw4w9WgXcQ', '135');
|
||||
$config = Config::getInstance();
|
||||
$downloader = $config->getDownloader();
|
||||
$video = $downloader->getVideo('https://www.youtube.com/watch?v=dQw4w9WgXcQ', '135');
|
||||
|
||||
$this->stream = new YoutubeStream($video);
|
||||
$this->stream = new YoutubeStream($downloader, $video);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue