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.

55 lines
1.9 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. fix_xml_ampersands,
  6. )
  7. class MetacriticIE(InfoExtractor):
  8. _VALID_URL = r'https?://www\.metacritic\.com/.+?/trailers/(?P<id>\d+)'
  9. _TEST = {
  10. 'url': 'http://www.metacritic.com/game/playstation-4/infamous-second-son/trailers/3698222',
  11. 'info_dict': {
  12. 'id': '3698222',
  13. 'ext': 'mp4',
  14. 'title': 'inFamous: Second Son - inSide Sucker Punch: Smoke & Mirrors',
  15. 'description': 'Take a peak behind-the-scenes to see how Sucker Punch brings smoke into the universe of inFAMOUS Second Son on the PS4.',
  16. 'duration': 221,
  17. },
  18. }
  19. def _real_extract(self, url):
  20. mobj = re.match(self._VALID_URL, url)
  21. video_id = mobj.group('id')
  22. webpage = self._download_webpage(url, video_id)
  23. # The xml is not well formatted, there are raw '&'
  24. info = self._download_xml('http://www.metacritic.com/video_data?video=' + video_id,
  25. video_id, 'Downloading info xml', transform_source=fix_xml_ampersands)
  26. clip = next(c for c in info.findall('playList/clip') if c.find('id').text == video_id)
  27. formats = []
  28. for videoFile in clip.findall('httpURI/videoFile'):
  29. rate_str = videoFile.find('rate').text
  30. video_url = videoFile.find('filePath').text
  31. formats.append({
  32. 'url': video_url,
  33. 'ext': 'mp4',
  34. 'format_id': rate_str,
  35. 'tbr': int(rate_str),
  36. })
  37. self._sort_formats(formats)
  38. description = self._html_search_regex(r'<b>Description:</b>(.*?)</p>',
  39. webpage, 'description', flags=re.DOTALL)
  40. return {
  41. 'id': video_id,
  42. 'title': clip.find('title').text,
  43. 'formats': formats,
  44. 'description': description,
  45. 'duration': int(clip.find('duration').text),
  46. }