vodlocker.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import re
  4. import time
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. determine_ext,
  8. compat_urllib_parse,
  9. compat_urllib_request,
  10. )
  11. class VodlockerIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?vodlocker.com/(?P<id>[0-9a-zA-Z]+)(?:\..*?)?'
  13. _TESTS = [{
  14. 'url': 'http://vodlocker.com/e8wvyzz4sl42',
  15. 'md5': 'ce0c2d18fa0735f1bd91b69b0e54aacf',
  16. 'info_dict': {
  17. 'id': 'e8wvyzz4sl42',
  18. 'ext': 'mp4',
  19. 'title': 'Germany vs Brazil',
  20. 'thumbnail': 're:http://.*\.jpg',
  21. },
  22. }]
  23. def _real_extract(self, url):
  24. mobj = re.match(self._VALID_URL, url)
  25. video_id = mobj.group('id')
  26. url = 'http://vodlocker.com/%s' % video_id
  27. webpage = self._download_webpage(url, video_id)
  28. fields = dict(re.findall(r'''(?x)<input\s+
  29. type="hidden"\s+
  30. name="([^"]+)"\s+
  31. (?:id="[^"]+"\s+)?
  32. value="([^"]*)"
  33. ''', webpage))
  34. if fields['op'] == 'download1':
  35. time.sleep(3) #they do detect when requests happen too fast!
  36. post = compat_urllib_parse.urlencode(fields)
  37. req = compat_urllib_request.Request(url, post)
  38. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  39. webpage = self._download_webpage(req, video_id, 'Downloading video page')
  40. title = self._search_regex(r'id="file_title".*?>\s*(.*?)\s*<span', webpage, 'title')
  41. thumbnail = self._search_regex(r'image:\s*"(http[^\"]+)",', webpage, 'thumbnail')
  42. url = self._search_regex(r'file:\s*"(http[^\"]+)",', webpage, 'file url')
  43. formats = [{
  44. 'format_id': 'sd',
  45. 'url': url,
  46. 'ext': determine_ext(url),
  47. 'quality': 1,
  48. }]
  49. return {
  50. 'id': video_id,
  51. 'title': title,
  52. 'thumbnail': thumbnail,
  53. 'formats': formats,
  54. }