]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/hearthisat.py
a19b31ac0605392b044ca14fad4ffa4e4752b281
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
19 class HearThisAtIE(InfoExtractor
):
20 _VALID_URL
= r
'https?://(?:www\.)?hearthis\.at/(?P<artist>[^/]+)/(?P<title>[A-Za-z0-9\-]+)/?$'
21 _PLAYLIST_URL
= 'https://hearthis.at/playlist.php'
23 'url': 'https://hearthis.at/moofi/dr-kreep',
24 'md5': 'ab6ec33c8fed6556029337c7885eb4e0',
28 'title': 'Moofi - Dr. Kreep',
29 'thumbnail': 're:^https?://.*\.jpg$',
30 'timestamp': 1421564134,
31 'description': 'Creepy Patch. Mutable Instruments Braids Vowel + Formant Mode.',
32 'upload_date': '20150118',
37 'categories': ['Experimental'],
41 def _real_extract(self
, url
):
42 m
= re
.match(self
._VALID
_URL
, url
)
43 display_id
= '{artist:s} - {title:s}'.format(**m
.groupdict())
45 webpage
= self
._download
_webpage
(url
, display_id
)
46 track_id
= self
._search
_regex
(
47 r
'intTrackId\s*=\s*(\d+)', webpage
, 'track ID')
49 payload
= urlencode_postdata({'tracks[]': track_id
})
50 req
= compat_urllib_request
.Request(self
._PLAYLIST
_URL
, payload
)
51 req
.add_header('Content-type', 'application/x-www-form-urlencoded')
53 track
= self
._download
_json
(req
, track_id
, 'Downloading playlist')[0]
54 title
= '{artist:s} - {title:s}'.format(**track
)
57 if track
.get('category'):
58 categories
= [track
['category']]
60 description
= self
._og
_search
_description
(webpage
)
61 thumbnail
= self
._og
_search
_thumbnail
(webpage
)
63 meta_span
= r
'<span[^>]+class="%s".*?</i>([^<]+)</span>'
64 view_count
= str_to_int(self
._search
_regex
(
65 meta_span
% 'plays_count', webpage
, 'view count', fatal
=False))
66 like_count
= str_to_int(self
._search
_regex
(
67 meta_span
% 'likes_count', webpage
, 'like count', fatal
=False))
68 comment_count
= str_to_int(self
._search
_regex
(
69 meta_span
% 'comment_count', webpage
, 'comment count', fatal
=False))
70 duration
= str_to_int(self
._search
_regex
(
71 r
'data-length="(\d+)', webpage
, 'duration', fatal
=False))
72 timestamp
= str_to_int(self
._search
_regex
(
73 r
'<span[^>]+class="calctime"[^>]+data-time="(\d+)', webpage
, 'timestamp', fatal
=False))
76 mp3_url
= self
._search
_regex
(
77 r
'(?s)<a class="player-link"\s+(?:[a-zA-Z0-9_:-]+="[^"]+"\s+)*?data-mp3="([^"]+)"',
78 webpage
, 'mp3 URL', fatal
=False)
86 download_path
= self
._search
_regex
(
87 r
'<a class="[^"]*download_fct[^"]*"\s+href="([^"]+)"',
88 webpage
, 'download URL', default
=None)
90 download_url
= compat_urlparse
.urljoin(url
, download_path
)
91 ext_req
= HEADRequest(download_url
)
92 ext_handle
= self
._request
_webpage
(
93 ext_req
, display_id
, note
='Determining extension')
94 ext
= urlhandle_detect_ext(ext_handle
)
96 'format_id': 'download',
100 'preference': 2, # Usually better quality
102 self
._sort
_formats
(formats
)
106 'display_id': display_id
,
109 'thumbnail': thumbnail
,
110 'description': description
,
111 'duration': duration
,
112 'timestamp': timestamp
,
113 'view_count': view_count
,
114 'comment_count': comment_count
,
115 'like_count': like_count
,
116 'categories': categories
,