Skip to content

Instantly share code, notes, and snippets.

@werrpy
Last active October 8, 2023 11:02
Show Gist options
  • Save werrpy/a4ff72e9bc78da645f42e25eccbacd7b to your computer and use it in GitHub Desktop.
Save werrpy/a4ff72e9bc78da645f42e25eccbacd7b to your computer and use it in GitHub Desktop.
rtorrent / deluge symlink and auto rename for plex and rclone upload
alias filter_filebot='cat ~/filebot/data/logs/filebot_auto_rclone.log | grep -i "move" | uniq > ~/filebot/data/logs/filebot_auto_rclone_filtered.log && cat ~/filebot/data/logs/filebot_auto_rclone_filtered.log'
#!/bin/bash
# staging and active directories
INCOMING=/USER/auto/incoming/NEW
ACTIVE=/USER/auto/active/NEW
# paths
FILEBOT=/USER/filebot/filebot.sh
FILEBOT_LOG=filebot_auto_rclone.log
RCLONE=/USER/bin/rclone
RCLONE_CONFIG=/USER/gdrive/config/rclone_vault.conf
function ppgrep() { pgrep "$1" | xargs --no-run-if-empty ps fp; }
function stage_media() {
# move all symlinks in $INCOMING to $ACTIVE directory
shopt -s dotglob nullglob
mv $INCOMING/* $ACTIVE/ > /dev/null 2>&1
shopt -u dotglob nullglob
}
function rename_media() { /bin/bash $FILEBOT -rename -non-strict --format "{n.replaceAll(/:/, ' -')} {tags} ({y})" --db TheMovieDB --log info --log-file "$FILEBOT_LOG" "$ACTIVE" > /dev/null 2>&1; }
function copy_media() { $RCLONE --config $RCLONE_CONFIG copy "$ACTIVE" media-remote-secret: > /dev/null 2>&1; }
function unlink_media() {
# unlink active media
SAVEIFS=$IFS
# fix for spaces in filenames
IFS=$(echo -en "\n\b")
for f in $(find "$ACTIVE" -maxdepth 1); do
unlink $f
done
IFS=$SAVEIFS
}
if [[ ! -n $(ppgrep "rclone" | grep -e "copy $ACTIVE") && ! -n $(ppgrep "filebot" | grep -e "TheMovieDB" | grep -e "$ACTIVE") ]]; then
stage_media;
rename_media;
copy_media;
unlink_media
fi
* * * * * /home/USER/bin/auto-rclone-move.sh
#
# auto symlink largest file to ~/auto/incoming/NEW
#
method.insert = d.data_path, simple, "if=(d.is_multi_file), (cat,(d.directory),/), (cat,(d.directory),/,(d.name))"
method.set_key = event.download.finished, simple, "execute=~/bin/hard-link-media.sh,$d.data_path="
@werrpy
Copy link
Author

werrpy commented Apr 16, 2019

This script will symlink largest mkv when torrent completes to another directory based on the label. A cronjob every minute will rename using filebot TMDB for plex as "Name (Year).mkv" and move the files with rclone. Uses staging and active directories to prevent race conditions.

rtorrent: .bashrc, auto-rclone-move.sh, crontab -e, hard-link-media.sh, rtorrent.rc
deluge: .bashrc, auto-rclone-move.sh, crontab -e, hard-link-media-deluge.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment