1
0

backlog of changes from the uconsole

This commit is contained in:
dtb
2025-03-07 05:36:27 -07:00
parent 55bb27a1de
commit 9846c7ad27
50 changed files with 1207 additions and 726 deletions

View File

@@ -1,23 +1,22 @@
Comic Book Archives (CB7, CBR, CBZ)
<http://justsolve.archiveteam.org/wiki/Comic_Book_Archive>
<https://en.wikipedia.org/wiki/Comic_book_archive>
A Comic Book Archive is just an archive with a bunch of sequentially-named
images in it which collate ASCIIbetically to the order in which they should be
read. Each image corresponds to a page presented by a comic book reader and a
Comic Book Archive represents a digital comic book.
No guarantees can be made regarding image format, image names (though you can
expect them to match [:digit:]*\..*; that is, a bunch of numbers followed by a
file extension), archive attributes (compression or metadata), or what is in
archives besides the images. In fact, when a comic book only has one image, the
most common type of file in a comic book archive may not be an image at all.
No guarantees can be made regarding image format, image names, archive
attributes (compression or metadata), or what is in archives besides the
images. In fact, when a comic book only has one image, the most common type of
file in a comic book archive may not be an image at all.
The extension corresponds to what type of archive is being used. I haven't seen
an extension that hasn't fit within DOS 8.3, which makes sense as amateur
skiddies and repackers mostly use Windows.
<http://justsolve.archiveteam.org/wiki/Comic_Book_Archive>
<https://en.wikipedia.org/wiki/Comic_book_archive>
Here's a table of Comic Book Archive types. I can't imagine this list is
comprehensive but I can't find more on-line.
____________________
@@ -32,10 +31,12 @@ comprehensive but I can't find more on-line.
I normalize the files I get to the following settings:
ARCHIVE: PKzip. DEFLATE algorithm. No other configuration.
ARCHIVE: PKzip. DEFLATE algorithm. No other configuration and no
subdirectories. ($ zip -jZ DEFLATE)
CONTENTS: ONLY images. Whatever encoding in which I found them.
Sequential naming starting from one, with leading zeroes to ensure file
names are all the same length.
names are all the same length. e.g. 5 pages are 1-5.ext, but 15 are
01-15.ext
<https://en.wikipedia.org/wiki/7-Zip>
7-Zip is free and open source. There are a number of implementations and you

View File

@@ -1,6 +1,6 @@
#!/bin/sh
set -e
set -ex
usage(){
printf 'Usage: %s [files...]\n' "$0"
@@ -22,9 +22,10 @@ else trap 'rm -rf "$d"; trap - EXIT; exit' EXIT INT HUP
fi
while test -n "$1"; do
unrar x -op"$d" "$1"
zip -jZ deflate "$1".cbz "$d"/*
rm "$d"/*
# unrar x -op"$d" "$1"
bsdtar xf "$1" -C "$d"
zip -jrZ deflate "$1".cbz "$d"/*
rm -r "$d"/*
shift
done

View File

@@ -10,49 +10,79 @@ usage(){
test -n "$2" \
|| usage
d="$(mktemp -d || printf '%s/.cbzcat' "$HOME/")"
trap 'rm -rf "$d"; trap - EXIT; exit' EXIT INT HUP
mkdir -p "$d"/x
d="$(mktemp -d || printf '%s/.cbzcat\n' "$HOME/")"
if test -n "$DEBUG"; then
printf 'Using temporary directory %s\n' "$d"
set -x
else
trap 'rm -rf "$d"; trap - EXIT; exit' EXIT INT HUP
fi
i=1 # index
il=1 # index length in digits
parallel \
test -e {} \
::: "$@" \
|| usage
for f in "$@"; do
test -e "$f" \
|| usage
parallel --bar \
unzip -qqd "$d/"{#} {} \
::: "$@"
unzip -d "$d"/x "$f"
# num is created by the shell (parallel in this case) before the pipeline is
# run, so we have to compensate for it already being in the directory when the
# files are listed
parallel \
rm -f {}/*.xml \; \
ls {} \
\| grep -v \
-e '^num$' \
\| wc -l \
\>{}/num \; \
printf '0\\n' \
'>>'{}/prevs \; \
::: "$d"/*
rm -f "$d"/x/*.xml
parallel \
test {1/} -lt {2/} \
'&&' dd \
'<'{1}/num \
'>>'{2}/prevs \
'2>'/dev/null \
'||' true \
::: "$d"/* \
::: "$d"/*
for g in "$d"/x/*; do
# if there aren't enough leading zeroes
if ! printf '%s' "$i" \
| wc -c \
| xargs test "$il" =; then
for h in "$d"/*
do test "$h" = "$d"/x \
|| printf '%s\n' "$h" \
| sed 's|[^/]*$|0&|' \
| xargs mv "$h"
done
# update index digit length
il="$(printf '1 + %s\n' "$il" | bc)"
fi
parallel \
\<{}/prevs \
sed 's/\\$/ + /' \
\| tr -d '\n' \
\| sed 's/ + \\$//' \
\| bc \
\>{}/sum \
::: "$d"/*
# move file to indexed position
printf '%s\n' "$g" \
| sed 's|^.*\.||' \
| xargs printf '%s/%s%s\n' "$d" "$i". \
| xargs mv "$g"
false
# increment i
i="$(printf '1 + %s\n' "$i" | bc)"
done
done
parallel \
ls {}/../ \; \
parallel -I [] --arg-sep :::: \
test [] -lt {} \
'&&' '<'[]/num xargs \
printf '%s + ' \
:::: {}/../* \
\| sed 's| + $||' \
\| bc \
\>{}/prevs \
::: "$d"/*
rm -r "$d"/x
zip -Z deflate out.cbz "$d"/*
mkdir "$d"/0
false
parallel --dry-run sh -c "\
for dir in "
zip -Z deflate out.cbz "$d"/0/*
rm -r "$d"