ign.py 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. parse_iso8601,
  7. )
  8. class IGNIE(InfoExtractor):
  9. """
  10. Extractor for some of the IGN sites, like www.ign.com, es.ign.com de.ign.com.
  11. Some videos of it.ign.com are also supported
  12. """
  13. _VALID_URL = r'https?://.+?\.ign\.com/(?:[^/]+/)?(?P<type>videos|show_videos|articles|feature|(?:[^/]+/\d+/video))(/.+)?/(?P<name_or_id>.+)'
  14. IE_NAME = 'ign.com'
  15. _API_URL_TEMPLATE = 'http://apis.ign.com/video/v3/videos/%s'
  16. _EMBED_RE = r'<iframe[^>]+?["\']((?:https?:)?//.+?\.ign\.com.+?/embed.+?)["\']'
  17. _TESTS = [
  18. {
  19. 'url': 'http://www.ign.com/videos/2013/06/05/the-last-of-us-review',
  20. 'md5': 'febda82c4bafecd2d44b6e1a18a595f8',
  21. 'info_dict': {
  22. 'id': '8f862beef863986b2785559b9e1aa599',
  23. 'ext': 'mp4',
  24. 'title': 'The Last of Us Review',
  25. 'description': 'md5:c8946d4260a4d43a00d5ae8ed998870c',
  26. 'timestamp': 1370440800,
  27. 'upload_date': '20130605',
  28. }
  29. },
  30. {
  31. 'url': 'http://me.ign.com/en/feature/15775/100-little-things-in-gta-5-that-will-blow-your-mind',
  32. 'info_dict': {
  33. 'id': '100-little-things-in-gta-5-that-will-blow-your-mind',
  34. },
  35. 'playlist': [
  36. {
  37. 'info_dict': {
  38. 'id': '5ebbd138523268b93c9141af17bec937',
  39. 'ext': 'mp4',
  40. 'title': 'GTA 5 Video Review',
  41. 'description': 'Rockstar drops the mic on this generation of games. Watch our review of the masterly Grand Theft Auto V.',
  42. 'timestamp': 1379339880,
  43. 'upload_date': '20130916',
  44. },
  45. },
  46. {
  47. 'info_dict': {
  48. 'id': '638672ee848ae4ff108df2a296418ee2',
  49. 'ext': 'mp4',
  50. 'title': '26 Twisted Moments from GTA 5 in Slow Motion',
  51. 'description': 'The twisted beauty of GTA 5 in stunning slow motion.',
  52. 'timestamp': 1386878820,
  53. 'upload_date': '20131212',
  54. },
  55. },
  56. ],
  57. 'params': {
  58. 'skip_download': True,
  59. },
  60. },
  61. {
  62. 'url': 'http://www.ign.com/articles/2014/08/15/rewind-theater-wild-trailer-gamescom-2014?watch',
  63. 'md5': '618fedb9c901fd086f6f093564ef8558',
  64. 'info_dict': {
  65. 'id': '078fdd005f6d3c02f63d795faa1b984f',
  66. 'ext': 'mp4',
  67. 'title': 'Rewind Theater - Wild Trailer Gamescom 2014',
  68. 'description': 'Brian and Jared explore Michel Ancel\'s captivating new preview.',
  69. 'timestamp': 1408047180,
  70. 'upload_date': '20140814',
  71. },
  72. },
  73. {
  74. 'url': 'http://me.ign.com/en/videos/112203/video/how-hitman-aims-to-be-different-than-every-other-s',
  75. 'only_matching': True,
  76. },
  77. {
  78. 'url': 'http://me.ign.com/ar/angry-birds-2/106533/video/lrd-ldyy-lwl-lfylm-angry-birds',
  79. 'only_matching': True,
  80. },
  81. ]
  82. def _find_video_id(self, webpage):
  83. res_id = [
  84. r'"video_id"\s*:\s*"(.*?)"',
  85. r'class="hero-poster[^"]*?"[^>]*id="(.+?)"',
  86. r'data-video-id="(.+?)"',
  87. r'<object id="vid_(.+?)"',
  88. r'<meta name="og:image" content=".*/(.+?)-(.+?)/.+.jpg"',
  89. ]
  90. return self._search_regex(res_id, webpage, 'video id', default=None)
  91. def _real_extract(self, url):
  92. mobj = re.match(self._VALID_URL, url)
  93. name_or_id = mobj.group('name_or_id')
  94. page_type = mobj.group('type')
  95. webpage = self._download_webpage(url, name_or_id)
  96. if page_type != 'video':
  97. multiple_urls = re.findall(
  98. '<param name="flashvars"[^>]*value="[^"]*?url=(https?://www\.ign\.com/videos/.*?)["&]',
  99. webpage)
  100. if multiple_urls:
  101. entries = [self.url_result(u, ie='IGN') for u in multiple_urls]
  102. return {
  103. '_type': 'playlist',
  104. 'id': name_or_id,
  105. 'entries': entries,
  106. }
  107. video_id = self._find_video_id(webpage)
  108. if not video_id:
  109. return self.url_result(self._search_regex(self._EMBED_RE, webpage, 'embed url'))
  110. return self._get_video_info(video_id)
  111. def _get_video_info(self, video_id):
  112. api_data = self._download_json(self._API_URL_TEMPLATE % video_id, video_id)
  113. formats = []
  114. m3u8_url = api_data['refs'].get('m3uUrl')
  115. if m3u8_url:
  116. formats.extend(self._extract_m3u8_formats(m3u8_url, video_id))
  117. f4m_url = api_data['refs'].get('f4mUrl')
  118. if f4m_url:
  119. formats.extend(self._extract_f4m_formats(f4m_url, video_id))
  120. for asset in api_data['assets']:
  121. formats.append({
  122. 'url': asset['url'],
  123. 'tbr': asset.get('actual_bitrate_kbps'),
  124. 'fps': asset.get('frame_rate'),
  125. 'height': int_or_none(asset.get('height')),
  126. 'width': int_or_none(asset.get('width')),
  127. })
  128. self._sort_formats(formats)
  129. thumbnails = []
  130. for thumbnail in api_data['thumbnails']:
  131. thumbnails.append({'url': thumbnail['url']})
  132. metadata = api_data['metadata']
  133. return {
  134. 'id': api_data.get('videoId') or video_id,
  135. 'title': metadata.get('longTitle') or metadata.get('name') or metadata.get['title'],
  136. 'description': metadata.get('description'),
  137. 'timestamp': parse_iso8601(metadata.get('publishDate')),
  138. 'duration': int_or_none(metadata.get('duration')),
  139. 'display_id': metadata.get('slug') or video_id,
  140. 'thumbnails': thumbnails,
  141. 'formats': formats,
  142. }
  143. class OneUPIE(IGNIE):
  144. _VALID_URL = r'https?://gamevideos\.1up\.com/(?P<type>video)/id/(?P<name_or_id>.+)\.html'
  145. IE_NAME = '1up.com'
  146. _TESTS = [{
  147. 'url': 'http://gamevideos.1up.com/video/id/34976.html',
  148. 'md5': 'c9cc69e07acb675c31a16719f909e347',
  149. 'info_dict': {
  150. 'id': '34976',
  151. 'ext': 'mp4',
  152. 'title': 'Sniper Elite V2 - Trailer',
  153. 'description': 'md5:bf0516c5ee32a3217aa703e9b1bc7826',
  154. 'timestamp': 1313099220,
  155. 'upload_date': '20110811',
  156. }
  157. }]
  158. def _real_extract(self, url):
  159. mobj = re.match(self._VALID_URL, url)
  160. result = super(OneUPIE, self)._real_extract(url)
  161. result['id'] = mobj.group('name_or_id')
  162. return result
  163. class PCMagIE(IGNIE):
  164. _VALID_URL = r'https?://(?:www\.)?pcmag\.com/(?P<type>videos|article2)(/.+)?/(?P<name_or_id>.+)'
  165. IE_NAME = 'pcmag'
  166. _EMBED_RE = r'iframe.setAttribute\("src",\s*__util.objToUrlString\("http://widgets\.ign\.com/video/embed/content.html?[^"]*url=([^"]+)["&]'
  167. _TESTS = [{
  168. 'url': 'http://www.pcmag.com/videos/2015/01/06/010615-whats-new-now-is-gogo-snooping-on-your-data',
  169. 'md5': '212d6154fd0361a2781075f1febbe9ad',
  170. 'info_dict': {
  171. 'id': 'ee10d774b508c9b8ec07e763b9125b91',
  172. 'ext': 'mp4',
  173. 'title': '010615_What\'s New Now: Is GoGo Snooping on Your Data?',
  174. 'description': 'md5:a7071ae64d2f68cc821c729d4ded6bb3',
  175. 'timestamp': 1420571160,
  176. 'upload_date': '20150106',
  177. }
  178. },{
  179. 'url': 'http://www.pcmag.com/article2/0,2817,2470156,00.asp',
  180. 'md5': '94130c1ca07ba0adb6088350681f16c1',
  181. 'info_dict': {
  182. 'id': '042e560ba94823d43afcb12ddf7142ca',
  183. 'ext': 'mp4',
  184. 'title': 'HTC\'s Weird New Re Camera - What\'s New Now',
  185. 'description': 'md5:53433c45df96d2ea5d0fda18be2ca908',
  186. 'timestamp': 1412953920,
  187. 'upload_date': '20141010',
  188. }
  189. }]