]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/steam.py
Fix description of the modularization.
[youtubedl] / youtube_dl / extractor / steam.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import (
5 ExtractorError,
6 unescapeHTML,
7 )
8
9
10 class SteamIE(InfoExtractor):
11 _VALID_URL = r"""http://store\.steampowered\.com/
12 (agecheck/)?
13 (?P<urltype>video|app)/ #If the page is only for videos or for a game
14 (?P<gameID>\d+)/?
15 (?P<videoID>\d*)(?P<extra>\??) #For urltype == video we sometimes get the videoID
16 """
17 _VIDEO_PAGE_TEMPLATE = 'http://store.steampowered.com/video/%s/'
18 _AGECHECK_TEMPLATE = 'http://store.steampowered.com/agecheck/video/%s/?snr=1_agecheck_agecheck__age-gate&ageDay=1&ageMonth=January&ageYear=1970'
19
20 @classmethod
21 def suitable(cls, url):
22 """Receives a URL and returns True if suitable for this IE."""
23 return re.match(cls._VALID_URL, url, re.VERBOSE) is not None
24
25 def _real_extract(self, url):
26 m = re.match(self._VALID_URL, url, re.VERBOSE)
27 gameID = m.group('gameID')
28
29 videourl = self._VIDEO_PAGE_TEMPLATE % gameID
30 webpage = self._download_webpage(videourl, gameID)
31
32 if re.search('<h2>Please enter your birth date to continue:</h2>', webpage) is not None:
33 videourl = self._AGECHECK_TEMPLATE % gameID
34 self.report_age_confirmation()
35 webpage = self._download_webpage(videourl, gameID)
36
37 self.report_extraction(gameID)
38 game_title = self._html_search_regex(r'<h2 class="pageheader">(.*?)</h2>',
39 webpage, 'game title')
40
41 urlRE = r"'movie_(?P<videoID>\d+)': \{\s*FILENAME: \"(?P<videoURL>[\w:/\.\?=]+)\"(,\s*MOVIE_NAME: \"(?P<videoName>[\w:/\.\?=\+-]+)\")?\s*\},"
42 mweb = re.finditer(urlRE, webpage)
43 namesRE = r'<span class="title">(?P<videoName>.+?)</span>'
44 titles = re.finditer(namesRE, webpage)
45 thumbsRE = r'<img class="movie_thumb" src="(?P<thumbnail>.+?)">'
46 thumbs = re.finditer(thumbsRE, webpage)
47 videos = []
48 for vid,vtitle,thumb in zip(mweb,titles,thumbs):
49 video_id = vid.group('videoID')
50 title = vtitle.group('videoName')
51 video_url = vid.group('videoURL')
52 video_thumb = thumb.group('thumbnail')
53 if not video_url:
54 raise ExtractorError(u'Cannot find video url for %s' % video_id)
55 info = {
56 'id':video_id,
57 'url':video_url,
58 'ext': 'flv',
59 'title': unescapeHTML(title),
60 'thumbnail': video_thumb
61 }
62 videos.append(info)
63 return [self.playlist_result(videos, gameID, game_title)]