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.

108 lines
3.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals, division
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_chr,
  6. compat_ord,
  7. )
  8. from ..utils import (
  9. determine_ext,
  10. ExtractorError,
  11. )
  12. class OpenloadIE(InfoExtractor):
  13. _VALID_URL = r'https?://openload\.(?:co|io)/(?:f|embed)/(?P<id>[a-zA-Z0-9-_]+)'
  14. _TESTS = [{
  15. 'url': 'https://openload.co/f/kUEfGclsU9o',
  16. 'md5': 'bf1c059b004ebc7a256f89408e65c36e',
  17. 'info_dict': {
  18. 'id': 'kUEfGclsU9o',
  19. 'ext': 'mp4',
  20. 'title': 'skyrim_no-audio_1080.mp4',
  21. 'thumbnail': 're:^https?://.*\.jpg$',
  22. },
  23. }, {
  24. 'url': 'https://openload.co/embed/rjC09fkPLYs',
  25. 'info_dict': {
  26. 'id': 'rjC09fkPLYs',
  27. 'ext': 'mp4',
  28. 'title': 'movie.mp4',
  29. 'thumbnail': 're:^https?://.*\.jpg$',
  30. 'subtitles': {
  31. 'en': [{
  32. 'ext': 'vtt',
  33. }],
  34. },
  35. },
  36. 'params': {
  37. 'skip_download': True, # test subtitles only
  38. },
  39. }, {
  40. 'url': 'https://openload.co/embed/kUEfGclsU9o/skyrim_no-audio_1080.mp4',
  41. 'only_matching': True,
  42. }, {
  43. 'url': 'https://openload.io/f/ZAn6oz-VZGE/',
  44. 'only_matching': True,
  45. }, {
  46. 'url': 'https://openload.co/f/_-ztPaZtMhM/',
  47. 'only_matching': True,
  48. }, {
  49. # unavailable via https://openload.co/f/Sxz5sADo82g/, different layout
  50. # for title and ext
  51. 'url': 'https://openload.co/embed/Sxz5sADo82g/',
  52. 'only_matching': True,
  53. }]
  54. def _real_extract(self, url):
  55. video_id = self._match_id(url)
  56. webpage = self._download_webpage('https://openload.co/embed/%s/' % video_id, video_id)
  57. if 'File not found' in webpage or 'deleted by the owner' in webpage:
  58. raise ExtractorError('File not found', expected=True)
  59. # The following decryption algorithm is written by @yokrysty and
  60. # declared to be freely used in youtube-dl
  61. # See https://github.com/rg3/youtube-dl/issues/10408
  62. enc_data = self._html_search_regex(
  63. r'<span[^>]*>([^<]+)</span>\s*<span[^>]*>[^<]+</span>\s*<span[^>]+id="streamurl"',
  64. webpage, 'encrypted data')
  65. magic = compat_ord(enc_data[-1])
  66. video_url_chars = []
  67. for idx, c in enumerate(enc_data):
  68. j = compat_ord(c)
  69. if j == magic:
  70. j -= 1
  71. elif j == magic - 1:
  72. j += 1
  73. if j >= 33 and j <= 126:
  74. j = ((j + 14) % 94) + 33
  75. if idx == len(enc_data) - 1:
  76. j += 2
  77. video_url_chars += compat_chr(j)
  78. video_url = 'https://openload.co/stream/%s?mime=true' % ''.join(video_url_chars)
  79. title = self._og_search_title(webpage, default=None) or self._search_regex(
  80. r'<span[^>]+class=["\']title["\'][^>]*>([^<]+)', webpage,
  81. 'title', default=None) or self._html_search_meta(
  82. 'description', webpage, 'title', fatal=True)
  83. entries = self._parse_html5_media_entries(url, webpage, video_id)
  84. subtitles = entries[0]['subtitles'] if entries else None
  85. info_dict = {
  86. 'id': video_id,
  87. 'title': title,
  88. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  89. 'url': video_url,
  90. # Seems all videos have extensions in their titles
  91. 'ext': determine_ext(title),
  92. 'subtitles': subtitles,
  93. }
  94. return info_dict