What I need:
Each file to be hard linked to another folder once they are downloaded, the purpose of this is so that I can use LFTP which is set to sync the hardlinks every 5mins, and delete each file after it has been downloaded to my local machine. Once on the local machine the files are moved by CP/Sonarr and put elsewhere into TV/Movie folders. Hard links are needed so that I don't have extra precious data being used on my remote server, but also so I can keep seeding the file instead of deleting the actual file (important due to Hit and runs, ratio).
Note: I also need to keep directory structure, and I know this complicates things with hard links.
What I've tried:
I started simple:
Code: Select all
#!/bin/bash
torrentid=$1
torrentname=$2
torrentpath=$3
sudo ln -s $torrentpath/$torrentname /mnt/example/movies/$torrentname
I tried this:
Code: Select all
#!/usr/bin/python
import sys
import os
if sys.argv[3].split('/')[3] == 'Files':
os.system("ln -s \""+sys.argv[3]+sys.argv[2]+"\" /media/2TB/New\ Files/")
Both of the above examples were found here: http://forum.deluge-torrent.org/viewtop ... =9&t=35057
I found another post on reddit and tried 2 other scripts.
Firstly:
Code: Select all
#!/bin/bash
torrentid=$1
torrentname=$2
torrentpath=$3
targetdir="/target/location"
newtorrentpath="$torrentpath$torrentname"
oldifs=$IFS
IFS='
'
find $newtorrentpath |
while read f
do
dest=$(echo $f | sed "s#$newtorrentpath#$targetdir#g")
[ -d "$f" ] && mkdir -p "$dest" || ln "$f" "$dest"
done
IFS=$oldifs
Lastly I used:
Code: Select all
#!/bin/bash
torrentid=$1
torrentname=$2
torrentpath=$3
cd $torrentpath
if [ -d "${torrentname}" ]; then
torrent_param="DIR"
else
if [ -f "${torrentname}" ]; then
torrent_param="FILE"
else
echo "${torrentname} is not valid (not file or directory)" >> "/scripts/checktorrent_script.log"
fi
fi
if [[ "${torrent_param}" == "FILE" ]]; then
if [[ "$torrentpath" == "/deluge/data/tv/" ]]; then
ln "$torrentpath/$torrentname" "/deluge/complete/tv/$torrentname"
fi
if [[ "$torrentpath" == "/deluge/data/movies/" ]]; then
ln "$torrentpath/$torrentname" "/deluge/complete/movies/$torrentname"
fi
if [[ "$torrentpath" == "/deluge/data/" ]]; then
ln "$torrentpath/$torrentname" "/deluge/complete/data/$torrentname"
fi
fi
if [[ "${torrent_param}" == "DIR" ]]; then
if [[ "$torrentpath" == "/deluge/data/tv/" ]]; then
targetdir="/deluge/complete/tv/$torrentname"
fi
if [[ "$torrentpath" == "/deluge/data/movies/" ]]; then
targetdir="/deluge/complete/movies/$torrentname"
fi
if [[ "$torrentpath" == "/deluge/data/" ]]; then
targetdir="/deluge/complete/data/$torrentname"
fi
torrentpath="$torrentpath$torrentname"
oldifs=$IFS
IFS='
'
find $torrentpath |
while read f
do
dest=$(echo $f | sed "s#$torrentpath#$targetdir#g")
[ -d "$f" ] && mkdir -p "$dest" || ln "$f" "$dest"
done
IFS=$oldifs
fi
Any help would be appreciated.