logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

metacritic.py (2675B)


  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. _TESTS = [{
  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. 'skip': 'Not providing trailers anymore',
  19. }, {
  20. 'url': 'http://www.metacritic.com/game/playstation-4/tales-from-the-borderlands-a-telltale-game-series/trailers/5740315',
  21. 'info_dict': {
  22. 'id': '5740315',
  23. 'ext': 'mp4',
  24. 'title': 'Tales from the Borderlands - Finale: The Vault of the Traveler',
  25. 'description': 'In the final episode of the season, all hell breaks loose. Jack is now in control of Helios\' systems, and he\'s ready to reclaim his rightful place as king of Hyperion (with or without you).',
  26. 'duration': 114,
  27. },
  28. }]
  29. def _real_extract(self, url):
  30. mobj = re.match(self._VALID_URL, url)
  31. video_id = mobj.group('id')
  32. webpage = self._download_webpage(url, video_id)
  33. # The xml is not well formatted, there are raw '&'
  34. info = self._download_xml('http://www.metacritic.com/video_data?video=' + video_id,
  35. video_id, 'Downloading info xml', transform_source=fix_xml_ampersands)
  36. clip = next(c for c in info.findall('playList/clip') if c.find('id').text == video_id)
  37. formats = []
  38. for videoFile in clip.findall('httpURI/videoFile'):
  39. rate_str = videoFile.find('rate').text
  40. video_url = videoFile.find('filePath').text
  41. formats.append({
  42. 'url': video_url,
  43. 'ext': 'mp4',
  44. 'format_id': rate_str,
  45. 'tbr': int(rate_str),
  46. })
  47. self._sort_formats(formats)
  48. description = self._html_search_regex(r'<b>Description:</b>(.*?)</p>',
  49. webpage, 'description', flags=re.DOTALL)
  50. return {
  51. 'id': video_id,
  52. 'title': clip.find('title').text,
  53. 'formats': formats,
  54. 'description': description,
  55. 'duration': int(clip.find('duration').text),
  56. }