This commit is contained in:
Pierre Rudloff 2020-05-13 21:18:32 +02:00
parent 81e9eaba4e
commit 71d49ad74f
13 changed files with 83 additions and 39 deletions

View file

@ -7,6 +7,7 @@
namespace Alltube; namespace Alltube;
use Exception; use Exception;
use Jawira\CaseConverter\CaseConverterException;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
use Jawira\CaseConverter\Convert; use Jawira\CaseConverter\Convert;
@ -121,13 +122,6 @@ class Config
*/ */
public $appName = 'AllTube Download'; public $appName = 'AllTube Download';
/**
* YAML config file path.
*
* @var string
*/
private $file;
/** /**
* Generic formats supported by youtube-dl. * Generic formats supported by youtube-dl.
* *
@ -195,10 +189,10 @@ class Config
/** /**
* Throw an exception if some of the options are invalid. * Throw an exception if some of the options are invalid.
* *
* @throws Exception If youtube-dl is missing * @return void
* @throws Exception If Python is missing * @throws Exception If Python is missing
* *
* @return void * @throws Exception If youtube-dl is missing
*/ */
private function validateOptions() private function validateOptions()
{ {
@ -235,6 +229,7 @@ class Config
* If the value is an array, you should use the YAML format: "CONVERT_ADVANCED_FORMATS='[foo, bar]'" * If the value is an array, you should use the YAML format: "CONVERT_ADVANCED_FORMATS='[foo, bar]'"
* *
* @return void * @return void
* @throws CaseConverterException
*/ */
private function getEnv() private function getEnv()
{ {
@ -265,6 +260,7 @@ class Config
* Set options from a YAML file. * Set options from a YAML file.
* *
* @param string $file Path to the YAML file * @param string $file Path to the YAML file
* @throws Exception
*/ */
public static function setFile($file) public static function setFile($file)
{ {
@ -282,6 +278,7 @@ class Config
* *
* @param array $options Options (see `config/config.example.yml` for available options) * @param array $options Options (see `config/config.example.yml` for available options)
* @param bool $update True to update an existing instance * @param bool $update True to update an existing instance
* @throws Exception
*/ */
public static function setOptions(array $options, $update = true) public static function setOptions(array $options, $update = true)
{ {

View file

@ -104,12 +104,14 @@ class Locale
/** /**
* Get country information from locale. * Get country information from locale.
* *
* @return Country|array * @return Country|array|null
*/ */
public function getCountry() public function getCountry()
{ {
if (isset($this->region)) { if (isset($this->region)) {
return country($this->getIso3166()); return country($this->getIso3166());
} }
return null;
} }
} }

View file

@ -7,7 +7,6 @@
namespace Alltube; namespace Alltube;
use Aura\Session\Segment; use Aura\Session\Segment;
use Symfony\Component\Process\Process;
use Symfony\Component\Translation\Translator; use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\Loader\PoFileLoader; use Symfony\Component\Translation\Loader\PoFileLoader;

View file

@ -38,7 +38,7 @@ class LocaleMiddleware
* *
* @param array $proposedLocale Locale array created by AcceptLanguage::parse() * @param array $proposedLocale Locale array created by AcceptLanguage::parse()
* *
* @return Locale Locale if chosen, nothing otherwise * @return Locale|null Locale if chosen, nothing otherwise
*/ */
public function testLocale(array $proposedLocale) public function testLocale(array $proposedLocale)
{ {
@ -52,6 +52,8 @@ class LocaleMiddleware
return new Locale($proposedLocale['language'] . '_' . $proposedLocale['region']); return new Locale($proposedLocale['language'] . '_' . $proposedLocale['region']);
} }
} }
return null;
} }
/** /**

View file

@ -10,6 +10,7 @@ use Alltube\Exception\EmptyUrlException;
use Alltube\Exception\PasswordException; use Alltube\Exception\PasswordException;
use Exception; use Exception;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Response;
use stdClass; use stdClass;
use Symfony\Component\Process\Process; use Symfony\Component\Process\Process;
@ -124,7 +125,9 @@ class Video
* List all extractors. * List all extractors.
* *
* @return string[] Extractors * @return string[] Extractors
* */ *
* @throws PasswordException
*/
public static function getExtractors() public static function getExtractors()
{ {
$video = new self(''); $video = new self('');
@ -172,6 +175,7 @@ class Video
* @param string $prop Property * @param string $prop Property
* *
* @return string * @return string
* @throws PasswordException
*/ */
private function getProp($prop = 'dump-json') private function getProp($prop = 'dump-json')
{ {
@ -196,7 +200,9 @@ class Video
* Get all information about a video. * Get all information about a video.
* *
* @return stdClass Decoded JSON * @return stdClass Decoded JSON
* */ *
* @throws PasswordException
*/
public function getJson() public function getJson()
{ {
if (!isset($this->json)) { if (!isset($this->json)) {
@ -212,12 +218,15 @@ class Video
* @param string $name Property * @param string $name Property
* *
* @return mixed * @return mixed
* @throws PasswordException
*/ */
public function __get($name) public function __get($name)
{ {
if (isset($this->$name)) { if (isset($this->$name)) {
return $this->getJson()->$name; return $this->getJson()->$name;
} }
return null;
} }
/** /**
@ -226,6 +235,7 @@ class Video
* @param string $name Property * @param string $name Property
* *
* @return bool * @return bool
* @throws PasswordException
*/ */
public function __isset($name) public function __isset($name)
{ {
@ -240,7 +250,9 @@ class Video
* (eg. bestvideo+bestaudio). * (eg. bestvideo+bestaudio).
* *
* @return string[] URLs of video * @return string[] URLs of video
* */ * @throws EmptyUrlException
* @throws PasswordException
*/
public function getUrl() public function getUrl()
{ {
// Cache the URLs. // Cache the URLs.
@ -259,7 +271,9 @@ class Video
* Get filename of video file from URL of page. * Get filename of video file from URL of page.
* *
* @return string Filename of extracted video * @return string Filename of extracted video
* */ *
* @throws PasswordException
*/
public function getFilename() public function getFilename()
{ {
return trim($this->getProp('get-filename')); return trim($this->getProp('get-filename'));
@ -271,6 +285,7 @@ class Video
* @param string $extension New file extension * @param string $extension New file extension
* *
* @return string Filename of extracted video with specified extension * @return string Filename of extracted video with specified extension
* @throws PasswordException
*/ */
public function getFileNameWithExtension($extension) public function getFileNameWithExtension($extension)
{ {
@ -601,6 +616,9 @@ class Video
* @param array $headers HTTP headers of the request * @param array $headers HTTP headers of the request
* *
* @return Response * @return Response
* @throws EmptyUrlException
* @throws PasswordException
* @throws GuzzleException
*/ */
public function getHttpResponse(array $headers = []) public function getHttpResponse(array $headers = [])
{ {

View file

@ -10,6 +10,7 @@ use Psr\Container\ContainerInterface;
use Slim\Http\Request; use Slim\Http\Request;
use Slim\Views\Smarty; use Slim\Views\Smarty;
use Slim\Views\SmartyPlugins; use Slim\Views\SmartyPlugins;
use SmartyException;
/** /**
* Create Smarty view object. * Create Smarty view object.
@ -23,6 +24,7 @@ class ViewFactory
* @param Request $request PSR-7 request * @param Request $request PSR-7 request
* *
* @return Smarty * @return Smarty
* @throws SmartyException
*/ */
public static function create(ContainerInterface $container, Request $request = null) public static function create(ContainerInterface $container, Request $request = null)
{ {

View file

@ -7,6 +7,7 @@
namespace Alltube\Stream; namespace Alltube\Stream;
use Alltube\Video; use Alltube\Video;
use Exception;
use Slim\Http\Stream; use Slim\Http\Stream;
/** /**
@ -20,6 +21,7 @@ class ConvertedPlaylistArchiveStream extends PlaylistArchiveStream
* @param Video $video Video to stream * @param Video $video Video to stream
* *
* @return void * @return void
* @throws Exception
*/ */
protected function startVideoStream(Video $video) protected function startVideoStream(Video $video)
{ {

View file

@ -86,7 +86,7 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface
* *
* @param string $string The string that is to be written * @param string $string The string that is to be written
* *
* @return int * @return void
*/ */
public function write($string) public function write($string)
{ {
@ -96,7 +96,7 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface
/** /**
* Get the size of the stream if known. * Get the size of the stream if known.
* *
* @return null * @return void
*/ */
public function getSize() public function getSize()
{ {
@ -170,6 +170,8 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface
if (isset($meta[$key])) { if (isset($meta[$key])) {
return $meta[$key]; return $meta[$key];
} }
return null;
} }
/** /**

View file

@ -124,21 +124,21 @@ class YoutubeChunkStream implements StreamInterface
* @param int $offset Stream offset * @param int $offset Stream offset
* @param int $whence Specifies how the cursor position will be calculated * @param int $whence Specifies how the cursor position will be calculated
* *
* @return mixed * @return void
*/ */
public function seek($offset, $whence = SEEK_SET) public function seek($offset, $whence = SEEK_SET)
{ {
return $this->response->getBody()->seek($offset, $whence); $this->response->getBody()->seek($offset, $whence);
} }
/** /**
* Seek to the beginning of the stream. * Seek to the beginning of the stream.
* *
* @return mixed * @return void
*/ */
public function rewind() public function rewind()
{ {
return $this->response->getBody()->rewind(); $this->response->getBody()->rewind();
} }
/** /**

View file

@ -16,7 +16,9 @@
"symfony/process": "^4.0", "symfony/process": "^4.0",
"symfony/translation": "^4.0", "symfony/translation": "^4.0",
"symfony/yaml": "^4.0", "symfony/yaml": "^4.0",
"zonuexe/http-accept-language": "~0.4.1" "zonuexe/http-accept-language": "~0.4.1",
"ext-intl": "*",
"ext-json": "*"
}, },
"require-dev": { "require-dev": {
"anam/phantomjs-linux-x86-binary": "~2.1.1", "anam/phantomjs-linux-x86-binary": "~2.1.1",

7
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "84661260029cd1e5b182272542fe65fa", "content-hash": "e2043abf0f043d0ef514f2e517b3b8fc",
"packages": [ "packages": [
{ {
"name": "aura/session", "name": "aura/session",
@ -6034,7 +6034,10 @@
}, },
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": [], "platform": {
"ext-intl": "*",
"ext-json": "*"
},
"platform-dev": [], "platform-dev": [],
"platform-overrides": { "platform-overrides": {
"php": "7.3.11" "php": "7.3.11"

View file

@ -13,6 +13,7 @@ use Alltube\Stream\PlaylistArchiveStream;
use Alltube\Stream\YoutubeStream; use Alltube\Stream\YoutubeStream;
use Alltube\Video; use Alltube\Video;
use Exception; use Exception;
use GuzzleHttp\Exception\GuzzleException;
use Slim\Http\Request; use Slim\Http\Request;
use Slim\Http\Response; use Slim\Http\Response;
use Slim\Http\Stream; use Slim\Http\Stream;
@ -70,6 +71,8 @@ class DownloadController extends BaseController
* @param Response $response PSR-7 response * @param Response $response PSR-7 response
* *
* @return Response HTTP response * @return Response HTTP response
* @throws PasswordException
* @throws Exception
*/ */
private function getConvertedAudioResponse(Request $request, Response $response) private function getConvertedAudioResponse(Request $request, Response $response)
{ {
@ -104,6 +107,7 @@ class DownloadController extends BaseController
* @param Response $response PSR-7 response * @param Response $response PSR-7 response
* *
* @return Response HTTP response * @return Response HTTP response
* @throws PasswordException
*/ */
private function getAudioResponse(Request $request, Response $response) private function getAudioResponse(Request $request, Response $response)
{ {
@ -139,10 +143,13 @@ class DownloadController extends BaseController
/** /**
* Get a video/audio stream piped through the server. * Get a video/audio stream piped through the server.
* *
* @param Response $response PSR-7 response
* @param Request $request PSR-7 request * @param Request $request PSR-7 request
* *
* @param Response $response PSR-7 response
* @return Response HTTP response * @return Response HTTP response
* @throws EmptyUrlException
* @throws PasswordException
* @throws GuzzleException
*/ */
private function getStream(Request $request, Response $response) private function getStream(Request $request, Response $response)
{ {
@ -208,6 +215,8 @@ class DownloadController extends BaseController
* @param Request $request PSR-7 request * @param Request $request PSR-7 request
* *
* @return Response HTTP response * @return Response HTTP response
* @throws PasswordException
* @throws Exception
*/ */
private function getRemuxStream(Request $request, Response $response) private function getRemuxStream(Request $request, Response $response)
{ {
@ -230,10 +239,14 @@ class DownloadController extends BaseController
* Get approriate HTTP response to download query. * Get approriate HTTP response to download query.
* Depends on whether we want to stream, remux or simply redirect. * Depends on whether we want to stream, remux or simply redirect.
* *
* @param Response $response PSR-7 response
* @param Request $request PSR-7 request * @param Request $request PSR-7 request
* *
* @param Response $response PSR-7 response
* @return Response HTTP response * @return Response HTTP response
* @throws EmptyUrlException
* @throws GuzzleException
* @throws PasswordException
* @throws Exception
*/ */
private function getDownloadResponse(Request $request, Response $response) private function getDownloadResponse(Request $request, Response $response)
{ {
@ -266,6 +279,8 @@ class DownloadController extends BaseController
* @param Response $response PSR-7 response * @param Response $response PSR-7 response
* *
* @return Response HTTP response * @return Response HTTP response
* @throws PasswordException
* @throws Exception
*/ */
private function getConvertedResponse(Request $request, Response $response) private function getConvertedResponse(Request $request, Response $response)
{ {

View file

@ -12,7 +12,6 @@ use Alltube\Video;
use Throwable; use Throwable;
use Exception; use Exception;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use Slim\Container;
use Slim\Http\Request; use Slim\Http\Request;
use Slim\Http\Response; use Slim\Http\Response;
use Slim\Views\Smarty; use Slim\Views\Smarty;
@ -96,6 +95,7 @@ class FrontController extends BaseController
* @param Response $response PSR-7 response * @param Response $response PSR-7 response
* *
* @return Response HTTP response * @return Response HTTP response
* @throws PasswordException
*/ */
public function extractors(Request $request, Response $response) public function extractors(Request $request, Response $response)
{ {