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.

232 lines
8.9 KiB

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