Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

After downloading tv shows and movies I would like them to be automatically moved to two separate folders (named "tv shows" and "Movies"). I know there are a lot of programs that you can do this with on windows / osx but I am not sure about ubuntu. If there are not any for ubuntu would it be possible to make some sort of script myself?

The simplest criteria that I thought of would be to sort video files over 1 hour in length to the movies folder that way it would be fully automatic. I could always make a comment on the torrent such as "movie" and then read that with a script maybe?

Any tips would be really appreciated, thanks!

share|improve this question
    
I can imagine how to do this with inotify or a cronjob. – Lekensteyn Feb 28 '12 at 11:03

This script should give you something to start off with. It does a decent job in moving videos (.mp4 and .mkv, but you can add more) longer than 1 hr to ~/Downloads/Movies and others to ~/Downloads/Shows.

#!/bin/bash
files=$(find -type f -name "*.mp4" -o -name "*.mkv") #include anyother formats you want
while read -r line
do
    time="$(ffmpeg -hide_banner -i "$line" 2>&1 | grep -Po '(?<=Duration: ).*(?=, start)'| cut -d : -f1)"
    if [[ $time -ge "1" ]] ; then
        if [ -d ~/Downloads/Movies ] ; then
            mv "$line" ~/Downloads/Movies
        else
            mkdir -p ~/Downloads/Movies
            mv "$line" ~/Downloads/Movies
        fi
    elif [[ $time == "00" ]] ; then
        if [ -d ~/Downloads/Shows ] ; then
            mv "$line" ~/Downloads/Shows
        else
            mkdir -p ~/Downloads/Shows
            mv "$line" ~/Downloads/Shows
        fi
    fi
done <<< "$files"

Additionally, if you are using torrent managers such as Deluge or Transmission or others that supports running scripts on completion of torrents, you can provide this as the script to run. You may have to tweak it a bit, if needed.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.