openload.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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[^>]+id="hiddenurl"[^>]*>([^<]+)</span>', webpage, 'encrypted data')
  48. video_url_chars = []
  49. for idx, c in enumerate(enc_data):
  50. j = compat_ord(c)
  51. if j >= 33 and j <= 126:
  52. j = ((j + 14) % 94) + 33
  53. if idx == len(enc_data) - 1:
  54. j += 2
  55. video_url_chars += compat_chr(j)
  56. video_url = 'https://openload.co/stream/%s?mime=true' % ''.join(video_url_chars)
  57. title = self._og_search_title(webpage, default=None) or self._search_regex(
  58. r'<span[^>]+class=["\']title["\'][^>]*>([^<]+)', webpage,
  59. 'title', default=None) or self._html_search_meta(
  60. 'description', webpage, 'title', fatal=True)
  61. return {
  62. 'id': video_id,
  63. 'title': title,
  64. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  65. 'url': video_url,
  66. # Seems all videos have extensions in their titles
  67. 'ext': determine_ext(title),
  68. }