Last active
October 8, 2023 11:02
-
-
Save werrpy/a4ff72e9bc78da645f42e25eccbacd7b to your computer and use it in GitHub Desktop.
rtorrent / deluge symlink and auto rename for plex and rclone upload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* * * * * /home/USER/bin/auto-rclone-move.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
torrentid=$1 | |
torrentname=$2 | |
torrentpath=$3 | |
# auto directories | |
ACTIVE=/USER/auto/active/NEW | |
INCOMING=/USER/auto/incoming/NEW | |
function hard_link_media() { | |
if [[ -d "$1" ]]; then | |
# $1 is a directory | |
# symlink all nested mkvs | |
shopt -s globstar | |
ln "$1/**/*.mkv" "$INCOMING/" | |
shopt -u globstar | |
else | |
# $1 is a file | |
ln "$1" "$INCOMING/" | |
fi | |
} | |
hard_link_media "$torrentpath/$torrentname" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# auto symlink largest file to ~/auto/incoming/NEW | |
# | |
# auto directories | |
ACTIVE=/USER/auto/active/NEW | |
INCOMING=/USER/auto/incoming/NEW | |
function hard_link_media() { | |
if [[ -d "$1" ]]; then | |
# $1 is a directory | |
# symlink all nested mkvs | |
shopt -s globstar | |
ln "$1/**/*.mkv" "$INCOMING/" | |
shopt -u globstar | |
else | |
# $1 is a file | |
ln "$1" "$INCOMING/" | |
fi | |
} | |
hard_link_media "$1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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=" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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