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.

123 lines
4.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals, division
  3. import math
  4. from .common import InfoExtractor
  5. from ..compat import compat_chr
  6. from ..utils import (
  7. decode_png,
  8. determine_ext,
  9. ExtractorError,
  10. )
  11. class OpenloadIE(InfoExtractor):
  12. _VALID_URL = r'https://openload.(?:co|io)/(?:f|embed)/(?P<id>[a-zA-Z0-9-_]+)'
  13. _TESTS = [{
  14. 'url': 'https://openload.co/f/kUEfGclsU9o',
  15. 'md5': 'bf1c059b004ebc7a256f89408e65c36e',
  16. 'info_dict': {
  17. 'id': 'kUEfGclsU9o',
  18. 'ext': 'mp4',
  19. 'title': 'skyrim_no-audio_1080.mp4',
  20. 'thumbnail': 're:^https?://.*\.jpg$',
  21. },
  22. }, {
  23. 'url': 'https://openload.co/embed/kUEfGclsU9o/skyrim_no-audio_1080.mp4',
  24. 'only_matching': True,
  25. }, {
  26. 'url': 'https://openload.io/f/ZAn6oz-VZGE/',
  27. 'only_matching': True,
  28. }, {
  29. 'url': 'https://openload.co/f/_-ztPaZtMhM/',
  30. 'only_matching': True,
  31. }, {
  32. # unavailable via https://openload.co/f/Sxz5sADo82g/, different layout
  33. # for title and ext
  34. 'url': 'https://openload.co/embed/Sxz5sADo82g/',
  35. 'only_matching': True,
  36. }]
  37. def _real_extract(self, url):
  38. video_id = self._match_id(url)
  39. webpage = self._download_webpage(url, video_id)
  40. if 'File not found' in webpage:
  41. raise ExtractorError('File not found', expected=True)
  42. # The following extraction logic is proposed by @Belderak and @gdkchan
  43. # and declared to be used freely in youtube-dl
  44. # See https://github.com/rg3/youtube-dl/issues/9706
  45. numbers_js = self._download_webpage(
  46. 'https://openload.co/assets/js/obfuscator/n.js', video_id,
  47. note='Downloading signature numbers')
  48. signums = self._search_regex(
  49. r'window\.signatureNumbers\s*=\s*[\'"](?P<data>[a-z]+)[\'"]',
  50. numbers_js, 'signature numbers', group='data')
  51. linkimg_uri = self._search_regex(
  52. r'<img[^>]+id="linkimg"[^>]+src="([^"]+)"', webpage, 'link image')
  53. linkimg = self._request_webpage(
  54. linkimg_uri, video_id, note=False).read()
  55. width, height, pixels = decode_png(linkimg)
  56. output = ''
  57. for y in range(height):
  58. for x in range(width):
  59. r, g, b = pixels[y][3 * x:3 * x + 3]
  60. if r == 0 and g == 0 and b == 0:
  61. break
  62. else:
  63. output += compat_chr(r)
  64. output += compat_chr(g)
  65. output += compat_chr(b)
  66. img_str_length = len(output) // 200
  67. img_str = [[0 for x in range(img_str_length)] for y in range(10)]
  68. sig_str_length = len(signums) // 260
  69. sig_str = [[0 for x in range(sig_str_length)] for y in range(10)]
  70. for i in range(10):
  71. for j in range(img_str_length):
  72. begin = i * img_str_length * 20 + j * 20
  73. img_str[i][j] = output[begin:begin + 20]
  74. for j in range(sig_str_length):
  75. begin = i * sig_str_length * 26 + j * 26
  76. sig_str[i][j] = signums[begin:begin + 26]
  77. parts = []
  78. # TODO: find better names for str_, chr_ and sum_
  79. str_ = ''
  80. for i in [2, 3, 5, 7]:
  81. str_ = ''
  82. sum_ = float(99)
  83. for j in range(len(sig_str[i])):
  84. for chr_idx in range(len(img_str[i][j])):
  85. if sum_ > float(122):
  86. sum_ = float(98)
  87. chr_ = compat_chr(int(math.floor(sum_)))
  88. if sig_str[i][j][chr_idx] == chr_ and j >= len(str_):
  89. sum_ += float(2.5)
  90. str_ += img_str[i][j][chr_idx]
  91. parts.append(str_.replace(',', ''))
  92. video_url = 'https://openload.co/stream/%s~%s~%s~%s' % (parts[3], parts[1], parts[2], parts[0])
  93. title = self._og_search_title(webpage, default=None) or self._search_regex(
  94. r'<span[^>]+class=["\']title["\'][^>]*>([^<]+)', webpage,
  95. 'title', default=None) or self._html_search_meta(
  96. 'description', webpage, 'title', fatal=True)
  97. return {
  98. 'id': video_id,
  99. 'title': title,
  100. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  101. 'url': video_url,
  102. # Seems all videos have extensions in their titles
  103. 'ext': determine_ext(title),
  104. }