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.

81 lines
2.7 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/kUEfGclsU9o/skyrim_no-audio_1080.mp4',
  25. 'only_matching': True,
  26. }, {
  27. 'url': 'https://openload.io/f/ZAn6oz-VZGE/',
  28. 'only_matching': True,
  29. }, {
  30. 'url': 'https://openload.co/f/_-ztPaZtMhM/',
  31. 'only_matching': True,
  32. }, {
  33. # unavailable via https://openload.co/f/Sxz5sADo82g/, different layout
  34. # for title and ext
  35. 'url': 'https://openload.co/embed/Sxz5sADo82g/',
  36. 'only_matching': True,
  37. }]
  38. def _real_extract(self, url):
  39. video_id = self._match_id(url)
  40. webpage = self._download_webpage('https://openload.co/embed/%s/' % video_id, video_id)
  41. if 'File not found' in webpage or 'deleted by the owner' in webpage:
  42. raise ExtractorError('File not found', expected=True)
  43. # The following decryption algorithm is written by @yokrysty and
  44. # declared to be freely used in youtube-dl
  45. # See https://github.com/rg3/youtube-dl/issues/10408
  46. enc_data = self._html_search_regex(
  47. r'<span[^>]*>([^<]+)</span>\s*<span[^>]*>[^<]+</span>\s*<span[^>]+id="streamurl"',
  48. webpage, 'encrypted data')
  49. video_url_chars = []
  50. for idx, c in enumerate(enc_data):
  51. j = compat_ord(c)
  52. if j >= 33 and j <= 126:
  53. j = ((j + 14) % 94) + 33
  54. if idx == len(enc_data) - 1:
  55. j += 2
  56. video_url_chars += compat_chr(j)
  57. video_url = 'https://openload.co/stream/%s?mime=true' % ''.join(video_url_chars)
  58. title = self._og_search_title(webpage, default=None) or self._search_regex(
  59. r'<span[^>]+class=["\']title["\'][^>]*>([^<]+)', webpage,
  60. 'title', default=None) or self._html_search_meta(
  61. 'description', webpage, 'title', fatal=True)
  62. return {
  63. 'id': video_id,
  64. 'title': title,
  65. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  66. 'url': video_url,
  67. # Seems all videos have extensions in their titles
  68. 'ext': determine_ext(title),
  69. }