Add --output command line option for use with --download.

This commit is contained in:
Solderpunk 2023-11-25 13:08:36 +01:00
parent 48c8fd9543
commit 4b759aec70
1 changed files with 11 additions and 5 deletions

View File

@ -1408,6 +1408,8 @@ def main():
help='start with your list of bookmarks')
parser.add_argument('--dl', '--download', action='store_true',
help='download a single URL and quit')
parser.add_argument('-o', '--output', metavar='FILE',
help='filename to save --dl URL to')
parser.add_argument('--tls-cert', metavar='FILE', help='TLS client certificate file')
parser.add_argument('--tls-key', metavar='FILE', help='TLS client certificate private key file')
parser.add_argument('--restricted', action="store_true", help='Disallow shell, add, and save commands')
@ -1438,12 +1440,16 @@ def main():
# Download
gi = GeminiItem(args.url[0])
gi, mime = gc._fetch_over_network(gi)
# Parse gemtext in the hopes of getting a gi.name for the filename
if mime == "text/gemini":
gc.active_raw_file = gc.raw_file_buffer
gc._handle_gemtext(gi)
# Decide on a filename
if args.output:
filename = args.output
else:
if mime == "text/gemini":
# Parse gemtext in the hopes of getting a gi.name for the filename
gc.active_raw_file = gc.raw_file_buffer
gc._handle_gemtext(gi)
filename = gi.derive_filename(mime)
# Copy from temp file to pwd with a nice name
filename = gi.derive_filename(mime)
shutil.copyfile(gc.raw_file_buffer, filename)
size = os.path.getsize(filename)
# Notify user where the file ended up