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.

129 lines
4.8 KiB

  1. import re
  2. import json
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. determine_ext,
  6. )
  7. class IGNIE(InfoExtractor):
  8. """
  9. Extractor for some of the IGN sites, like www.ign.com, es.ign.com de.ign.com.
  10. Some videos of it.ign.com are also supported
  11. """
  12. _VALID_URL = r'https?://.+?\.ign\.com/(?P<type>videos|show_videos|articles|(?:[^/]*/feature))(/.+)?/(?P<name_or_id>.+)'
  13. IE_NAME = u'ign.com'
  14. _CONFIG_URL_TEMPLATE = 'http://www.ign.com/videos/configs/id/%s.config'
  15. _DESCRIPTION_RE = [r'<span class="page-object-description">(.+?)</span>',
  16. r'id="my_show_video">.*?<p>(.*?)</p>',
  17. ]
  18. _TESTS = [
  19. {
  20. u'url': u'http://www.ign.com/videos/2013/06/05/the-last-of-us-review',
  21. u'file': u'8f862beef863986b2785559b9e1aa599.mp4',
  22. u'md5': u'eac8bdc1890980122c3b66f14bdd02e9',
  23. u'info_dict': {
  24. u'title': u'The Last of Us Review',
  25. u'description': u'md5:c8946d4260a4d43a00d5ae8ed998870c',
  26. }
  27. },
  28. {
  29. u'url': u'http://me.ign.com/en/feature/15775/100-little-things-in-gta-5-that-will-blow-your-mind',
  30. u'playlist': [
  31. {
  32. u'file': u'5ebbd138523268b93c9141af17bec937.mp4',
  33. u'info_dict': {
  34. u'title': u'GTA 5 Video Review',
  35. u'description': u'Rockstar drops the mic on this generation of games. Watch our review of the masterly Grand Theft Auto V.',
  36. },
  37. },
  38. {
  39. u'file': u'638672ee848ae4ff108df2a296418ee2.mp4',
  40. u'info_dict': {
  41. u'title': u'GTA 5\'s Twisted Beauty in Super Slow Motion',
  42. u'description': u'The twisted beauty of GTA 5 in stunning slow motion.',
  43. },
  44. },
  45. ],
  46. u'params': {
  47. u'skip_download': True,
  48. },
  49. },
  50. ]
  51. def _find_video_id(self, webpage):
  52. res_id = [r'data-video-id="(.+?)"',
  53. r'<object id="vid_(.+?)"',
  54. r'<meta name="og:image" content=".*/(.+?)-(.+?)/.+.jpg"',
  55. ]
  56. return self._search_regex(res_id, webpage, 'video id')
  57. def _real_extract(self, url):
  58. mobj = re.match(self._VALID_URL, url)
  59. name_or_id = mobj.group('name_or_id')
  60. page_type = mobj.group('type')
  61. webpage = self._download_webpage(url, name_or_id)
  62. if page_type == 'articles':
  63. video_url = self._search_regex(r'var videoUrl = "(.+?)"', webpage, u'video url')
  64. return self.url_result(video_url, ie='IGN')
  65. elif page_type != 'video':
  66. multiple_urls = re.findall(
  67. '<param name="flashvars" value="[^"]*?url=(https?://www\.ign\.com/videos/.*?)["&]',
  68. webpage)
  69. if multiple_urls:
  70. return [self.url_result(u, ie='IGN') for u in multiple_urls]
  71. video_id = self._find_video_id(webpage)
  72. result = self._get_video_info(video_id)
  73. description = self._html_search_regex(self._DESCRIPTION_RE,
  74. webpage, 'video description',
  75. flags=re.DOTALL)
  76. result['description'] = description
  77. return result
  78. def _get_video_info(self, video_id):
  79. config_url = self._CONFIG_URL_TEMPLATE % video_id
  80. config = json.loads(self._download_webpage(config_url, video_id,
  81. u'Downloading video info'))
  82. media = config['playlist']['media']
  83. video_url = media['url']
  84. return {'id': media['metadata']['videoId'],
  85. 'url': video_url,
  86. 'ext': determine_ext(video_url),
  87. 'title': media['metadata']['title'],
  88. 'thumbnail': media['poster'][0]['url'].replace('{size}', 'grande'),
  89. }
  90. class OneUPIE(IGNIE):
  91. """Extractor for 1up.com, it uses the ign videos system."""
  92. _VALID_URL = r'https?://gamevideos\.1up\.com/(?P<type>video)/id/(?P<name_or_id>.+)'
  93. IE_NAME = '1up.com'
  94. _DESCRIPTION_RE = r'<div id="vid_summary">(.+?)</div>'
  95. _TEST = {
  96. u'url': u'http://gamevideos.1up.com/video/id/34976',
  97. u'file': u'34976.mp4',
  98. u'md5': u'68a54ce4ebc772e4b71e3123d413163d',
  99. u'info_dict': {
  100. u'title': u'Sniper Elite V2 - Trailer',
  101. u'description': u'md5:5d289b722f5a6d940ca3136e9dae89cf',
  102. }
  103. }
  104. # Override IGN tests
  105. _TESTS = []
  106. def _real_extract(self, url):
  107. mobj = re.match(self._VALID_URL, url)
  108. id = mobj.group('name_or_id')
  109. result = super(OneUPIE, self)._real_extract(url)
  110. result['id'] = id
  111. return result