From 46c26bc656a0608a9917916afd1833c06546181a Mon Sep 17 00:00:00 2001 From: Tomas Date: Thu, 10 Nov 2016 07:42:56 +0200 Subject: [PATCH] Prevent from downloading soundcloud sets --- src/Exception/UrlNotSupportedException.php | 7 +++++++ src/YoutubeDl.php | 14 ++++++++++++++ tests/YoutubeDl/YoutubeDlTest.php | 11 +++++++++++ 3 files changed, 32 insertions(+) create mode 100644 src/Exception/UrlNotSupportedException.php diff --git a/src/Exception/UrlNotSupportedException.php b/src/Exception/UrlNotSupportedException.php new file mode 100644 index 0000000..7e1cd39 --- /dev/null +++ b/src/Exception/UrlNotSupportedException.php @@ -0,0 +1,7 @@ +isUrlSupported($url)) { + throw new UrlNotSupportedException(sprintf('Provided url "%s" is not supported.', $url)); + } + $processBuilder = $this->createProcessBuilder([ $url, '--no-playlist', @@ -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; + } } diff --git a/tests/YoutubeDl/YoutubeDlTest.php b/tests/YoutubeDl/YoutubeDlTest.php index 34afbe2..6ba870a 100644 --- a/tests/YoutubeDl/YoutubeDlTest.php +++ b/tests/YoutubeDl/YoutubeDlTest.php @@ -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 */