From 45b0596290c28eb395aebe6e535476ec4000b6a9 Mon Sep 17 00:00:00 2001 From: Ashish <39122144+Ashish0804@users.noreply.github.com> Date: Sat, 21 Aug 2021 01:09:59 +0530 Subject: [PATCH] [HearThisAtIE] Fix extractor (#742) Closes: #740 Authored by: Ashish0804 --- yt_dlp/extractor/hearthisat.py | 85 +++++++++++----------------------- 1 file changed, 26 insertions(+), 59 deletions(-) diff --git a/yt_dlp/extractor/hearthisat.py b/yt_dlp/extractor/hearthisat.py index aeb216c71..59043164d 100644 --- a/yt_dlp/extractor/hearthisat.py +++ b/yt_dlp/extractor/hearthisat.py @@ -4,14 +4,10 @@ from __future__ import unicode_literals import re from .common import InfoExtractor -from ..compat import compat_urlparse from ..utils import ( - HEADRequest, + determine_ext, KNOWN_EXTENSIONS, - sanitized_Request, str_to_int, - urlencode_postdata, - urlhandle_detect_ext, ) @@ -27,13 +23,11 @@ class HearThisAtIE(InfoExtractor): 'title': 'Moofi - Dr. Kreep', 'thumbnail': r're:^https?://.*\.jpg$', 'timestamp': 1421564134, - 'description': 'Listen to Dr. Kreep by Moofi on hearthis.at - Modular, Eurorack, Mutable Intruments Braids, Valhalla-DSP', + 'description': 'md5:1adb0667b01499f9d27e97ddfd53852a', 'upload_date': '20150118', - 'comment_count': int, 'view_count': int, - 'like_count': int, 'duration': 71, - 'categories': ['Experimental'], + 'genre': 'Experimental', } }, { # 'download' link redirects to the original webpage @@ -43,78 +37,53 @@ class HearThisAtIE(InfoExtractor): 'id': '811296', 'ext': 'mp3', 'title': 'TwitchSF - DJ Jim Hopkins - Totally Bitchin\' 80\'s Dance Mix!', - 'description': 'Listen to DJ Jim Hopkins - Totally Bitchin\' 80\'s Dance Mix! by TwitchSF on hearthis.at - Dance', + 'description': 'md5:ef26815ca8f483272a87b137ff175be2', 'upload_date': '20160328', 'timestamp': 1459186146, 'thumbnail': r're:^https?://.*\.jpg$', - 'comment_count': int, 'view_count': int, - 'like_count': int, 'duration': 4360, - 'categories': ['Dance'], + 'genre': 'Dance', }, }] def _real_extract(self, url): m = re.match(self._VALID_URL, url) display_id = '{artist:s} - {title:s}'.format(**m.groupdict()) - - webpage = self._download_webpage(url, display_id) - track_id = self._search_regex( - r'intTrackId\s*=\s*(\d+)', webpage, 'track ID') - - payload = urlencode_postdata({'tracks[]': track_id}) - req = sanitized_Request(self._PLAYLIST_URL, payload) - req.add_header('Content-type', 'application/x-www-form-urlencoded') - - track = self._download_json(req, track_id, 'Downloading playlist')[0] - title = '{artist:s} - {title:s}'.format(**track) - - categories = None - if track.get('category'): - categories = [track['category']] - - description = self._og_search_description(webpage) - thumbnail = self._og_search_thumbnail(webpage) - - meta_span = r']+class="%s".*?([^<]+)' - view_count = str_to_int(self._search_regex( - meta_span % 'plays_count', webpage, 'view count', fatal=False)) - like_count = str_to_int(self._search_regex( - meta_span % 'likes_count', webpage, 'like count', fatal=False)) - comment_count = str_to_int(self._search_regex( - meta_span % 'comment_count', webpage, 'comment count', fatal=False)) - duration = str_to_int(self._search_regex( - r'data-length="(\d+)', webpage, 'duration', fatal=False)) - timestamp = str_to_int(self._search_regex( - r']+class="calctime"[^>]+data-time="(\d+)', webpage, 'timestamp', fatal=False)) + 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') formats = [] - mp3_url = self._search_regex( - r'(?s)