From fc300fafd378fe6f2fde15e95ff8fbf13361b248 Mon Sep 17 00:00:00 2001 From: Alessandro Clerici Date: Mon, 31 May 2021 17:05:42 +0200 Subject: [PATCH] UI fixes --- CHANGELOG.md | 6 +++++- README.md | 2 +- unimi_dl/cmd.py | 50 +++++++++++++++++++++++++++---------------------- 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index adb427e..8dce578 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,14 @@ -## [UNRELEASED] v0.3 Menus +## v0.3 Menus Major improvements to usability. +### Download +See [PyPI release page](https://pypi.org/project/unimi-dl/0.3.0) + + ### Release notes #### Added diff --git a/README.md b/README.md index 568f183..ef88744 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Major improvements to usability. #### Changed - The default behavior for downloading is now the interactive choice. For the previously default behavior use `-a` -- IMPORTANT: the downloaded list now stores both the manifests and the video titles. The new format is not compatible with the old one, therefore you might have to delete `downloaded.json` (it resides in the same directory specified for `credentials.json` in `unimi-dl --help`) +- IMPORTANT: the downloaded list now stores both the manifests and the video titles. The new format is not compatible with the old one, therefore you might have to delete `downloaded.json` (it resides in the same directory specified for `credentials.json` in `unimi-dl --help`). In this case you may find useful using `--add-to-downloaded-only` for re-adding previously downloaded videos. diff --git a/unimi_dl/cmd.py b/unimi_dl/cmd.py index f129f01..acfc897 100644 --- a/unimi_dl/cmd.py +++ b/unimi_dl/cmd.py @@ -223,11 +223,12 @@ def cleanup_downloaded(downloaded_path: str) -> None: main_logger.error("Your selection is not valid") exit(1) main_logger.debug(f"{len(chosen)} names chosen") - for manifest in chosen: - downloaded_dict.pop(manifest) - downloaded_file.seek(0) - downloaded_file.write(json_dumps(downloaded_dict)) - downloaded_file.truncate() + if len(chosen) != 0: + for manifest in chosen: + downloaded_dict.pop(manifest) + downloaded_file.seek(0) + downloaded_file.write(json_dumps(downloaded_dict)) + downloaded_file.truncate() downloaded_file.close() main_logger.info("Cleanup done") @@ -299,23 +300,28 @@ def main(): all_manifest_dict = getPlatform( email, password, opts.platform).get_manifests(opts.url) - if opts.all or opts.platform == "panopto": - manifest_dict = all_manifest_dict + if len(all_manifest_dict) == 0: + main_logger.warning("No videos found") else: - try: - selection = multi_select( - list(all_manifest_dict.keys()), selection_text="\nVideos to download: ") - except WrongSelectionError: - main_logger.error("Your selection is not valid") - exit(1) - manifest_dict = {name: all_manifest_dict[name] for name in selection} - - main_logger.info(f"Videos: {list(manifest_dict.keys())}") - - downloaded_dict, downloaded_file = get_downloaded(downloaded_path) - - download(opts.output, manifest_dict, downloaded_dict, - downloaded_file, opts.simulate, opts.add_to_downloaded_only) - downloaded_file.close() + if opts.all or opts.platform == "panopto": + manifest_dict = all_manifest_dict + else: + try: + selection = multi_select( + list(all_manifest_dict.keys()), selection_text="\nVideos to download: ") + except WrongSelectionError: + main_logger.error("Your selection is not valid") + exit(1) + manifest_dict = { + name: all_manifest_dict[name] for name in selection} + + if len(manifest_dict) != 0: + main_logger.info(f"Videos: {list(manifest_dict.keys())}") + + downloaded_dict, downloaded_file = get_downloaded(downloaded_path) + + download(opts.output, manifest_dict, downloaded_dict, + downloaded_file, opts.simulate, opts.add_to_downloaded_only) + downloaded_file.close() main_logger.debug( f"=============job end at {datetime.now()}=============\n")