2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_urllib_request
14 class HearThisAtIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?hearthis\.at/(?P<artist>[^/]+)/(?P<title>[A-Za-z0-9\-]+)/?$'
16 _PLAYLIST_URL = 'https://hearthis.at/playlist.php'
18 'url': 'https://hearthis.at/moofi/dr-kreep',
19 'md5': 'd594c573227a89f4256f0b03e68c80cc',
23 'title': 'Moofi - Dr. Kreep',
24 'thumbnail': 're:^https?://.*\.jpg$',
25 'timestamp': 1421564134,
26 'description': 'Creepy Patch. Mutable Instruments Braids Vowel + Formant Mode.',
27 'upload_date': '20150118',
32 'categories': ['Experimental'],
36 def _real_extract(self, url):
37 m = re.match(self._VALID_URL, url)
38 display_id = '{artist:s} - {title:s}'.format(**m.groupdict())
40 webpage = self._download_webpage(url, display_id)
41 track_id = self._search_regex(
42 r'intTrackId\s*=\s*(\d+)', webpage, 'track ID')
44 payload = urlencode_postdata({'tracks[]': track_id})
45 req = compat_urllib_request.Request(self._PLAYLIST_URL, payload)
46 req.add_header('Content-type', 'application/x-www-form-urlencoded')
48 track = self._download_json(req, track_id, 'Downloading playlist')[0]
49 title = '{artist:s} - {title:s}'.format(**track)
52 if track.get('category'):
53 categories = [track['category']]
55 description = self._og_search_description(webpage)
56 thumbnail = self._og_search_thumbnail(webpage)
58 meta_span = r'<span[^>]+class="%s".*?</i>([^<]+)</span>'
59 view_count = str_to_int(self._search_regex(
60 meta_span % 'plays_count', webpage, 'view count', fatal=False))
61 like_count = str_to_int(self._search_regex(
62 meta_span % 'likes_count', webpage, 'like count', fatal=False))
63 comment_count = str_to_int(self._search_regex(
64 meta_span % 'comment_count', webpage, 'comment count', fatal=False))
65 duration = str_to_int(self._search_regex(
66 r'data-length="(\d+)', webpage, 'duration', fatal=False))
67 timestamp = str_to_int(self._search_regex(
68 r'<span[^>]+class="calctime"[^>]+data-time="(\d+)', webpage, 'timestamp', fatal=False))
70 track_url = self._search_regex(
71 r'<a[^>]+data-mp3="([^"]+)"', webpage, 'track URL')
81 'display-id': display_id,
84 'thumbnail': thumbnail,
85 'description': description,
87 'timestamp': timestamp,
88 'view_count': view_count,
89 'comment_count': comment_count,
90 'like_count': like_count,
91 'categories': categories,