]>
Commit | Line | Data |
---|---|---|
3fa6b6e2 PH |
1 | from __future__ import unicode_literals |
2 | ||
462dc88b PH |
3 | import re |
4 | ||
5 | from .common import InfoExtractor | |
6 | from ..utils import ( | |
7fee3377 | 7 | extract_attributes, |
462dc88b | 8 | ExtractorError, |
7fee3377 RA |
9 | get_element_by_class, |
10 | js_to_json, | |
462dc88b PH |
11 | ) |
12 | ||
13 | ||
14 | class SteamIE(InfoExtractor): | |
1f27d2c0 PH |
15 | _VALID_URL = r"""(?x) |
16 | https?://store\.steampowered\.com/ | |
17 | (agecheck/)? | |
18 | (?P<urltype>video|app)/ #If the page is only for videos or for a game | |
19 | (?P<gameID>\d+)/? | |
20 | (?P<videoID>\d*)(?P<extra>\??) # For urltype == video we sometimes get the videoID | |
21 | | | |
22 | https?://(?:www\.)?steamcommunity\.com/sharedfiles/filedetails/\?id=(?P<fileID>[0-9]+) | |
23 | """ | |
462dc88b PH |
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' | |
1f27d2c0 | 26 | _TESTS = [{ |
611c1dd9 S |
27 | 'url': 'http://store.steampowered.com/video/105600/', |
28 | 'playlist': [ | |
08217714 | 29 | { |
7fee3377 | 30 | 'md5': '6a294ee0c4b1f47f5bb76a65e31e3592', |
611c1dd9 | 31 | 'info_dict': { |
7fee3377 RA |
32 | 'id': '2040428', |
33 | 'ext': 'mp4', | |
34 | 'title': 'Terraria 1.3 Trailer', | |
3fa6b6e2 | 35 | 'playlist_index': 1, |
08217714 PH |
36 | } |
37 | }, | |
38 | { | |
7fee3377 | 39 | 'md5': '911672b20064ca3263fa89650ba5a7aa', |
611c1dd9 | 40 | 'info_dict': { |
7fee3377 RA |
41 | 'id': '2029566', |
42 | 'ext': 'mp4', | |
43 | 'title': 'Terraria 1.2 Trailer', | |
3fa6b6e2 | 44 | 'playlist_index': 2, |
08217714 PH |
45 | } |
46 | } | |
7f9c31df | 47 | ], |
7fee3377 RA |
48 | 'info_dict': { |
49 | 'id': '105600', | |
50 | 'title': 'Terraria', | |
51 | }, | |
7f9c31df PH |
52 | 'params': { |
53 | 'playlistend': 2, | |
54 | } | |
1f27d2c0 PH |
55 | }, { |
56 | 'url': 'http://steamcommunity.com/sharedfiles/filedetails/?id=242472205', | |
57 | 'info_dict': { | |
7fee3377 | 58 | 'id': 'X8kpJBlzD2E', |
1f27d2c0 | 59 | 'ext': 'mp4', |
7fee3377 RA |
60 | 'upload_date': '20140617', |
61 | 'title': 'FRONTIERS - Trapping', | |
62 | 'description': 'md5:bf6f7f773def614054089e5769c12a6e', | |
1f27d2c0 PH |
63 | 'uploader': 'AAD Productions', |
64 | 'uploader_id': 'AtomicAgeDogGames', | |
65 | } | |
66 | }] | |
08217714 | 67 | |
462dc88b | 68 | def _real_extract(self, url): |
1f27d2c0 PH |
69 | m = re.match(self._VALID_URL, url) |
70 | fileID = m.group('fileID') | |
71 | if fileID: | |
72 | videourl = url | |
73 | playlist_id = fileID | |
74 | else: | |
75 | gameID = m.group('gameID') | |
76 | playlist_id = gameID | |
77 | videourl = self._VIDEO_PAGE_TEMPLATE % playlist_id | |
717ea4e1 S |
78 | |
79 | self._set_cookie('steampowered.com', 'mature_content', '1') | |
80 | ||
1f27d2c0 | 81 | webpage = self._download_webpage(videourl, playlist_id) |
462dc88b PH |
82 | |
83 | if re.search('<h2>Please enter your birth date to continue:</h2>', webpage) is not None: | |
1f27d2c0 | 84 | videourl = self._AGECHECK_TEMPLATE % playlist_id |
462dc88b | 85 | self.report_age_confirmation() |
1f27d2c0 PH |
86 | webpage = self._download_webpage(videourl, playlist_id) |
87 | ||
7fee3377 RA |
88 | flash_vars = self._parse_json(self._search_regex( |
89 | r'(?s)rgMovieFlashvars\s*=\s*({.+?});', webpage, | |
90 | 'flash vars'), playlist_id, js_to_json) | |
91 | ||
92 | playlist_title = None | |
93 | entries = [] | |
1f27d2c0 | 94 | if fileID: |
7fee3377 RA |
95 | playlist_title = get_element_by_class('workshopItemTitle', webpage) |
96 | for movie in flash_vars.values(): | |
97 | if not movie: | |
98 | continue | |
99 | youtube_id = movie.get('YOUTUBE_VIDEO_ID') | |
100 | if not youtube_id: | |
101 | continue | |
102 | entries.append({ | |
103 | '_type': 'url', | |
104 | 'url': youtube_id, | |
105 | 'ie_key': 'Youtube', | |
106 | }) | |
1f27d2c0 | 107 | else: |
7fee3377 RA |
108 | playlist_title = get_element_by_class('apphub_AppName', webpage) |
109 | for movie_id, movie in flash_vars.items(): | |
110 | if not movie: | |
111 | continue | |
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: | |
115 | continue | |
116 | entry = { | |
1f27d2c0 | 117 | 'id': video_id, |
7fee3377 RA |
118 | 'title': title.replace('+', ' '), |
119 | } | |
120 | formats = [] | |
121 | flv_url = movie.get('FILENAME') | |
122 | if flv_url: | |
123 | formats.append({ | |
124 | 'format_id': 'flv', | |
125 | 'url': flv_url, | |
126 | }) | |
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)) | |
137 | if video_url: | |
138 | formats.append({ | |
139 | 'format_id': ext + quality, | |
140 | 'url': video_url, | |
141 | }) | |
a06916d9 | 142 | if not formats and not self.get_param('ignore_no_formats'): |
7fee3377 RA |
143 | continue |
144 | entry['formats'] = formats | |
145 | entries.append(entry) | |
146 | if not entries: | |
1f27d2c0 | 147 | raise ExtractorError('Could not find any videos') |
462dc88b | 148 | |
7fee3377 | 149 | return self.playlist_result(entries, playlist_id, playlist_title) |