From fc057270b9528582534d4d024884b2c8577c49e2 Mon Sep 17 00:00:00 2001 From: zeus Date: Sat, 2 May 2026 23:53:32 +0200 Subject: [PATCH] ptouch autosplit and makemkv-key-grabber --- almost_oneliners/makemkv-key.sh | 29 +++++++++++ almost_oneliners/ptouch-autosplit.sh | 74 ++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100755 almost_oneliners/makemkv-key.sh create mode 100755 almost_oneliners/ptouch-autosplit.sh diff --git a/almost_oneliners/makemkv-key.sh b/almost_oneliners/makemkv-key.sh new file mode 100755 index 0000000..5324eca --- /dev/null +++ b/almost_oneliners/makemkv-key.sh @@ -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/ / /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/ / /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 diff --git a/almost_oneliners/ptouch-autosplit.sh b/almost_oneliners/ptouch-autosplit.sh new file mode 100755 index 0000000..689e2b7 --- /dev/null +++ b/almost_oneliners/ptouch-autosplit.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +# Default values +INVERT=false + +# Help function +usage() { + echo "Usage: $0 [-i] " + 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}"