From 2edaba449db55fc0f8bb6873840272287e5bfece Mon Sep 17 00:00:00 2001 From: Ludwig Lehnert Date: Sun, 16 Feb 2025 09:01:07 +0100 Subject: [PATCH] using curl now --- dl | 10 ++++++++++ dl.py | 22 +++++++++++++--------- lib.py | 14 +++++++------- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/dl b/dl index 3a28b50..7c7eb03 100755 --- a/dl +++ b/dl @@ -2,6 +2,16 @@ set DIR (cd (dirname (status -f)); and pwd) +if ! type -q curl + echo "curl is required to run this script" + exit +end + +if ! type -q ffmpeg + echo "ffmpeg is required to run this script" + exit +end + if ! test -d "$DIR/venv" /bin/env python3 -m venv "$DIR/venv" . "$DIR/venv/bin/activate.fish" diff --git a/dl.py b/dl.py index 8d05d89..eafb394 100644 --- a/dl.py +++ b/dl.py @@ -28,18 +28,22 @@ def parse_args(): def main(): args = parse_args() - if not args.no_auth and args.auth_token and args.session_id and args.session_ci: - set_token(args.auth_token, args.session_id, args.session_ci) - elif not args.no_auth: - load_token(args.starter_url) + try: + if not args.no_auth and args.auth_token and args.session_id and args.session_ci: + set_token(args.auth_token, args.session_id, args.session_ci) + elif not args.no_auth: + load_token(args.starter_url) - os.makedirs(args.out_dir, exist_ok=True) + os.makedirs(args.out_dir, exist_ok=True) - for index, clip_id in enumerate(get_course_clip_ids(args.course_id)): - if index < args.start_at - 1: - continue + for index, clip_id in enumerate(get_course_clip_ids(args.course_id)): + if index < args.start_at - 1: + continue - download_clip(clip_id, f'{args.out_dir}/{index+1: 04d}_{clip_id}.mp4') + download_clip( + clip_id, f'{args.out_dir}/{index+1: 04d}_{clip_id}.mp4') + except KeyboardInterrupt: + pass if __name__ == '__main__': diff --git a/lib.py b/lib.py index 2ccff9a..612a9cf 100644 --- a/lib.py +++ b/lib.py @@ -147,14 +147,14 @@ def download_media(media_id: str, outfile_path: str): url = f'https://itunes.video.uni-erlangen.de/get/file/' + \ str(media_id) + '?download=1' - with requests.get(url, stream=True, cookies=_cookies()) as r: - if (r.status_code != 200): - return False + cookie_args = [] + if len(_cookies()) > 0: + for key, value in _cookies().items(): + cookie_args.append('--cookie') + cookie_args.append(f'{key}={value}') - with open(outfile_path, 'wb') as f: - shutil.copyfileobj(r.raw, f) - - return True + status = subprocess.call(['curl', '-o', outfile_path, url] + cookie_args) + return status == 0 def download_playlist(playlist_url: str, outfile_path: str):