Skip to content

Commit

Permalink
set header data at the beginning of function
Browse files Browse the repository at this point in the history
  • Loading branch information
kanishka-linux committed Jul 12, 2019
1 parent 34e3a8f commit 5de8234
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions kawaii_player/get_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@ def ccurl(url, external_cookie=None, user_auth=None, verify_peer=None,
nUrl = url
postfield = ''
legacy = True
if hdr_data and isinstance(hdr_data, dict) and len(hdr_data) > 0:
c.setopt(c.HTTPHEADER, [k+': '+v for k,v in hdr_data.items()])
else:
c.setopt(c.USERAGENT, hdr)
if '#' in url and legacy:
curl_opt = nUrl.split('#')[1]
url = nUrl.split('#')[0]
Expand Down Expand Up @@ -515,11 +519,9 @@ def ccurl(url, external_cookie=None, user_auth=None, verify_peer=None,
else:
pass
if verify_peer is False:
print(verify_peer,'--verify-peer-')
c.setopt(c.SSL_VERIFYPEER, False)
if curl_opt == '-o':
c.setopt(c.FOLLOWLOCATION, True)
c.setopt(c.USERAGENT, hdr)
if cookie_file:
c.setopt(c.COOKIEFILE, cookie_file)
try:
Expand All @@ -544,27 +546,23 @@ def ccurl(url, external_cookie=None, user_auth=None, verify_peer=None,
else:
if curl_opt == '-I':
c.setopt(c.FOLLOWLOCATION, True)
c.setopt(c.USERAGENT, hdr)
c.setopt(c.NOBODY, 1)
c.setopt(c.HEADERFUNCTION, storage.write)
elif curl_opt == '-Ie':
c.setopt(c.FOLLOWLOCATION, True)
c.setopt(c.USERAGENT, hdr)
c.setopt(pycurl.REFERER, rfr)
c.setopt(c.NOBODY, 1)
c.setopt(c.HEADERFUNCTION, storage.write)
elif curl_opt == '-e':
c.setopt(c.FOLLOWLOCATION, True)
c.setopt(pycurl.REFERER, rfr)
c.setopt(c.USERAGENT, hdr)
c.setopt(c.WRITEDATA, storage)
elif curl_opt == '-IA':
c.setopt(c.FOLLOWLOCATION, True)
c.setopt(c.NOBODY, 1)
c.setopt(c.HEADERFUNCTION, storage.write)
elif curl_opt == '-Icb':
c.setopt(c.FOLLOWLOCATION, True)
c.setopt(c.USERAGENT, hdr)
c.setopt(c.NOBODY, 1)
c.setopt(c.HEADERFUNCTION, storage.write)
if os.path.exists(cookie_file):
Expand All @@ -573,52 +571,42 @@ def ccurl(url, external_cookie=None, user_auth=None, verify_peer=None,
c.setopt(c.COOKIEFILE, cookie_file)
elif curl_opt == '-Ib':
c.setopt(c.FOLLOWLOCATION, True)
c.setopt(c.USERAGENT, hdr)
c.setopt(c.NOBODY, 1)
c.setopt(c.HEADERFUNCTION, storage.write)
if os.path.exists(cookie_file):
os.remove(cookie_file)
c.setopt(c.COOKIEFILE, cookie_file)
elif curl_opt == '-bc':
c.setopt(c.FOLLOWLOCATION, True)
c.setopt(c.USERAGENT, hdr)
c.setopt(c.WRITEDATA, storage)
c.setopt(c.COOKIEJAR, cookie_file)
c.setopt(c.COOKIEFILE, cookie_file)
elif curl_opt == '-L':
c.setopt(c.USERAGENT, hdr)
c.setopt(c.WRITEDATA, storage)
elif curl_opt == '-H':
c.setopt(c.USERAGENT, hdr)
if hdr_data and isinstance(hdr_data, dict) and len(hdr_data) > 0:
#c.setopt(c.HEADER, True)
c.setopt(c.HTTPHEADER, [k+': '+v for k,v in hdr_data.items()])
c.setopt(c.WRITEDATA, storage)
else:
c.setopt(c.NOBODY, 1)
c.setopt(c.HEADERFUNCTION, storage.write)
elif curl_opt == '-d':
c.setopt(c.USERAGENT, hdr)
c.setopt(c.WRITEDATA, storage)
c.setopt(c.POSTFIELDS, postfield)
elif curl_opt == '-postfile':
c.setopt(c.USERAGENT, hdr)
c.setopt(c.POST, 1)
c.setopt(c.HTTPPOST, [("parameters",(c.FORM_FILE, post_data))])
c.setopt(c.WRITEDATA, storage)
elif curl_opt == '-b':
c.setopt(c.FOLLOWLOCATION, True)
c.setopt(c.USERAGENT, hdr)
c.setopt(c.WRITEDATA, storage)
c.setopt(c.COOKIEFILE, cookie_file)
elif curl_opt == '-c':
c.setopt(c.FOLLOWLOCATION, True)
c.setopt(c.USERAGENT, hdr)
c.setopt(c.WRITEDATA, storage)
c.setopt(c.COOKIEJAR, cookie_file)
else:
c.setopt(c.FOLLOWLOCATION, True)
c.setopt(c.USERAGENT, hdr)
c.setopt(c.WRITEDATA, storage)
try:
if user_auth is not None:
Expand Down

0 comments on commit 5de8234

Please sign in to comment.