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.

74 lines
2.6 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'c6793dbda81388f4264c1ba18684a74d',
  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. if mobj is None:
  24. raise ExtractorError(u'Invalid URL: %s' % url)
  25. showName = mobj.group('showname')
  26. videoId = mobj.group('episode')
  27. self.report_extraction(videoId)
  28. webpage = self._download_webpage(url, videoId)
  29. videoDesc = self._html_search_regex('<meta name="description" content="([^"]*)"',
  30. webpage, u'description', fatal=False)
  31. playerUrl = self._og_search_video_url(webpage, name='player url')
  32. title = self._html_search_regex('<meta name="title" content="([^"]*)"',
  33. webpage, u'player url').split(' : ')[-1]
  34. configUrl = self._search_regex('config=(.*)$', playerUrl, u'config url')
  35. configUrl = compat_urllib_parse.unquote(configUrl)
  36. configJSON = self._download_webpage(configUrl, videoId,
  37. u'Downloading configuration',
  38. u'unable to download configuration')
  39. # Technically, it's JavaScript, not JSON
  40. configJSON = configJSON.replace("'", '"')
  41. try:
  42. config = json.loads(configJSON)
  43. except (ValueError,) as err:
  44. raise ExtractorError(u'Invalid JSON in configuration file: ' + compat_str(err))
  45. playlist = config['playlist']
  46. videoUrl = playlist[1]['url']
  47. info = {
  48. 'id': videoId,
  49. 'url': videoUrl,
  50. 'uploader': showName,
  51. 'upload_date': None,
  52. 'title': title,
  53. 'ext': 'mp4',
  54. 'thumbnail': self._og_search_thumbnail(webpage),
  55. 'description': videoDesc,
  56. 'player_url': playerUrl,
  57. }
  58. return [info]