Updated readme regarding cookies. Added --session-auth cookie option. Fixed #32, Fixed #37, Fixed #30

This commit is contained in:
Eddy Hintze
2021-02-14 14:51:40 +00:00
parent b335e35242
commit c451d407d8
3 changed files with 34 additions and 17 deletions

View File

@@ -25,10 +25,14 @@ def cli():
'download',
help="Download content in your humble bundle library",
)
parser_download.add_argument(
cookie = parser_download.add_mutually_exclusive_group(required=True)
cookie.add_argument(
'-c', '--cookie-file', type=str,
help="Location of the cookies file",
required=True,
)
cookie.add_argument(
'-s', '--session-auth', type=str,
help="Value of the cookie _simpleauth_sess. WRAP IN QUOTES",
)
parser_download.add_argument(
'-l', '--library-path', type=str,
@@ -80,8 +84,9 @@ def cli():
# Still keep the download action to keep compatibility
from .download_library import DownloadLibrary
DownloadLibrary(
cli_args.cookie_file,
cli_args.library_path,
cookie_path=cli_args.cookie_file,
cookie_auth=cli_args.session_auth,
progress_bar=cli_args.progress,
ext_include=cli_args.include,
ext_exclude=cli_args.exclude,

View File

@@ -23,9 +23,10 @@ def _clean_name(dirty_str):
class DownloadLibrary:
def __init__(self, cookie_path, library_path, progress_bar=False,
ext_include=None, ext_exclude=None, platform_include=None,
purchase_keys=None, trove=False, update=False):
def __init__(self, library_path, cookie_path=None, cookie_auth=None,
progress_bar=False, ext_include=None, ext_exclude=None,
platform_include=None, purchase_keys=None, trove=False,
update=False):
self.library_path = library_path
self.progress_bar = progress_bar
self.ext_include = [] if ext_include is None else list(map(str.lower, ext_include)) # noqa: E501
@@ -42,14 +43,19 @@ class DownloadLibrary:
self.update = update
self.session = requests.Session()
try:
cookie_jar = http.cookiejar.MozillaCookieJar(cookie_path)
cookie_jar.load()
self.session.cookies = cookie_jar
except http.cookiejar.LoadError:
# Still support the original cookie method
with open(cookie_path, 'r') as f:
self.session.headers.update({'cookie': f.read().strip()})
if cookie_path:
try:
cookie_jar = http.cookiejar.MozillaCookieJar(cookie_path)
cookie_jar.load()
self.session.cookies = cookie_jar
except http.cookiejar.LoadError:
# Still support the original cookie method
with open(cookie_path, 'r') as f:
self.session.headers.update({'cookie': f.read().strip()})
elif cookie_auth:
self.session.headers.update(
{'cookie': '_simpleauth_sess={}'.format(cookie_auth)}
)
def start(self):