using curl now

This commit is contained in:
Ludwig Lehnert 2025-02-16 09:01:07 +01:00
parent e51a12a965
commit 2edaba449d
3 changed files with 30 additions and 16 deletions

10
dl
View File

@ -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"

22
dl.py
View File

@ -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__':

14
lib.py
View File

@ -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):