openload.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. first_char = int(ol_id[0])
  69. urlcode = []
  70. num = 1
  71. while num < len(ol_id):
  72. i = ord(ol_id[num])
  73. key = 0
  74. if i <= 90:
  75. key = i - 65
  76. elif i >= 97:
  77. key = 25 + i - 97
  78. urlcode.append((key, compat_chr(int(ol_id[num + 2:num + 5]) // int(ol_id[num + 1]) - first_char)))
  79. num += 5
  80. video_url = 'https://openload.co/stream/' + ''.join(
  81. [value for _, value in sorted(urlcode, key=lambda x: x[0])])
  82. title = self._og_search_title(webpage, default=None) or self._search_regex(
  83. r'<span[^>]+class=["\']title["\'][^>]*>([^<]+)', webpage,
  84. 'title', default=None) or self._html_search_meta(
  85. 'description', webpage, 'title', fatal=True)
  86. entries = self._parse_html5_media_entries(url, webpage, video_id)
  87. subtitles = entries[0]['subtitles'] if entries else None
  88. info_dict = {
  89. 'id': video_id,
  90. 'title': title,
  91. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  92. 'url': video_url,
  93. # Seems all videos have extensions in their titles
  94. 'ext': determine_ext(title, 'mp4'),
  95. 'subtitles': subtitles,
  96. }
  97. return info_dict