ign.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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': 'Giant skeletons, bloody hunts, and captivating'
  60. ' natural beauty take our breath away.',
  61. },
  62. },
  63. ]
  64. def _find_video_id(self, webpage):
  65. res_id = [
  66. r'"video_id"\s*:\s*"(.*?)"',
  67. r'data-video-id="(.+?)"',
  68. r'<object id="vid_(.+?)"',
  69. r'<meta name="og:image" content=".*/(.+?)-(.+?)/.+.jpg"',
  70. r'class="hero-poster[^"]*?"[^>]*id="(.+?)"',
  71. ]
  72. return self._search_regex(res_id, webpage, 'video id')
  73. def _real_extract(self, url):
  74. mobj = re.match(self._VALID_URL, url)
  75. name_or_id = mobj.group('name_or_id')
  76. page_type = mobj.group('type')
  77. webpage = self._download_webpage(url, name_or_id)
  78. if page_type != 'video':
  79. multiple_urls = re.findall(
  80. '<param name="flashvars"[^>]*value="[^"]*?url=(https?://www\.ign\.com/videos/.*?)["&]',
  81. webpage)
  82. if multiple_urls:
  83. entries = [self.url_result(u, ie='IGN') for u in multiple_urls]
  84. return {
  85. '_type': 'playlist',
  86. 'id': name_or_id,
  87. 'entries': entries,
  88. }
  89. video_id = self._find_video_id(webpage)
  90. result = self._get_video_info(video_id)
  91. description = self._html_search_regex(self._DESCRIPTION_RE,
  92. webpage, 'video description', flags=re.DOTALL)
  93. result['description'] = description
  94. return result
  95. def _get_video_info(self, video_id):
  96. config_url = self._CONFIG_URL_TEMPLATE % video_id
  97. config = self._download_json(config_url, video_id)
  98. media = config['playlist']['media']
  99. return {
  100. 'id': media['metadata']['videoId'],
  101. 'url': media['url'],
  102. 'title': media['metadata']['title'],
  103. 'thumbnail': media['poster'][0]['url'].replace('{size}', 'grande'),
  104. }
  105. class OneUPIE(IGNIE):
  106. _VALID_URL = r'https?://gamevideos\.1up\.com/(?P<type>video)/id/(?P<name_or_id>.+)\.html'
  107. IE_NAME = '1up.com'
  108. _DESCRIPTION_RE = r'<div id="vid_summary">(.+?)</div>'
  109. _TESTS = [{
  110. 'url': 'http://gamevideos.1up.com/video/id/34976.html',
  111. 'md5': '68a54ce4ebc772e4b71e3123d413163d',
  112. 'info_dict': {
  113. 'id': '34976',
  114. 'ext': 'mp4',
  115. 'title': 'Sniper Elite V2 - Trailer',
  116. 'description': 'md5:5d289b722f5a6d940ca3136e9dae89cf',
  117. }
  118. }]
  119. def _real_extract(self, url):
  120. mobj = re.match(self._VALID_URL, url)
  121. result = super(OneUPIE, self)._real_extract(url)
  122. result['id'] = mobj.group('name_or_id')
  123. return result