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.

68 lines
2.2 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. def _real_extract(self, url):
  12. mobj = re.match(self._VALID_URL, url)
  13. if mobj is None:
  14. raise ExtractorError(u'Invalid URL: %s' % url)
  15. showName = mobj.group('showname')
  16. videoId = mobj.group('episode')
  17. self.report_extraction(videoId)
  18. webpage = self._download_webpage(url, videoId)
  19. videoDesc = self._html_search_regex('<meta name="description" content="([^"]*)"',
  20. webpage, u'description', fatal=False)
  21. imgUrl = self._html_search_regex('<meta property="og:image" content="([^"]*)"',
  22. webpage, u'thumbnail', fatal=False)
  23. playerUrl = self._html_search_regex('<meta property="og:video" content="([^"]*)"',
  24. webpage, u'player url')
  25. title = self._html_search_regex('<meta name="title" content="([^"]*)"',
  26. webpage, u'player url').split(' : ')[-1]
  27. configUrl = self._search_regex('config=(.*)$', playerUrl, u'config url')
  28. configUrl = compat_urllib_parse.unquote(configUrl)
  29. configJSON = self._download_webpage(configUrl, videoId,
  30. u'Downloading configuration',
  31. u'unable to download configuration')
  32. # Technically, it's JavaScript, not JSON
  33. configJSON = configJSON.replace("'", '"')
  34. try:
  35. config = json.loads(configJSON)
  36. except (ValueError,) as err:
  37. raise ExtractorError(u'Invalid JSON in configuration file: ' + compat_str(err))
  38. playlist = config['playlist']
  39. videoUrl = playlist[1]['url']
  40. info = {
  41. 'id': videoId,
  42. 'url': videoUrl,
  43. 'uploader': showName,
  44. 'upload_date': None,
  45. 'title': title,
  46. 'ext': 'mp4',
  47. 'thumbnail': imgUrl,
  48. 'description': videoDesc,
  49. 'player_url': playerUrl,
  50. }
  51. return [info]