You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.6 KiB

  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. @classmethod
  17. def suitable(cls, url):
  18. """Receives a URL and returns True if suitable for this IE."""
  19. return re.match(cls._VALID_URL, url, re.VERBOSE) is not None
  20. def _real_extract(self, url):
  21. m = re.match(self._VALID_URL, url, re.VERBOSE)
  22. gameID = m.group('gameID')
  23. videourl = self._VIDEO_PAGE_TEMPLATE % gameID
  24. webpage = self._download_webpage(videourl, gameID)
  25. if re.search('<h2>Please enter your birth date to continue:</h2>', webpage) is not None:
  26. videourl = self._AGECHECK_TEMPLATE % gameID
  27. self.report_age_confirmation()
  28. webpage = self._download_webpage(videourl, gameID)
  29. self.report_extraction(gameID)
  30. game_title = self._html_search_regex(r'<h2 class="pageheader">(.*?)</h2>',
  31. webpage, 'game title')
  32. urlRE = r"'movie_(?P<videoID>\d+)': \{\s*FILENAME: \"(?P<videoURL>[\w:/\.\?=]+)\"(,\s*MOVIE_NAME: \"(?P<videoName>[\w:/\.\?=\+-]+)\")?\s*\},"
  33. mweb = re.finditer(urlRE, webpage)
  34. namesRE = r'<span class="title">(?P<videoName>.+?)</span>'
  35. titles = re.finditer(namesRE, webpage)
  36. thumbsRE = r'<img class="movie_thumb" src="(?P<thumbnail>.+?)">'
  37. thumbs = re.finditer(thumbsRE, webpage)
  38. videos = []
  39. for vid,vtitle,thumb in zip(mweb,titles,thumbs):
  40. video_id = vid.group('videoID')
  41. title = vtitle.group('videoName')
  42. video_url = vid.group('videoURL')
  43. video_thumb = thumb.group('thumbnail')
  44. if not video_url:
  45. raise ExtractorError(u'Cannot find video url for %s' % video_id)
  46. info = {
  47. 'id':video_id,
  48. 'url':video_url,
  49. 'ext': 'flv',
  50. 'title': unescapeHTML(title),
  51. 'thumbnail': video_thumb
  52. }
  53. videos.append(info)
  54. return [self.playlist_result(videos, gameID, game_title)]