Compare commits

..

No commits in common. "98cf2eede45f1b79c8c200a0d1637b658303065d" and "bad7b3346fea68656b36ff104eb211b988670380" have entirely different histories.

View File

@ -5,8 +5,8 @@ from .common import InfoExtractor
from ..utils import (
ExtractorError,
OnDemandPagedList,
UnsupportedError,
int_or_none,
join_nonempty,
parse_qs,
traverse_obj,
urljoin,
@ -60,44 +60,36 @@ _QUERIES = {
class AllstarBaseIE(InfoExtractor):
@staticmethod
def _parse_video_data(video_data):
def media_url_or_none(path):
def _media_url_or_none(path):
return urljoin('https://media.allstar.gg/', path)
info = traverse_obj(video_data, {
def _profile_url_or_none(path):
return urljoin('https://allstar.gg/u/', path)
return traverse_obj(video_data, {
'id': ('_id', {str}),
'display_id': ('shareId', {str}),
'title': ('clipTitle', {str}),
'url': ('clipLink', {media_url_or_none}),
'thumbnail': ('clipImageThumb', {media_url_or_none}),
'url': ('clipLink', {_media_url_or_none}),
'thumbnail': ('clipImageThumb', {_media_url_or_none}),
'duration': ('clipLength', {int_or_none}),
'filesize': ('clipSizeBytes', {int_or_none}),
'timestamp': ('createdDate', {functools.partial(int_or_none, scale=1000)}),
'timestamp': ('createdDate', {int_or_none}),
'uploader': ('username', {str}),
'uploader_id': ('user', '_id', {str}),
'uploader_url': ('user', '_id', {_profile_url_or_none}),
'view_count': ('views', {int_or_none}),
})
if info.get('id') and info.get('url'):
basename = 'clip' if '/clips/' in info['url'] else 'montage'
info['webpage_url'] = f'https://allstar.gg/{basename}?{basename}={info["id"]}'
info.update({
'extractor_key': AllstarIE.ie_key(),
'extractor': AllstarIE.IE_NAME,
'uploader_url': urljoin('https://allstar.gg/u/', info.get('uploader_id')),
})
return info
def _call_api(self, query, variables, path, video_id=None, note=None):
def _send_query(self, query, variables={}, path=(), video_id=None, note=None):
response = self._download_json(
'https://a1.allstar.gg/graphql', video_id, note=note,
headers={'content-type': 'application/json'},
data=json.dumps({'variables': variables, 'query': query}).encode())
errors = traverse_obj(response, ('errors', ..., 'message', {str}))
errors = response.get('errors')
if errors:
raise ExtractorError('; '.join(errors))
raise ExtractorError(errors, expected=True)
return traverse_obj(response, path)
@ -116,10 +108,8 @@ class AllstarIE(AllstarBaseIE):
'ext': 'mp4',
'duration': 20,
'filesize': 21199257,
'timestamp': 1682451501,
'timestamp': 1682451501555,
'uploader_id': '62b8bdfc9021052f7905882d',
'uploader_url': 'https://allstar.gg/u/62b8bdfc9021052f7905882d',
'upload_date': '20230425',
'view_count': int,
}
}, {
@ -133,11 +123,9 @@ class AllstarIE(AllstarBaseIE):
'thumbnail': 'md5:90564b121f5fd7a4924920ef45614634',
'duration': 16,
'filesize': 30175859,
'timestamp': 1688333419,
'timestamp': 1688333419392,
'uploader': 'cherokee',
'uploader_id': '62b8bdfc9021052f7905882d',
'uploader_url': 'https://allstar.gg/u/62b8bdfc9021052f7905882d',
'upload_date': '20230702',
'view_count': int,
}
}, {
@ -149,11 +137,9 @@ class AllstarIE(AllstarBaseIE):
'url': 'md5:a3ee356022115db2b27c81321d195945',
'thumbnail': 'md5:f1a5e811864e173f180b738d956356f4',
'ext': 'mp4',
'timestamp': 1681810448,
'timestamp': 1681810448040,
'uploader': 'cherokee',
'uploader_id': '62b8bdfc9021052f7905882d',
'uploader_url': 'https://allstar.gg/u/62b8bdfc9021052f7905882d',
'upload_date': '20230418',
'view_count': int,
}
}, {
@ -164,12 +150,10 @@ class AllstarIE(AllstarBaseIE):
'title': 'cherokee Rapid Fire Snipers Montage',
'url': 'md5:d5672e6f88579730c2310a80fdbc4030',
'thumbnail': 'md5:60872f0d236863bb9a6f3dff1623403c',
'ext': 'mp4',
'timestamp': 1688365434,
'uploader': 'cherokee',
'ext': 'mp4',
'timestamp': 1688365434271,
'uploader_id': '62b8bdfc9021052f7905882d',
'uploader_url': 'https://allstar.gg/u/62b8bdfc9021052f7905882d',
'upload_date': '20230703',
'view_count': int,
}
}]
@ -178,8 +162,9 @@ class AllstarIE(AllstarBaseIE):
query_id, video_id = self._match_valid_url(url).group('type', 'id')
return self._parse_video_data(
self._call_api(
_QUERIES.get(query_id), {'id': video_id}, ('data', 'video'), video_id))
self._send_query(
_QUERIES.get(query_id), {'id': video_id},
('data', 'video'), video_id))
class AllstarProfileIE(AllstarBaseIE):
@ -188,28 +173,28 @@ class AllstarProfileIE(AllstarBaseIE):
_TESTS = [{
'url': 'https://allstar.gg/profile?user=62b8bdfc9021052f7905882d',
'info_dict': {
'id': '62b8bdfc9021052f7905882d-clips',
'id': '62b8bdfc9021052f7905882d',
'title': 'cherokee - Clips',
},
'playlist_mincount': 15
}, {
'url': 'https://allstar.gg/u/cherokee?game=730&view=Clips',
'info_dict': {
'id': '62b8bdfc9021052f7905882d-clips-730',
'title': 'cherokee - Clips - 730',
'id': '62b8bdfc9021052f7905882d',
'title': 'cherokee - Clips',
},
'playlist_mincount': 15
}, {
'url': 'https://allstar.gg/u/62b8bdfc9021052f7905882d?view=Montages',
'info_dict': {
'id': '62b8bdfc9021052f7905882d-montages',
'id': '62b8bdfc9021052f7905882d',
'title': 'cherokee - Montages',
},
'playlist_mincount': 4
}, {
'url': 'https://allstar.gg/profile?user=cherokee&view=Mobile Clips',
'info_dict': {
'id': '62b8bdfc9021052f7905882d-mobile',
'id': '62b8bdfc9021052f7905882d',
'title': 'cherokee - Mobile Clips',
},
'playlist_mincount': 1
@ -217,36 +202,50 @@ class AllstarProfileIE(AllstarBaseIE):
_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, display_id, game, query, page_num):
page_num += 1
for video_data in self._call_api(
for video_data in self._send_query(
query, {
'user': user_id,
'page': page_num,
'game': game,
}, ('data', 'videos', 'data'), display_id, f'Downloading page {page_num}'):
yield self._parse_video_data(video_data)
yield self._set_webpage_url(self._parse_video_data(video_data))
def _real_extract(self, url):
display_id = self._match_id(url)
profile_data = self._download_json(
urljoin('https://api.allstar.gg/v1/users/profile/', display_id), display_id)
user_id = traverse_obj(profile_data, ('data', ('_id'), {str}))
if not user_id:
raise ExtractorError('Unable to extract the user id')
if user_id is None:
raise ExtractorError('Can not extract the user_id')
username = traverse_obj(profile_data, ('data', 'profile', ('username'), {str}))
url_query = parse_qs(url)
game = traverse_obj(url_query, ('game', 0, {int_or_none}))
game = traverse_obj(url_query, ('game', 0, {int}))
query_id = traverse_obj(url_query, ('view', 0), default='Clips')
if query_id not in ('Clips', 'Montages', 'Mobile Clips'):
raise ExtractorError(f'Unsupported playlist URL type {query_id!r}')
raise UnsupportedError(url)
return self.playlist_result(
OnDemandPagedList(
functools.partial(
self._get_page, user_id, display_id, game, _QUERIES.get(query_id)), self._PAGE_SIZE),
playlist_id=join_nonempty(user_id, query_id.lower().split()[0], game),
playlist_title=join_nonempty((username or display_id), query_id, game, delim=' - '))
user_id, f'{username or display_id} - {query_id}')