steam.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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"""(?x)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. 'params': {
  40. 'playlistend': 2,
  41. }
  42. }
  43. def _real_extract(self, url):
  44. m = re.match(self._VALID_URL, url, re.VERBOSE)
  45. gameID = m.group('gameID')
  46. videourl = self._VIDEO_PAGE_TEMPLATE % gameID
  47. webpage = self._download_webpage(videourl, gameID)
  48. if re.search('<h2>Please enter your birth date to continue:</h2>', webpage) is not None:
  49. videourl = self._AGECHECK_TEMPLATE % gameID
  50. self.report_age_confirmation()
  51. webpage = self._download_webpage(videourl, gameID)
  52. self.report_extraction(gameID)
  53. game_title = self._html_search_regex(r'<h2 class="pageheader">(.*?)</h2>',
  54. webpage, 'game title')
  55. mweb = re.finditer(
  56. r"'movie_(?P<videoID>\d+)': \{\s*FILENAME: \"(?P<videoURL>[\w:/\.\?=]+)\"(,\s*MOVIE_NAME: \"(?P<videoName>[\w:/\.\?=\+-]+)\")?\s*\},",
  57. webpage)
  58. titles = re.finditer(
  59. r'<span class="title">(?P<videoName>.+?)</span>', webpage)
  60. thumbs = re.finditer(
  61. r'<img class="movie_thumb" src="(?P<thumbnail>.+?)">', 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. videos.append({
  71. 'id': video_id,
  72. 'url': video_url,
  73. 'ext': 'flv',
  74. 'title': unescapeHTML(title),
  75. 'thumbnail': video_thumb
  76. })
  77. return self.playlist_result(videos, gameID, game_title)