steam.py 3.2 KB

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