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.

95 lines
3.4 KiB

  1. import re
  2. import json
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. determine_ext,
  6. )
  7. class IGNIE(InfoExtractor):
  8. """
  9. Extractor for some of the IGN sites, like www.ign.com, es.ign.com de.ign.com.
  10. Some videos of it.ign.com are also supported
  11. """
  12. _VALID_URL = r'https?://.+?\.ign\.com/(?P<type>videos|show_videos|articles)(/.+)?/(?P<name_or_id>.+)'
  13. IE_NAME = u'ign.com'
  14. _CONFIG_URL_TEMPLATE = 'http://www.ign.com/videos/configs/id/%s.config'
  15. _DESCRIPTION_RE = [r'<span class="page-object-description">(.+?)</span>',
  16. r'id="my_show_video">.*?<p>(.*?)</p>',
  17. ]
  18. _TEST = {
  19. u'url': u'http://www.ign.com/videos/2013/06/05/the-last-of-us-review',
  20. u'file': u'8f862beef863986b2785559b9e1aa599.mp4',
  21. u'md5': u'eac8bdc1890980122c3b66f14bdd02e9',
  22. u'info_dict': {
  23. u'title': u'The Last of Us Review',
  24. u'description': u'md5:c8946d4260a4d43a00d5ae8ed998870c',
  25. }
  26. }
  27. def _find_video_id(self, webpage):
  28. res_id = [r'data-video-id="(.+?)"',
  29. r'<object id="vid_(.+?)"',
  30. r'<meta name="og:image" content=".*/(.+?)-(.+?)/.+.jpg"',
  31. ]
  32. return self._search_regex(res_id, webpage, 'video id')
  33. def _real_extract(self, url):
  34. mobj = re.match(self._VALID_URL, url)
  35. name_or_id = mobj.group('name_or_id')
  36. page_type = mobj.group('type')
  37. webpage = self._download_webpage(url, name_or_id)
  38. if page_type == 'articles':
  39. video_url = self._search_regex(r'var videoUrl = "(.+?)"', webpage, u'video url')
  40. return self.url_result(video_url, ie='IGN')
  41. video_id = self._find_video_id(webpage)
  42. result = self._get_video_info(video_id)
  43. description = self._html_search_regex(self._DESCRIPTION_RE,
  44. webpage, 'video description',
  45. flags=re.DOTALL)
  46. result['description'] = description
  47. return result
  48. def _get_video_info(self, video_id):
  49. config_url = self._CONFIG_URL_TEMPLATE % video_id
  50. config = json.loads(self._download_webpage(config_url, video_id,
  51. u'Downloading video info'))
  52. media = config['playlist']['media']
  53. video_url = media['url']
  54. return {'id': media['metadata']['videoId'],
  55. 'url': video_url,
  56. 'ext': determine_ext(video_url),
  57. 'title': media['metadata']['title'],
  58. 'thumbnail': media['poster'][0]['url'].replace('{size}', 'grande'),
  59. }
  60. class OneUPIE(IGNIE):
  61. """Extractor for 1up.com, it uses the ign videos system."""
  62. _VALID_URL = r'https?://gamevideos.1up.com/(?P<type>video)/id/(?P<name_or_id>.+)'
  63. IE_NAME = '1up.com'
  64. _DESCRIPTION_RE = r'<div id="vid_summary">(.+?)</div>'
  65. _TEST = {
  66. u'url': u'http://gamevideos.1up.com/video/id/34976',
  67. u'file': u'34976.mp4',
  68. u'md5': u'68a54ce4ebc772e4b71e3123d413163d',
  69. u'info_dict': {
  70. u'title': u'Sniper Elite V2 - Trailer',
  71. u'description': u'md5:5d289b722f5a6d940ca3136e9dae89cf',
  72. }
  73. }
  74. def _real_extract(self, url):
  75. mobj = re.match(self._VALID_URL, url)
  76. id = mobj.group('name_or_id')
  77. result = super(OneUPIE, self)._real_extract(url)
  78. result['id'] = id
  79. return result