Miscellaneous updates.

This commit is contained in:
voussoir 2023-12-31 14:17:00 -08:00
parent ab24374041
commit bcac3d716e
4 changed files with 44 additions and 5 deletions

View file

@ -1,4 +1,5 @@
import argparse
import PIL.Image
import glob
import math
import os

39
q.py
View file

@ -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',

View file

@ -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

View file

@ -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):