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.

107 lines
3.3 KiB

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