steam.py 3.3 KB

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