escapist.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. from __future__ import unicode_literals
  2. import json
  3. from .common import InfoExtractor
  4. from ..compat import compat_urllib_request
  5. from ..utils import (
  6. determine_ext,
  7. clean_html,
  8. int_or_none,
  9. )
  10. def _decrypt_config(key, string):
  11. a = ''
  12. i = ''
  13. r = ''
  14. while len(a) < (len(string) / 2):
  15. a += key
  16. a = a[0:int(len(string) / 2)]
  17. t = 0
  18. while t < len(string):
  19. i += chr(int(string[t] + string[t + 1], 16))
  20. t += 2
  21. icko = [s for s in i]
  22. for t, c in enumerate(a):
  23. r += chr(ord(c) ^ ord(icko[t]))
  24. return r
  25. class EscapistIE(InfoExtractor):
  26. _VALID_URL = r'https?://?(www\.)?escapistmagazine\.com/videos/view/[^/?#]+/(?P<id>[0-9]+)-[^/?#]*(?:$|[?#])'
  27. _TESTS = [{
  28. 'url': 'http://www.escapistmagazine.com/videos/view/the-escapist-presents/6618-Breaking-Down-Baldurs-Gate',
  29. 'md5': 'ab3a706c681efca53f0a35f1415cf0d1',
  30. 'info_dict': {
  31. 'id': '6618',
  32. 'ext': 'mp4',
  33. '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.",
  34. 'title': "Breaking Down Baldur's Gate",
  35. 'thumbnail': 're:^https?://.*\.jpg$',
  36. 'duration': 264,
  37. }
  38. }, {
  39. 'url': 'http://www.escapistmagazine.com/videos/view/zero-punctuation/10044-Evolve-One-vs-Multiplayer',
  40. 'md5': '9e8c437b0dbb0387d3bd3255ca77f6bf',
  41. 'info_dict': {
  42. 'id': '10044',
  43. 'ext': 'mp4',
  44. 'description': 'This week, Zero Punctuation reviews Evolve.',
  45. 'title': 'Evolve - One vs Multiplayer',
  46. 'thumbnail': 're:^https?://.*\.jpg$',
  47. 'duration': 304,
  48. }
  49. }]
  50. def _real_extract(self, url):
  51. video_id = self._match_id(url)
  52. webpage = self._download_webpage(url, video_id)
  53. imsVideo = self._parse_json(
  54. self._search_regex(
  55. r'imsVideo\.play\(({.+?})\);', webpage, 'imsVideo'),
  56. video_id)
  57. video_id = imsVideo['videoID']
  58. key = imsVideo['hash']
  59. config_req = compat_urllib_request.Request(
  60. 'http://www.escapistmagazine.com/videos/'
  61. 'vidconfig.php?videoID=%s&hash=%s' % (video_id, key))
  62. config_req.add_header('Referer', url)
  63. config = self._download_webpage(config_req, video_id, 'Downloading video config')
  64. data = json.loads(_decrypt_config(key, config))
  65. title = clean_html(data['videoData']['title'])
  66. duration = data['videoData']['duration'] / 1000
  67. formats = [{
  68. 'url': video['src'],
  69. 'format_id': '%s-%sp' % (determine_ext(video['src']), video['res']),
  70. 'height': int_or_none(video.get('res')),
  71. } for video in data['files']['videos']]
  72. self._sort_formats(formats)
  73. return {
  74. 'id': video_id,
  75. 'formats': formats,
  76. 'title': title,
  77. 'thumbnail': self._og_search_thumbnail(webpage),
  78. 'description': self._og_search_description(webpage),
  79. 'duration': duration,
  80. }