escapist.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. formats.append({
  48. 'url': playlist[1]['url'],
  49. 'format_id': name,
  50. 'quality': quality,
  51. })
  52. _add_format('normal', config_url, quality=0)
  53. hq_url = (config_url +
  54. ('&hq=1' if '?' in config_url else config_url + '?hq=1'))
  55. try:
  56. _add_format('hq', hq_url, quality=1)
  57. except ExtractorError:
  58. pass # That's fine, we'll just use normal quality
  59. self._sort_formats(formats)
  60. return {
  61. 'id': video_id,
  62. 'formats': formats,
  63. 'uploader': uploader,
  64. 'uploader_id': uploader_id,
  65. 'title': title,
  66. 'thumbnail': self._og_search_thumbnail(webpage),
  67. 'description': description,
  68. 'player_url': player_url,
  69. }