mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-15 21:03:18 +00:00
[vidto] Several simplifications and improvements
1. Use InfoExtractor._hidden_inputs 2. Fetch title from <title> tag 3. Cookies are preserved automatically 4. Use single quotes everywhere 5. Do not declare variables for one-time use only
This commit is contained in:
parent
990e6e8fa3
commit
8b8a39e279
|
@ -4,24 +4,24 @@
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import encode_dict
|
from ..utils import (
|
||||||
from ..compat import (
|
encode_dict,
|
||||||
compat_urllib_request,
|
remove_end,
|
||||||
compat_urllib_parse
|
urlencode_postdata,
|
||||||
)
|
)
|
||||||
|
from ..compat import compat_urllib_request
|
||||||
|
|
||||||
|
|
||||||
class VidtoIE(InfoExtractor):
|
class VidtoIE(InfoExtractor):
|
||||||
IE_NAME = 'vidto'
|
IE_NAME = 'vidto'
|
||||||
IE_DESC = 'VidTo.me'
|
IE_DESC = 'VidTo.me'
|
||||||
_VALID_URL = r'https?://(?:www\.)?vidto\.me/(?P<id>[0-9a-zA-Z]+)\.html'
|
_VALID_URL = r'https?://(?:www\.)?vidto\.me/(?P<id>[0-9a-zA-Z]+)\.html'
|
||||||
_HOST = 'vidto.me'
|
|
||||||
_TEST = {
|
_TEST = {
|
||||||
'url': 'http://vidto.me/ku5glz52nqe1.html',
|
'url': 'http://vidto.me/ku5glz52nqe1.html',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': 'ku5glz52nqe1',
|
'id': 'ku5glz52nqe1',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'test.mp4'
|
'title': 'test'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,41 +29,26 @@ def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
|
|
||||||
page = self._download_webpage(
|
page = self._download_webpage(
|
||||||
'http://%s/%s.html' % (self._HOST, video_id), video_id, 'Downloading video page')
|
'http://vidto.me/%s.html' % 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 = {
|
title = remove_end(self._html_search_regex(
|
||||||
'op': 'download1',
|
r'<Title>\s*([^<]+)\s*</Title>', page, 'title'), ' - Vidto')
|
||||||
'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')
|
|
||||||
cookie_string = ""
|
|
||||||
for key in cookies.keys():
|
|
||||||
cookie_string += "%s=%s;" % (key, cookies[key].value)
|
|
||||||
|
|
||||||
req.add_header('Cookie', '%s' % cookie_string)
|
hidden_fields = self._hidden_inputs(page)
|
||||||
|
|
||||||
self.to_screen("Waiting for countdown...")
|
self.to_screen('Waiting for countdown...')
|
||||||
time.sleep(7)
|
time.sleep(7)
|
||||||
|
|
||||||
|
req = compat_urllib_request.Request(
|
||||||
|
url, urlencode_postdata(encode_dict(hidden_fields)))
|
||||||
|
req.add_header('Content-type', 'application/x-www-form-urlencoded')
|
||||||
|
|
||||||
post_result = self._download_webpage(
|
post_result = self._download_webpage(
|
||||||
req, video_id,
|
req, video_id,
|
||||||
note='Proceed to video...', errnote='unable to proceed')
|
note='Proceed to video...', errnote='unable to proceed')
|
||||||
|
|
||||||
file_link_regex = r'file_link\s*=\s*\'(https?:\/\/[0-9a-zA-z.\/\-_]+)'
|
file_link = self._search_regex(
|
||||||
file_link = self._search_regex(file_link_regex, post_result, 'file_link')
|
r'file_link\s*=\s*\'(https?:\/\/[0-9a-zA-z.\/\-_]+)', post_result, 'file_link')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
|
|
Loading…
Reference in a new issue