Wiki

Clone wiki

Cubox-i / Setup incrontab + script for auto-manager movies & tv shows

Install Python Guessit

easy_install --upgrade pip
pip install guessit

Setup Incrontab

apt-get install incron

Add your users who is allowed and run incrontab

echo "root" >> /etc/incron.allow
incrontab -e

The syntax in incrontab is*

<folder> <mask> <command>
in our case when deluge completed his download, the file is moved to "Completed" directory
/mnt/Media/Downloads/Completed IN_CREATE,IN_MOVED_TO /usr/bin/python /root/VideoConverter/video_manager.py

Video manager

This script take the video and verify if it's a Movie or a Episode. If it's a Episode, the script will create the right architecture of directory in Plex folder.

video_manager.py

#!python

#!/usr/bin/python
#-*- coding: utf8 -*-

from os import walk
from guessit import guess_file_info
import sys, os, shutil, string

DOWNLOAD_PATH = "/mnt/Media/Downloads/Completed"
TVSHOWS_PATH = "/mnt/Media/TV Shows"
MOVIES_PATH = "/mnt/Media/Movies"
ACCEPTED_FORMAT = ".mp4"

def main(argv):
    for (dirpath, dirnames, filenames) in walk(DOWNLOAD_PATH):
        for filename in filenames:
            absFilePath = dirpath + "/" + filename
            extFile = os.path.splitext(filename)[1]
            print "\nVerification de '%s'" % filename

            if extFile != ACCEPTED_FORMAT:
                continue

            fileInfo = guess_file_info(filename)

            if fileInfo['type'] == "episode":
                seriesFolder = TVSHOWS_PATH + "/" + string.capitalize(fileInfo['series'])
                seasonFolder = seriesFolder + "/Season " + str(fileInfo['season'])

                # Verifier si un dossier du nom de la series n'existe pas
                if os.path.isdir(seasonFolder) == False:
                    os.makedirs(seasonFolder)

                destinationFolder = seasonFolder
                print "[TV SHOW] Le fichier '%s' a ete deplacer vers '%s'." % (filename, destinationFolder) 

            elif fileInfo['type'] == "movie":
                destinationFolder = MOVIES_PATH 
                print "[MOVIE] Le fichier '%s' a ete de placer vers '%s'." % (filename, MOVIES_PATH)

            shutil.move(absFilePath, destinationFolder)

    print "Done"

if __name__ == "__main__":
    main(sys.argv)

##References ## * http://linux.die.net/man/5/incrontab * http://www.garron.me/en/linux/use-incron-rsync-dropbox-backup.html

Updated