ptouch autosplit and makemkv-key-grabber

This commit is contained in:
2026-05-02 23:53:32 +02:00
parent a35e9b8cf3
commit fc057270b9
2 changed files with 103 additions and 0 deletions

29
almost_oneliners/makemkv-key.sh Executable file
View File

@@ -0,0 +1,29 @@
#!/bin/bash
# small script to extract the makemkv-beta-key from the forum as it changes once a month
# URL of the MakeMKV forum post
FORUM_URL="https://forum.makemkv.com/forum/viewtopic.php?f=5&t=1053"
# Fetch the page content
CONTENT=$(curl -sL "$FORUM_URL")
# 1. Extract the key (T- followed by 66 alphanumeric characters)
KEY=$(echo "$CONTENT" | grep -oP 'T-[a-zA-Z0-9]{66}')
# 2. Extract the line immediately following the key
# - sed 's/<[^>]*>/\n/g': Replaces all HTML tags with newlines to isolate text
# - grep -A 5 "$KEY": Gets 5 lines of context after the key
# - grep -v "$KEY": Removes the line containing the key itself
# - grep -m 1 "[[:alnum:]]": Grabs the very next line containing actual text
# - sed 's/&nbsp;/ /g': Cleans up non-breaking space entities
VALIDITY=$(echo "$CONTENT" | sed 's/<[^>]*>/\n/g' | grep -A 5 "$KEY" | grep -v "$KEY" | grep -m 1 "[[:alnum:]]" | sed 's/&nbsp;/ /g; s/^[[:space:]]*//; s/[[:space:]]*$//')
# Output
if [ -n "$KEY" ]; then
echo "$KEY"
echo "$VALIDITY"
else
echo "Error: Could not retrieve data from the forum."
exit 1
fi

View File

@@ -0,0 +1,74 @@
#!/bin/bash
# Default values
INVERT=false
# Help function
usage() {
echo "Usage: $0 [-i] <tape_width_mm> <input_image.png>"
echo "Options:"
echo " -i Invert colors (Black -> White, White -> Black)"
echo "Example: $0 -i 12 sticker.png"
exit 1
}
# Parse options
while getopts "i" opt; do
case $opt in
i) INVERT=true ;;
*) usage ;;
esac
done
shift $((OPTIND-1))
# Check for remaining arguments
if [ "$#" -ne 2 ]; then
usage
fi
TAPE_WIDTH=$1
INPUT_FILE=$2
# Map tape width (mm) to pixel height
case $TAPE_WIDTH in
3.5) PIXELS=24 ;;
6) PIXELS=32 ;;
9) PIXELS=48 ;;
12) PIXELS=64 ;;
18) PIXELS=96 ;;
24) PIXELS=128 ;;
36) PIXELS=192 ;;
*)
echo "Error: Unsupported tape width ($TAPE_WIDTH mm)."
exit 1
;;
esac
if [ ! -f "$INPUT_FILE" ]; then
echo "Error: File $INPUT_FILE not found."
exit 1
fi
FILENAME=$(basename -- "$INPUT_FILE")
EXTENSION="${FILENAME##*.}"
BASENAME="${FILENAME%.*}"
# Prepare the magick command parts
INVERT_CMD=""
if [ "$INVERT" = true ]; then
INVERT_CMD="-negate"
echo "Color inversion: ENABLED"
fi
echo "Processing $INPUT_FILE for ${TAPE_WIDTH}mm tape (${PIXELS}px slices)..."
# Execute ImageMagick
magick "$INPUT_FILE" \
$INVERT_CMD \
-threshold 50% \
-type Bilevel \
-crop x${PIXELS} \
+repage \
"${BASENAME}_${TAPE_WIDTH}mm_%d.${EXTENSION}"
echo "Done! Slices saved as: ${BASENAME}_${TAPE_WIDTH}mm_*.${EXTENSION}"