openload.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_chr
  6. from ..utils import (
  7. determine_ext,
  8. ExtractorError,
  9. )
  10. class OpenloadIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:openload\.(?:co|io)|oload\.tv)/(?:f|embed)/(?P<id>[a-zA-Z0-9-_]+)'
  12. _TESTS = [{
  13. 'url': 'https://openload.co/f/kUEfGclsU9o',
  14. 'md5': 'bf1c059b004ebc7a256f89408e65c36e',
  15. 'info_dict': {
  16. 'id': 'kUEfGclsU9o',
  17. 'ext': 'mp4',
  18. 'title': 'skyrim_no-audio_1080.mp4',
  19. 'thumbnail': r're:^https?://.*\.jpg$',
  20. },
  21. }, {
  22. 'url': 'https://openload.co/embed/rjC09fkPLYs',
  23. 'info_dict': {
  24. 'id': 'rjC09fkPLYs',
  25. 'ext': 'mp4',
  26. 'title': 'movie.mp4',
  27. 'thumbnail': r're:^https?://.*\.jpg$',
  28. 'subtitles': {
  29. 'en': [{
  30. 'ext': 'vtt',
  31. }],
  32. },
  33. },
  34. 'params': {
  35. 'skip_download': True, # test subtitles only
  36. },
  37. }, {
  38. 'url': 'https://openload.co/embed/kUEfGclsU9o/skyrim_no-audio_1080.mp4',
  39. 'only_matching': True,
  40. }, {
  41. 'url': 'https://openload.io/f/ZAn6oz-VZGE/',
  42. 'only_matching': True,
  43. }, {
  44. 'url': 'https://openload.co/f/_-ztPaZtMhM/',
  45. 'only_matching': True,
  46. }, {
  47. # unavailable via https://openload.co/f/Sxz5sADo82g/, different layout
  48. # for title and ext
  49. 'url': 'https://openload.co/embed/Sxz5sADo82g/',
  50. 'only_matching': True,
  51. }, {
  52. 'url': 'https://oload.tv/embed/KnG-kKZdcfY/',
  53. 'only_matching': True,
  54. }]
  55. @staticmethod
  56. def _extract_urls(webpage):
  57. return re.findall(
  58. r'<iframe[^>]+src=["\']((?:https?://)?(?:openload\.(?:co|io)|oload\.tv)/embed/[a-zA-Z0-9-_]+)',
  59. webpage)
  60. def _real_extract(self, url):
  61. video_id = self._match_id(url)
  62. webpage = self._download_webpage('https://openload.co/embed/%s/' % video_id, video_id)
  63. if 'File not found' in webpage or 'deleted by the owner' in webpage:
  64. raise ExtractorError('File not found', expected=True)
  65. ol_id = self._search_regex(
  66. '<span[^>]+id="[^"]+"[^>]*>([0-9A-Za-z]+)</span>',
  67. webpage, 'openload ID')
  68. video_url_chars = []
  69. first_char = ord(ol_id[0])
  70. key = first_char - 50
  71. maxKey = max(2, key)
  72. key = min(maxKey, len(ol_id) - 22)
  73. t = ol_id[key:key + 20]
  74. hashMap = {}
  75. v = ol_id.replace(t, "")
  76. h = 0
  77. while h < len(t):
  78. f = t[h:h + 2]
  79. i = int(f, 16)
  80. hashMap[h / 2] = i
  81. h += 2
  82. h = 0
  83. while h < len(v):
  84. B = v[h:h + 2]
  85. i = int(B, 16)
  86. index = (h / 2) % 10
  87. A = hashMap[index]
  88. i = i ^ 137
  89. i = i ^ A
  90. video_url_chars.append(compat_chr(i))
  91. h += 2
  92. video_url = 'https://openload.co/stream/%s?mime=true'
  93. video_url = video_url % (''.join(video_url_chars))
  94. title = self._og_search_title(webpage, default=None) or self._search_regex(
  95. r'<span[^>]+class=["\']title["\'][^>]*>([^<]+)', webpage,
  96. 'title', default=None) or self._html_search_meta(
  97. 'description', webpage, 'title', fatal=True)
  98. entries = self._parse_html5_media_entries(url, webpage, video_id)
  99. subtitles = entries[0]['subtitles'] if entries else None
  100. info_dict = {
  101. 'id': video_id,
  102. 'title': title,
  103. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  104. 'url': video_url,
  105. # Seems all videos have extensions in their titles
  106. 'ext': determine_ext(title, 'mp4'),
  107. 'subtitles': subtitles,
  108. }
  109. return info_dict