1 from __future__ import unicode_literals
5 from .common import InfoExtractor
14 class SteamIE(InfoExtractor):
16 https?://store\.steampowered\.com/
18 (?P<urltype>video|app)/ #If the page is only for videos or for a game
20 (?P<videoID>\d*)(?P<extra>\??) # For urltype == video we sometimes get the videoID
22 https?://(?:www\.)?steamcommunity\.com/sharedfiles/filedetails/\?id=(?P<fileID>[0-9]+)
24 _VIDEO_PAGE_TEMPLATE = 'http://store.steampowered.com/video/%s/'
25 _AGECHECK_TEMPLATE = 'http://store.steampowered.com/agecheck/video/%s/?snr=1_agecheck_agecheck__age-gate&ageDay=1&ageMonth=January&ageYear=1970'
27 'url': 'http://store.steampowered.com/video/105600/',
30 'md5': '6a294ee0c4b1f47f5bb76a65e31e3592',
34 'title': 'Terraria 1.3 Trailer',
39 'md5': '911672b20064ca3263fa89650ba5a7aa',
43 'title': 'Terraria 1.2 Trailer',
56 'url': 'http://steamcommunity.com/sharedfiles/filedetails/?id=242472205',
60 'upload_date': '20140617',
61 'title': 'FRONTIERS - Trapping',
62 'description': 'md5:bf6f7f773def614054089e5769c12a6e',
63 'uploader': 'AAD Productions',
64 'uploader_id': 'AtomicAgeDogGames',
68 def _real_extract(self, url):
69 m = re.match(self._VALID_URL, url)
70 fileID = m.group('fileID')
75 gameID = m.group('gameID')
77 videourl = self._VIDEO_PAGE_TEMPLATE % playlist_id
79 self._set_cookie('steampowered.com', 'mature_content', '1')
81 webpage = self._download_webpage(videourl, playlist_id)
83 if re.search('<h2>Please enter your birth date to continue:</h2>', webpage) is not None:
84 videourl = self._AGECHECK_TEMPLATE % playlist_id
85 self.report_age_confirmation()
86 webpage = self._download_webpage(videourl, playlist_id)
88 flash_vars = self._parse_json(self._search_regex(
89 r'(?s)rgMovieFlashvars\s*=\s*({.+?});', webpage,
90 'flash vars'), playlist_id, js_to_json)
95 playlist_title = get_element_by_class('workshopItemTitle', webpage)
96 for movie in flash_vars.values():
99 youtube_id = movie.get('YOUTUBE_VIDEO_ID')
108 playlist_title = get_element_by_class('apphub_AppName', webpage)
109 for movie_id, movie in flash_vars.items():
112 video_id = self._search_regex(r'movie_(\d+)', movie_id, 'video id', fatal=False)
113 title = movie.get('MOVIE_NAME')
114 if not title or not video_id:
118 'title': title.replace('+', ' '),
121 flv_url = movie.get('FILENAME')
127 highlight_element = self._search_regex(
128 r'(<div[^>]+id="highlight_movie_%s"[^>]+>)' % video_id,
129 webpage, 'highlight element', fatal=False)
130 if highlight_element:
131 highlight_attribs = extract_attributes(highlight_element)
132 if highlight_attribs:
133 entry['thumbnail'] = highlight_attribs.get('data-poster')
134 for quality in ('', '-hd'):
135 for ext in ('webm', 'mp4'):
136 video_url = highlight_attribs.get('data-%s%s-source' % (ext, quality))
139 'format_id': ext + quality,
144 entry['formats'] = formats
145 entries.append(entry)
147 raise ExtractorError('Could not find any videos')
149 return self.playlist_result(entries, playlist_id, playlist_title)