ign.py 5.2 KB

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