Hard link on torrent completion.

General support for problems installing or using Deluge
Post Reply
socol

Hard link on torrent completion.

Post by socol »

Hello, I am trying to create a script to hard link(or even soft link would work) my downloads. I am no coder, and have googled around for a solution and found several, however none appear to work for my purpose.

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 with and without -s, and with and without sudo but it didn't seem to do anything, nothing appeared in the destination folder.

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/")
I changes "Files" to the name of my completed folder, and what appeared in my destination folder were files that went like this: <Completed Download Folder Name><Actual Torrent Name>. They were 1kb files that did not appear to be valid hard links either.

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
Nothing show up in my destination folder with this script :/

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
Funnily enough the most complicated script I used worked. But it only worked for files not in folders, and my deluge seemed to crash after a while (not sure if that is related since it has crashed before)

Any help would be appreciated.
Post Reply