2015-01-21 14:47:55 -05:00
|
|
|
from .common import InfoExtractor
|
|
|
|
from ..utils import (
|
2021-08-20 15:39:59 -04:00
|
|
|
determine_ext,
|
2016-05-15 03:35:31 -04:00
|
|
|
KNOWN_EXTENSIONS,
|
2015-01-21 14:47:55 -05:00
|
|
|
str_to_int,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class HearThisAtIE(InfoExtractor):
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?hearthis\.at/(?P<artist>[^/]+)/(?P<title>[A-Za-z0-9\-]+)/?$'
|
|
|
|
_PLAYLIST_URL = 'https://hearthis.at/playlist.php'
|
2016-05-15 03:35:31 -04:00
|
|
|
_TESTS = [{
|
2015-01-21 14:47:55 -05:00
|
|
|
'url': 'https://hearthis.at/moofi/dr-kreep',
|
2015-01-22 06:04:07 -05:00
|
|
|
'md5': 'ab6ec33c8fed6556029337c7885eb4e0',
|
2015-01-21 14:47:55 -05:00
|
|
|
'info_dict': {
|
|
|
|
'id': '150939',
|
2015-01-22 06:04:07 -05:00
|
|
|
'ext': 'wav',
|
2015-01-21 14:47:55 -05:00
|
|
|
'title': 'Moofi - Dr. Kreep',
|
2017-01-02 07:08:07 -05:00
|
|
|
'thumbnail': r're:^https?://.*\.jpg$',
|
2015-01-21 14:47:55 -05:00
|
|
|
'timestamp': 1421564134,
|
2021-08-20 15:39:59 -04:00
|
|
|
'description': 'md5:1adb0667b01499f9d27e97ddfd53852a',
|
2015-01-21 14:47:55 -05:00
|
|
|
'upload_date': '20150118',
|
|
|
|
'view_count': int,
|
|
|
|
'duration': 71,
|
2021-08-20 15:39:59 -04:00
|
|
|
'genre': 'Experimental',
|
2015-01-21 14:47:55 -05:00
|
|
|
}
|
2016-05-15 03:35:31 -04:00
|
|
|
}, {
|
|
|
|
# 'download' link redirects to the original webpage
|
|
|
|
'url': 'https://hearthis.at/twitchsf/dj-jim-hopkins-totally-bitchin-80s-dance-mix/',
|
|
|
|
'md5': '5980ceb7c461605d30f1f039df160c6e',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '811296',
|
|
|
|
'ext': 'mp3',
|
|
|
|
'title': 'TwitchSF - DJ Jim Hopkins - Totally Bitchin\' 80\'s Dance Mix!',
|
2021-08-20 15:39:59 -04:00
|
|
|
'description': 'md5:ef26815ca8f483272a87b137ff175be2',
|
2016-05-15 03:35:31 -04:00
|
|
|
'upload_date': '20160328',
|
|
|
|
'timestamp': 1459186146,
|
2017-01-02 07:08:07 -05:00
|
|
|
'thumbnail': r're:^https?://.*\.jpg$',
|
2016-05-15 03:35:31 -04:00
|
|
|
'view_count': int,
|
|
|
|
'duration': 4360,
|
2021-08-20 15:39:59 -04:00
|
|
|
'genre': 'Dance',
|
2016-05-15 03:35:31 -04:00
|
|
|
},
|
|
|
|
}]
|
2015-01-21 14:47:55 -05:00
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2021-08-18 21:41:24 -04:00
|
|
|
m = self._match_valid_url(url)
|
2015-01-21 14:47:55 -05:00
|
|
|
display_id = '{artist:s} - {title:s}'.format(**m.groupdict())
|
2021-08-20 15:39:59 -04:00
|
|
|
api_url = url.replace('www.', '').replace('hearthis.at', 'api-v2.hearthis.at')
|
|
|
|
data_json = self._download_json(api_url, display_id)
|
|
|
|
track_id = data_json.get('id')
|
|
|
|
artist_json = data_json.get('user')
|
|
|
|
title = '{} - {}'.format(artist_json.get('username'), data_json.get('title'))
|
|
|
|
genre = data_json.get('genre')
|
|
|
|
description = data_json.get('description')
|
|
|
|
thumbnail = data_json.get('artwork_url') or data_json.get('thumb')
|
|
|
|
view_count = str_to_int(data_json.get('playback_count'))
|
|
|
|
duration = str_to_int(data_json.get('duration'))
|
|
|
|
timestamp = data_json.get('release_timestamp')
|
2015-01-21 14:47:55 -05:00
|
|
|
|
2015-01-22 06:04:07 -05:00
|
|
|
formats = []
|
2021-08-20 15:39:59 -04:00
|
|
|
mp3_url = data_json.get('stream_url')
|
|
|
|
|
2015-01-22 06:04:07 -05:00
|
|
|
if mp3_url:
|
|
|
|
formats.append({
|
|
|
|
'format_id': 'mp3',
|
|
|
|
'vcodec': 'none',
|
|
|
|
'acodec': 'mp3',
|
|
|
|
'url': mp3_url,
|
2021-08-20 15:39:59 -04:00
|
|
|
'ext': 'mp3',
|
2015-01-22 06:04:07 -05:00
|
|
|
})
|
2021-08-20 15:39:59 -04:00
|
|
|
|
|
|
|
if data_json.get('download_url'):
|
|
|
|
download_url = data_json['download_url']
|
|
|
|
ext = determine_ext(data_json['download_filename'])
|
2016-05-15 03:35:31 -04:00
|
|
|
if ext in KNOWN_EXTENSIONS:
|
|
|
|
formats.append({
|
2021-08-20 15:39:59 -04:00
|
|
|
'format_id': ext,
|
2016-05-15 03:35:31 -04:00
|
|
|
'vcodec': 'none',
|
|
|
|
'ext': ext,
|
|
|
|
'url': download_url,
|
2021-08-20 15:39:59 -04:00
|
|
|
'acodec': ext,
|
2021-02-18 17:03:16 -05:00
|
|
|
'quality': 2, # Usually better quality
|
2016-05-15 03:35:31 -04:00
|
|
|
})
|
2015-01-21 14:47:55 -05:00
|
|
|
|
|
|
|
return {
|
|
|
|
'id': track_id,
|
2015-01-22 06:04:07 -05:00
|
|
|
'display_id': display_id,
|
2015-01-21 14:47:55 -05:00
|
|
|
'title': title,
|
|
|
|
'formats': formats,
|
|
|
|
'thumbnail': thumbnail,
|
|
|
|
'description': description,
|
|
|
|
'duration': duration,
|
|
|
|
'timestamp': timestamp,
|
|
|
|
'view_count': view_count,
|
2021-08-20 15:39:59 -04:00
|
|
|
'genre': genre,
|
2015-01-21 14:47:55 -05:00
|
|
|
}
|