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.

83 lines
2.7 KiB

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