diff --git a/README.md b/README.md index ca7cefc..2818c91 100644 --- a/README.md +++ b/README.md @@ -6,20 +6,24 @@ This software is provided without warranty. Usage is discouraged! Usage of this ## Usage ```bash -usage: dl [-h] [--outDir OUTDIR] [--starterUrl STARTERURL] - [--startAt STARTAT] - courseId +usage: dl.py [-h] [--out-dir OUT_DIR] [--starter=url STARTER=URL] [--start-at START_AT] [--auth-token AUTH_TOKEN] + [--session-id SESSION_ID] [--session-ci SESSION_CI] + course-id Download clips from a course positional arguments: - courseId Course ID + course-id Course ID options: - -h, --help show this help message and exit - --outDir OUTDIR Output directory - --starterUrl STARTERURL Starter URL - --startAt STARTAT Skip all previous indizes (starts at 1) + -h, --help show this help message and exit + --out-dir OUT_DIR Output directory + --starter=url STARTER=URL + Starter URL + --start-at START_AT Skip all previous indices (defaults to 1) + --auth-token AUTH_TOKEN + --session-id SESSION_ID + --session-ci SESSION_CI ``` ## Procedure diff --git a/dl b/dl index 9546d0d..3a28b50 100755 --- a/dl +++ b/dl @@ -1,39 +1,14 @@ -#!/usr/bin/env python3 -from lib import * -import sys -import os -import argparse +#!/bin/env fish +set DIR (cd (dirname (status -f)); and pwd) -def parse_args(): - parser = argparse.ArgumentParser( - description='Download clips from a course', - ) +if ! test -d "$DIR/venv" + /bin/env python3 -m venv "$DIR/venv" + . "$DIR/venv/bin/activate.fish" + /bin/env python3 -m pip install -r "$DIR/requirements.txt" + echo +else + . "$DIR/venv/bin/activate.fish" +end - parser.add_argument('courseId', type=str, help='Course ID') - parser.add_argument('--outDir', type=str, - help='Output directory', default='./out') - parser.add_argument('--starterUrl', type=str, - help='Starter URL', default="https://www.fau.tv/auth/sso") - parser.add_argument('--startAt', type=int, - help='Skip all previous indizes (starts at 1)', default=1) - - return parser.parse_args() - - -def main(): - args = parse_args() - - load_token(args.starterUrl) - - os.makedirs(args.outDir, exist_ok=True) - - for index, clip_id in enumerate(get_course_clip_ids(args.courseId)): - if index < args.startAt - 1: - continue - - download_clip(clip_id, f'{args.outDir}/{index+1: 04d}_{clip_id}.mp4') - - -if __name__ == '__main__': - main() +/bin/env python3 "$DIR/dl.py" $argv diff --git a/dl.py b/dl.py new file mode 100644 index 0000000..00c75fb --- /dev/null +++ b/dl.py @@ -0,0 +1,44 @@ +from lib import * +import os +import argparse + + +def parse_args(): + parser = argparse.ArgumentParser( + description='Download clips from a course', + ) + + parser.add_argument('course-id', type=str, help='Course ID') + parser.add_argument('--out-dir', type=str, + help='Output directory', default='./out') + parser.add_argument('--starter=url', type=str, + help='Starter URL', default="https://www.fau.tv/auth/sso") + parser.add_argument('--start-at', type=int, + help='Skip all previous indices (defaults to 1)', default=1) + + parser.add_argument('--auth-token', type=str) + parser.add_argument('--session-id', type=str) + parser.add_argument('--session-ci', type=str) + + return parser.parse_args() + + +def main(): + args = parse_args() + + if args.authToken and args.sessionID and args.sessionCI: + set_token(args.authToken, args.sessionID, args.sessionCI) + else: + load_token(args.starterUrl) + + os.makedirs(args.outDir, exist_ok=True) + + for index, clip_id in enumerate(get_course_clip_ids(args.courseId)): + if index < args.startAt - 1: + continue + + download_clip(clip_id, f'{args.outDir}/{index+1: 04d}_{clip_id}.mp4') + + +if __name__ == '__main__': + main() diff --git a/lib.py b/lib.py index b954f84..677eae4 100644 --- a/lib.py +++ b/lib.py @@ -1,4 +1,3 @@ -from selenium import webdriver import time from dataclasses import dataclass import requests @@ -57,9 +56,16 @@ class ClipDetails(): ] if url is not None] +def set_token(auth_token: str, session_id: str, session_ci: str): + global _token + _token = Token(auth_token, session_id, session_ci) + + def load_token(auth_url: str): global _token + from selenium import webdriver + driver = webdriver.Firefox() driver.get(auth_url) @@ -165,5 +171,6 @@ def download_clip(clip_id: str, outfile_path: str): if len(details.playlist_urls()) > 0: playlist_url = details.playlist_urls()[0] - print(f"Trying to download clip {clip_id} using playlist url {playlist_url}") + print( + f"Trying to download clip {clip_id} using playlist url {playlist_url}") download_playlist(playlist_url, outfile_path) diff --git a/pyvenv.cfg b/pyvenv.cfg deleted file mode 100644 index ec986ab..0000000 --- a/pyvenv.cfg +++ /dev/null @@ -1,5 +0,0 @@ -home = /usr/bin -include-system-site-packages = false -version = 3.12.4 -executable = /usr/bin/python3.12 -command = /usr/bin/python -m venv /home/ludwig/git/fau-tv-dl diff --git a/requirements.txt b/requirements.txt index fdd089e..ae62ce7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ selenium -requests \ No newline at end of file +requests