phpstan update
Better typying
This commit is contained in:
parent
74db3b9ad0
commit
6adc1df213
17 changed files with 166 additions and 158 deletions
|
@ -40,7 +40,7 @@ class Config
|
|||
/**
|
||||
* youtube-dl parameters.
|
||||
*
|
||||
* @var array
|
||||
* @var string[]
|
||||
*/
|
||||
public $params = ['--no-warnings', '--ignore-errors', '--flat-playlist', '--restrict-filenames', '--no-playlist'];
|
||||
|
||||
|
@ -61,7 +61,7 @@ class Config
|
|||
/**
|
||||
* List of formats available in advanced conversion mode.
|
||||
*
|
||||
* @var array
|
||||
* @var string[]
|
||||
*/
|
||||
public $convertAdvancedFormats = ['mp3', 'avi', 'flv', 'wav'];
|
||||
|
||||
|
@ -125,7 +125,7 @@ class Config
|
|||
/**
|
||||
* Generic formats supported by youtube-dl.
|
||||
*
|
||||
* @var array
|
||||
* @var string[]
|
||||
*/
|
||||
public $genericFormats = [];
|
||||
|
||||
|
@ -139,7 +139,8 @@ class Config
|
|||
/**
|
||||
* Config constructor.
|
||||
*
|
||||
* @param array $options Options
|
||||
* @param mixed[] $options Options
|
||||
* @throws CaseConverterException
|
||||
*/
|
||||
private function __construct(array $options = [])
|
||||
{
|
||||
|
@ -210,7 +211,7 @@ class Config
|
|||
/**
|
||||
* Apply the provided options.
|
||||
*
|
||||
* @param array $options Options
|
||||
* @param mixed[] $options Options
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
@ -260,12 +261,13 @@ class Config
|
|||
* Set options from a YAML file.
|
||||
*
|
||||
* @param string $file Path to the YAML file
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function setFile($file)
|
||||
{
|
||||
if (is_file($file)) {
|
||||
$options = Yaml::parse(file_get_contents($file));
|
||||
$options = Yaml::parse(strval(file_get_contents($file)));
|
||||
self::$instance = new self($options);
|
||||
self::$instance->validateOptions();
|
||||
} else {
|
||||
|
@ -276,8 +278,9 @@ class Config
|
|||
/**
|
||||
* Manually set some options.
|
||||
*
|
||||
* @param array $options Options (see `config/config.example.yml` for available options)
|
||||
* @param mixed[] $options Options (see `config/config.example.yml` for available options)
|
||||
* @param bool $update True to update an existing instance
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function setOptions(array $options, $update = true)
|
||||
|
|
|
@ -104,7 +104,7 @@ class Locale
|
|||
/**
|
||||
* Get country information from locale.
|
||||
*
|
||||
* @return Country|array|null
|
||||
* @return Country|Country[]|null
|
||||
*/
|
||||
public function getCountry()
|
||||
{
|
||||
|
|
|
@ -18,7 +18,7 @@ class LocaleManager
|
|||
/**
|
||||
* Supported locales.
|
||||
*
|
||||
* @var array
|
||||
* @var string[]
|
||||
*/
|
||||
private $supportedLocales = ['en_US', 'fr_FR', 'zh_CN', 'es_ES', 'pt_BR', 'de_DE', 'ar', 'pl_PL', 'tr_TR'];
|
||||
|
||||
|
@ -111,6 +111,7 @@ class LocaleManager
|
|||
* Set the current locale.
|
||||
*
|
||||
* @param Locale $locale Locale
|
||||
* @return void
|
||||
*/
|
||||
public function setLocale(Locale $locale)
|
||||
{
|
||||
|
@ -121,6 +122,7 @@ class LocaleManager
|
|||
|
||||
/**
|
||||
* Unset the current locale.
|
||||
* @return void
|
||||
*/
|
||||
public function unsetLocale()
|
||||
{
|
||||
|
@ -132,8 +134,8 @@ class LocaleManager
|
|||
/**
|
||||
* Smarty "t" block.
|
||||
*
|
||||
* @param array $params Block parameters
|
||||
* @param string $text Block content
|
||||
* @param mixed[] $params Block parameters
|
||||
* @param string $text Block content
|
||||
*
|
||||
* @return string Translated string
|
||||
*/
|
||||
|
@ -151,6 +153,7 @@ class LocaleManager
|
|||
*
|
||||
* @param string $string String to translate
|
||||
*
|
||||
* @param mixed[] $params
|
||||
* @return string Translated string
|
||||
*/
|
||||
public function t($string, array $params = [])
|
||||
|
|
|
@ -36,7 +36,7 @@ class LocaleMiddleware
|
|||
/**
|
||||
* Test if a locale can be used for the current user.
|
||||
*
|
||||
* @param array $proposedLocale Locale array created by AcceptLanguage::parse()
|
||||
* @param mixed[] $proposedLocale Locale array created by AcceptLanguage::parse()
|
||||
*
|
||||
* @return Locale|null Locale if chosen, nothing otherwise
|
||||
*/
|
||||
|
@ -59,9 +59,9 @@ class LocaleMiddleware
|
|||
/**
|
||||
* Main middleware function.
|
||||
*
|
||||
* @param Request $request PSR request
|
||||
* @param Request $request PSR request
|
||||
* @param Response $response PSR response
|
||||
* @param callable $next Next middleware
|
||||
* @param callable $next Next middleware
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
|
|
|
@ -21,7 +21,7 @@ class UglyRouter extends Router
|
|||
*
|
||||
* @param ServerRequestInterface $request The current HTTP request object
|
||||
*
|
||||
* @return array
|
||||
* @return mixed[]
|
||||
*
|
||||
* @link https://github.com/nikic/FastRoute/blob/master/src/Dispatcher.php
|
||||
*/
|
||||
|
@ -42,14 +42,14 @@ class UglyRouter extends Router
|
|||
/**
|
||||
* Build the path for a named route including the base path.
|
||||
*
|
||||
* @param string $name Route name
|
||||
* @param array $data Named argument replacement data
|
||||
* @param array $queryParams Optional query string parameters
|
||||
*
|
||||
* @throws RuntimeException If named route does not exist
|
||||
* @throws InvalidArgumentException If required data not provided
|
||||
* @param string $name Route name
|
||||
* @param string[] $data Named argument replacement data
|
||||
* @param string[] $queryParams Optional query string parameters
|
||||
*
|
||||
* @return string
|
||||
* @throws InvalidArgumentException If required data not provided
|
||||
*
|
||||
* @throws RuntimeException If named route does not exist
|
||||
*/
|
||||
public function pathFor($name, array $data = [], array $queryParams = [])
|
||||
{
|
||||
|
|
|
@ -19,16 +19,16 @@ use Symfony\Component\Process\Process;
|
|||
*
|
||||
* Due to the way youtube-dl behaves, this class can also contain information about a playlist.
|
||||
*
|
||||
* @property-read string $title Title
|
||||
* @property-read string $protocol Network protocol (HTTP, RTMP, etc.)
|
||||
* @property-read string $url File URL
|
||||
* @property-read string $ext File extension
|
||||
* @property-read string $extractor_key youtube-dl extractor class used
|
||||
* @property-read array $entries List of videos (if the object contains information about a playlist)
|
||||
* @property-read array $rtmp_conn
|
||||
* @property-read string $title Title
|
||||
* @property-read string $protocol Network protocol (HTTP, RTMP, etc.)
|
||||
* @property-read string $url File URL
|
||||
* @property-read string $ext File extension
|
||||
* @property-read string $extractor_key youtube-dl extractor class used
|
||||
* @property-read array $entries List of videos (if the object contains information about a playlist)
|
||||
* @property-read array $rtmp_conn
|
||||
* @property-read string|null $_type Object type (usually "playlist" or null)
|
||||
* @property-read stdClass $downloader_options
|
||||
* @property-read stdClass $http_headers
|
||||
* @property-read stdClass $downloader_options
|
||||
* @property-read stdClass $http_headers
|
||||
*/
|
||||
class Video
|
||||
{
|
||||
|
@ -70,7 +70,7 @@ class Video
|
|||
/**
|
||||
* URLs of the video files.
|
||||
*
|
||||
* @var array
|
||||
* @var string[]
|
||||
*/
|
||||
private $urls;
|
||||
|
||||
|
@ -84,11 +84,11 @@ class Video
|
|||
/**
|
||||
* VideoDownload constructor.
|
||||
*
|
||||
* @param string $webpageUrl URL of the page containing the video
|
||||
* @param string $webpageUrl URL of the page containing the video
|
||||
* @param string $requestedFormat Requested video format
|
||||
* (can be any format string accepted by youtube-dl,
|
||||
* including selectors like "[height<=720]")
|
||||
* @param string $password Password
|
||||
* @param string $password Password
|
||||
*/
|
||||
public function __construct($webpageUrl, $requestedFormat = 'best', $password = null)
|
||||
{
|
||||
|
@ -105,7 +105,7 @@ class Video
|
|||
*
|
||||
* @param string[] $arguments Arguments
|
||||
*
|
||||
* @return Process
|
||||
* @return Process<string>
|
||||
*/
|
||||
private static function getProcess(array $arguments)
|
||||
{
|
||||
|
@ -137,13 +137,13 @@ class Video
|
|||
/**
|
||||
* Call youtube-dl.
|
||||
*
|
||||
* @param array $arguments Arguments
|
||||
* @param string[] $arguments Arguments
|
||||
*
|
||||
* @throws PasswordException If the video is protected by a password and no password was specified
|
||||
* @return string Result
|
||||
* @throws Exception If the password is wrong
|
||||
* @throws Exception If youtube-dl returns an error
|
||||
*
|
||||
* @return string Result
|
||||
* @throws PasswordException If the video is protected by a password and no password was specified
|
||||
*/
|
||||
private function callYoutubedl(array $arguments)
|
||||
{
|
||||
|
@ -155,7 +155,7 @@ class Video
|
|||
$process->run();
|
||||
if (!$process->isSuccessful()) {
|
||||
$errorOutput = trim($process->getErrorOutput());
|
||||
$exitCode = $process->getExitCode();
|
||||
$exitCode = intval($process->getExitCode());
|
||||
if ($errorOutput == 'ERROR: This video is protected by a password, use the --video-password option') {
|
||||
throw new PasswordException($errorOutput, $exitCode);
|
||||
} elseif (substr($errorOutput, 0, 21) == 'ERROR: Wrong password') {
|
||||
|
@ -294,7 +294,7 @@ class Video
|
|||
/**
|
||||
* Return arguments used to run rtmp for a specific video.
|
||||
*
|
||||
* @return array Arguments
|
||||
* @return string[] Arguments
|
||||
*/
|
||||
private function getRtmpArguments()
|
||||
{
|
||||
|
@ -303,12 +303,12 @@ class Video
|
|||
if ($this->protocol == 'rtmp') {
|
||||
foreach (
|
||||
[
|
||||
'url' => '-rtmp_tcurl',
|
||||
'webpage_url' => '-rtmp_pageurl',
|
||||
'player_url' => '-rtmp_swfverify',
|
||||
'flash_version' => '-rtmp_flashver',
|
||||
'play_path' => '-rtmp_playpath',
|
||||
'app' => '-rtmp_app',
|
||||
'url' => '-rtmp_tcurl',
|
||||
'webpage_url' => '-rtmp_pageurl',
|
||||
'player_url' => '-rtmp_swfverify',
|
||||
'flash_version' => '-rtmp_flashver',
|
||||
'play_path' => '-rtmp_playpath',
|
||||
'app' => '-rtmp_app',
|
||||
] as $property => $option
|
||||
) {
|
||||
if (isset($this->{$property})) {
|
||||
|
@ -331,7 +331,7 @@ class Video
|
|||
/**
|
||||
* Check if a command runs successfully.
|
||||
*
|
||||
* @param array $command Command and arguments
|
||||
* @param string[] $command Command and arguments
|
||||
*
|
||||
* @return bool False if the command returns an error, true otherwise
|
||||
*/
|
||||
|
@ -346,15 +346,15 @@ class Video
|
|||
/**
|
||||
* Get a process that runs avconv in order to convert a video.
|
||||
*
|
||||
* @param int $audioBitrate Audio bitrate of the converted file
|
||||
* @param string $filetype Filetype of the converted file
|
||||
* @param bool $audioOnly True to return an audio-only file
|
||||
* @param string $from Start the conversion at this time
|
||||
* @param string $to End the conversion at this time
|
||||
* @param int $audioBitrate Audio bitrate of the converted file
|
||||
* @param string $filetype Filetype of the converted file
|
||||
* @param bool $audioOnly True to return an audio-only file
|
||||
* @param string $from Start the conversion at this time
|
||||
* @param string $to End the conversion at this time
|
||||
*
|
||||
* @return Process<string> Process
|
||||
* @throws Exception If avconv/ffmpeg is missing
|
||||
*
|
||||
* @return Process Process
|
||||
*/
|
||||
private function getAvconvProcess(
|
||||
$audioBitrate,
|
||||
|
@ -425,12 +425,12 @@ class Video
|
|||
* Get audio stream of converted video.
|
||||
*
|
||||
* @param string $from Start the conversion at this time
|
||||
* @param string $to End the conversion at this time
|
||||
*
|
||||
* @throws Exception If your try to convert an M3U8 video
|
||||
* @throws Exception If the popen stream was not created correctly
|
||||
* @param string $to End the conversion at this time
|
||||
*
|
||||
* @return resource popen stream
|
||||
* @throws Exception If the popen stream was not created correctly
|
||||
*
|
||||
* @throws Exception If your try to convert an M3U8 video
|
||||
*/
|
||||
public function getAudioStream($from = null, $to = null)
|
||||
{
|
||||
|
@ -460,10 +460,10 @@ class Video
|
|||
/**
|
||||
* Get video stream from an M3U playlist.
|
||||
*
|
||||
* @throws Exception If avconv/ffmpeg is missing
|
||||
* @return resource popen stream
|
||||
* @throws Exception If the popen stream was not created correctly
|
||||
*
|
||||
* @return resource popen stream
|
||||
* @throws Exception If avconv/ffmpeg is missing
|
||||
*/
|
||||
public function getM3uStream()
|
||||
{
|
||||
|
@ -502,9 +502,9 @@ class Video
|
|||
/**
|
||||
* Get an avconv stream to remux audio and video.
|
||||
*
|
||||
* @return resource popen stream
|
||||
* @throws Exception If the popen stream was not created correctly
|
||||
*
|
||||
* @return resource popen stream
|
||||
*/
|
||||
public function getRemuxStream()
|
||||
{
|
||||
|
@ -539,9 +539,9 @@ class Video
|
|||
/**
|
||||
* Get video stream from an RTMP video.
|
||||
*
|
||||
* @return resource popen stream
|
||||
* @throws Exception If the popen stream was not created correctly
|
||||
*
|
||||
* @return resource popen stream
|
||||
*/
|
||||
public function getRtmpStream()
|
||||
{
|
||||
|
@ -572,13 +572,13 @@ class Video
|
|||
/**
|
||||
* Get the stream of a converted video.
|
||||
*
|
||||
* @param int $audioBitrate Audio bitrate of the converted file
|
||||
* @param string $filetype Filetype of the converted file
|
||||
*
|
||||
* @throws Exception If your try to convert and M3U8 video
|
||||
* @throws Exception If the popen stream was not created correctly
|
||||
* @param int $audioBitrate Audio bitrate of the converted file
|
||||
* @param string $filetype Filetype of the converted file
|
||||
*
|
||||
* @return resource popen stream
|
||||
* @throws Exception If the popen stream was not created correctly
|
||||
*
|
||||
* @throws Exception If your try to convert and M3U8 video
|
||||
*/
|
||||
public function getConvertedStream($audioBitrate, $filetype)
|
||||
{
|
||||
|
@ -612,7 +612,7 @@ class Video
|
|||
/**
|
||||
* Get a HTTP response containing the video.
|
||||
*
|
||||
* @param array $headers HTTP headers of the request
|
||||
* @param mixed[] $headers HTTP headers of the request
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws EmptyUrlException
|
||||
|
@ -628,7 +628,7 @@ class Video
|
|||
$urls[0],
|
||||
[
|
||||
'stream' => true,
|
||||
'headers' => array_merge((array) $this->http_headers, $headers)
|
||||
'headers' => array_merge((array)$this->http_headers, $headers)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class ViewFactory
|
|||
public static function create(ContainerInterface $container, Request $request = null)
|
||||
{
|
||||
if (!isset($request)) {
|
||||
$request = $container['request'];
|
||||
$request = $container->get('request');
|
||||
}
|
||||
|
||||
$view = new Smarty(__DIR__ . '/../templates/');
|
||||
|
@ -37,9 +37,10 @@ class ViewFactory
|
|||
$request = $request->withUri($request->getUri()->withScheme('https')->withPort(443));
|
||||
}
|
||||
|
||||
$localeManager = $container['locale'];
|
||||
/** @var LocaleManager $localeManager */
|
||||
$localeManager = $container->get('locale');
|
||||
|
||||
$smartyPlugins = new SmartyPlugins($container['router'], $request->getUri()->withUserInfo(null));
|
||||
$smartyPlugins = new SmartyPlugins($container->get('router'), $request->getUri()->withUserInfo(null));
|
||||
$view->registerPlugin('function', 'path_for', [$smartyPlugins, 'pathFor']);
|
||||
$view->registerPlugin('function', 'base_url', [$smartyPlugins, 'baseUrl']);
|
||||
$view->registerPlugin('block', 't', [$localeManager, 'smartyTranslate']);
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
namespace Alltube\Stream;
|
||||
|
||||
use Alltube\Exception\EmptyUrlException;
|
||||
use Alltube\Exception\PasswordException;
|
||||
use Alltube\Video;
|
||||
use Barracuda\ArchiveStream\ZipArchive;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
@ -86,20 +88,21 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface
|
|||
*
|
||||
* @param string $string The string that is to be written
|
||||
*
|
||||
* @return void
|
||||
* @return int|false
|
||||
*/
|
||||
public function write($string)
|
||||
{
|
||||
fwrite($this->buffer, $string);
|
||||
return fwrite($this->buffer, $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the stream if known.
|
||||
*
|
||||
* @return void
|
||||
* @return int|null
|
||||
*/
|
||||
public function getSize()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,7 +148,7 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface
|
|||
/**
|
||||
* Returns the remaining contents in a string.
|
||||
*
|
||||
* @return string
|
||||
* @return string|false
|
||||
*/
|
||||
public function getContents()
|
||||
{
|
||||
|
@ -196,7 +199,7 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface
|
|||
{
|
||||
$this->rewind();
|
||||
|
||||
return $this->getContents();
|
||||
return strval($this->getContents());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -238,6 +241,8 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface
|
|||
* @param Video $video Video to stream
|
||||
*
|
||||
* @return void
|
||||
* @throws PasswordException
|
||||
* @throws EmptyUrlException
|
||||
*/
|
||||
protected function startVideoStream(Video $video)
|
||||
{
|
||||
|
@ -248,7 +253,7 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface
|
|||
|
||||
$this->init_file_stream_transfer(
|
||||
$video->getFilename(),
|
||||
$contentLengthHeaders[0]
|
||||
intval($contentLengthHeaders[0])
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ class YoutubeChunkStream implements StreamInterface
|
|||
*/
|
||||
public function read($length)
|
||||
{
|
||||
$size = $this->response->getHeader('Content-Length')[0];
|
||||
$size = intval($this->response->getHeader('Content-Length')[0]);
|
||||
if ($size - $this->tell() < $length) {
|
||||
// Don't try to read further than the end of the stream.
|
||||
$length = $size - $this->tell();
|
||||
|
@ -55,7 +55,7 @@ class YoutubeChunkStream implements StreamInterface
|
|||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return (string) $this->response->getBody();
|
||||
return (string)$this->response->getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
namespace Alltube\Stream;
|
||||
|
||||
use Alltube\Exception\EmptyUrlException;
|
||||
use Alltube\Exception\PasswordException;
|
||||
use Alltube\Video;
|
||||
use GuzzleHttp\Psr7\AppendStream;
|
||||
|
||||
|
@ -19,6 +21,8 @@ class YoutubeStream extends AppendStream
|
|||
* YoutubeStream constructor.
|
||||
*
|
||||
* @param Video $video Video to stream
|
||||
* @throws EmptyUrlException
|
||||
* @throws PasswordException
|
||||
*/
|
||||
public function __construct(Video $video)
|
||||
{
|
||||
|
@ -31,7 +35,7 @@ class YoutubeStream extends AppendStream
|
|||
while ($rangeStart < $contentLenghtHeader[0]) {
|
||||
$rangeEnd = $rangeStart + $video->downloader_options->http_chunk_size;
|
||||
if ($rangeEnd >= $contentLenghtHeader[0]) {
|
||||
$rangeEnd = $contentLenghtHeader[0] - 1;
|
||||
$rangeEnd = intval($contentLenghtHeader[0]) - 1;
|
||||
}
|
||||
$response = $video->getHttpResponse(['Range' => 'bytes=' . $rangeStart . '-' . $rangeEnd]);
|
||||
$this->addStream(new YoutubeChunkStream($response));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue