]>
jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/mixcloud.py
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
15 class MixcloudIE(InfoExtractor
):
16 _VALID_URL
= r
'^(?:https?://)?(?:www\.)?mixcloud\.com/([^/]+)/([^/]+)'
20 'url': 'http://www.mixcloud.com/dholbach/cryptkeeper/',
22 'id': 'dholbach-cryptkeeper',
24 'title': 'Cryptkeeper',
25 'description': 'After quite a long silence from myself, finally another Drum\'n\'Bass mix with my favourite current dance floor bangers.',
26 'uploader': 'Daniel Holbach',
27 'uploader_id': 'dholbach',
28 'upload_date': '20111115',
29 'timestamp': 1321359578,
30 'thumbnail': 're:https?://.*\.jpg',
36 def check_urls(self
, url_list
):
37 """Returns 1st active url from list"""
40 # We only want to know if the request succeed
41 # don't download the whole file
42 self
._request
_webpage
(HEADRequest(url
), None, False)
44 except ExtractorError
:
49 def _get_url(self
, template_url
):
50 return self
.check_urls(template_url
% i
for i
in range(30))
52 def _real_extract(self
, url
):
53 mobj
= re
.match(self
._VALID
_URL
, url
)
54 uploader
= mobj
.group(1)
55 cloudcast_name
= mobj
.group(2)
56 track_id
= compat_urllib_parse
.unquote('-'.join((uploader
, cloudcast_name
)))
58 webpage
= self
._download
_webpage
(url
, track_id
)
60 preview_url
= self
._search
_regex
(
61 r
'\s(?:data-preview-url|m-preview)="(.+?)"', webpage
, 'preview url')
62 song_url
= preview_url
.replace('/previews/', '/c/originals/')
63 template_url
= re
.sub(r
'(stream\d*)', 'stream%d', song_url
)
64 final_song_url
= self
._get
_url
(template_url
)
65 if final_song_url
is None:
66 self
.to_screen('Trying with m4a extension')
67 template_url
= template_url
.replace('.mp3', '.m4a').replace('originals/', 'm4a/64/')
68 final_song_url
= self
._get
_url
(template_url
)
69 if final_song_url
is None:
70 raise ExtractorError('Unable to extract track url')
73 r
'<div class="cloudcast-play-button-container[^"]*?"'
74 r
'(?:\s+[a-zA-Z0-9-]+(?:="[^"]+")?)*?\s+')
75 title
= self
._html
_search
_regex
(
76 PREFIX
+ r
'm-title="([^"]+)"', webpage
, 'title')
77 thumbnail
= self
._proto
_relative
_url
(self
._html
_search
_regex
(
78 PREFIX
+ r
'm-thumbnail-url="([^"]+)"', webpage
, 'thumbnail',
80 uploader
= self
._html
_search
_regex
(
81 PREFIX
+ r
'm-owner-name="([^"]+)"',
82 webpage
, 'uploader', fatal
=False)
83 uploader_id
= self
._search
_regex
(
84 r
'\s+"profile": "([^"]+)",', webpage
, 'uploader id', fatal
=False)
85 description
= self
._og
_search
_description
(webpage
)
86 like_count
= int_or_none(self
._search
_regex
(
87 r
'<meta itemprop="interactionCount" content="UserLikes:([0-9]+)"',
88 webpage
, 'like count', fatal
=False))
89 view_count
= int_or_none(self
._search
_regex
(
90 r
'<meta itemprop="interactionCount" content="UserPlays:([0-9]+)"',
91 webpage
, 'play count', fatal
=False))
92 timestamp
= parse_iso8601(self
._search
_regex
(
93 r
'<time itemprop="dateCreated" datetime="([^"]+)">',
94 webpage
, 'upload date'))
99 'url': final_song_url
,
100 'description': description
,
101 'thumbnail': thumbnail
,
102 'uploader': uploader
,
103 'uploader_id': uploader_id
,
104 'timestamp': timestamp
,
105 'view_count': view_count
,
106 'like_count': like_count
,