1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-08-21 10:51:27 +00:00

[ie/steam] Fix extractor (#14008)

Closes #14000
Authored by: AzartX47
This commit is contained in:
Arseniy D. 2025-08-19 13:14:20 -10:00 committed by GitHub
parent 86d74e5cf0
commit d3d1ac8eb2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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,
) )
@ -19,44 +27,22 @@ class SteamIE(InfoExtractor):
| |
https?://(?:www\.)?steamcommunity\.com/sharedfiles/filedetails/\?id=(?P<fileID>[0-9]+) https?://(?:www\.)?steamcommunity\.com/sharedfiles/filedetails/\?id=(?P<fileID>[0-9]+)
''' '''
_VIDEO_PAGE_TEMPLATE = 'http://store.steampowered.com/video/%s/' _VIDEO_PAGE_TEMPLATE = 'https://store.steampowered.com/video/%s/'
_AGECHECK_TEMPLATE = 'http://store.steampowered.com/agecheck/video/%s/?snr=1_agecheck_agecheck__age-gate&ageDay=1&ageMonth=January&ageYear=1970' _AGECHECK_TEMPLATE = 'https://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': 'https://store.steampowered.com/video/105600/',
'playlist': [
{
'md5': '695242613303ffa2a4c44c9374ddc067',
'info_dict': {
'id': '256785003',
'ext': 'mp4',
'title': 'Terraria video 256785003',
'thumbnail': r're:^https://cdn\.[^\.]+\.steamstatic\.com',
},
},
{
'md5': '6a294ee0c4b1f47f5bb76a65e31e3592',
'info_dict': {
'id': '2040428',
'ext': 'mp4',
'title': 'Terraria video 2040428',
'thumbnail': r're:^https://cdn\.[^\.]+\.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,32 +67,29 @@ 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})):
entry['thumbnail'] = movie.get('data-poster') formats.extend(self._extract_m3u8_formats(
for quality in ('', '-hd'): hls_manifest, playlist_id, 'mp4', m3u8_id='hls', fatal=False))
for ext in ('webm', 'mp4'):
video_url = movie.get(f'data-{ext}{quality}-source') for dash_manifest in traverse_obj(data_prop, ('dashManifests', ..., {url_or_none})):
if video_url: formats.extend(self._extract_mpd_formats(
formats.append({ dash_manifest, playlist_id, mpd_id='dash', fatal=False))
'format_id': ext + quality,
'url': video_url, movie_id = traverse_obj(data_prop, ('id', {trim_str(start='highlight_movie_')}))
}) entries.append({
entry['formats'] = formats 'id': movie_id,
entries.append(entry) 'title': f'{app_name} video {movie_id}',
'formats': formats,
'thumbnail': traverse_obj(data_prop, ('screenshot', {url_or_none})),
})
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')
@ -121,7 +104,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):