escapist.py 3.5 KB

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