Files
oneliners/almost_oneliners/makemkv-key.sh

30 lines
1.1 KiB
Bash
Executable File

#!/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