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.

111 lines
3.5 KiB

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