1
0
mirror of https://github.com/l1ving/youtube-dl synced 2024-11-27 20:32:58 +08:00
youtube-dl/youtube_dl/extractor/vidto.py

73 lines
2.4 KiB
Python
Raw Normal View History

2015-10-14 17:11:52 +08:00
# coding: utf-8
from __future__ import unicode_literals
import time
from .common import InfoExtractor
2015-10-18 01:35:41 +08:00
from ..utils import encode_dict
2015-10-14 17:11:52 +08:00
from ..compat import (
compat_urllib_request,
2015-10-18 01:35:41 +08:00
compat_urllib_parse
2015-10-14 17:11:52 +08:00
)
class VidtoIE(InfoExtractor):
IE_NAME = 'vidto'
IE_DESC = 'VidTo.me'
_VALID_URL = r'https?://(?:www\.)?vidto\.me/(?P<id>[0-9a-zA-Z]+)\.html'
_HOST = 'vidto.me'
_TEST = {
'url': 'http://vidto.me/ku5glz52nqe1.html',
'info_dict': {
'id': 'ku5glz52nqe1',
'ext': 'mp4',
'title': 'test.mp4'
}
}
def _real_extract(self, url):
2015-10-18 01:35:41 +08:00
video_id = self._match_id(url)
2015-10-14 17:11:52 +08:00
page = self._download_webpage(
'http://%s/%s.html' % (self._HOST, video_id), video_id, 'Downloading video page')
hash_regex = r'<input type="hidden" name="hash" value="(.*)">'
hash_value = self._search_regex(hash_regex, page, 'hash', fatal=True)
title_regex = r'<input type="hidden" name="fname" value="(.*)">'
title = self._search_regex(title_regex, page, 'title', fatal=False)
id_regex = r'<input type="hidden" name="id" value="(.*)">'
id_value = self._search_regex(id_regex, page, 'id', fatal=True)
cookies = self._get_cookies('http://%s/%s.html' % (self._HOST, video_id))
form_str = {
'op': 'download1',
'imhuman': 'Proceed to video',
'usr_login': '',
'id': id_value,
'fname': title,
'referer': '',
'hash': hash_value,
}
post_data = compat_urllib_parse.urlencode(encode_dict(form_str)).encode('ascii')
req = compat_urllib_request.Request(url, post_data)
req.add_header('Content-type', 'application/x-www-form-urlencoded')
2015-10-18 01:35:41 +08:00
cookie_string = ""
for key in cookies.keys():
cookie_string += "%s=%s;" % (key, cookies[key].value)
req.add_header('Cookie', '%s' % cookie_string)
2015-10-14 17:11:52 +08:00
2015-10-18 01:35:41 +08:00
self.to_screen("Waiting for countdown...")
2015-10-14 17:11:52 +08:00
time.sleep(7)
post_result = self._download_webpage(
2015-10-18 01:35:41 +08:00
req, video_id,
note='Proceed to video...', errnote='unable to proceed')
2015-10-14 17:11:52 +08:00
2015-10-18 01:35:41 +08:00
file_link_regex = r'file_link\s*=\s*\'(https?:\/\/[0-9a-zA-z.\/\-_]+)'
file_link = self._search_regex(file_link_regex, post_result, 'file_link')
2015-10-14 17:11:52 +08:00
return {
'id': video_id,
'url': file_link,
'title': title,
}