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) 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" if ! test -d "$DIR/venv"
/bin/env python3 -m venv "$DIR/venv" /bin/env python3 -m venv "$DIR/venv"
. "$DIR/venv/bin/activate.fish" . "$DIR/venv/bin/activate.fish"

22
dl.py
View File

@ -28,18 +28,22 @@ def parse_args():
def main(): def main():
args = parse_args() args = parse_args()
if not args.no_auth and args.auth_token and args.session_id and args.session_ci: try:
set_token(args.auth_token, args.session_id, args.session_ci) if not args.no_auth and args.auth_token and args.session_id and args.session_ci:
elif not args.no_auth: set_token(args.auth_token, args.session_id, args.session_ci)
load_token(args.starter_url) 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)): for index, clip_id in enumerate(get_course_clip_ids(args.course_id)):
if index < args.start_at - 1: if index < args.start_at - 1:
continue 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__': 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/' + \ url = f'https://itunes.video.uni-erlangen.de/get/file/' + \
str(media_id) + '?download=1' str(media_id) + '?download=1'
with requests.get(url, stream=True, cookies=_cookies()) as r: cookie_args = []
if (r.status_code != 200): if len(_cookies()) > 0:
return False for key, value in _cookies().items():
cookie_args.append('--cookie')
cookie_args.append(f'{key}={value}')
with open(outfile_path, 'wb') as f: status = subprocess.call(['curl', '-o', outfile_path, url] + cookie_args)
shutil.copyfileobj(r.raw, f) return status == 0
return True
def download_playlist(playlist_url: str, outfile_path: str): def download_playlist(playlist_url: str, outfile_path: str):