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.

145 lines
5.3 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
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. r'<meta name="description" content="(.*?)"',
  16. ]
  17. _TESTS = [
  18. {
  19. 'url': 'http://www.ign.com/videos/2013/06/05/the-last-of-us-review',
  20. 'md5': 'eac8bdc1890980122c3b66f14bdd02e9',
  21. 'info_dict': {
  22. 'id': '8f862beef863986b2785559b9e1aa599',
  23. 'ext': 'mp4',
  24. 'title': 'The Last of Us Review',
  25. 'description': 'md5:c8946d4260a4d43a00d5ae8ed998870c',
  26. }
  27. },
  28. {
  29. 'url': 'http://me.ign.com/en/feature/15775/100-little-things-in-gta-5-that-will-blow-your-mind',
  30. 'info_dict': {
  31. 'id': '100-little-things-in-gta-5-that-will-blow-your-mind',
  32. },
  33. 'playlist': [
  34. {
  35. 'info_dict': {
  36. 'id': '5ebbd138523268b93c9141af17bec937',
  37. 'ext': 'mp4',
  38. 'title': 'GTA 5 Video Review',
  39. 'description': 'Rockstar drops the mic on this generation of games. Watch our review of the masterly Grand Theft Auto V.',
  40. },
  41. },
  42. {
  43. 'info_dict': {
  44. 'id': '638672ee848ae4ff108df2a296418ee2',
  45. 'ext': 'mp4',
  46. 'title': '26 Twisted Moments from GTA 5 in Slow Motion',
  47. 'description': 'The twisted beauty of GTA 5 in stunning slow motion.',
  48. },
  49. },
  50. ],
  51. 'params': {
  52. 'skip_download': True,
  53. },
  54. },
  55. {
  56. 'url': 'http://www.ign.com/articles/2014/08/15/rewind-theater-wild-trailer-gamescom-2014?watch',
  57. 'md5': '618fedb9c901fd086f6f093564ef8558',
  58. 'info_dict': {
  59. 'id': '078fdd005f6d3c02f63d795faa1b984f',
  60. 'ext': 'mp4',
  61. 'title': 'Rewind Theater - Wild Trailer Gamescom 2014',
  62. 'description': (
  63. 'Giant skeletons, bloody hunts, and captivating'
  64. ' natural beauty take our breath away.'
  65. ),
  66. },
  67. },
  68. ]
  69. def _find_video_id(self, webpage):
  70. res_id = [
  71. r'"video_id"\s*:\s*"(.*?)"',
  72. r'class="hero-poster[^"]*?"[^>]*id="(.+?)"',
  73. r'data-video-id="(.+?)"',
  74. r'<object id="vid_(.+?)"',
  75. r'<meta name="og:image" content=".*/(.+?)-(.+?)/.+.jpg"',
  76. ]
  77. return self._search_regex(res_id, webpage, 'video id')
  78. def _real_extract(self, url):
  79. mobj = re.match(self._VALID_URL, url)
  80. name_or_id = mobj.group('name_or_id')
  81. page_type = mobj.group('type')
  82. webpage = self._download_webpage(url, name_or_id)
  83. if page_type != 'video':
  84. multiple_urls = re.findall(
  85. '<param name="flashvars"[^>]*value="[^"]*?url=(https?://www\.ign\.com/videos/.*?)["&]',
  86. webpage)
  87. if multiple_urls:
  88. entries = [self.url_result(u, ie='IGN') for u in multiple_urls]
  89. return {
  90. '_type': 'playlist',
  91. 'id': name_or_id,
  92. 'entries': entries,
  93. }
  94. video_id = self._find_video_id(webpage)
  95. result = self._get_video_info(video_id)
  96. description = self._html_search_regex(self._DESCRIPTION_RE,
  97. webpage, 'video description', flags=re.DOTALL)
  98. result['description'] = description
  99. return result
  100. def _get_video_info(self, video_id):
  101. config_url = self._CONFIG_URL_TEMPLATE % video_id
  102. config = self._download_json(config_url, video_id)
  103. media = config['playlist']['media']
  104. return {
  105. 'id': media['metadata']['videoId'],
  106. 'url': media['url'],
  107. 'title': media['metadata']['title'],
  108. 'thumbnail': media['poster'][0]['url'].replace('{size}', 'grande'),
  109. }
  110. class OneUPIE(IGNIE):
  111. _VALID_URL = r'https?://gamevideos\.1up\.com/(?P<type>video)/id/(?P<name_or_id>.+)\.html'
  112. IE_NAME = '1up.com'
  113. _DESCRIPTION_RE = r'<div id="vid_summary">(.+?)</div>'
  114. _TESTS = [{
  115. 'url': 'http://gamevideos.1up.com/video/id/34976.html',
  116. 'md5': '68a54ce4ebc772e4b71e3123d413163d',
  117. 'info_dict': {
  118. 'id': '34976',
  119. 'ext': 'mp4',
  120. 'title': 'Sniper Elite V2 - Trailer',
  121. 'description': 'md5:5d289b722f5a6d940ca3136e9dae89cf',
  122. }
  123. }]
  124. def _real_extract(self, url):
  125. mobj = re.match(self._VALID_URL, url)
  126. result = super(OneUPIE, self)._real_extract(url)
  127. result['id'] = mobj.group('name_or_id')
  128. return result