4 from .common import InfoExtractor
13 class SoundcloudIE(InfoExtractor):
14 """Information extractor for soundcloud.com
15 To access the media, the uid of the song and a stream token
16 must be extracted from the page source and the script must make
17 a request to media.soundcloud.com/crossdomain.xml. Then
18 the media can be grabbed by requesting from an url composed
19 of the stream token and uid
22 _VALID_URL = r'^(?:https?://)?(?:www\.)?soundcloud\.com/([\w\d-]+)/([\w\d-]+)/?(?:[?].*)?$'
23 IE_NAME = u'soundcloud'
25 u'url': u'http://soundcloud.com/ethmusic/lostin-powers-she-so-heavy',
26 u'file': u'62986583.mp3',
27 u'md5': u'ebef0a451b909710ed1d7787dddbf0d7',
29 u"upload_date": u"20121011",
30 u"description": u"No Downloads untill we record the finished version this weekend, i was too pumped n i had to post it , earl is prolly gonna b hella p.o'd",
31 u"uploader": u"E.T. ExTerrestrial Music",
32 u"title": u"Lostin Powers - She so Heavy (SneakPreview) Adrian Ackers Blueprint 1"
36 _CLIENT_ID = 'b45b1aa10f1ac2941910a7f0d10f8e28'
38 def report_resolve(self, video_id):
39 """Report information extraction."""
40 self.to_screen(u'%s: Resolving id' % video_id)
43 def _resolv_url(cls, url):
44 return 'http://api.soundcloud.com/resolve.json?url=' + url + '&client_id=' + cls._CLIENT_ID
46 def _extract_info_dict(self, info, full_title=None):
48 name = full_title or video_id
49 self.report_extraction(name)
51 thumbnail = info['artwork_url']
52 if thumbnail is not None:
53 thumbnail = thumbnail.replace('-large', '-t500x500')
56 'url': info['stream_url'] + '?client_id=' + self._CLIENT_ID,
57 'uploader': info['user']['username'],
58 'upload_date': unified_strdate(info['created_at']),
59 'title': info['title'],
61 'description': info['description'],
62 'thumbnail': thumbnail,
65 def _real_extract(self, url):
66 mobj = re.match(self._VALID_URL, url)
68 raise ExtractorError(u'Invalid URL: %s' % url)
70 # extract uploader (which is in the url)
71 uploader = mobj.group(1)
72 # extract simple title (uploader + slug of song title)
73 slug_title = mobj.group(2)
74 full_title = '%s/%s' % (uploader, slug_title)
76 self.report_resolve(full_title)
78 url = 'http://soundcloud.com/%s/%s' % (uploader, slug_title)
79 resolv_url = self._resolv_url(url)
80 info_json = self._download_webpage(resolv_url, full_title, u'Downloading info JSON')
82 info = json.loads(info_json)
83 return self._extract_info_dict(info, full_title)
85 class SoundcloudSetIE(SoundcloudIE):
86 _VALID_URL = r'^(?:https?://)?(?:www\.)?soundcloud\.com/([\w\d-]+)/sets/([\w\d-]+)(?:[?].*)?$'
87 IE_NAME = u'soundcloud:set'
89 u"url":"https://soundcloud.com/the-concept-band/sets/the-royal-concept-ep",
92 u"file":"30510138.mp3",
93 u"md5":"f9136bf103901728f29e419d2c70f55d",
95 u"upload_date": u"20111213",
96 u"description": u"The Royal Concept from Stockholm\r\nFilip / Povel / David / Magnus\r\nwww.royalconceptband.com",
97 u"uploader": u"The Royal Concept",
98 u"title": u"D-D-Dance"
102 u"file":"47127625.mp3",
103 u"md5":"09b6758a018470570f8fd423c9453dd8",
105 u"upload_date": u"20120521",
106 u"description": u"The Royal Concept from Stockholm\r\nFilip / Povel / David / Magnus\r\nwww.royalconceptband.com",
107 u"uploader": u"The Royal Concept",
108 u"title": u"The Royal Concept - Gimme Twice"
112 u"file":"47127627.mp3",
113 u"md5":"154abd4e418cea19c3b901f1e1306d9c",
115 u"upload_date": u"20120521",
116 u"uploader": u"The Royal Concept",
117 u"title": u"Goldrushed"
121 u"file":"47127629.mp3",
122 u"md5":"2f5471edc79ad3f33a683153e96a79c1",
124 u"upload_date": u"20120521",
125 u"description": u"The Royal Concept from Stockholm\r\nFilip / Povel / David / Magnus\r\nwww.royalconceptband.com",
126 u"uploader": u"The Royal Concept",
127 u"title": u"In the End"
131 u"file":"47127631.mp3",
132 u"md5":"f9ba87aa940af7213f98949254f1c6e2",
134 u"upload_date": u"20120521",
135 u"description": u"The Royal Concept from Stockholm\r\nFilip / David / Povel / Magnus\r\nwww.theroyalconceptband.com",
136 u"uploader": u"The Royal Concept",
137 u"title": u"Knocked Up"
141 u"file":"75206121.mp3",
142 u"md5":"f9d1fe9406717e302980c30de4af9353",
144 u"upload_date": u"20130116",
145 u"description": u"The unreleased track World on Fire premiered on the CW's hit show Arrow (8pm/7pm central). \r\nAs a gift to our fans we would like to offer you a free download of the track! ",
146 u"uploader": u"The Royal Concept",
147 u"title": u"World On Fire"
153 def _real_extract(self, url):
154 mobj = re.match(self._VALID_URL, url)
156 raise ExtractorError(u'Invalid URL: %s' % url)
158 # extract uploader (which is in the url)
159 uploader = mobj.group(1)
160 # extract simple title (uploader + slug of song title)
161 slug_title = mobj.group(2)
162 full_title = '%s/sets/%s' % (uploader, slug_title)
164 self.report_resolve(full_title)
166 url = 'http://soundcloud.com/%s/sets/%s' % (uploader, slug_title)
167 resolv_url = self._resolv_url(url)
168 info_json = self._download_webpage(resolv_url, full_title)
171 info = json.loads(info_json)
173 for err in info['errors']:
174 self._downloader.report_error(u'unable to download video webpage: %s' % compat_str(err['error_message']))
177 self.report_extraction(full_title)
178 return {'_type': 'playlist',
179 'entries': [self._extract_info_dict(track) for track in info['tracks']],
181 'title': info['title'],