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.

62 lines
2.2 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. int_or_none,
  5. parse_age_limit,
  6. url_basename,
  7. )
  8. class GametrailersIE(InfoExtractor):
  9. _VALID_URL = r'http://www\.gametrailers\.com/videos/view/[^/]+/(?P<id>.+)'
  10. _TEST = {
  11. 'url': 'http://www.gametrailers.com/videos/view/gametrailers-com/116437-Just-Cause-3-Review',
  12. 'md5': 'f28c4efa0bdfaf9b760f6507955b6a6a',
  13. 'info_dict': {
  14. 'id': '2983958',
  15. 'ext': 'mp4',
  16. 'display_id': '116437-Just-Cause-3-Review',
  17. 'title': 'Just Cause 3 - Review',
  18. 'description': 'It\'s a lot of fun to shoot at things and then watch them explode in Just Cause 3, but should there be more to the experience than that?',
  19. },
  20. }
  21. def _real_extract(self, url):
  22. display_id = self._match_id(url)
  23. webpage = self._download_webpage(url, display_id)
  24. title = self._html_search_regex(
  25. r'<title>(.+?)\|', webpage, 'title').strip()
  26. embed_url = self._proto_relative_url(
  27. self._search_regex(
  28. r'src=\'(//embed.gametrailers.com/embed/[^\']+)\'', webpage,
  29. 'embed url'),
  30. scheme='http:')
  31. video_id = url_basename(embed_url)
  32. embed_page = self._download_webpage(embed_url, video_id)
  33. embed_vars_json = self._search_regex(
  34. r'(?s)var embedVars = (\{.*?\})\s*</script>', embed_page,
  35. 'embed vars')
  36. info = self._parse_json(embed_vars_json, video_id)
  37. formats = []
  38. for media in info['media']:
  39. if media['mediaPurpose'] == 'play':
  40. formats.append({
  41. 'url': media['uri'],
  42. 'height': media['height'],
  43. 'width:': media['width'],
  44. })
  45. self._sort_formats(formats)
  46. return {
  47. 'id': video_id,
  48. 'display_id': display_id,
  49. 'title': title,
  50. 'formats': formats,
  51. 'thumbnail': info.get('thumbUri'),
  52. 'description': self._og_search_description(webpage),
  53. 'duration': int_or_none(info.get('videoLengthInSeconds')),
  54. 'age_limit': parse_age_limit(info.get('audienceRating')),
  55. }