You are not logged in.

#1 2010-02-12 17:07:30

jumzi
Member
Registered: 2009-02-20
Posts: 69

rtorrentMove

This idea is essentially all markp1989 (see command line script thingy on the general programing forum)

I only cleaned it up abit to be easy to use and put it out here cause i think it's been very useful for me and i was thrilled when i saw markp1989s first draft of the idea. It's a bash script to use with rtorrent: that makes certain files you download from the intraweb fall into the correct directories direct. It's made so that if you where to download shows that get's catagorized into seasons you should have a well formated "tvshow/season_3" so that the files also comes down into the latest season if you are a follower of a great show. It doesn't explode if you dont catagorize into seasons, it will just move the file into the "tvshow" folder then... unless you have some other folders in there wich makes no sense to me, but i might be wrong. It also gives you email notifications of finished downloads via the mail program that has to be properly configured at you site.

You put this line in the config of an updated version of the rtorrent

system.method.set_key = event.download.finished,notify_me,"execute=/PATH/TO/rtorrentmove.sh,$d.get_name="

and the script is here (GPLed incase it where to make a werewolves out of your speakers)

#!/bin/bash
#markp1989 is 100% the idea maker, i only rewrote his script to make it easier to use

#Change value to 1 if you want Email notifications
WANTEMAIL=0
#Email to mail for notification... obviously...
EMAIL=someusername@someprovider.sometopleveldomain
#Define files that will go to a certain directory
#First name is a part of the name of the file you're downloading followed by save path
# e.g.
#DLS=( The.Simpsons media/series/the_simpsons House media/series/House )
#it must be relative to $MVDIR
DLS=()
#The directory wich rtorrent downloads files into
DLDIR=/absolute/path/to/DLDIR
#Dir where to count from when moving the files in place e.g. storage area
MVDIR=/absolute/path/to/MVDIR
#Where non-defined files should go after download
FINISHED=/absolute/path/to/FINISHED

##                                             ##
## --------------------------------------------##
##                                             ##
#   rtorrentMove, makes files go where they should go
#    Copyright (C) 2010  Jesper Vesterberg with inspiration by markp1989, who easily could get into this line if he wants :P
#
#    This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.



n=${#DLS[@]}

#Sets the $TARGET dir for a certain defined file
for ((i=0;i<n;i++));
do
    if [[ "$1" =~ ${DLS[i]}  ]]
    then
        
        TARGET=${DLS[i+1]}"/$(ls $MVDIR/${DLS[i+1]}/ | tail -n 1)"
        #Change target if you do not want automatic season sorting
        #TARGET=${DLS[i+]}
        
    fi

    (( i = i+1 ))
done

#---#


if [ -z $TARGET ]
then
    #Undefined files go to $FINISHED
    mv $DLDIR/$1 $FINISHED
    REPORTDIR=$FINISHED
else
    #Moves defined files to place
    mv $DLDIR/$1 $MVDIR/$TARGET
    REPORTDIR=$MVDIR/$TARGET
fi


if [ $WANTEMAIL = 1 ]
then
    echo -e "$(date) : $1 - Download completed. \n\nfile has been moved to $REPORTDIR" | \
           mail -s "[rtorrent] - Download completed : $1" $EMAIL
else
    exit
fi

exit

I'm a utter begginer when it comes to programming wich is another reason i put it out here, i would be thrilled to hear what you think and maybe some pointers on improving it... Or god forbid... You might find some buggs!. Atm i'm thinking of splitting up config and script but then i feel it has to expand some before that, i'm also thinking of making music files automatically fall into another directory even if it isn't defined so it would be easy to use with mpd/ncmpc. Another tought might be some other way of notificating one that a download is finished?

Anyway...
Happy coding, from me, to you all.

Last edited by jumzi (2010-02-12 17:10:32)

Offline

#2 2010-02-13 00:17:33

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: rtorrentMove

Use associative arrays instead of stacking it all in one flat list.

Offline

Board footer

Powered by FluxBB