Download Tar archives from playlists

This commit is contained in:
Pierre Rudloff 2017-05-02 17:04:55 +02:00
parent e46d8544ed
commit d7927fc442
11 changed files with 419 additions and 3 deletions

View file

@ -453,4 +453,29 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase
{
$this->assertRequestIsServerError('redirect', ['url'=>'http://example.com/foo']);
}
/**
* Test the redirect() function with an video that returns an empty URL.
* This can be caused by trying to redirect to a playlist.
*
* @return void
*/
public function testRedirectWithEmptyUrl()
{
$this->assertRequestIsServerError('redirect', ['url'=>'https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC']);
}
/**
* Test the redirect() function with a playlist stream.
*
* @return void
*/
public function testRedirectWithPlaylist()
{
$this->assertRequestIsOk(
'redirect',
['url'=> 'https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC'],
new Config(['stream'=>true])
);
}
}

View file

@ -0,0 +1,98 @@
<?php
/**
* PlaylistArchiveStreamTest class.
*/
namespace Alltube\Test;
use Alltube\PlaylistArchiveStream;
/**
* Unit tests for the ViewFactory class.
*/
class PlaylistArchiveStreamTest extends \PHPUnit_Framework_TestCase
{
/**
* Prepare tests.
*/
protected function setUp()
{
$this->stream = new PlaylistArchiveStream();
}
/**
* Test the stream_open() function.
*
* @return void
*/
public function testStreamOpen()
{
$this->assertTrue($this->stream->stream_open('playlist://foo', 'r'));
}
/**
* Test the stream_write() function.
*
* @return void
*/
public function testStreamWrite()
{
$this->assertEquals(0, $this->stream->stream_write());
}
/**
* Test the stream_stat() function.
*
* @return void
*/
public function testStreamStat()
{
$this->assertEquals(['mode'=>4096], $this->stream->stream_stat());
}
/**
* Test the stream_tell() function.
*
* @return void
*/
public function testStreamTell()
{
$this->stream->stream_open('playlist://foo', 'r');
$this->assertInternalType('int', $this->stream->stream_tell());
}
/**
* Test the stream_seek() function.
*
* @return void
*/
public function testStreamSeek()
{
$this->stream->stream_open('playlist://foo', 'r');
$this->assertInternalType('bool', $this->stream->stream_seek(3));
}
/**
* Test the stream_read() function.
*
* @return void
*/
public function testStreamRead()
{
$this->stream->stream_open('playlist://BaW_jenozKc;BaW_jenozKc/worst', 'r');
while (!$this->stream->stream_eof()) {
$this->assertLessThanOrEqual(8192, strlen($this->stream->stream_read(8192)));
}
}
/**
* Test the stream_eof() function.
*
* @return void
*/
public function testStreamEof()
{
$this->stream->stream_open('playlist://foo', 'r');
$this->assertFalse($this->stream->stream_eof(3));
}
}

View file

@ -480,4 +480,15 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
$video = $download->getJSON($url, $format);
$download->getM3uStream($video);
}
/**
* Test getPlaylistArchiveStream function without avconv.
*
* @return void
*/
public function testGetPlaylistArchiveStream()
{
$video = $this->download->getJSON('https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC', 'best');
$this->assertStream($this->download->getPlaylistArchiveStream($video, 'best'));
}
}

View file

@ -2,6 +2,7 @@
/**
* File used to bootstrap tests.
*/
use Alltube\PlaylistArchiveStream;
/**
* Composer autoload.
@ -9,3 +10,5 @@
require_once __DIR__.'/../vendor/autoload.php';
session_start();
stream_wrapper_register('playlist', PlaylistArchiveStream::class);