From bcac3d716e0ceb9a3305428a215da119c985425a Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 31 Dec 2023 14:17:00 -0800 Subject: [PATCH] Miscellaneous updates. --- eval.py | 1 + q.py | 39 +++++++++++++++++++++++++++++++++++---- stitch.py | 8 +++++++- threaded_dl.py | 1 + 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/eval.py b/eval.py index 2a5e821..0d90ff8 100644 --- a/eval.py +++ b/eval.py @@ -1,4 +1,5 @@ import argparse +import PIL.Image import glob import math import os diff --git a/q.py b/q.py index 9d7a68f..e2c86c9 100644 --- a/q.py +++ b/q.py @@ -84,6 +84,7 @@ def handle_failure(file): def override_extension_commands(extension, command): extension = extension.lower().strip('.') + print(command) if command: command = [f'"{x}"' if ' ' in x else x for x in command] command = ' '.join(command).strip() @@ -91,7 +92,7 @@ def override_extension_commands(extension, command): command = qcommands.EXTENSION_COMMANDS[extension] qcommands.EXTENSION_COMMANDS.clear() - qcommands.EXTENSION_COMMANDS[extension] = command + qcommands.EXTENSION_COMMANDS[extension] = (command, '{id}') def parse_collaborate(collaborate): if collaborate is None: @@ -237,10 +238,40 @@ def q_argparse(args): @operatornotify.main_decorator(subject='q.py', notify_every_line=True) @vlogging.main_decorator def main(argv): - parser = argparse.ArgumentParser(description=__doc__) + parser = argparse.ArgumentParser(description=''' + This program is used to process so-called "queuefiles". - parser.add_argument('extension', nargs='?', default=None) - parser.add_argument('command', nargs='*', default=None) + The queuefile is a file where the extension indicates what command + should be used to handle it, and the command's argument is either the + file's name, or the content of the file. + + If the queuefile is zero bytes, then the name of the file is the + argument to the command. If the file is non-empty, then the contents + are read as lines, and the command is invoked once for each line as + an argument. + + For example, 0123456789a.youtube could be a zero-byte queuefile + that will be handled by youtube-dl to download the youtube video + with 0123456789a. + + On the other hand, 012345789.wayback could be a queuefile that contains + an HTTP link inside, and the command will post it to web.archive.org. + ''') + + parser.add_argument( + 'extension', + nargs='?', + default=None, + help=''' + Process only queuefiles with this particular extension. Leave blank + to process all recognized extensions. + ''', + ) + parser.add_argument( + 'command', + nargs='*', + default=None, + ) parser.add_argument('--folders', nargs='*', default=None) parser.add_argument( '--once', diff --git a/stitch.py b/stitch.py index a25bd07..2111bed 100644 --- a/stitch.py +++ b/stitch.py @@ -3,6 +3,7 @@ import argparse import sys from voussoirkit import betterhelp +from voussoirkit import imagetools from voussoirkit import pathclass from voussoirkit import pipeable from voussoirkit import sentinel @@ -17,6 +18,7 @@ def stitch_argparse(args): patterns = pipeable.input_many(args.image_files, skip_blank=True, strip=True) files = pathclass.glob_many_files(patterns) images = [PIL.Image.open(file.absolute_path) for file in files] + images = [imagetools.rotate_by_exif(image)[0] for image in images] if args.grid: (grid_x, grid_y) = [int(part) for part in args.grid.split('x')] @@ -68,8 +70,12 @@ def stitch_argparse(args): offset_y += row_heights[index_y] offset_y += args.gap + output_file = pathclass.Path(args.output) + if output_file.extension in {'jpg', 'jpeg'}: + final_image = final_image.convert('RGB') + log.info(args.output) - final_image.save(args.output) + final_image.save(output_file.absolute_path) return 0 @vlogging.main_decorator diff --git a/threaded_dl.py b/threaded_dl.py index 18b0a03..ec7febc 100644 --- a/threaded_dl.py +++ b/threaded_dl.py @@ -121,6 +121,7 @@ def prepare_urls_filenames(urls, filename_format): index=index, index1=index1, now=now, + random=random.getrandbits(32), ) if os.path.exists(filename):