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.

82 lines
2.7 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. compat_urllib_parse,
  6. ExtractorError,
  7. )
  8. class EscapistIE(InfoExtractor):
  9. _VALID_URL = r'^https?://?(www\.)?escapistmagazine\.com/videos/view/(?P<showname>[^/]+)/(?P<id>[0-9]+)-'
  10. _TEST = {
  11. 'url': 'http://www.escapistmagazine.com/videos/view/the-escapist-presents/6618-Breaking-Down-Baldurs-Gate',
  12. 'md5': 'ab3a706c681efca53f0a35f1415cf0d1',
  13. 'info_dict': {
  14. 'id': '6618',
  15. 'ext': 'mp4',
  16. '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.",
  17. 'uploader': 'the-escapist-presents',
  18. 'title': "Breaking Down Baldur's Gate",
  19. }
  20. }
  21. def _real_extract(self, url):
  22. mobj = re.match(self._VALID_URL, url)
  23. showName = mobj.group('showname')
  24. video_id = mobj.group('id')
  25. self.report_extraction(video_id)
  26. webpage = self._download_webpage(url, video_id)
  27. videoDesc = self._html_search_regex(
  28. r'<meta name="description" content="([^"]*)"',
  29. webpage, 'description', fatal=False)
  30. playerUrl = self._og_search_video_url(webpage, name='player URL')
  31. title = self._html_search_regex(
  32. r'<meta name="title" content="([^"]*)"',
  33. webpage, 'title').split(' : ')[-1]
  34. configUrl = self._search_regex('config=(.*)$', playerUrl, 'config URL')
  35. configUrl = compat_urllib_parse.unquote(configUrl)
  36. formats = []
  37. def _add_format(name, cfgurl, quality):
  38. config = self._download_json(
  39. cfgurl, video_id,
  40. 'Downloading ' + name + ' configuration',
  41. 'Unable to download ' + name + ' configuration',
  42. transform_source=lambda s: s.replace("'", '"'))
  43. playlist = config['playlist']
  44. formats.append({
  45. 'url': playlist[1]['url'],
  46. 'format_id': name,
  47. 'quality': quality,
  48. })
  49. _add_format('normal', configUrl, quality=0)
  50. hq_url = (configUrl +
  51. ('&hq=1' if '?' in configUrl else configUrl + '?hq=1'))
  52. try:
  53. _add_format('hq', hq_url, quality=1)
  54. except ExtractorError:
  55. pass # That's fine, we'll just use normal quality
  56. self._sort_formats(formats)
  57. return {
  58. 'id': video_id,
  59. 'formats': formats,
  60. 'uploader': showName,
  61. 'title': title,
  62. 'thumbnail': self._og_search_thumbnail(webpage),
  63. 'description': videoDesc,
  64. 'player_url': playerUrl,
  65. }