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
2.9 KiB

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