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.

149 lines
5.5 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. extract_attributes,
  6. ExtractorError,
  7. get_element_by_class,
  8. js_to_json,
  9. )
  10. class SteamIE(InfoExtractor):
  11. _VALID_URL = r"""(?x)
  12. https?://store\.steampowered\.com/
  13. (agecheck/)?
  14. (?P<urltype>video|app)/ #If the page is only for videos or for a game
  15. (?P<gameID>\d+)/?
  16. (?P<videoID>\d*)(?P<extra>\??) # For urltype == video we sometimes get the videoID
  17. |
  18. https?://(?:www\.)?steamcommunity\.com/sharedfiles/filedetails/\?id=(?P<fileID>[0-9]+)
  19. """
  20. _VIDEO_PAGE_TEMPLATE = 'http://store.steampowered.com/video/%s/'
  21. _AGECHECK_TEMPLATE = 'http://store.steampowered.com/agecheck/video/%s/?snr=1_agecheck_agecheck__age-gate&ageDay=1&ageMonth=January&ageYear=1970'
  22. _TESTS = [{
  23. 'url': 'http://store.steampowered.com/video/105600/',
  24. 'playlist': [
  25. {
  26. 'md5': '6a294ee0c4b1f47f5bb76a65e31e3592',
  27. 'info_dict': {
  28. 'id': '2040428',
  29. 'ext': 'mp4',
  30. 'title': 'Terraria 1.3 Trailer',
  31. 'playlist_index': 1,
  32. }
  33. },
  34. {
  35. 'md5': '911672b20064ca3263fa89650ba5a7aa',
  36. 'info_dict': {
  37. 'id': '2029566',
  38. 'ext': 'mp4',
  39. 'title': 'Terraria 1.2 Trailer',
  40. 'playlist_index': 2,
  41. }
  42. }
  43. ],
  44. 'info_dict': {
  45. 'id': '105600',
  46. 'title': 'Terraria',
  47. },
  48. 'params': {
  49. 'playlistend': 2,
  50. }
  51. }, {
  52. 'url': 'http://steamcommunity.com/sharedfiles/filedetails/?id=242472205',
  53. 'info_dict': {
  54. 'id': 'X8kpJBlzD2E',
  55. 'ext': 'mp4',
  56. 'upload_date': '20140617',
  57. 'title': 'FRONTIERS - Trapping',
  58. 'description': 'md5:bf6f7f773def614054089e5769c12a6e',
  59. 'uploader': 'AAD Productions',
  60. 'uploader_id': 'AtomicAgeDogGames',
  61. }
  62. }]
  63. def _real_extract(self, url):
  64. m = re.match(self._VALID_URL, url)
  65. fileID = m.group('fileID')
  66. if fileID:
  67. videourl = url
  68. playlist_id = fileID
  69. else:
  70. gameID = m.group('gameID')
  71. playlist_id = gameID
  72. videourl = self._VIDEO_PAGE_TEMPLATE % playlist_id
  73. self._set_cookie('steampowered.com', 'mature_content', '1')
  74. webpage = self._download_webpage(videourl, playlist_id)
  75. if re.search('<h2>Please enter your birth date to continue:</h2>', webpage) is not None:
  76. videourl = self._AGECHECK_TEMPLATE % playlist_id
  77. self.report_age_confirmation()
  78. webpage = self._download_webpage(videourl, playlist_id)
  79. flash_vars = self._parse_json(self._search_regex(
  80. r'(?s)rgMovieFlashvars\s*=\s*({.+?});', webpage,
  81. 'flash vars'), playlist_id, js_to_json)
  82. playlist_title = None
  83. entries = []
  84. if fileID:
  85. playlist_title = get_element_by_class('workshopItemTitle', webpage)
  86. for movie in flash_vars.values():
  87. if not movie:
  88. continue
  89. youtube_id = movie.get('YOUTUBE_VIDEO_ID')
  90. if not youtube_id:
  91. continue
  92. entries.append({
  93. '_type': 'url',
  94. 'url': youtube_id,
  95. 'ie_key': 'Youtube',
  96. })
  97. else:
  98. playlist_title = get_element_by_class('apphub_AppName', webpage)
  99. for movie_id, movie in flash_vars.items():
  100. if not movie:
  101. continue
  102. video_id = self._search_regex(r'movie_(\d+)', movie_id, 'video id', fatal=False)
  103. title = movie.get('MOVIE_NAME')
  104. if not title or not video_id:
  105. continue
  106. entry = {
  107. 'id': video_id,
  108. 'title': title.replace('+', ' '),
  109. }
  110. formats = []
  111. flv_url = movie.get('FILENAME')
  112. if flv_url:
  113. formats.append({
  114. 'format_id': 'flv',
  115. 'url': flv_url,
  116. })
  117. highlight_element = self._search_regex(
  118. r'(<div[^>]+id="highlight_movie_%s"[^>]+>)' % video_id,
  119. webpage, 'highlight element', fatal=False)
  120. if highlight_element:
  121. highlight_attribs = extract_attributes(highlight_element)
  122. if highlight_attribs:
  123. entry['thumbnail'] = highlight_attribs.get('data-poster')
  124. for quality in ('', '-hd'):
  125. for ext in ('webm', 'mp4'):
  126. video_url = highlight_attribs.get('data-%s%s-source' % (ext, quality))
  127. if video_url:
  128. formats.append({
  129. 'format_id': ext + quality,
  130. 'url': video_url,
  131. })
  132. if not formats:
  133. continue
  134. entry['formats'] = formats
  135. entries.append(entry)
  136. if not entries:
  137. raise ExtractorError('Could not find any videos')
  138. return self.playlist_result(entries, playlist_id, playlist_title)