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.

78 lines
2.7 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. imgUrl = self._html_search_regex('<meta property="og:image" content="([^"]*)"',
  32. webpage, u'thumbnail', fatal=False)
  33. playerUrl = self._html_search_regex('<meta property="og:video" content="([^"]*)"',
  34. webpage, u'player url')
  35. title = self._html_search_regex('<meta name="title" content="([^"]*)"',
  36. webpage, u'player url').split(' : ')[-1]
  37. configUrl = self._search_regex('config=(.*)$', playerUrl, u'config url')
  38. configUrl = compat_urllib_parse.unquote(configUrl)
  39. configJSON = self._download_webpage(configUrl, videoId,
  40. u'Downloading configuration',
  41. u'unable to download 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. videoUrl = playlist[1]['url']
  50. info = {
  51. 'id': videoId,
  52. 'url': videoUrl,
  53. 'uploader': showName,
  54. 'upload_date': None,
  55. 'title': title,
  56. 'ext': 'mp4',
  57. 'thumbnail': imgUrl,
  58. 'description': videoDesc,
  59. 'player_url': playerUrl,
  60. }
  61. return [info]