]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/hearthisat.py
[youtube:comments] Add more options for limiting number of comments extracted (#1626)
[yt-dlp.git] / yt_dlp / extractor / hearthisat.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4
5 from .common import InfoExtractor
6 from ..utils import (
7 determine_ext,
8 KNOWN_EXTENSIONS,
9 str_to_int,
10 )
11
12
13 class HearThisAtIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?hearthis\.at/(?P<artist>[^/]+)/(?P<title>[A-Za-z0-9\-]+)/?$'
15 _PLAYLIST_URL = 'https://hearthis.at/playlist.php'
16 _TESTS = [{
17 'url': 'https://hearthis.at/moofi/dr-kreep',
18 'md5': 'ab6ec33c8fed6556029337c7885eb4e0',
19 'info_dict': {
20 'id': '150939',
21 'ext': 'wav',
22 'title': 'Moofi - Dr. Kreep',
23 'thumbnail': r're:^https?://.*\.jpg$',
24 'timestamp': 1421564134,
25 'description': 'md5:1adb0667b01499f9d27e97ddfd53852a',
26 'upload_date': '20150118',
27 'view_count': int,
28 'duration': 71,
29 'genre': 'Experimental',
30 }
31 }, {
32 # 'download' link redirects to the original webpage
33 'url': 'https://hearthis.at/twitchsf/dj-jim-hopkins-totally-bitchin-80s-dance-mix/',
34 'md5': '5980ceb7c461605d30f1f039df160c6e',
35 'info_dict': {
36 'id': '811296',
37 'ext': 'mp3',
38 'title': 'TwitchSF - DJ Jim Hopkins - Totally Bitchin\' 80\'s Dance Mix!',
39 'description': 'md5:ef26815ca8f483272a87b137ff175be2',
40 'upload_date': '20160328',
41 'timestamp': 1459186146,
42 'thumbnail': r're:^https?://.*\.jpg$',
43 'view_count': int,
44 'duration': 4360,
45 'genre': 'Dance',
46 },
47 }]
48
49 def _real_extract(self, url):
50 m = self._match_valid_url(url)
51 display_id = '{artist:s} - {title:s}'.format(**m.groupdict())
52 api_url = url.replace('www.', '').replace('hearthis.at', 'api-v2.hearthis.at')
53 data_json = self._download_json(api_url, display_id)
54 track_id = data_json.get('id')
55 artist_json = data_json.get('user')
56 title = '{} - {}'.format(artist_json.get('username'), data_json.get('title'))
57 genre = data_json.get('genre')
58 description = data_json.get('description')
59 thumbnail = data_json.get('artwork_url') or data_json.get('thumb')
60 view_count = str_to_int(data_json.get('playback_count'))
61 duration = str_to_int(data_json.get('duration'))
62 timestamp = data_json.get('release_timestamp')
63
64 formats = []
65 mp3_url = data_json.get('stream_url')
66
67 if mp3_url:
68 formats.append({
69 'format_id': 'mp3',
70 'vcodec': 'none',
71 'acodec': 'mp3',
72 'url': mp3_url,
73 'ext': 'mp3',
74 })
75
76 if data_json.get('download_url'):
77 download_url = data_json['download_url']
78 ext = determine_ext(data_json['download_filename'])
79 if ext in KNOWN_EXTENSIONS:
80 formats.append({
81 'format_id': ext,
82 'vcodec': 'none',
83 'ext': ext,
84 'url': download_url,
85 'acodec': ext,
86 'quality': 2, # Usually better quality
87 })
88 self._sort_formats(formats)
89
90 return {
91 'id': track_id,
92 'display_id': display_id,
93 'title': title,
94 'formats': formats,
95 'thumbnail': thumbnail,
96 'description': description,
97 'duration': duration,
98 'timestamp': timestamp,
99 'view_count': view_count,
100 'genre': genre,
101 }