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.

107 lines
3.5 KiB

  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-9]+)</span>',
  67. webpage, 'openload ID')
  68. first_three_chars = int(float(ol_id[0:][:3]))
  69. fifth_char = int(float(ol_id[3:5]))
  70. urlcode = ''
  71. num = 5
  72. while num < len(ol_id):
  73. urlcode += compat_chr(int(float(ol_id[num:][:3])) +
  74. first_three_chars - fifth_char * int(float(ol_id[num + 3:][:2])))
  75. num += 5
  76. video_url = 'https://openload.co/stream/' + urlcode
  77. title = self._og_search_title(webpage, default=None) or self._search_regex(
  78. r'<span[^>]+class=["\']title["\'][^>]*>([^<]+)', webpage,
  79. 'title', default=None) or self._html_search_meta(
  80. 'description', webpage, 'title', fatal=True)
  81. entries = self._parse_html5_media_entries(url, webpage, video_id)
  82. subtitles = entries[0]['subtitles'] if entries else None
  83. info_dict = {
  84. 'id': video_id,
  85. 'title': title,
  86. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  87. 'url': video_url,
  88. # Seems all videos have extensions in their titles
  89. 'ext': determine_ext(title, 'mp4'),
  90. 'subtitles': subtitles,
  91. }
  92. return info_dict