From 20991253334c069efac6986bb51cc28058809026 Mon Sep 17 00:00:00 2001 From: Philipp Hagemeister Date: Mon, 5 May 2014 03:12:41 +0200 Subject: [PATCH] [soundcloud/generic] Add support for playlists --- test/test_playlists.py | 13 +++++ youtube_dl/extractor/__init__.py | 7 ++- youtube_dl/extractor/common.py | 8 ++++ youtube_dl/extractor/generic.py | 13 +++-- youtube_dl/extractor/soundcloud.py | 77 +++++++++++++++++++----------- 5 files changed, 86 insertions(+), 32 deletions(-) diff --git a/test/test_playlists.py b/test/test_playlists.py index 02fcde1f7..fe6274e60 100644 --- a/test/test_playlists.py +++ b/test/test_playlists.py @@ -10,6 +10,7 @@ import unittest sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from test.helper import ( + assertRegexpMatches, expect_info_dict, FakeYDL, ) @@ -25,6 +26,7 @@ from youtube_dl.extractor import ( UstreamChannelIE, SoundcloudSetIE, SoundcloudUserIE, + SoundcloudPlaylistIE, LivestreamIE, NHLVideocenterIE, BambuserChannelIE, @@ -124,6 +126,17 @@ class TestPlaylists(unittest.TestCase): self.assertEqual(result['id'], '9615865') self.assertTrue(len(result['entries']) >= 12) + def test_soundcloud_playlist(self): + dl = FakeYDL() + ie = SoundcloudPlaylistIE(dl) + result = ie.extract('http://api.soundcloud.com/playlists/4110309') + self.assertIsPlaylist(result) + self.assertEqual(result['id'], '4110309') + self.assertEqual(result['title'], 'TILT Brass - Bowery Poetry Club, August \'03 [Non-Site SCR 02]') + assertRegexpMatches( + self, result['description'], r'TILT Brass - Bowery Poetry Club') + self.assertEqual(len(result['entries']), 6) + def test_livestream_event(self): dl = FakeYDL() ie = LivestreamIE(dl) diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index f8ece261a..9529077c7 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -237,7 +237,12 @@ from .smotri import ( SmotriBroadcastIE, ) from .sohu import SohuIE -from .soundcloud import SoundcloudIE, SoundcloudSetIE, SoundcloudUserIE +from .soundcloud import ( + SoundcloudIE, + SoundcloudSetIE, + SoundcloudUserIE, + SoundcloudPlaylistIE +) from .southparkstudios import ( SouthParkStudiosIE, SouthparkDeIE, diff --git a/youtube_dl/extractor/common.py b/youtube_dl/extractor/common.py index ef02b6896..10b0cbe69 100644 --- a/youtube_dl/extractor/common.py +++ b/youtube_dl/extractor/common.py @@ -548,6 +548,13 @@ class InfoExtractor(object): ) formats.sort(key=_formats_key) + def http_scheme(self): + """ Either "https:" or "https:", depending on the user's preferences """ + return ( + 'http:' + if self._downloader.params.get('prefer_insecure', False) + else 'https:') + class SearchInfoExtractor(InfoExtractor): """ @@ -591,3 +598,4 @@ class SearchInfoExtractor(InfoExtractor): @property def SEARCH_KEY(self): return self._SEARCH_KEY + diff --git a/youtube_dl/extractor/generic.py b/youtube_dl/extractor/generic.py index d7f0a4d39..1ae55dc5a 100644 --- a/youtube_dl/extractor/generic.py +++ b/youtube_dl/extractor/generic.py @@ -348,10 +348,7 @@ class GenericIE(InfoExtractor): if url.startswith('//'): return { '_type': 'url', - 'url': ( - 'http:' - if self._downloader.params.get('prefer_insecure', False) - else 'https:') + url, + 'url': self.http_scheme() + url, } parsed_url = compat_urlparse.urlparse(url) @@ -636,6 +633,14 @@ class GenericIE(InfoExtractor): if smotri_url: return self.url_result(smotri_url, 'Smotri') + # Look for embeded soundcloud player + mobj = re.search( + r'