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.

141 lines
4.2 KiB

  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 - 55
  71. maxKey = max(2, key)
  72. key = min(maxKey, len(ol_id) - 38)
  73. t = ol_id[key:key + 36]
  74. hashMap = {}
  75. v = ol_id.replace(t, '')
  76. h = 0
  77. while h < len(t):
  78. f = t[h:h + 3]
  79. i = int(f, 8)
  80. hashMap[h / 3] = i
  81. h += 3
  82. h = 0
  83. H = 0
  84. while h < len(v):
  85. B = ''
  86. C = ''
  87. if len(v) >= h + 2:
  88. B = v[h:h + 2]
  89. if len(v) >= h + 3:
  90. C = v[h:h + 3]
  91. i = int(B, 16)
  92. h += 2
  93. if H % 3 == 0:
  94. i = int(C, 8)
  95. h += 1
  96. elif H % 2 == 0 and H != 0 and ord(v[H - 1]) < 60:
  97. i = int(C, 10)
  98. h += 1
  99. index = H % 7
  100. A = hashMap[index]
  101. i ^= 213
  102. i ^= A
  103. video_url_chars.append(compat_chr(i))
  104. H += 1
  105. video_url = 'https://openload.co/stream/%s?mime=true'
  106. video_url = video_url % (''.join(video_url_chars))
  107. title = self._og_search_title(webpage, default=None) or self._search_regex(
  108. r'<span[^>]+class=["\']title["\'][^>]*>([^<]+)', webpage,
  109. 'title', default=None) or self._html_search_meta(
  110. 'description', webpage, 'title', fatal=True)
  111. entries = self._parse_html5_media_entries(url, webpage, video_id)
  112. subtitles = entries[0]['subtitles'] if entries else None
  113. info_dict = {
  114. 'id': video_id,
  115. 'title': title,
  116. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  117. 'url': video_url,
  118. # Seems all videos have extensions in their titles
  119. 'ext': determine_ext(title, 'mp4'),
  120. 'subtitles': subtitles,
  121. }
  122. return info_dict