Compare commits

..

No commits in common. "5a80ab553baaf2aaf7c1c9d36a2ff18fd8df9e13" and "7d19d305f23d102f6378f97eaacd67bb1f81ecc9" have entirely different histories.

View File

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