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.

91 lines
3.2 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/(?:videos|show_videos)(/.+)?/(?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. webpage = self._download_webpage(url, name_or_id)
  37. video_id = self._find_video_id(webpage)
  38. result = self._get_video_info(video_id)
  39. description = self._html_search_regex(self._DESCRIPTION_RE,
  40. webpage, 'video description',
  41. flags=re.DOTALL)
  42. result['description'] = description
  43. return result
  44. def _get_video_info(self, video_id):
  45. config_url = self._CONFIG_URL_TEMPLATE % video_id
  46. config = json.loads(self._download_webpage(config_url, video_id,
  47. u'Downloading video info'))
  48. media = config['playlist']['media']
  49. video_url = media['url']
  50. return {'id': media['metadata']['videoId'],
  51. 'url': video_url,
  52. 'ext': determine_ext(video_url),
  53. 'title': media['metadata']['title'],
  54. 'thumbnail': media['poster'][0]['url'].replace('{size}', 'grande'),
  55. }
  56. class OneUPIE(IGNIE):
  57. """Extractor for 1up.com, it uses the ign videos system."""
  58. _VALID_URL = r'https?://gamevideos.1up.com/video/id/(?P<name_or_id>.+)'
  59. IE_NAME = '1up.com'
  60. _DESCRIPTION_RE = r'<div id="vid_summary">(.+?)</div>'
  61. _TEST = {
  62. u'url': u'http://gamevideos.1up.com/video/id/34976',
  63. u'file': u'34976.mp4',
  64. u'md5': u'68a54ce4ebc772e4b71e3123d413163d',
  65. u'info_dict': {
  66. u'title': u'Sniper Elite V2 - Trailer',
  67. u'description': u'md5:5d289b722f5a6d940ca3136e9dae89cf',
  68. }
  69. }
  70. def _real_extract(self, url):
  71. mobj = re.match(self._VALID_URL, url)
  72. id = mobj.group('name_or_id')
  73. result = super(OneUPIE, self)._real_extract(url)
  74. result['id'] = id
  75. return result