]>
jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/mixcloud.py
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
13 class MixcloudIE(InfoExtractor
):
14 _VALID_URL
= r
'^(?:https?://)?(?:www\.)?mixcloud\.com/([^/]+)/([^/]+)'
18 'url': 'http://www.mixcloud.com/dholbach/cryptkeeper/',
20 'id': 'dholbach-cryptkeeper',
22 'title': 'Cryptkeeper',
23 'description': 'After quite a long silence from myself, finally another Drum\'n\'Bass mix with my favourite current dance floor bangers.',
24 'uploader': 'Daniel Holbach',
25 'uploader_id': 'dholbach',
26 'upload_date': '20111115',
30 def check_urls(self
, url_list
):
31 """Returns 1st active url from list"""
34 # We only want to know if the request succeed
35 # don't download the whole file
36 self
._request
_webpage
(url
, None, False)
38 except ExtractorError
:
43 def _get_url(self
, template_url
):
44 return self
.check_urls(template_url
% i
for i
in range(30))
46 def _real_extract(self
, url
):
47 mobj
= re
.match(self
._VALID
_URL
, url
)
48 uploader
= mobj
.group(1)
49 cloudcast_name
= mobj
.group(2)
50 track_id
= compat_urllib_parse
.unquote('-'.join((uploader
, cloudcast_name
)))
52 webpage
= self
._download
_webpage
(url
, track_id
)
54 api_url
= 'http://api.mixcloud.com/%s/%s/' % (uploader
, cloudcast_name
)
55 info
= self
._download
_json
(
56 api_url
, track_id
, 'Downloading cloudcast info')
58 preview_url
= self
._search
_regex
(
59 r
'\s(?:data-preview-url|m-preview)="(.+?)"', webpage
, 'preview url')
60 song_url
= preview_url
.replace('/previews/', '/c/originals/')
61 template_url
= re
.sub(r
'(stream\d*)', 'stream%d', song_url
)
62 final_song_url
= self
._get
_url
(template_url
)
63 if final_song_url
is None:
64 self
.to_screen('Trying with m4a extension')
65 template_url
= template_url
.replace('.mp3', '.m4a').replace('originals/', 'm4a/64/')
66 final_song_url
= self
._get
_url
(template_url
)
67 if final_song_url
is None:
68 raise ExtractorError(u
'Unable to extract track url')
72 'title': info
['name'],
73 'url': final_song_url
,
74 'description': info
.get('description'),
75 'thumbnail': info
['pictures'].get('extra_large'),
76 'uploader': info
['user']['name'],
77 'uploader_id': info
['user']['username'],
78 'upload_date': unified_strdate(info
['created_time']),
79 'view_count': info
['play_count'],