This commit is contained in:
Pierre Rudloff 2020-10-17 22:47:16 +02:00
parent 3280e60871
commit 69d09b780e
5 changed files with 50 additions and 31 deletions

View file

@ -4,6 +4,7 @@ namespace Alltube\Library;
use Alltube\Library\Exception\AlltubeLibraryException;
use Alltube\Library\Exception\AvconvException;
use Alltube\Library\Exception\EmptyUrlException;
use Alltube\Library\Exception\InvalidProtocolConversionException;
use Alltube\Library\Exception\InvalidTimeException;
use Alltube\Library\Exception\PasswordException;
@ -111,10 +112,10 @@ class Downloader
/**
* @param string $webpageUrl URL of the page containing the video
* @param string $requestedFormat Requested video format
* @param string $password Password
* @param string|null $password Password
* @return Video
*/
public function getVideo($webpageUrl, $requestedFormat = 'best/bestvideo', $password = null)
public function getVideo(string $webpageUrl, $requestedFormat = 'best/bestvideo', string $password = null)
{
return new Video($this, $webpageUrl, $requestedFormat, $password);
}
@ -159,21 +160,24 @@ class Downloader
* @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 string|null $from Start the conversion at this time
* @param string|null $to End the conversion at this time
*
* @return Process<string> Process
* @throws AlltubeLibraryException
* @throws AvconvException If avconv/ffmpeg is missing
* @throws EmptyUrlException
* @throws InvalidTimeException
* @throws PasswordException
* @throws WrongPasswordException
* @throws YoutubedlException
*/
private function getAvconvProcess(
Video $video,
$audioBitrate,
int $audioBitrate,
$filetype = 'mp3',
$audioOnly = true,
$from = null,
$to = null
string $from = null,
string $to = null
) {
if (!$this->checkCommand([$this->avconv, '-version'])) {
throw new AvconvException($this->avconv);
@ -309,13 +313,22 @@ class Downloader
*
* @param Video $video Video object
* @param int $audioBitrate MP3 bitrate when converting (in kbit/s)
* @param string $from Start the conversion at this time
* @param string $to End the conversion at this time
* @param string|null $from Start the conversion at this time
* @param string|null $to End the conversion at this time
*
* @return resource popen stream
* @throws AlltubeLibraryException
* @throws AvconvException
* @throws EmptyUrlException
* @throws InvalidProtocolConversionException
* @throws InvalidTimeException
* @throws PasswordException
* @throws PlaylistConversionException
* @throws PopenStreamException
* @throws RemuxException
* @throws WrongPasswordException
* @throws YoutubedlException
*/
public function getAudioStream(Video $video, $audioBitrate = 128, $from = null, $to = null)
public function getAudioStream(Video $video, $audioBitrate = 128, string $from = null, string $to = null)
{
return $this->getConvertedStream($video, $audioBitrate, 'mp3', true, $from, $to);
}
@ -402,22 +415,28 @@ class Downloader
* @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 string|null $from Start the conversion at this time
* @param string|null $to End the conversion at this time
*
* @return resource popen stream
* @throws AlltubeLibraryException
* @throws PopenStreamException If the popen stream was not created correctly
* @throws AvconvException
* @throws EmptyUrlException
* @throws InvalidProtocolConversionException If you try to convert an M3U or Dash media
* @throws InvalidTimeException
* @throws PasswordException
* @throws PlaylistConversionException If you try to convert a playlist
* @throws PopenStreamException If the popen stream was not created correctly
* @throws RemuxException
* @throws WrongPasswordException
* @throws YoutubedlException
*/
public function getConvertedStream(
Video $video,
$audioBitrate,
$filetype,
int $audioBitrate,
string $filetype,
$audioOnly = false,
$from = null,
$to = null
string $from = null,
string $to = null
) {
if (isset($video->_type) && $video->_type == 'playlist') {
throw new PlaylistConversionException();

View file

@ -11,7 +11,7 @@ class AvconvException extends AlltubeLibraryException
* AvconvException constructor.
* @param string $path Path to avconv or ffmpeg.
*/
public function __construct($path)
public function __construct(string $path)
{
parent::__construct("Can't find avconv or ffmpeg at " . $path . '.');
}

View file

@ -11,7 +11,7 @@ class InvalidProtocolConversionException extends AlltubeLibraryException
* InvalidProtocolConversionException constructor.
* @param string $protocol Protocol
*/
public function __construct($protocol)
public function __construct(string $protocol)
{
parent::__construct($protocol . ' protocol is not supported in conversions.');
}

View file

@ -12,7 +12,7 @@ class InvalidTimeException extends AlltubeLibraryException
* InvalidTimeException constructor.
* @param string $time Invalid time
*/
public function __construct($time)
public function __construct(string $time)
{
parent::__construct('Invalid time: ' . $time);
}

View file

@ -81,13 +81,13 @@ class 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|null $password Password
*/
public function __construct(
Downloader $downloader,
$webpageUrl,
$requestedFormat,
$password = null
string $webpageUrl,
string $requestedFormat,
string $password = null
) {
$this->downloader = $downloader;
$this->webpageUrl = $webpageUrl;
@ -151,7 +151,7 @@ class Video
* @throws WrongPasswordException
* @throws YoutubedlException
*/
public function __get($name)
public function __get(string $name)
{
if (isset($this->$name)) {
return $this->getJson()->$name;
@ -170,7 +170,7 @@ class Video
* @throws WrongPasswordException
* @throws YoutubedlException
*/
public function __isset($name)
public function __isset(string $name)
{
return isset($this->getJson()->$name);
}
@ -225,7 +225,7 @@ class Video
* @throws WrongPasswordException
* @throws YoutubedlException
*/
public function getFileNameWithExtension($extension)
public function getFileNameWithExtension(string $extension)
{
if (isset($this->ext)) {
return str_replace('.' . $this->ext, '.' . $extension, $this->getFilename());
@ -278,7 +278,7 @@ class Video
*
* @return Video
*/
public function withFormat($format)
public function withFormat(string $format)
{
return new self($this->downloader, $this->webpageUrl, $format, $this->password);
}