openload.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_chr
  5. from ..utils import (
  6. determine_ext,
  7. ExtractorError,
  8. )
  9. class OpenloadIE(InfoExtractor):
  10. _VALID_URL = r'https?://openload\.(?:co|io)/(?:f|embed)/(?P<id>[a-zA-Z0-9-_]+)'
  11. _TESTS = [{
  12. 'url': 'https://openload.co/f/kUEfGclsU9o',
  13. 'md5': 'bf1c059b004ebc7a256f89408e65c36e',
  14. 'info_dict': {
  15. 'id': 'kUEfGclsU9o',
  16. 'ext': 'mp4',
  17. 'title': 'skyrim_no-audio_1080.mp4',
  18. 'thumbnail': 're:^https?://.*\.jpg$',
  19. },
  20. }, {
  21. 'url': 'https://openload.co/embed/rjC09fkPLYs',
  22. 'info_dict': {
  23. 'id': 'rjC09fkPLYs',
  24. 'ext': 'mp4',
  25. 'title': 'movie.mp4',
  26. 'thumbnail': 're:^https?://.*\.jpg$',
  27. 'subtitles': {
  28. 'en': [{
  29. 'ext': 'vtt',
  30. }],
  31. },
  32. },
  33. 'params': {
  34. 'skip_download': True, # test subtitles only
  35. },
  36. }, {
  37. 'url': 'https://openload.co/embed/kUEfGclsU9o/skyrim_no-audio_1080.mp4',
  38. 'only_matching': True,
  39. }, {
  40. 'url': 'https://openload.io/f/ZAn6oz-VZGE/',
  41. 'only_matching': True,
  42. }, {
  43. 'url': 'https://openload.co/f/_-ztPaZtMhM/',
  44. 'only_matching': True,
  45. }, {
  46. # unavailable via https://openload.co/f/Sxz5sADo82g/, different layout
  47. # for title and ext
  48. 'url': 'https://openload.co/embed/Sxz5sADo82g/',
  49. 'only_matching': True,
  50. }]
  51. def _real_extract(self, url):
  52. video_id = self._match_id(url)
  53. webpage = self._download_webpage('https://openload.co/embed/%s/' % video_id, video_id)
  54. if 'File not found' in webpage or 'deleted by the owner' in webpage:
  55. raise ExtractorError('File not found', expected=True)
  56. ol_id = self._search_regex(
  57. '<span[^>]+id="[a-zA-Z0-9]+x"[^>]*>([0-9]+)</span>',
  58. webpage, 'openload ID')
  59. first_two_chars = int(float(ol_id[0:][:2]))
  60. urlcode = ''
  61. num = 2
  62. while num < len(ol_id):
  63. urlcode += compat_chr(int(float(ol_id[num:][:3])) -
  64. first_two_chars * int(float(ol_id[num + 3:][:2])))
  65. num += 5
  66. video_url = 'https://openload.co/stream/' + urlcode
  67. title = self._og_search_title(webpage, default=None) or self._search_regex(
  68. r'<span[^>]+class=["\']title["\'][^>]*>([^<]+)', webpage,
  69. 'title', default=None) or self._html_search_meta(
  70. 'description', webpage, 'title', fatal=True)
  71. entries = self._parse_html5_media_entries(url, webpage, video_id)
  72. subtitles = entries[0]['subtitles'] if entries else None
  73. info_dict = {
  74. 'id': video_id,
  75. 'title': title,
  76. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  77. 'url': video_url,
  78. # Seems all videos have extensions in their titles
  79. 'ext': determine_ext(title),
  80. 'subtitles': subtitles,
  81. }
  82. return info_dict