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.1 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\s+class='headline'>\s*<a\s+href='/videos/view/(.*?)'",
  30. webpage, 'uploader ID', fatal=False)
  31. uploader = self._html_search_regex(
  32. r"<h1\s+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'''(?x)
  39. (?:
  40. <param\s+name="flashvars".*?\s+value="config=|
  41. flashvars=&quot;config=
  42. )
  43. (https?://[^"&]+)
  44. ''',
  45. webpage, 'config URL'))
  46. formats = []
  47. def _add_format(name, cfgurl, quality):
  48. config = self._download_json(
  49. cfgurl, video_id,
  50. 'Downloading ' + name + ' configuration',
  51. 'Unable to download ' + name + ' configuration',
  52. transform_source=js_to_json)
  53. playlist = config['playlist']
  54. video_url = next(
  55. p['url'] for p in playlist
  56. if p.get('eventCategory') == 'Video')
  57. formats.append({
  58. 'url': video_url,
  59. 'format_id': name,
  60. 'quality': quality,
  61. })
  62. _add_format('normal', config_url, quality=0)
  63. hq_url = (config_url +
  64. ('&hq=1' if '?' in config_url else config_url + '?hq=1'))
  65. try:
  66. _add_format('hq', hq_url, quality=1)
  67. except ExtractorError:
  68. pass # That's fine, we'll just use normal quality
  69. self._sort_formats(formats)
  70. return {
  71. 'id': video_id,
  72. 'formats': formats,
  73. 'uploader': uploader,
  74. 'uploader_id': uploader_id,
  75. 'title': title,
  76. 'thumbnail': self._og_search_thumbnail(webpage),
  77. 'description': description,
  78. }