Compare commits

...

7 Commits

Author SHA1 Message Date
sfn
5a80ab553b rename AllstarBase to AllstarBaseIE 2023-11-16 00:34:11 +01:00
Safouane Aarab
bee4168d9a
Update yt_dlp/extractor/allstar.py
Co-authored-by: sepro <4618135+seproDev@users.noreply.github.com>
2023-11-16 00:14:24 +01:00
sfn
5d126a5cb6 delete extra lines 2023-11-16 00:12:40 +01:00
sfn
557261814a move _set_webpage_url inside AllstarProfileIE 2023-11-16 00:06:49 +01:00
sfn
b43caed0a6 move _profile_video_data inside AllstarBase 2023-11-16 00:02:24 +01:00
sfn
2bbf686566 add note argument to _send_query 2023-11-15 23:46:58 +01:00
sfn
b8190cb035 rename _PAGESIZE and moved inside AllstarProfileIE 2023-11-15 23:41:18 +01:00

View File

@ -59,18 +59,16 @@ _QUERIES = {
}''' % (_FIELDS, _EXTRA_FIELDS),
}
_PAGESIZE = 10
def _media_url_or_none(path):
class AllstarBaseIE(InfoExtractor):
@staticmethod
def _parse_video_data(video_data):
def _media_url_or_none(path):
return urljoin('https://media.allstar.gg/', str_or_none(path))
def _profile_url_or_none(path):
def _profile_url_or_none(path):
return urljoin('https:/allstar.gg/u/', str_or_none(path))
def _parse_video_data(video_data):
return traverse_obj(video_data, {
'id': ('_id', {str_or_none}),
'display_id': ('shareId', {str_or_none}),
@ -87,25 +85,9 @@ def _parse_video_data(video_data):
'categories': ('game', {str_or_none}),
})
def _set_webpage_url(info_dict):
video_id = info_dict.get('id')
video_url = info_dict.get('url')
if video_url is None or video_id is None:
return info_dict
base_name = 'clip' if '/clips/' in video_url else 'montage'
info_dict['webpage_url'] = f'https://allstar.gg/{base_name}?{base_name}={video_id}'
info_dict['webpage_url_basename'] = base_name
return info_dict
class AllstarBase(InfoExtractor):
def _send_query(self, query, variables={}, path=(), video_id=None):
def _send_query(self, query, variables={}, path=(), video_id=None, note=None):
response = self._download_json(
'https://a1.allstar.gg/graphql', video_id,
'https://a1.allstar.gg/graphql', video_id, note=note,
headers={'content-type': 'application/json'},
data=json.dumps({'variables': variables, 'query': query}).encode())
@ -116,7 +98,7 @@ class AllstarBase(InfoExtractor):
return traverse_obj(response, path)
class AllstarIE(AllstarBase):
class AllstarIE(AllstarBaseIE):
_VALID_URL = r'https?://(?:www\.)?allstar\.gg/(?P<type>(?:clip|montage))\?(?P=type)=(?P<id>[^/?#&]+)'
_TESTS = [{
@ -187,13 +169,13 @@ class AllstarIE(AllstarBase):
assert query_id in _QUERIES
return _parse_video_data(
return self._parse_video_data(
self._send_query(
_QUERIES.get(query_id), {'id': video_id},
('data', 'video'), video_id))
class AllstarProfileIE(AllstarBase):
class AllstarProfileIE(AllstarBaseIE):
_VALID_URL = r'https?://(?:www\.)?allstar\.gg/(?:profile\?user=|u/)(?P<id>[^/?#&]+)'
_TESTS = [{
@ -226,6 +208,22 @@ class AllstarProfileIE(AllstarBase):
'playlist_mincount': 1
}]
_PAGE_SIZE = 10
@staticmethod
def _set_webpage_url(info_dict):
video_id = info_dict.get('id')
video_url = info_dict.get('url')
if video_url is None or video_id is None:
return info_dict
base_name = 'clip' if '/clips/' in video_url else 'montage'
info_dict['webpage_url'] = f'https://allstar.gg/{base_name}?{base_name}={video_id}'
info_dict['webpage_url_basename'] = base_name
return info_dict
def _get_page(self, user_id, game, query_id, page_num):
page_num += 1
@ -234,8 +232,8 @@ class AllstarProfileIE(AllstarBase):
'user': user_id,
'page': page_num,
'game': int_or_none(game),
}, ('data', 'videos', 'data'), f'{user_id} page {page_num}'):
yield _set_webpage_url(_parse_video_data(video_data))
}, ('data', 'videos', 'data'), user_id, f'Downloading page {page_num}'):
yield self._set_webpage_url(self._parse_video_data(video_data))
def _get_user_data(self, user_id, path=()):
return traverse_obj(
@ -253,12 +251,12 @@ class AllstarProfileIE(AllstarBase):
query_id = view.lower()
if query_id not in ('clips', 'montages', 'mobile clips'):
raise UnsupportedError(f'view={view}')
raise UnsupportedError(url)
assert query_id in _QUERIES
return self.playlist_result(
OnDemandPagedList(
functools.partial(
self._get_page, user_id, game, query_id), _PAGESIZE),
self._get_page, user_id, game, query_id), self._PAGE_SIZE),
user_id, f'{user_name} - {view}')