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.

128 lines
4.0 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. decoded = ''
  69. a = ol_id[0:24]
  70. b = []
  71. for i in range(0, len(a), 8):
  72. b.append(int(a[i:i + 8] or '0', 16))
  73. ol_id = ol_id[24:]
  74. j = 0
  75. k = 0
  76. while j < len(ol_id):
  77. c = 128
  78. d = 0
  79. e = 0
  80. f = 0
  81. _more = True
  82. while _more:
  83. if j + 1 >= len(ol_id):
  84. c = 143
  85. f = int(ol_id[j:j + 2] or '0', 16)
  86. j += 2
  87. d += (f & 127) << e
  88. e += 7
  89. _more = f >= c
  90. g = d ^ b[k % 3]
  91. for i in range(4):
  92. char_dec = (g >> 8 * i) & (c + 127)
  93. char = compat_chr(char_dec)
  94. if char != '#':
  95. decoded += char
  96. k += 1
  97. video_url = 'https://openload.co/stream/%s?mime=true'
  98. video_url = video_url % decoded
  99. title = self._og_search_title(webpage, default=None) or self._search_regex(
  100. r'<span[^>]+class=["\']title["\'][^>]*>([^<]+)', webpage,
  101. 'title', default=None) or self._html_search_meta(
  102. 'description', webpage, 'title', fatal=True)
  103. entries = self._parse_html5_media_entries(url, webpage, video_id)
  104. subtitles = entries[0]['subtitles'] if entries else None
  105. info_dict = {
  106. 'id': video_id,
  107. 'title': title,
  108. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  109. 'url': video_url,
  110. # Seems all videos have extensions in their titles
  111. 'ext': determine_ext(title, 'mp4'),
  112. 'subtitles': subtitles,
  113. }
  114. return info_dict