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.

85 lines
3.0 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..compat import (
  4. compat_urllib_parse,
  5. )
  6. from ..utils import (
  7. ExtractorError,
  8. js_to_json,
  9. )
  10. class EscapistIE(InfoExtractor):
  11. _VALID_URL = r'https?://?(www\.)?escapistmagazine\.com/videos/view/[^/?#]+/(?P<id>[0-9]+)-[^/?#]*(?:$|[?#])'
  12. _TEST = {
  13. 'url': 'http://www.escapistmagazine.com/videos/view/the-escapist-presents/6618-Breaking-Down-Baldurs-Gate',
  14. 'md5': 'ab3a706c681efca53f0a35f1415cf0d1',
  15. 'info_dict': {
  16. 'id': '6618',
  17. 'ext': 'mp4',
  18. 'description': "Baldur's Gate: Original, Modded or Enhanced Edition? I'll break down what you can expect from the new Baldur's Gate: Enhanced Edition.",
  19. 'uploader_id': 'the-escapist-presents',
  20. 'uploader': 'The Escapist Presents',
  21. 'title': "Breaking Down Baldur's Gate",
  22. }
  23. }
  24. def _real_extract(self, url):
  25. video_id = self._match_id(url)
  26. webpage = self._download_webpage(url, video_id)
  27. uploader_id = self._html_search_regex(
  28. r"<h1 class='headline'><a href='/videos/view/(.*?)'",
  29. webpage, 'uploader ID', fatal=False)
  30. uploader = self._html_search_regex(
  31. r"<h1 class='headline'>(.*?)</a>",
  32. webpage, 'uploader', fatal=False)
  33. description = self._html_search_meta('description', webpage)
  34. raw_title = self._html_search_meta('title', webpage, fatal=True)
  35. title = raw_title.partition(' : ')[2]
  36. player_url = self._og_search_video_url(webpage, name='player URL')
  37. config_url = compat_urllib_parse.unquote(self._search_regex(
  38. r'config=(.*)$', player_url, 'config URL'))
  39. formats = []
  40. def _add_format(name, cfgurl, quality):
  41. config = self._download_json(
  42. cfgurl, video_id,
  43. 'Downloading ' + name + ' configuration',
  44. 'Unable to download ' + name + ' configuration',
  45. transform_source=js_to_json)
  46. playlist = config['playlist']
  47. video_url = next(
  48. p['url'] for p in playlist
  49. if p.get('eventCategory') == 'Video')
  50. formats.append({
  51. 'url': video_url,
  52. 'format_id': name,
  53. 'quality': quality,
  54. })
  55. _add_format('normal', config_url, quality=0)
  56. hq_url = (config_url +
  57. ('&hq=1' if '?' in config_url else config_url + '?hq=1'))
  58. try:
  59. _add_format('hq', hq_url, quality=1)
  60. except ExtractorError:
  61. pass # That's fine, we'll just use normal quality
  62. self._sort_formats(formats)
  63. return {
  64. 'id': video_id,
  65. 'formats': formats,
  66. 'uploader': uploader,
  67. 'uploader_id': uploader_id,
  68. 'title': title,
  69. 'thumbnail': self._og_search_thumbnail(webpage),
  70. 'description': description,
  71. 'player_url': player_url,
  72. }