]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/steam.py
Merge tag 'upstream/2013.08.17'
[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 _TEST = {
20 u"url": u"http://store.steampowered.com/video/105600/",
21 u"playlist": [
22 {
23 u"file": u"81300.flv",
24 u"md5": u"f870007cee7065d7c76b88f0a45ecc07",
25 u"info_dict": {
26 u"title": u"Terraria 1.1 Trailer",
27 u'playlist_index': 1,
28 }
29 },
30 {
31 u"file": u"80859.flv",
32 u"md5": u"61aaf31a5c5c3041afb58fb83cbb5751",
33 u"info_dict": {
34 u"title": u"Terraria Trailer",
35 u'playlist_index': 2,
36 }
37 }
38 ]
39 }
40
41
42 @classmethod
43 def suitable(cls, url):
44 """Receives a URL and returns True if suitable for this IE."""
45 return re.match(cls._VALID_URL, url, re.VERBOSE) is not None
46
47 def _real_extract(self, url):
48 m = re.match(self._VALID_URL, url, re.VERBOSE)
49 gameID = m.group('gameID')
50
51 videourl = self._VIDEO_PAGE_TEMPLATE % gameID
52 webpage = self._download_webpage(videourl, gameID)
53
54 if re.search('<h2>Please enter your birth date to continue:</h2>', webpage) is not None:
55 videourl = self._AGECHECK_TEMPLATE % gameID
56 self.report_age_confirmation()
57 webpage = self._download_webpage(videourl, gameID)
58
59 self.report_extraction(gameID)
60 game_title = self._html_search_regex(r'<h2 class="pageheader">(.*?)</h2>',
61 webpage, 'game title')
62
63 urlRE = r"'movie_(?P<videoID>\d+)': \{\s*FILENAME: \"(?P<videoURL>[\w:/\.\?=]+)\"(,\s*MOVIE_NAME: \"(?P<videoName>[\w:/\.\?=\+-]+)\")?\s*\},"
64 mweb = re.finditer(urlRE, webpage)
65 namesRE = r'<span class="title">(?P<videoName>.+?)</span>'
66 titles = re.finditer(namesRE, webpage)
67 thumbsRE = r'<img class="movie_thumb" src="(?P<thumbnail>.+?)">'
68 thumbs = re.finditer(thumbsRE, webpage)
69 videos = []
70 for vid,vtitle,thumb in zip(mweb,titles,thumbs):
71 video_id = vid.group('videoID')
72 title = vtitle.group('videoName')
73 video_url = vid.group('videoURL')
74 video_thumb = thumb.group('thumbnail')
75 if not video_url:
76 raise ExtractorError(u'Cannot find video url for %s' % video_id)
77 info = {
78 'id':video_id,
79 'url':video_url,
80 'ext': 'flv',
81 'title': unescapeHTML(title),
82 'thumbnail': video_thumb
83 }
84 videos.append(info)
85 return [self.playlist_result(videos, gameID, game_title)]