diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index dfe0770..0000000 --- a/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto diff --git a/.gitignore b/.gitignore index 51ef61a..9a0e9a5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ -# Aulavirtuale-dl ignores -VideoLezioni/ +# bbbdl ignores +*.json +*.mp4 # Python ignores **/__pycache__/ diff --git a/README.md b/README.md index f3ade08..2883c0b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ # bbbdl A tool for downloading BigBlueButton meetings + +## Installing + +``` +pip install bbbdl +``` \ No newline at end of file diff --git a/bbbdl/__main__.py b/bbbdl/__main__.py index 1579766..6dc7013 100644 --- a/bbbdl/__main__.py +++ b/bbbdl/__main__.py @@ -1,20 +1,65 @@ +import requests import ffmpeg import click +import json +import os from .resources import Meeting from .composer import compose_lesson -@click.command() +@click.group() +def main(): + pass + + +@main.command() @click.option("-i", "--input-url", type=str, prompt=True, help="The URL of the meeting to download.") @click.option("-o", "--output-file", type=str, prompt=True, help="The file the video should be written to.") -def download(input_url, output_file): +@click.option("-O", "--overwrite", is_flag=True, + help="Overwrite existing files instead of skipping them.") +@click.option("-v", "--verbose-ffmpeg", is_flag=True, + help="Print ffmpeg info to stderr.") +def download(input_url, output_file, overwrite=False, verbose_ffmpeg=False): + if not overwrite and os.path.exists(output_file): + raise click.ClickException(f"Output file already exists: {output_file}") + + click.echo(f"Downloading: {input_url} -> {output_file}", err=True) + meeting = Meeting.from_url(input_url) streams = compose_lesson(meeting) output = ffmpeg.output(*streams, output_file) - output.run() + + output.run(quiet=not verbose_ffmpeg, overwrite_output=True) + + +@main.command() +@click.option("-f", "--file", type=click.File(), + help="The JSON file containing the files to download.") +@click.option("-r", "--remote-file", type=str, + help="The URL where the JSON file containing the files to download can be fetched.") +@click.option("-O", "--overwrite", is_flag=True, + help="Overwrite existing files instead of skipping them.") +@click.option("-v", "--verbose-ffmpeg", is_flag=True, + help="Print ffmpeg info to stderr.") +@click.pass_context +def sync(ctx: click.Context, file=None, remote_file=None, overwrite=False, verbose_ffmpeg=False): + if file: + click.echo(f"Syncing from local file: {file.name}", err=True) + j = json.load(file) + elif remote_file: + click.echo(f"Syncing from remote file: {remote_file}", err=True) + j = requests.get(remote_file).json() + else: + raise click.ClickException("No JSON file was specified.") + + for output_file, input_url in j.items(): + try: + ctx.invoke(download, input_url=input_url, output_file=output_file, overwrite=overwrite, verbose_ffmpeg=verbose_ffmpeg) + except click.ClickException: + click.echo(f"Skipped: {input_url} -> {output_file}", err=True) if __name__ == "__main__": - download() + main() diff --git a/pyproject.toml b/pyproject.toml index ce7ab34..d30f925 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,10 @@ [tool.poetry] name = "bbbdl" -version = "0.1.0" +version = "1.0.0" description = "A downloader for BigBlueButton meetings" authors = [ + "Stefano Pigozzi ", "g.minoccari ", - "Stefano Pigozzi " ] license = "AGPL-3.0-or-later"