gofile

Module and tool to upload files to gofile.io
git clone https://code.alwayswait.ing/gofile.git
Log | Files | Refs

commit 098756ab42b03ba67f455a449d3242edfbacb82a
parent 002639d748ff3f1aba74670c775da6d6e9c8a777
Author: archiveanon <>
Date:   Sat, 28 Oct 2023 05:21:25 +0000

Unify code paths for uploading single and multiple files

Diffstat:
Msrc/gofile/api.py | 29++++++++++++++++++++---------
1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/src/gofile/api.py b/src/gofile/api.py @@ -149,6 +149,7 @@ def upload_multiple( def main(): # you may save and reuse a guest token # there's no clear indicator on whether or not it expires + # there may be duplicate filenames in a folder parser = argparse.ArgumentParser() parser.add_argument("path", type=pathlib.Path, help="Path to single file or folder") @@ -161,24 +162,34 @@ def main(): args = parser.parse_args() - upload = None - if not args.path.exists(): print(f"Path '{args.path}' does not exist") return - elif args.path.is_dir(): - files = args.path.glob("*") + files = [] + + if args.path.is_dir(): + files = args.path.glob("*") if args.fast_link: # sort by ascending size so we can produce a link as fast as possible files = sorted(files, key=lambda x: os.stat(x).st_size) - - for upload in upload_multiple(files): - print(upload) elif args.path.is_file(): - upload = upload_single(args.path) + files = [args.path] + + uploads = upload_multiple(files) + + # force generator to evaluate and yield the first result + first_upload = next(uploads) + + print(f"- Download URL: {first_upload.result.download_page}") + print(f"- Folder ID: {first_upload.result.parent_folder}") + + if first_upload.result.guest_token: + print(f"- Guest token: {first_upload.result.guest_token}") - print(upload.result) + # let the rest of the uploads process + for upload in uploads: + pass if __name__ == "__main__":