vodlocker.py 2.0 KB

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