mirror of
https://github.com/soimort/you-get.git
synced 2025-01-24 05:55:02 +03:00
[common] support both cookies.txt and cookies.sqlite
This commit is contained in:
parent
1496c77978
commit
ede432659c
@ -21,7 +21,6 @@ force = False
|
|||||||
player = None
|
player = None
|
||||||
extractor_proxy = None
|
extractor_proxy = None
|
||||||
cookies = None
|
cookies = None
|
||||||
cookies_txt = None
|
|
||||||
|
|
||||||
fake_headers = {
|
fake_headers = {
|
||||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
||||||
@ -152,6 +151,11 @@ def undeflate(data):
|
|||||||
|
|
||||||
# DEPRECATED in favor of get_content()
|
# DEPRECATED in favor of get_content()
|
||||||
def get_response(url, faker = False):
|
def get_response(url, faker = False):
|
||||||
|
# install cookies
|
||||||
|
if cookies:
|
||||||
|
opener = request.build_opener(request.HTTPCookieProcessor(cookies))
|
||||||
|
request.install_opener(opener)
|
||||||
|
|
||||||
if faker:
|
if faker:
|
||||||
response = request.urlopen(request.Request(url, headers = fake_headers), None)
|
response = request.urlopen(request.Request(url, headers = fake_headers), None)
|
||||||
else:
|
else:
|
||||||
@ -199,8 +203,8 @@ def get_content(url, headers={}, decoded=True):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
req = request.Request(url, headers=headers)
|
req = request.Request(url, headers=headers)
|
||||||
if cookies_txt:
|
if cookies:
|
||||||
cookies_txt.add_cookie_header(req)
|
cookies.add_cookie_header(req)
|
||||||
req.headers.update(req.unredirected_hdrs)
|
req.headers.update(req.unredirected_hdrs)
|
||||||
response = request.urlopen(req)
|
response = request.urlopen(req)
|
||||||
data = response.read()
|
data = response.read()
|
||||||
@ -894,7 +898,6 @@ def script_main(script_name, download, download_playlist = None):
|
|||||||
global player
|
global player
|
||||||
global extractor_proxy
|
global extractor_proxy
|
||||||
global cookies
|
global cookies
|
||||||
global cookies_txt
|
|
||||||
|
|
||||||
info_only = False
|
info_only = False
|
||||||
playlist = False
|
playlist = False
|
||||||
@ -925,24 +928,26 @@ def script_main(script_name, download, download_playlist = None):
|
|||||||
dry_run = True
|
dry_run = True
|
||||||
info_only = False
|
info_only = False
|
||||||
elif o in ('-c', '--cookies'):
|
elif o in ('-c', '--cookies'):
|
||||||
#cookies_txt = cookiejar.MozillaCookieJar(a)
|
try:
|
||||||
#cookies_txt.load()
|
cookies = cookiejar.MozillaCookieJar(a)
|
||||||
import sqlite3
|
cookies.load()
|
||||||
cookies = cookiejar.MozillaCookieJar(a)
|
except:
|
||||||
con = sqlite3.connect(a)
|
import sqlite3
|
||||||
cur = con.cursor()
|
cookies = cookiejar.MozillaCookieJar()
|
||||||
cur.execute("SELECT host, path, isSecure, expiry, name, value FROM moz_cookies")
|
con = sqlite3.connect(a)
|
||||||
for item in cur.fetchall():
|
cur = con.cursor()
|
||||||
c = cookiejar.Cookie(0, item[4], item[5],
|
cur.execute("SELECT host, path, isSecure, expiry, name, value FROM moz_cookies")
|
||||||
None, False,
|
for item in cur.fetchall():
|
||||||
item[0],
|
c = cookiejar.Cookie(0, item[4], item[5],
|
||||||
item[0].startswith('.'),
|
None, False,
|
||||||
item[0].startswith('.'),
|
item[0],
|
||||||
item[1], False,
|
item[0].startswith('.'),
|
||||||
item[2],
|
item[0].startswith('.'),
|
||||||
item[3], item[3]=="",
|
item[1], False,
|
||||||
None, None, {})
|
item[2],
|
||||||
cookies.set_cookie(c)
|
item[3], item[3]=="",
|
||||||
|
None, None, {})
|
||||||
|
cookies.set_cookie(c)
|
||||||
|
|
||||||
elif o in ('-l', '--playlist'):
|
elif o in ('-l', '--playlist'):
|
||||||
playlist = True
|
playlist = True
|
||||||
|
Loading…
Reference in New Issue
Block a user