logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

vodlocker.py (2796B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. NO_DEFAULT,
  7. sanitized_Request,
  8. urlencode_postdata,
  9. )
  10. class VodlockerIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?vodlocker\.(?:com|city)/(?:embed-)?(?P<id>[0-9a-zA-Z]+)(?:\..*?)?'
  12. _TESTS = [{
  13. 'url': 'http://vodlocker.com/e8wvyzz4sl42',
  14. 'md5': 'ce0c2d18fa0735f1bd91b69b0e54aacf',
  15. 'info_dict': {
  16. 'id': 'e8wvyzz4sl42',
  17. 'ext': 'mp4',
  18. 'title': 'Germany vs Brazil',
  19. 'thumbnail': r're:http://.*\.jpg',
  20. },
  21. }]
  22. def _real_extract(self, url):
  23. video_id = self._match_id(url)
  24. webpage = self._download_webpage(url, video_id)
  25. if any(p in webpage for p in (
  26. '>THIS FILE WAS DELETED<',
  27. '>File Not Found<',
  28. 'The file you were looking for could not be found, sorry for any inconvenience.<',
  29. '>The file was removed')):
  30. raise ExtractorError('Video %s does not exist' % video_id, expected=True)
  31. fields = self._hidden_inputs(webpage)
  32. if fields['op'] == 'download1':
  33. self._sleep(3, video_id) # they do detect when requests happen too fast!
  34. post = urlencode_postdata(fields)
  35. req = sanitized_Request(url, post)
  36. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  37. webpage = self._download_webpage(
  38. req, video_id, 'Downloading video page')
  39. def extract_file_url(html, default=NO_DEFAULT):
  40. return self._search_regex(
  41. r'file:\s*"(http[^\"]+)",', html, 'file url', default=default)
  42. video_url = extract_file_url(webpage, default=None)
  43. if not video_url:
  44. embed_url = self._search_regex(
  45. r'<iframe[^>]+src=(["\'])(?P<url>(?:https?://)?vodlocker\.(?:com|city)/embed-.+?)\1',
  46. webpage, 'embed url', group='url')
  47. embed_webpage = self._download_webpage(
  48. embed_url, video_id, 'Downloading embed webpage')
  49. video_url = extract_file_url(embed_webpage)
  50. thumbnail_webpage = embed_webpage
  51. else:
  52. thumbnail_webpage = webpage
  53. title = self._search_regex(
  54. r'id="file_title".*?>\s*(.*?)\s*<(?:br|span)', webpage, 'title')
  55. thumbnail = self._search_regex(
  56. r'image:\s*"(http[^\"]+)",', thumbnail_webpage, 'thumbnail', fatal=False)
  57. formats = [{
  58. 'format_id': 'sd',
  59. 'url': video_url,
  60. }]
  61. return {
  62. 'id': video_id,
  63. 'title': title,
  64. 'thumbnail': thumbnail,
  65. 'formats': formats,
  66. }