Setting Up an Automated Media Center using XBMC and Torrents

Step by step walk through on creating an automated media center by using XBMC and Torrents.

** Now with updated Python scripting and EventGhost configuration. **


Index

Click any of the sections to jump down to it


Programs you’ll need installed:

(version I used) – (link) – (notes)

3.1.26563 - uTorrent
0.4.1.r1544 - EventGhost (just grab the latest release)
0.9.4.3 - SCRU (download link is on the right)
7.54 - theRenamer
10.1 “Dharma” - XBMC
3.425B Weekly - Media Companion (MC)

I did this under Windows 7, you may have different results on different Windows operating systems. This guide is NOT to be used on any *nix based system, including Mac OS.


I’m going to assume that you have a functioning XBMC setup, either on the same PC or on another PC on your network. I use a dedicated HTPC for XBMC and the media storage, with all the downloading/scraping/sorting getting done a separate PC on my network. Your XBMC needs to have the web interface turned on (System -> Network Settings).

  • Username, password, port and web interface can be whatever you want, just remember them.
  • Make sure both “Allow programs…” boxes at the bottom are checked.

I’m also going to assume that you understand how uTorrent works and the basic configuration thereof. I will be making some configuration changes, but I’ll hold your hand for that.



Objective and Prep:

Ultimately we want to have our TV shows/movies download for us and then moved into our media libraries with all the file data properly scraped from the internet.

There are 5 sections that we’re going to break that into:

  1. Setting up uTorrent to download our stuff at the right time and into the right place
  2. Setting up SCRU to properly unpack our downloaded scene releases.
  3. Setting up theRenamer to properly rename and move our media
  4. Setting up MediaCompanion to properly scrape the media info
  5. Setting up EventGhost to prep our files and tie this all together
Prep:
  • We just need to create a few directories within your completed downloads folder. Specifically “movieproc”, “moviezip” and “TVproc”, “TVzip”. You can call them whatever you want, but be sure you have 4 extra directories within completed downloads folder. I’ll be referring to them with the names that I used. Example of my mine (you’re looking at J:\DL\):
The “game”, “movie” and “TV” directories will be created by uTorrent, do not manually create these. See uTorrent section for details.

uTorrent:

Your existing uTorrent configuration can stay mostly untouched, with the exception of a few things.
We have to configure torrent labeling:

  • Open up uTorrent and go to Options -> Preferences ->Advanced -> UI extras
  • Edit the “Persistent Labels” text field to contain your labels, separated by ” | ” (no spaces, no quotes) Example:
  • Still in Preferences, we want to go to Directories next. There, check the “Append the torrent’s label” box. This will create directories within your completed download directory where finished downloads that were given labels will be kept. They will be created when something finishes downloading and is put in them. Example:
If you just can’t wait, feel free to create them manually but be sure they are named the exact same as their corresponding label.
  • Now we must set up our RSS Downloads, which will automatically start downloading the TV shows we specify as soon as they appear online. To do this, you need an RSS Feed. Most torrent sites have an RSS feed, but not all. Each torrent site will have a different feed, but instructions can usually be found through your favorite site’s forums or FAQ. Please go there with questions on how to obtain a feed URL.
  • Go to File -> Add RSS Feed…
  • Enter the Feed URL. It should look something like this (this URL is for EZTV, a public tracker):
Feel free to add a custom alias if you want.
  • Hit OK and then go to Options -> RSS Downloader
  • Here we actually specify which shows we want to grab from the feed. Click “Add” to add a show.
    • Enter the filter conditions, feed, quality and choose the label from the dropdown box(TV). Be sure to check the “Smart ep. filter” box. Also note the asterisk at the end of the filter. Example:

  • That’ll do it for scheduled TV downloads, but for manual downloads and movie downloads we still have to apply the label. This can be set by right clicking on an existing torrent, selecting “Labels” from the context menu and then selecting the appropriate label from the sub-menu. Also, you’re given the chance to apply a label as part of the “Add New Torrent” dialog box that pops up when adding a new torrent.
The labeling part of the “Add New Torrent” box

That about does it for uTorrent. I’ve covered how to set up RSS downloads, and we’ve established labels and told uTorrent to create a directory for each label


SCRU:

The SCRU setup is simple, since all we’ll be using this for is to unpack your TV shows and Movie downloads if they’re compressed at all (rar, zip, 7z, etc.). You should have already created 4 extra directories within your completed downloads folder (as outlined in the “Prep”) section, we’ll be using them here.

  • Open SCRU and go to the Settings tab. Set the “Default output directory” to TVProc. Set the rest of the settings tab to look like mine:
  • Next, edit the default profile by clicking the “Edit profile” button, highlighted in blue in the above picture. Make those settings look like mine:
  • That’s all for SCRU

theRenamer:

theRenamer is simply awesome, and doesn’t involve much configuration. We’ll be using it to rename and move our files. It has two sides, Movies and TV Shows and each need to be configured separately. You switch sides by clicking on the big green “tvshows” or big blue “movies”.

  • Open theRenamer. It should be in TV mode by default. Click the “settings” wrench in the top right and make yours look like mine:
  • The fetch folder should be set to the same directory we used in the SCRU configuration, mine is TVProc. The archive folder should be where you’re storing all your TV.
  • Switch to movies mode and open the settings again. Make yours like mine:
  • The fetch folder should be set to movieproc, which was another of those directories we created. The archive folder should be where you’re storing all your movies. Be sure to check “Contains Movies Only”.
  • That’s all for theRenamer.

MediaCompanion (MC):

MediaCompanion is, at best, fickle. There are other programs out there that scrape movie and TV data, like Ember Media Manager, but MediaCompanion can be run from the command line and that’s where we need it. There is some configuration, but most of this is personal preference. I highly recommend just messing around with the scraping settings to see what works best for you, I’ll only be covering the mission critical settings here.

I could probably write a book on MediaCompanion configuration, maybe someday I will. I hope this guide helps a bit.

MOVIES:

  • Open MediaCompanion. Since there was no installation, you just run the downloaded executable. Select the “Movies” tab in the first row, and then the “Folders” tab in the second row. Click “Add Movie Folder Browser” and navigate to wherever you’re storing your movies. Click OK, and then click “Save & Quick Refresh”. MC will search the folder(s) you specified for media items. Note that it hasn’t scraped anything yet.
  • On the second tab row (still in Movies) select “Movie Preferences”. These settings are all optional, except that “Use Folder Names for Scraping” (near the bottom left) MUST be checked. See example:
  • Choose “Save Changes” when you’re done.
  • On the second tab row (still in Movies) select “Main Browser”. This is where you can view all the movies MC has found. It’s probably a little messy at the moment, but we’ll be cleaning that up a bit.
  • Above both tab rows, select the Movies menu. From that menu, select “Batch Rescraper Wizard”. In the wizard, select (at minimum) YEAR and RUNTIME. The rest is optional. Click Start Update and it will run through attempting to find the year and runtime of all the movies in your collection. Just so you know, it searches the IMDB, using the name of the folder the movies are stored in. So you may want to clean up those folder names if they’re messy. Best format looks like this:
TV:
  • Choose “TV Shows” from the first tab row, and “Folders” from the second.
  • Just like we did for movies, select “Browse for Folder” and choose the folder where your TV shows are stored. They should already be stored in this format:
  • Choose “TV Preferences” from the second tab row. Make yours look like mine, Save Changes when you’re done:
Most of this is admittedly optional. Feel free to play with it.
  • Up above the tab bars, choose “Check Roots for New TV Shows” from the “TV Shows” menu.
  • In the second tab bar, still under “TV Shows”, choose Main Browser. You can watch this populate with your shows as MC finds them.
  • When it looks like it’s done, right click on any show and choose “Unlock all shows”. This will open each show to scraping.
  • Now, go back to the “TV Shows” menu and choose “Search for new episodes”. This will find and scrape each show, season, and episode you possess. May take a bit.
  • When that’s done, you’re library is fully prepared for automation, congratulations you’re done with the hard parts.

EventGhost (EG):

EventGhost (EG) is where the magic really happens. EG ties together everything we’ve done with some slick automation. EG also has vast possibilities outside of what we use it for here, but it’s extremely effective for our purposes.These are the basic instructions. If you want an explanation of what you’re actually doing here, please check out my other post where I talk a little more about the Python scripts and how EventGhost works.
  • Close all theRenamer, MC or SCRU windows. uTorrent can remain open.
  • Open EG. Select everything underneath Autostart in the Configuration Tree and delete it.
  • Right click Autostart and choose Add Plugin…
    • Find the Directory Watcher plugin from the list and hit ok. Set it’s path to your TV downloads folder in your completed downloads directory. This is the directory created by the TV label. Here’s mine:
Don’t check the “Watch subdirectories… box in either watcher.
    • Add another Directory Watcher plugin, this time set it’s path to your Movie downloads folder in your completed downloads directory. This is the directory created by the Movie label. Mine is just J:\DL\movie
    • Finally, add the XBMC2 plugin and point it at the IP address of your XBMC server, and give it the port before hitting OK.
TV
  • Now we want to create a Macro to automate our TV actions for us. Right click Autostart and choose Add Macro…
    • It will ask for an action, choose “Wait some time” (use 5.0 seconds) under the EventChost actions
    • Rename this macro “TV”
    • Right click on the Macro and choose Add Action…
      • This time add a Python Script, which will contain:
import shutil
import os
SubFileTypes = (‘sub’,'srt’,'txt’)
ZipFileTypes = (‘rar’,'zip’,’7z’,'r0′)
MediaFileTypes = (‘mkv’,'avi’,'mp4′,’wmv’)
DownloadName = ”.join(eg.event.payload)
FileName = os.path.basename(DownloadName)
isFolder = os.path.isdir(DownloadName)
eg.globals.tvzip = ‘J:\\DL\\TVzip\\
eg.globals.tvzipdir = eg.globals.tvzip+FileName+’\\’
eg.globals.tvproc = ‘J:\\DL\\TVProc\\’
if isFolder == True:
os.mkdir(eg.globals.tvzipdir)
for root, dirs, files in os.walk(DownloadName):
for f in files:
if f.endswith(ZipFileTypes) or re.search(r’\.r\d+$’, f):
shutil.copy(os.path.join(root,f),eg.globals.tvzipdir)
if f.endswith(SubFileTypes) or f.endswith(MediaFileTypes):
shutil.copy(os.path.join(root,f),eg.globals.tvproc)
elif isFolder == False:
shutil.copy(DownloadName,eg.globals.tvproc)
else:
print ‘I\’m confused!’
    • Please see this pastebin for the proper formatting. DO NOT copy/paste from this post, use the pastebin instead: http://pastebin.com/6eun7X11

    • ‘J:\\DL\\TVzip\\’ and J:\\DL\\TVProc\\ should be replaced with the location of your TVzip and TVProc folders (or whatever you called them when they were created). Be sure to use double slashes and keep the single quotes around the outside.

Now, add another action: “Start Application”:
Executable: C:\Program Files\SCRU\scru.exe
Path to scru.exe, may be different on your system.
Command line options“J:\DL\TVzip” “J:\DL\TVProc”
These paths should be altered to match yours directories.
Be sure to match the other options to my example

 

 

 

 

 

Now, add another action: “Start Application”:
ExecutableC:\Program Files (x86)\theRenamer\theRenamer.exe
Path to theRenamer.exe, may be different on your system.
Command line options: -fetch
Be sure to match the other options to my example

 

 

 

 

 

 

Now, add another action: “Start Application”:
ExecutableC:\MC 3.425b Weekly\mc_com.exe
mc_com.exe is the command line executable for MediaCompanion. It is found in the same directory as the MediaCompanion.exe. The path may be different on your system.
Command line options-e
Be sure to match the other options to my example

 

 

 

 

 

    • Now, add another action: “Python Script”
    • It should contain:
import os
import shutil
    for root, dirs, files in os.walk(eg.globals.tvzip):
        for f in files:
            os.remove(os.path.join(root, f))
        for d in dirs:
            shutil.rmtree(os.path.join(root, d))
    for root, dirs, files in os.walk(eg.globals.tvproc):
        for f in files:
            os.remove(os.path.join(root, f))
        for d in dirs:
            shutil.rmtree(os.path.join(root, d))
      • Please see this pastebin for the proper formatting. DO NOT copy/paste from this post, use the pastebin instead:http://pastebin.com/TCpDSBVt

      • This script acts as a cleaner; it removes all files and folders from the movieproc and moviezip folders.
      • This script should be placed immediately after the ”Start Program: theRenamer.exe” action.
  • Now, add another action: XBMC2 -> Actions -> Media Playing -> Update Video Library
    • Place it at the end of the macro, above the disable/enable actions.
  • Finally, add an event, with the name of DirectoryWatcher.Created and place it at the beginning of the macro.

  • That’s all for the TV macro, the finished product should look something like this (I added waits between each command and I have it play a sound when it starts and a different sound when it finishes):

MOVIES

  • Now we want to create a Macro to automate our Movie actions for us. Right click Autostart and choose Add Macro…
    • It will ask for an action, choose “Wait some time” (use 5.0 seconds) under the EventChost actions
    • Rename this macro “Movie”
    • Right click on the Macro and choose Add Action…
      • This time add a Python Script, which will contain:
import shutil
import os
SubFileTypes = ('sub','srt','txt')
ZipFileTypes = ('rar','zip','7z','r0')
MediaFileTypes = ('mkv','avi','mp4','wmv')
DownloadName = ''.join(eg.event.payload)
FileName = os.path.basename(DownloadName)
isFolder = os.path.isdir(DownloadName)
eg.globals.moviezip = 'J:\\DL\\moviezip\\'
eg.globals.moviezipdir = eg.globals.moviezip+FileName+'\\'
eg.globals.movieproc = 'J:\\DL\\movieproc\\'
if isFolder == True:
    os.mkdir(eg.globals.moviezipdir)
    for root, dirs, files in os.walk(DownloadName):
        for f in files:
            if f.endswith(ZipFileTypes) or re.search(r'\.r\d+$', f):
                shutil.copy(os.path.join(root,f),eg.globals.moviezipdir)
            if f.endswith(SubFileTypes) or f.endswith(MediaFileTypes):
                shutil.copy(os.path.join(root,f),eg.globals.movieproc)
elif isFolder == False:
    shutil.copy(DownloadName,eg.globals.movieproc)
else:
    print 'I\'m confused!'
    • Please see this pastebin for the proper formatting. DO NOT copy/paste from this post, use the pastebin instead: http://pastebin.com/wdtfW5wg

    • ‘J:\\DL\\movieproc\\’ should be replaced with the location of your movieproc folder (or whatever you called it when we created it). Be sure to use double slashes and keep the single quotes around the outside.
    • ‘J:\\DL\\moviezip\\’ should be replaced with the location of your moviezip folder (or whatever you called it when we created it). Be sure to use double slashes and keep the single quotes around the outside.

 Now, add another action: “Start Application”:
Executable: C:\Program Files\SCRU\scru.exe
Path to scru.exe, may be different on your system.
Command line options“J:\DL\moviezip” “J:\DL\movieProc”
These paths should be altered to match yours directories.
Be sure to match the other options to my example

 

 

 

 

 

Now, add another action: “Start Application”:
ExecutableC:\Program Files
(x86)\theRen
amer\theRenamer.exe
Path to theRenamer.exe, may be different on your system.
Command line options: -fetchmovie
Be sure to match the other options to my example

 

 

 

 

 

Now, add another action: “Start Application”:
ExecutableC:\MC 3.425b Weekly\mc_com.exe
mc_com.exe is the command line executable for MediaCompanion. It is found in the same directory as the MediaCompanion.exe. The path may be different on your system.
Command line options-m
Be sure to match the other options to my example

 

 

 

 

 

  • Now, add another action: “Python Script”
    • It should contain:
import os
import shutil

for root, dirs, files in os.walk(eg.globals.moviezip):
    for f in files:
        os.remove(os.path.join(root, f))
    for d in dirs:
        shutil.rmtree(os.path.join(root, d))
            
for root, dirs, files in os.walk(eg.globals.movieproc):
    for f in files:
        os.remove(os.path.join(root, f))
    for d in dirs:
        shutil.rmtree(os.path.join(root, d))
    • Please see this pastebin for the proper formatting. DO NOT copy/paste from this post, use the pastebin instead: http://pastebin.com/A3XMSq7k

    • This script acts as a cleaner; it removes all files and folders from the movieproc and moviezip folders.
    • This script should be placed immediately after the ”Start Program: theRenamer.exe” action.
  • Now, add another action: XBMC2 -> Actions -> Media Playing -> Update Video Library
    • Place it at the end of the macro, above the disable/enable actions.
  • Finally, add an event, with the name of DirectoryWatcher2.Created and put it at the top of the macro
  • That’s all for the Movie macro, the finished product should look something like this (I added waits between each command and I have it play a sound when it starts and a different sound when it finishes):

Learn Anything? Share it!