refactoring
This commit is contained in:
		
							parent
							
								
									a20b0b27a8
								
							
						
					
					
						commit
						b32ae9fea7
					
				
							
								
								
									
										18
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								README.md
									
									
									
									
									
								
							@ -6,20 +6,24 @@ This software is provided without warranty. Usage is discouraged! Usage of this
 | 
				
			|||||||
## Usage
 | 
					## Usage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```bash
 | 
					```bash
 | 
				
			||||||
usage: dl [-h] [--outDir OUTDIR] [--starterUrl STARTERURL]
 | 
					usage: dl.py [-h] [--out-dir OUT_DIR] [--starter=url STARTER=URL] [--start-at START_AT] [--auth-token AUTH_TOKEN]
 | 
				
			||||||
          [--startAt STARTAT]
 | 
					             [--session-id SESSION_ID] [--session-ci SESSION_CI]
 | 
				
			||||||
          courseId
 | 
					             course-id
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Download clips from a course
 | 
					Download clips from a course
 | 
				
			||||||
 | 
					
 | 
				
			||||||
positional arguments:
 | 
					positional arguments:
 | 
				
			||||||
  courseId                  Course ID
 | 
					  course-id             Course ID
 | 
				
			||||||
 | 
					
 | 
				
			||||||
options:
 | 
					options:
 | 
				
			||||||
  -h, --help            show this help message and exit
 | 
					  -h, --help            show this help message and exit
 | 
				
			||||||
  --outDir OUTDIR           Output directory
 | 
					  --out-dir OUT_DIR     Output directory
 | 
				
			||||||
  --starterUrl STARTERURL   Starter URL
 | 
					  --starter=url STARTER=URL
 | 
				
			||||||
  --startAt STARTAT         Skip all previous indizes (starts at 1)
 | 
					                        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
 | 
					## Procedure
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										47
									
								
								dl
									
									
									
									
									
								
							
							
						
						
									
										47
									
								
								dl
									
									
									
									
									
								
							@ -1,39 +1,14 @@
 | 
				
			|||||||
#!/usr/bin/env python3
 | 
					#!/bin/env fish
 | 
				
			||||||
from lib import *
 | 
					 | 
				
			||||||
import sys
 | 
					 | 
				
			||||||
import os
 | 
					 | 
				
			||||||
import argparse
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					set DIR (cd (dirname (status -f)); and pwd)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def parse_args():
 | 
					if ! test -d "$DIR/venv"
 | 
				
			||||||
    parser = argparse.ArgumentParser(
 | 
					  /bin/env python3 -m venv "$DIR/venv"
 | 
				
			||||||
        description='Download clips from a course',
 | 
					  . "$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')
 | 
					/bin/env python3 "$DIR/dl.py" $argv
 | 
				
			||||||
    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()
 | 
					 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										44
									
								
								dl.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								dl.py
									
									
									
									
									
										Normal file
									
								
							@ -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()
 | 
				
			||||||
							
								
								
									
										11
									
								
								lib.py
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								lib.py
									
									
									
									
									
								
							@ -1,4 +1,3 @@
 | 
				
			|||||||
from selenium import webdriver
 | 
					 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
from dataclasses import dataclass
 | 
					from dataclasses import dataclass
 | 
				
			||||||
import requests
 | 
					import requests
 | 
				
			||||||
@ -57,9 +56,16 @@ class ClipDetails():
 | 
				
			|||||||
        ] if url is not None]
 | 
					        ] 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):
 | 
					def load_token(auth_url: str):
 | 
				
			||||||
    global _token
 | 
					    global _token
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    from selenium import webdriver
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    driver = webdriver.Firefox()
 | 
					    driver = webdriver.Firefox()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    driver.get(auth_url)
 | 
					    driver.get(auth_url)
 | 
				
			||||||
@ -165,5 +171,6 @@ def download_clip(clip_id: str, outfile_path: str):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if len(details.playlist_urls()) > 0:
 | 
					    if len(details.playlist_urls()) > 0:
 | 
				
			||||||
        playlist_url = 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)
 | 
					        download_playlist(playlist_url, outfile_path)
 | 
				
			||||||
 | 
				
			|||||||
@ -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
 | 
					 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user