mirror of
https://github.com/soimort/you-get.git
synced 2025-02-11 12:42:29 +03:00
Solve HTTP redirect
Hot fix this problem
This commit is contained in:
parent
100d1c5b75
commit
3503eb12da
@ -5,6 +5,28 @@ __all__ = ['tv66wz_download']
|
|||||||
|
|
||||||
from ..common import *
|
from ..common import *
|
||||||
import re
|
import re
|
||||||
|
import urllib.parse as urlparse
|
||||||
|
import http.client as httplib
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
def resolve_http_redirect(url, depth=0):
|
||||||
|
"""http://www.zacwitte.com/resolving-http-redirects-in-python
|
||||||
|
"""
|
||||||
|
if depth > 10:
|
||||||
|
raise Exception("Redirected "+depth+" times, giving up.")
|
||||||
|
o = urlparse.urlparse(url,allow_fragments=True)
|
||||||
|
conn = httplib.HTTPConnection(o.netloc)
|
||||||
|
path = o.path
|
||||||
|
if o.query:
|
||||||
|
path +='?'+o.query
|
||||||
|
conn.request("HEAD", path)
|
||||||
|
res = conn.getresponse()
|
||||||
|
headers = dict(res.getheaders())
|
||||||
|
if 'Location' in headers and headers['Location'] != url:
|
||||||
|
return resolve_http_redirect(headers['Location'], depth+1)
|
||||||
|
else:
|
||||||
|
return url
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def tv66wz_download(url, output_dir = '.', merge = False, info_only = False):
|
def tv66wz_download(url, output_dir = '.', merge = False, info_only = False):
|
||||||
@ -38,17 +60,15 @@ def tv66wz_download_by_id(id, title, output_dir = '.', merge = False, info_only
|
|||||||
|
|
||||||
p = re.compile(r'.+filevalue=(.+)&copyvalue')
|
p = re.compile(r'.+filevalue=(.+)&copyvalue')
|
||||||
for m in p.finditer(html):
|
for m in p.finditer(html):
|
||||||
url = m.group(1)
|
url_temp = m.group(1)
|
||||||
break
|
break
|
||||||
|
|
||||||
#print(url)
|
url = resolve_http_redirect(url_temp)
|
||||||
|
|
||||||
print('This will take very very long...')
|
|
||||||
|
|
||||||
type_, ext, size = url_info(url)
|
type_, ext, size = url_info(url)
|
||||||
print_info('66wz', title, 'flv', 0)
|
print_info('66wz', title, 'flv', size)
|
||||||
if not info_only:
|
if not info_only:
|
||||||
download_urls([url], title, 'flv', total_size=None, output_dir=output_dir, merge=merge)
|
download_urls([url], title, ext, total_size=None, output_dir=output_dir, merge=merge)
|
||||||
|
|
||||||
site_info = "66wz"
|
site_info = "66wz"
|
||||||
download = tv66wz_download
|
download = tv66wz_download
|
||||||
|
Loading…
Reference in New Issue
Block a user