From a59381c364c4b7d057c8a6160b0952c823eea3a0 Mon Sep 17 00:00:00 2001 From: Vitaly Strizhenok Date: Tue, 30 Apr 2019 18:29:19 +0300 Subject: [PATCH] added CAUTH parameter for command line --- README.md | 2 ++ coursera/commandline.py | 10 +++++++++- coursera/coursera_dl.py | 5 ++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a0059f8..1d102be 100644 --- a/README.md +++ b/README.md @@ -280,6 +280,8 @@ class names, as well as any additional parameters: General: coursera-dl -u -p modelthinking-004 + With CAUTH parameter: coursera-dl -ca 'some-ca-value-from-browser' modelthinking-004 + If you don't want to type your password in command line as plain text, you can use the script without `-p` option. In this case you will be prompted for password once the script is run. Without -p field: coursera-dl -u modelthinking-004 diff --git a/coursera/commandline.py b/coursera/commandline.py index 9047b0a..2fd80d7 100644 --- a/coursera/commandline.py +++ b/coursera/commandline.py @@ -341,6 +341,14 @@ def parse_args(args=None): group_adv_auth = parser.add_argument_group( 'Advanced authentication options') + group_adv_auth.add_argument( + '-ca', + '--cauth', + dest='cookies_cauth', + action='store', + default=None, + help='cauth cookie value from browser') + group_adv_auth.add_argument( '-c', '--cookies_file', @@ -492,7 +500,7 @@ def parse_args(args=None): logging.error('Cookies file not found: %s', args.cookies_file) sys.exit(1) - if not args.cookies_file: + if not args.cookies_file and not args.cookies_cauth: try: args.username, args.password = get_credentials( username=args.username, password=args.password, diff --git a/coursera/coursera_dl.py b/coursera/coursera_dl.py index 8b7c204..64a48db 100644 --- a/coursera/coursera_dl.py +++ b/coursera/coursera_dl.py @@ -233,7 +233,10 @@ def main(): return session = get_session() - login(session, args.username, args.password) + if args.cookies_cauth: + session.cookies.set('CAUTH', args.cookies_cauth) + else: + login(session, args.username, args.password) if args.specialization: args.class_names = expand_specializations(session, args.class_names)