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.

83 lines
3.2 KiB

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