]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/mixcloud.py
125d81551c26ea67eff82f2d2189bd058d16b873
4 from .common
import InfoExtractor
11 class MixcloudIE(InfoExtractor
):
12 _VALID_URL
= r
'^(?:https?://)?(?:www\.)?mixcloud\.com/([\w\d-]+)/([\w\d-]+)'
16 u
'url': u
'http://www.mixcloud.com/dholbach/cryptkeeper/',
17 u
'file': u
'dholbach-cryptkeeper.mp3',
19 u
'title': u
'Cryptkeeper',
20 u
'description': u
'After quite a long silence from myself, finally another Drum\'n\'Bass mix with my favourite current dance floor bangers.',
21 u
'uploader': u
'Daniel Holbach',
22 u
'uploader_id': u
'dholbach',
23 u
'upload_date': u
'20111115',
27 def check_urls(self
, url_list
):
28 """Returns 1st active url from list"""
31 # We only want to know if the request succeed
32 # don't download the whole file
33 self
._request
_webpage
(url
, None, False)
35 except ExtractorError
:
40 def _get_url(self
, template_url
):
41 return self
.check_urls(template_url
% i
for i
in range(30))
43 def _real_extract(self
, url
):
44 mobj
= re
.match(self
._VALID
_URL
, url
)
46 uploader
= mobj
.group(1)
47 cloudcast_name
= mobj
.group(2)
48 track_id
= '-'.join((uploader
, cloudcast_name
))
49 api_url
= 'http://api.mixcloud.com/%s/%s/' % (uploader
, cloudcast_name
)
50 webpage
= self
._download
_webpage
(url
, track_id
)
51 json_data
= self
._download
_webpage
(api_url
, track_id
,
52 u
'Downloading cloudcast info')
53 info
= json
.loads(json_data
)
55 preview_url
= self
._search
_regex
(r
'data-preview-url="(.+?)"', webpage
, u
'preview url')
56 song_url
= preview_url
.replace('/previews/', '/cloudcasts/originals/')
57 template_url
= re
.sub(r
'(stream\d*)', 'stream%d', song_url
)
58 final_song_url
= self
._get
_url
(template_url
)
59 if final_song_url
is None:
60 self
.to_screen('Trying with m4a extension')
61 template_url
= template_url
.replace('.mp3', '.m4a').replace('originals/', 'm4a/64/')
62 final_song_url
= self
._get
_url
(template_url
)
63 if final_song_url
is None:
64 raise ExtractorError(u
'Unable to extract track url')
68 'title': info
['name'],
69 'url': final_song_url
,
70 'description': info
.get('description'),
71 'thumbnail': info
['pictures'].get('extra_large'),
72 'uploader': info
['user']['name'],
73 'uploader_id': info
['user']['username'],
74 'upload_date': unified_strdate(info
['created_time']),
75 'view_count': info
['play_count'],