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.

124 lines
4.4 KiB

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