escapist.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 = json.loads(self._search_regex(r'imsVideo\.play\(([^\)]+)\);', webpage, 'imsVideo'))
  54. video_id = imsVideo['videoID']
  55. key = imsVideo['hash']
  56. quality = qualities(['lq', 'hq', 'hd'])
  57. formats = []
  58. for q in ['lq', 'hq', 'hd']:
  59. config_req = compat_urllib_request.Request('http://www.escapistmagazine.com/videos/'
  60. 'vidconfig.php?videoID=%s&hash=%s&quality=%s' % (video_id, key, 'mp4_' + q))
  61. config_req.add_header('Referer', url)
  62. config = self._download_webpage(config_req, video_id, 'Downloading video config ' + q.upper())
  63. data = json.loads(_decrypt_config(key, config))
  64. title = clean_html(data['videoData']['title'])
  65. duration = data['videoData']['duration'] / 1000
  66. for i, v in enumerate(data['files']['videos']):
  67. formats.append({
  68. 'url': v,
  69. 'format_id': determine_ext(v) + '_' + q + str(i),
  70. 'quality': quality(q),
  71. })
  72. return {
  73. 'id': video_id,
  74. 'formats': formats,
  75. 'title': title,
  76. 'thumbnail': self._og_search_thumbnail(webpage),
  77. 'description': self._og_search_description(webpage),
  78. 'duration': duration,
  79. }