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.

84 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. 'thumbnail': 're:^https?://.*\.jpg$',
  23. }
  24. }
  25. def _real_extract(self, url):
  26. video_id = self._match_id(url)
  27. webpage = self._download_webpage(url, video_id)
  28. uploader_id = self._html_search_regex(
  29. r"<h1 class='headline'><a href='/videos/view/(.*?)'",
  30. webpage, 'uploader ID', fatal=False)
  31. uploader = self._html_search_regex(
  32. r"<h1 class='headline'>(.*?)</a>",
  33. webpage, 'uploader', fatal=False)
  34. description = self._html_search_meta('description', webpage)
  35. raw_title = self._html_search_meta('title', webpage, fatal=True)
  36. title = raw_title.partition(' : ')[2]
  37. config_url = compat_urllib_parse.unquote(self._html_search_regex(
  38. r'<param name="flashvars" value="config=([^"&]+)', webpage, '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. }