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.

105 lines
3.2 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. }
  39. }, {
  40. 'url': 'http://www.escapistmagazine.com/videos/view/zero-punctuation/10044-Evolve-One-vs-Multiplayer',
  41. 'md5': '9e8c437b0dbb0387d3bd3255ca77f6bf',
  42. 'info_dict': {
  43. 'id': '10044',
  44. 'ext': 'mp4',
  45. 'description': 'This week, Zero Punctuation reviews Evolve.',
  46. 'title': 'Evolve - One vs Multiplayer',
  47. 'thumbnail': 're:^https?://.*\.jpg$',
  48. 'duration': 304,
  49. }
  50. }]
  51. def _real_extract(self, url):
  52. video_id = self._match_id(url)
  53. webpage = self._download_webpage(url, video_id)
  54. ims_video = self._parse_json(
  55. self._search_regex(
  56. r'imsVideo\.play\(({.+?})\);', webpage, 'imsVideo'),
  57. video_id)
  58. video_id = ims_video['videoID']
  59. key = ims_video['hash']
  60. config_req = compat_urllib_request.Request(
  61. 'http://www.escapistmagazine.com/videos/'
  62. 'vidconfig.php?videoID=%s&hash=%s' % (video_id, key))
  63. config_req.add_header('Referer', url)
  64. config = self._download_webpage(config_req, video_id, 'Downloading video config')
  65. data = json.loads(_decrypt_config(key, config))
  66. video_data = data['videoData']
  67. title = clean_html(video_data['title'])
  68. duration = float_or_none(video_data.get('duration'), 1000)
  69. uploader = video_data.get('publisher')
  70. formats = [{
  71. 'url': video['src'],
  72. 'format_id': '%s-%sp' % (determine_ext(video['src']), video['res']),
  73. 'height': int_or_none(video.get('res')),
  74. } for video in data['files']['videos']]
  75. self._sort_formats(formats)
  76. return {
  77. 'id': video_id,
  78. 'formats': formats,
  79. 'title': title,
  80. 'thumbnail': self._og_search_thumbnail(webpage),
  81. 'description': self._og_search_description(webpage),
  82. 'duration': duration,
  83. 'uploader': uploader,
  84. }