mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-08-20 14:16:46 +00:00
+35
-12
@@ -4,14 +4,30 @@ from ..utils import (
|
||||
int_or_none,
|
||||
parse_iso8601,
|
||||
str_or_none,
|
||||
traverse_obj,
|
||||
url_or_none,
|
||||
)
|
||||
from ..utils.traversal import require, traverse_obj
|
||||
|
||||
|
||||
class WhypIE(InfoExtractor):
|
||||
_VALID_URL = r'https?://(?:www\.)?whyp\.it/tracks/(?P<id>\d+)'
|
||||
_VALID_URL = r'https?://(?:www\.)?whyp\.it/tracks/(?:(?P<id>\d{5,})/)?(?P<display_id>[^/?#]+)'
|
||||
_TESTS = [{
|
||||
'url': 'https://whyp.it/tracks/example-track-HPuZgly3yViP',
|
||||
'md5': '02fd96427acd9547445979bf0496b013',
|
||||
'info_dict': {
|
||||
'id': '18337',
|
||||
'title': 'Example Track',
|
||||
'display_id': 'example-track',
|
||||
'description': 'md5:e0b1bcf1d267dc1a0f15efff09c8f297',
|
||||
'ext': 'flac',
|
||||
'duration': 135.63,
|
||||
'timestamp': 1643216583,
|
||||
'upload_date': '20220126',
|
||||
'uploader': 'Brad',
|
||||
'uploader_id': '1',
|
||||
'thumbnail': r're:https://cdn\.whyp\.it/.+\.jpg',
|
||||
},
|
||||
}, {
|
||||
'url': 'https://www.whyp.it/tracks/18337/home-page-example-track-b4kq7',
|
||||
'md5': '02fd96427acd9547445979bf0496b013',
|
||||
'info_dict': {
|
||||
@@ -25,7 +41,7 @@ class WhypIE(InfoExtractor):
|
||||
'upload_date': '20220126',
|
||||
'uploader': 'Brad',
|
||||
'uploader_id': '1',
|
||||
'thumbnail': 'https://cdn.whyp.it/6ad0bbd9-577d-42bb-9b61-2a4f57f647eb.jpg',
|
||||
'thumbnail': r're:https://cdn\.whyp\.it/.+\.jpg',
|
||||
},
|
||||
}, {
|
||||
'url': 'https://www.whyp.it/tracks/18337',
|
||||
@@ -33,28 +49,35 @@ class WhypIE(InfoExtractor):
|
||||
}]
|
||||
|
||||
def _real_extract(self, url):
|
||||
unique_id = self._match_id(url)
|
||||
webpage = self._download_webpage(url, unique_id)
|
||||
data = self._search_nuxt_data(webpage, unique_id)['rawTrack']
|
||||
unique_id, display_id = self._match_valid_url(url).group('id', 'display_id')
|
||||
webpage = self._download_webpage(url, unique_id or display_id)
|
||||
data = traverse_obj(
|
||||
self._search_nuxt_json(webpage, unique_id or display_id),
|
||||
('pinia', {dict}, {require('pinia data')}))
|
||||
track_data = traverse_obj(
|
||||
data, ('track', 'data', ..., {dict}, any, {require('track data')}))
|
||||
|
||||
return {
|
||||
'id': unique_id,
|
||||
'formats': [{
|
||||
'url': data[f'{prefix}_url'],
|
||||
'url': track_data[f'{prefix}_url'],
|
||||
'format_id': prefix,
|
||||
'filesize': int_or_none(data.get(f'{prefix}_size')),
|
||||
'filesize': int_or_none(track_data.get(f'{prefix}_size')),
|
||||
'vcodec': 'none',
|
||||
'quality': 10 if prefix == 'lossless' else -1,
|
||||
'http_headers': {'Referer': 'https://whyp.it/'},
|
||||
} for prefix in ('audio', 'lossy', 'lossless') if url_or_none(data.get(f'{prefix}_url'))],
|
||||
**traverse_obj(data, {
|
||||
} for prefix in ('audio', 'lossy', 'lossless') if url_or_none(track_data.get(f'{prefix}_url'))],
|
||||
**traverse_obj(track_data, {
|
||||
'id': ('id', {int}, {str_or_none}),
|
||||
'title': ('title', {str}),
|
||||
'display_id': ('slug', {str}),
|
||||
'description': 'description',
|
||||
'duration': ('duration', {float_or_none}),
|
||||
'timestamp': ('created_at', {parse_iso8601}),
|
||||
'uploader': ('user', 'username', {str}),
|
||||
'uploader_id': ('user', 'id', {str_or_none}),
|
||||
'thumbnail': ('artwork_url', {url_or_none}),
|
||||
}),
|
||||
**traverse_obj(data, ('user', 'data', ..., {dict}, any, {
|
||||
'uploader': ('username', {str}),
|
||||
'uploader_id': ('id', {int}, {str_or_none}),
|
||||
})),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user