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. qualities,
  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': 'c6793dbda81388f4264c1ba18684a74d',
  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': 'cf8842a8a46444d241f9a9980d7874f2',
  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. quality = qualities(['lq', 'hq', 'hd'])
  60. formats = []
  61. for q in ['lq', 'hq', 'hd']:
  62. config_req = compat_urllib_request.Request(
  63. 'http://www.escapistmagazine.com/videos/'
  64. 'vidconfig.php?videoID=%s&hash=%s&quality=%s' % (video_id, key, 'mp4_' + q))
  65. config_req.add_header('Referer', url)
  66. config = self._download_webpage(config_req, video_id, 'Downloading video config ' + q.upper())
  67. data = json.loads(_decrypt_config(key, config))
  68. title = clean_html(data['videoData']['title'])
  69. duration = data['videoData']['duration'] / 1000
  70. for i, v in enumerate(data['files']['videos']):
  71. formats.append({
  72. 'url': v,
  73. 'format_id': determine_ext(v) + '_' + q + str(i),
  74. 'quality': quality(q),
  75. })
  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. }