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.

108 lines
3.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. determine_ext,
  7. ExtractorError,
  8. get_element_by_id,
  9. PhantomJSwrapper,
  10. )
  11. class OpenloadIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:openload\.(?:co|io)|oload\.tv)/(?:f|embed)/(?P<id>[a-zA-Z0-9-_]+)'
  13. _TESTS = [{
  14. 'url': 'https://openload.co/f/kUEfGclsU9o',
  15. 'md5': 'bf1c059b004ebc7a256f89408e65c36e',
  16. 'info_dict': {
  17. 'id': 'kUEfGclsU9o',
  18. 'ext': 'mp4',
  19. 'title': 'skyrim_no-audio_1080.mp4',
  20. 'thumbnail': r're:^https?://.*\.jpg$',
  21. },
  22. }, {
  23. 'url': 'https://openload.co/embed/rjC09fkPLYs',
  24. 'info_dict': {
  25. 'id': 'rjC09fkPLYs',
  26. 'ext': 'mp4',
  27. 'title': 'movie.mp4',
  28. 'thumbnail': r're:^https?://.*\.jpg$',
  29. 'subtitles': {
  30. 'en': [{
  31. 'ext': 'vtt',
  32. }],
  33. },
  34. },
  35. 'params': {
  36. 'skip_download': True, # test subtitles only
  37. },
  38. }, {
  39. 'url': 'https://openload.co/embed/kUEfGclsU9o/skyrim_no-audio_1080.mp4',
  40. 'only_matching': True,
  41. }, {
  42. 'url': 'https://openload.io/f/ZAn6oz-VZGE/',
  43. 'only_matching': True,
  44. }, {
  45. 'url': 'https://openload.co/f/_-ztPaZtMhM/',
  46. 'only_matching': True,
  47. }, {
  48. # unavailable via https://openload.co/f/Sxz5sADo82g/, different layout
  49. # for title and ext
  50. 'url': 'https://openload.co/embed/Sxz5sADo82g/',
  51. 'only_matching': True,
  52. }, {
  53. 'url': 'https://oload.tv/embed/KnG-kKZdcfY/',
  54. 'only_matching': True,
  55. }]
  56. _USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'
  57. @staticmethod
  58. def _extract_urls(webpage):
  59. return re.findall(
  60. r'<iframe[^>]+src=["\']((?:https?://)?(?:openload\.(?:co|io)|oload\.tv)/embed/[a-zA-Z0-9-_]+)',
  61. webpage)
  62. def _real_extract(self, url):
  63. video_id = self._match_id(url)
  64. url = 'https://openload.co/embed/%s/' % video_id
  65. headers = {
  66. 'User-Agent': self._USER_AGENT,
  67. }
  68. webpage = self._download_webpage(url, video_id, headers=headers)
  69. if 'File not found' in webpage or 'deleted by the owner' in webpage:
  70. raise ExtractorError('File not found', expected=True, video_id=video_id)
  71. phantom = PhantomJSwrapper(self)
  72. webpage, _ = phantom.get(url, html=webpage, video_id=video_id, headers=headers)
  73. decoded_id = get_element_by_id('streamurl', webpage)
  74. video_url = 'https://openload.co/stream/%s?mime=true' % decoded_id
  75. title = self._og_search_title(webpage, default=None) or self._search_regex(
  76. r'<span[^>]+class=["\']title["\'][^>]*>([^<]+)', webpage,
  77. 'title', default=None) or self._html_search_meta(
  78. 'description', webpage, 'title', fatal=True)
  79. entries = self._parse_html5_media_entries(url, webpage, video_id)
  80. entry = entries[0] if entries else {}
  81. subtitles = entry.get('subtitles')
  82. info_dict = {
  83. 'id': video_id,
  84. 'title': title,
  85. 'thumbnail': entry.get('thumbnail') or self._og_search_thumbnail(webpage, default=None),
  86. 'url': video_url,
  87. # Seems all videos have extensions in their titles
  88. 'ext': determine_ext(title, 'mp4'),
  89. 'subtitles': subtitles,
  90. 'http_headers': headers,
  91. }
  92. return info_dict