I am a Star Wars fan but I am Canadian first
I cannot support the US so that means Disney, and more specifically Disney+, is a no go. So I needed to find some not so legal ways to watch the current Star Wars releases, Andor to be specific. I use a pihole to block ads which makes most of the torrent sites nearly unusable, as you have to look at ads to see the torrent link and even then you may not press the right button! I use an iPad (that I got prior to the US boycott) and Safari does not let me copy magnet links, I could try other browsers but I am lazy and do not want to do the hard work of downloading a new browser just to try an get a link. I have tried moving to a different browser before but found that they just did not work for how I use Safari, side note I may look into a different browser again now that I have changed how I use my network but that is another story. I thought about it, how was I going to strip the magnet links from the pages? First I thought I know enough html and Java to know what I was looking for if I looked into the page source, but then I thought about how much crap I would have to look through to find the actual link to maybe the right magnet so that was a no. Then I thought “hey what does complex manual tasks easily?” ChatGPT does that, so I asked ChatGPT to get the magnet link out of the webpage for me but the thing said no because it is illegal to download things like that.
I could have just excepted defeat, but no I was going to make that AI my bitch and tell it what to do! I could have decided to ask it again in different ways to get me the link, but I decided it would be better if I just got it to do all the work for me. The searching for the torrent magnet links, the copying of the magnet links into transmission (my BitTorrent client of choice), then the copying of the video into my Jellyfin library with all the metadata copied onto it. I waited a few weeks into this season of Andor being out before I got started on making this script, so every week it would be adjusted just a little to fix whatever issue. As of last night (or early this morning I guess) I think I have the script all figured out to work properly but sadly yesterday was the final 3 episodes of the series. I have however been working on scripts for other shows along with my Andor script, so every little or major change I made to my Andor script I made it to my other scripts. Along with that I made another script that would watch for new Star Wars live action shows and make a script for those shows as well.
Because ChatGPT would not get a magnet link for me I worked my Jedi mind control and computer geekery to get ChatGPT to help me write the scripts for automation in my pirating ways. The crontab on one of my pi’s now has a section labelled #Arr… so that’s cool! I will share my Andor script, I know the show is over but there are other shows you may want to use it for but if maybe you can share some thoughts on my script as I am not to familiar with bash.
!/bin/bash
--- Config ---
SHOW_NAME="Andor"
API_URL="https://api.tvmaze.com/singlesearch/shows?q=${SHOW_NAME// /%20}&embed=episodes"
LAST_CHECK_FILE="$HOME/.last_andor_check"
LOG_DIR="$HOME/scripts/TV/logs"
DOWNLOAD_LOG="$LOG_DIR/Andor_downloaded.txt"
LOGFILE="$LOG_DIR/andor_$(date +%Y-%m-%d).log"
JACKETT_URL="http://localhost:9117"
API_KEY=""
INDEXERS=("1337x" "limetorrent" "thepiratebay" "torlock")
mkdir -p "$LOG_DIR"
mkdir -p "$(dirname "$LAST_CHECK_FILE")"
touch "$LAST_CHECK_FILE" "$DOWNLOAD_LOG"
echo "========== $(date) ==========" >> "$LOGFILE"
--- Fetch latest episode info ---
response=$(curl -s "$API_URL")
latest_episode=$(echo "$response" | jq '._embedded.episodes[-1]')
airdate=$(echo "$latest_episode" | jq -r '.airdate')
season=$(echo "$latest_episode" | jq -r '.season')
number=$(echo "$latest_episode" | jq -r '.number')
title=$(echo "$latest_episode" | jq -r '.name')
query="${SHOW_NAME} S$(printf "%02d" "$season")E$(printf "%02d" "$number") x264"
--- Airdate check ---
TODAY=$(date +%Y-%m-%d)
if [[ "$TODAY" < "$(date -d "$airdate +1 day" +%Y-%m-%d)" ]]; then echo "Waiting until the day after airdate: $airdate" >> "$LOGFILE"
exit 0
fi
--- Skip if already downloaded ---
if grep -q "$query" "$DOWNLOAD_LOG"; then
echo "Already handled: $query" >> "$LOGFILE"
exit 0
fi
echo "New episode detected: $title ($airdate)" >> "$LOGFILE"
echo "$airdate" > "$LAST_CHECK_FILE"
echo "Searching for: $query" >> "$LOGFILE"
--- Torrent search via Jackett ---
for indexer in "${INDEXERS[@]}"; do
echo " Searching indexer: $indexer" >> "$LOGFILE"search_query=$(jq -rn --arg q "$query" '$q|@uri') url="$JACKETT_URL/api/v2.0/indexers/$indexer/results/torznab/api?apikey=$API_KEY&t=search&q=$search_query" response=$(curl -s "$url") torrent_url=$(echo "$response" | grep -oP '<enclosure url="\K[^"]+' | head -n 1) if [[ -n "$torrent_url" ]]; then echo " Found: $torrent_url" >> "$LOGFILE" tmpfile=$(mktemp --suffix=.torrent) curl -Lso "$tmpfile" "$torrent_url" if file "$tmpfile" | grep -q "BitTorrent"; then transmission-remote -a "$tmpfile" >> "$LOGFILE" 2>&1 echo "$query" >> "$DOWNLOAD_LOG" echo " Added to Transmission!" >> "$LOGFILE" rm -f "$tmpfile" exit 0 else echo " Invalid torrent file, skipping." >> "$LOGFILE" rm -f "$tmpfile" fi else echo " No torrents found on $indexer" >> "$LOGFILE" fi
done
echo "No torrents were successfully added." >> "$LOGFILE"
exit 1