vidto.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. import time
  5. from ..utils import encode_dict
  6. from ..compat import (
  7. compat_urllib_request,
  8. compat_urllib_parse
  9. )
  10. class VidtoIE(InfoExtractor):
  11. IE_NAME = 'vidto'
  12. IE_DESC = 'VidTo.me'
  13. _VALID_URL = r'https?://(?:www\.)?vidto\.me/(?P<id>[0-9a-zA-Z]+)\.html'
  14. _HOST = 'vidto.me'
  15. _TEST = {
  16. 'url': 'http://vidto.me/ku5glz52nqe1.html',
  17. 'info_dict': {
  18. 'id': 'ku5glz52nqe1',
  19. 'ext': 'mp4',
  20. 'title': 'test.mp4'
  21. }
  22. }
  23. def _real_extract(self, url):
  24. video_id = self._match_id(url)
  25. page = self._download_webpage(
  26. 'http://%s/%s.html' % (self._HOST, video_id), video_id, 'Downloading video page')
  27. hash_regex = r'<input type="hidden" name="hash" value="(.*)">'
  28. hash_value = self._search_regex(hash_regex, page, 'hash', fatal=True)
  29. title_regex = r'<input type="hidden" name="fname" value="(.*)">'
  30. title = self._search_regex(title_regex, page, 'title', fatal=False)
  31. id_regex = r'<input type="hidden" name="id" value="(.*)">'
  32. id_value = self._search_regex(id_regex, page, 'id', fatal=True)
  33. cookies = self._get_cookies('http://%s/%s.html' % (self._HOST, video_id))
  34. form_str = {
  35. 'op': 'download1',
  36. 'imhuman': 'Proceed to video',
  37. 'usr_login': '',
  38. 'id': id_value,
  39. 'fname': title,
  40. 'referer': '',
  41. 'hash': hash_value,
  42. }
  43. post_data = compat_urllib_parse.urlencode(encode_dict(form_str)).encode('ascii')
  44. req = compat_urllib_request.Request(url, post_data)
  45. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  46. cookie_string = ""
  47. for key in cookies.keys():
  48. cookie_string += "%s=%s;" % (key, cookies[key].value)
  49. req.add_header('Cookie', '%s' % cookie_string)
  50. self.to_screen("Waiting for countdown...")
  51. time.sleep(7)
  52. post_result = self._download_webpage(
  53. req, video_id,
  54. note='Proceed to video...', errnote='unable to proceed', fatal=True)
  55. file_link_regex = r'file_link\s*=\s*\'(https?:\/\/[0-9a-zA-z.\/\-_]+)'
  56. file_link = self._search_regex(file_link_regex, post_result, 'file_link', fatal=True)
  57. return {
  58. 'id': video_id,
  59. 'url': file_link,
  60. 'title': title,
  61. }