]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/steam.py
   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
 
  78         webpage 
= self
._download
_webpage
(videourl
, playlist_id
) 
  80         if re
.search('<h2>Please enter your birth date to continue:</h2>', webpage
) is not None: 
  81             videourl 
= self
._AGECHECK
_TEMPLATE 
% playlist_id
 
  82             self
.report_age_confirmation() 
  83             webpage 
= self
._download
_webpage
(videourl
, playlist_id
) 
  85         flash_vars 
= self
._parse
_json
(self
._search
_regex
( 
  86             r
'(?s)rgMovieFlashvars\s*=\s*({.+?});', webpage
, 
  87             'flash vars'), playlist_id
, js_to_json
) 
  92             playlist_title 
= get_element_by_class('workshopItemTitle', webpage
) 
  93             for movie 
in flash_vars
.values(): 
  96                 youtube_id 
= movie
.get('YOUTUBE_VIDEO_ID') 
 105             playlist_title 
= get_element_by_class('apphub_AppName', webpage
) 
 106             for movie_id
, movie 
in flash_vars
.items(): 
 109                 video_id 
= self
._search
_regex
(r
'movie_(\d+)', movie_id
, 'video id', fatal
=False) 
 110                 title 
= movie
.get('MOVIE_NAME') 
 111                 if not title 
or not video_id
: 
 115                     'title': title
.replace('+', ' '), 
 118                 flv_url 
= movie
.get('FILENAME') 
 124                 highlight_element 
= self
._search
_regex
( 
 125                     r
'(<div[^>]+id="highlight_movie_%s"[^>]+>)' % video_id
, 
 126                     webpage
, 'highlight element', fatal
=False) 
 127                 if highlight_element
: 
 128                     highlight_attribs 
= extract_attributes(highlight_element
) 
 129                     if highlight_attribs
: 
 130                         entry
['thumbnail'] = highlight_attribs
.get('data-poster') 
 131                         for quality 
in ('', '-hd'): 
 132                             for ext 
in ('webm', 'mp4'): 
 133                                 video_url 
= highlight_attribs
.get('data-%s%s-source' % (ext
, quality
)) 
 136                                         'format_id': ext 
+ quality
, 
 141                 entry
['formats'] = formats
 
 142                 entries
.append(entry
) 
 144             raise ExtractorError('Could not find any videos') 
 146         return self
.playlist_result(entries
, playlist_id
, playlist_title
)