vidto.py 2.4 KB

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