Skip to content

Commit

Permalink
Set --no-playlist in the command line always
Browse files Browse the repository at this point in the history
Disable playlist options
Handle "video is protected by password" error
Handle "account terminated error"
CS fixes
  • Loading branch information
norkunas committed Sep 8, 2016
1 parent d217e31 commit b86b29c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ $dl->setDownloadPath('/home/user/downloads');
try {
$video = $dl->download('https://www.youtube.com/watch?v=oDAw7vW7H0c');
echo $video->getTitle(); // Will return Phonebloks
// $dl->getFile(); // \SplFileInfo instance of downloaded file
// $video->getFile(); // \SplFileInfo instance of downloaded file
} catch (NotFoundException $e) {
// Video not found
} catch (PrivateVideoException $e) {
Expand Down Expand Up @@ -78,4 +78,4 @@ $video = $dl->download('https://www.youtube.com/watch?v=oDAw7vW7H0c');

**Disabled options which would break download:**

list-formats, list-subs, list-thumbnails, get-url, get-title, get-id, get-thumbnail, get-description, get-duration, get-filename, get-format, dump-json, dump-single-json, print-json (used internally), newline, no-progress, console-title, verbose, dump-pages, write-pages, print-traffic, ignore-config (used internally), all-formats.
list-formats, list-subs, list-thumbnails, get-url, get-title, get-id, get-thumbnail, get-description, get-duration, get-filename, get-format, dump-json, dump-single-json, print-json (used internally), newline, no-progress, console-title, verbose, dump-pages, write-pages, print-traffic, ignore-config (used internally), all-formats, playlist-start, playlist-end, playlist-items, playlist-reverse, yes-playlist, no-playlist (used internally).
7 changes: 7 additions & 0 deletions src/Exception/AccountTerminatedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace YoutubeDl\Exception;

class AccountTerminatedException extends \RuntimeException
{
}
27 changes: 8 additions & 19 deletions src/YoutubeDl.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\Process\Process;
use Symfony\Component\Process\ProcessUtils;
use YoutubeDl\Entity\Video;
use YoutubeDl\Exception\AccountTerminatedException;
use YoutubeDl\Exception\CopyrightException;
use YoutubeDl\Exception\NotFoundException;
use YoutubeDl\Exception\PrivateVideoException;
Expand Down Expand Up @@ -198,7 +199,7 @@ public function getCommandLine()
}
}

$c .= '--print-json --ignore-config';
$c .= '--no-playlist --print-json --ignore-config';

return $c;
}
Expand Down Expand Up @@ -279,9 +280,6 @@ protected function configureOptions(OptionsResolver $resolver)
'force-ipv4' => 'bool',
'force-ipv6' => 'bool',
// Video selection options
'playlist-start' => 'int',
'playlist-end' => 'int|string',
'playlist-items' => 'string',
'match-title' => 'string',
'reject-title' => 'string',
'max-downloads' => 'int',
Expand All @@ -293,16 +291,13 @@ protected function configureOptions(OptionsResolver $resolver)
'min-views' => 'int',
'max-views' => 'int',
'match-filter' => 'string',
'no-playlist' => 'bool',
'yes-playlist' => 'bool',
'download-archive' => 'string',
'include-ads' => 'bool',
// Download Options
'rate-limit' => 'string',
'retries' => 'int|string',
'buffer-size' => 'string',
'no-resize-buffer' => 'bool',
'playlist-reverse' => 'bool',
'xattr-set-filesize' => 'bool',
'hls-prefer-native' => 'bool',
'external-downloader' => 'string',
Expand Down Expand Up @@ -399,14 +394,6 @@ protected function configureOptions(OptionsResolver $resolver)

$resolver->setAllowedValues('external-downloader', ['aria2c', 'curl', 'wget']);

$resolver->setAllowedValues('playlist-end', function ($value) {
if (is_string($value) && 'last' != $value) {
return false;
}

return true;
});

$resolver->setAllowedValues('audio-format', $this->allowedAudioFormats);

$resolver->setAllowedValues('ffmpeg-location', function ($value) {
Expand Down Expand Up @@ -479,9 +466,9 @@ protected function processDownloadOutput($output)

if ($downloadedFilePath !== '/') {
if ($this->moveWithPhp) {
$searchPattern = sys_get_temp_dir() . '/' . $searchPattern;
$searchPattern = sys_get_temp_dir().'/'.$searchPattern;
} else {
$searchPattern = $downloadedFilePath . $searchPattern;
$searchPattern = $downloadedFilePath.$searchPattern;
}
}
// http://php.net/manual/en/function.glob.php#75752
Expand All @@ -493,7 +480,7 @@ protected function processDownloadOutput($output)
$videoData['_filename'] = pathinfo($audioFile, PATHINFO_BASENAME);

if ($this->moveWithPhp) {
rename(sys_get_temp_dir() . '/' . $videoData['_filename'], $downloadedFilePath . $videoData['_filename']);
rename(sys_get_temp_dir().'/'.$videoData['_filename'], $downloadedFilePath.$videoData['_filename']);
}

$videoData['file'] = new \SplFileInfo($downloadedFilePath.$videoData['_filename']);
Expand All @@ -508,12 +495,14 @@ protected function handleException(\Exception $e)
{
$message = $e->getMessage();

if (preg_match('/please sign in to view this video/i', $message)) {
if (preg_match('/please sign in to view this video|video is protected by a password/i', $message)) {
return new PrivateVideoException();
} elseif (preg_match('/copyright infringement/i', $message)) {
return new CopyrightException();
} elseif (preg_match('/this video does not exist|404/i', $message)) {
return new NotFoundException();
} elseif (preg_match('/account associated with this video has been terminated/', $message)) {
return new AccountTerminatedException();
}

return $e;
Expand Down

0 comments on commit b86b29c

Please sign in to comment.