refactor: add changes suggested by @doe1080

pull/14008/head
AzartX47 2 days ago
parent 0217b9c575
commit 67e0506461

@ -1,11 +1,19 @@
import json
import re import re
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
ExtractorError, ExtractorError,
clean_html,
extract_attributes, extract_attributes,
get_element_by_class,
str_or_none, str_or_none,
url_or_none,
)
from ..utils.traversal import (
find_element,
find_elements,
traverse_obj,
trim_str,
) )
@ -23,40 +31,18 @@ class SteamIE(InfoExtractor):
_AGECHECK_TEMPLATE = 'http://store.steampowered.com/agecheck/video/%s/?snr=1_agecheck_agecheck__age-gate&ageDay=1&ageMonth=January&ageYear=1970' _AGECHECK_TEMPLATE = 'http://store.steampowered.com/agecheck/video/%s/?snr=1_agecheck_agecheck__age-gate&ageDay=1&ageMonth=January&ageYear=1970'
_TESTS = [{ _TESTS = [{
'url': 'http://store.steampowered.com/video/105600/', 'url': 'http://store.steampowered.com/video/105600/',
'playlist': [
{
'md5': 'e800bd0baf47286d8b434d07b357247e',
'info_dict': {
'id': '256785003',
'ext': 'mp4',
'title': 'Terraria video 256785003',
'thumbnail': r're:^https?://[^/]*steamstatic\.com',
},
},
{
'md5': '9612ee058ebd645371c5ddd69adb310f',
'info_dict': {
'id': '2040428',
'ext': 'mp4',
'title': 'Terraria video 2040428',
'thumbnail': r're:^https?://[^/]*steamstatic\.com',
},
},
],
'info_dict': { 'info_dict': {
'id': '105600', 'id': '105600',
'title': 'Terraria', 'title': 'Terraria',
}, },
'params': { 'playlist_mincount': 3,
'playlistend': 2,
},
}, { }, {
'url': 'https://store.steampowered.com/app/271590/Grand_Theft_Auto_V/', 'url': 'https://store.steampowered.com/app/271590/Grand_Theft_Auto_V/',
'info_dict': { 'info_dict': {
'id': '271590', 'id': '271590',
'title': 'Grand Theft Auto V', 'title': 'Grand Theft Auto V Legacy',
}, },
'playlist_count': 23, 'playlist_mincount': 26,
}] }]
def _real_extract(self, url): def _real_extract(self, url):
@ -81,36 +67,31 @@ class SteamIE(InfoExtractor):
self.report_age_confirmation() self.report_age_confirmation()
webpage = self._download_webpage(video_url, playlist_id) webpage = self._download_webpage(video_url, playlist_id)
videos = re.findall(r'(<div[^>]+id=[\'"]highlight_movie_(\d+)[\'"][^>]+>)', webpage) app_name = traverse_obj(webpage, ({find_element(cls='apphub_AppName')}, {clean_html}))
entries = [] entries = []
playlist_title = get_element_by_class('apphub_AppName', webpage) for data_prop in traverse_obj(webpage, (
for movie, movie_id in videos: {find_elements(cls='highlight_player_item highlight_movie', html=True)},
if not movie: ..., {extract_attributes}, 'data-props', {json.loads}, {dict},
continue )):
movie = extract_attributes(movie)
if not movie_id:
continue
entry = {
'id': movie_id,
'title': f'{playlist_title} video {movie_id}',
}
formats = [] formats = []
if movie: if hls_manifest := traverse_obj(data_prop, ('hlsManifest', {url_or_none})):
data = self._parse_json(movie['data-props'], video_id=movie_id) formats.extend(self._extract_m3u8_formats(
hls_manifest, playlist_id, 'mp4', m3u8_id='hls', fatal=False))
entry['thumbnail'] = data.get('screenshot')
for dash_manifest in traverse_obj(data_prop, (
for dash_url in data.get('dashManifests', []): 'dashManifests', ..., {url_or_none}, filter, all, filter,
formats.extend(self._extract_mpd_formats( )):
dash_url, movie_id, mpd_id='dash', fatal=False)) formats.extend(self._extract_mpd_formats(
dash_manifest, playlist_id, mpd_id='dash', fatal=False))
hls_url = data.get('hlsManifest')
if hls_url: movie_id = traverse_obj(data_prop, ('id', {trim_str(start='highlight_movie_')}))
formats.extend(self._extract_m3u8_formats( entries.append({
hls_url, movie_id, entry_protocol='m3u8', m3u8_id='hls', fatal=False)) 'id': movie_id,
'title': f'{app_name} video {movie_id}',
'formats': formats,
'thumbnail': traverse_obj(data_prop, ('screenshot', {url_or_none})),
})
entry['formats'] = formats
entries.append(entry)
embedded_videos = re.findall(r'(<iframe[^>]+>)', webpage) embedded_videos = re.findall(r'(<iframe[^>]+>)', webpage)
for evideos in embedded_videos: for evideos in embedded_videos:
evideos = extract_attributes(evideos).get('src') evideos = extract_attributes(evideos).get('src')
@ -125,7 +106,7 @@ class SteamIE(InfoExtractor):
if not entries: if not entries:
raise ExtractorError('Could not find any videos') raise ExtractorError('Could not find any videos')
return self.playlist_result(entries, playlist_id, playlist_title) return self.playlist_result(entries, playlist_id, app_name)
class SteamCommunityBroadcastIE(InfoExtractor): class SteamCommunityBroadcastIE(InfoExtractor):

Loading…
Cancel
Save