Skip to content

Commit

Permalink
Prevent from downloading soundcloud sets
Browse files Browse the repository at this point in the history
  • Loading branch information
norkunas committed Nov 10, 2016
1 parent 468f373 commit 46c26bc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Exception/UrlNotSupportedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace YoutubeDl\Exception;

class UrlNotSupportedException extends YoutubeDlException
{
}
14 changes: 14 additions & 0 deletions src/YoutubeDl.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use YoutubeDl\Exception\ExecutableNotFoundException;
use YoutubeDl\Exception\NotFoundException;
use YoutubeDl\Exception\PrivateVideoException;
use YoutubeDl\Exception\UrlNotSupportedException;

class YoutubeDl
{
Expand Down Expand Up @@ -72,6 +73,10 @@ public function download(string $url): Video
throw new \RuntimeException('No download path was set.');
}

if (!$this->isUrlSupported($url)) {
throw new UrlNotSupportedException(sprintf('Provided url "%s" is not supported.', $url));
}

$processBuilder = $this->createProcessBuilder([
$url,
'--no-playlist',
Expand Down Expand Up @@ -328,4 +333,13 @@ private function configureOptions(OptionsResolver $resolver)
return $value;
});
}

private function isUrlSupported(string $url): bool
{
if (preg_match('#soundcloud.com/.+/sets.+#', $url)) {
return false;
}

return true;
}
}
11 changes: 11 additions & 0 deletions tests/YoutubeDl/YoutubeDlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ public function testYoutubeAccountTerminatedVideoDownload()
$yt->download('https://www.youtube.com/watch?v=oIdgb-vwAQI');
}

/**
* @expectedException \YoutubeDl\Exception\UrlNotSupportedException
* @expectedExceptionMessageRegExp /Provided url ".+" is not supported\./
*/
public function testUrlNotSupported()
{
$yt = new YoutubeDl();
$yt->setDownloadPath('/');
$yt->download('https://soundcloud.com/csimpi/sets/go4it-demo');
}

/**
* @expectedException \Symfony\Component\Process\Exception\ProcessFailedException
*/
Expand Down

0 comments on commit 46c26bc

Please sign in to comment.