]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/mixcloud.py
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
16 class MixcloudIE(InfoExtractor
):
17 _VALID_URL
= r
'^(?:https?://)?(?:www\.)?mixcloud\.com/([^/]+)/([^/]+)'
21 'url': 'http://www.mixcloud.com/dholbach/cryptkeeper/',
23 'id': 'dholbach-cryptkeeper',
25 'title': 'Cryptkeeper',
26 'description': 'After quite a long silence from myself, finally another Drum\'n\'Bass mix with my favourite current dance floor bangers.',
27 'uploader': 'Daniel Holbach',
28 'uploader_id': 'dholbach',
29 'thumbnail': 're:https?://.*\.jpg',
34 'url': 'http://www.mixcloud.com/gillespeterson/caribou-7-inch-vinyl-mix-chat/',
36 'id': 'gillespeterson-caribou-7-inch-vinyl-mix-chat',
38 'title': 'Caribou 7 inch Vinyl Mix & Chat',
39 'description': 'md5:2b8aec6adce69f9d41724647c65875e8',
40 'uploader': 'Gilles Peterson Worldwide',
41 'uploader_id': 'gillespeterson',
42 'thumbnail': 're:https?://.*/images/',
48 def _check_url(self
, url
, track_id
, ext
):
50 # We only want to know if the request succeed
51 # don't download the whole file
52 self
._request
_webpage
(
53 HEADRequest(url
), track_id
,
54 'Trying %s URL' % ext
)
56 except ExtractorError
:
59 def _real_extract(self
, url
):
60 mobj
= re
.match(self
._VALID
_URL
, url
)
61 uploader
= mobj
.group(1)
62 cloudcast_name
= mobj
.group(2)
63 track_id
= compat_urllib_parse
.unquote('-'.join((uploader
, cloudcast_name
)))
65 webpage
= self
._download
_webpage
(url
, track_id
)
67 preview_url
= self
._search
_regex
(
68 r
'\s(?:data-preview-url|m-preview)="([^"]+)"', webpage
, 'preview url')
69 song_url
= preview_url
.replace('/previews/', '/c/originals/')
70 if not self
._check
_url
(song_url
, track_id
, 'mp3'):
71 song_url
= song_url
.replace('.mp3', '.m4a').replace('originals/', 'm4a/64/')
72 if not self
._check
_url
(song_url
, track_id
, 'm4a'):
73 raise ExtractorError('Unable to extract track url')
76 r
'm-play-on-spacebar[^>]+'
77 r
'(?:\s+[a-zA-Z0-9-]+(?:="[^"]+")?)*?\s+')
78 title
= self
._html
_search
_regex
(
79 PREFIX
+ r
'm-title="([^"]+)"', webpage
, 'title')
80 thumbnail
= self
._proto
_relative
_url
(self
._html
_search
_regex
(
81 PREFIX
+ r
'm-thumbnail-url="([^"]+)"', webpage
, 'thumbnail',
83 uploader
= self
._html
_search
_regex
(
84 PREFIX
+ r
'm-owner-name="([^"]+)"',
85 webpage
, 'uploader', fatal
=False)
86 uploader_id
= self
._search
_regex
(
87 r
'\s+"profile": "([^"]+)",', webpage
, 'uploader id', fatal
=False)
88 description
= self
._og
_search
_description
(webpage
)
89 like_count
= str_to_int(self
._search
_regex
(
90 r
'\bbutton-favorite\b[^>]+m-ajax-toggle-count="([^"]+)"',
91 webpage
, 'like count', fatal
=False))
92 view_count
= str_to_int(self
._search
_regex
(
93 [r
'<meta itemprop="interactionCount" content="UserPlays:([0-9]+)"',
94 r
'/listeners/?">([0-9,.]+)</a>'],
95 webpage
, 'play count', fatal
=False))
101 'description': description
,
102 'thumbnail': thumbnail
,
103 'uploader': uploader
,
104 'uploader_id': uploader_id
,
105 'view_count': view_count
,
106 'like_count': like_count
,