Setting up automatic torrent downloads and imports into plex

This entry has nothing to do with Nokia or an N95 but I’m really excited about my setup and needed a place to talk about it.

EDIT: 2009/02/20 – Added screenshots (at the bottom)

Disclaimer: This article is only a guide on how to setup automatic downloading of torrents and injection into Plex’s library. Any resemblance to persons, places or objects, living, dead or otherwise is unintentional and purely coincidental. Please check with your local laws before downloading, uploading or viewing content found in any of the fictitious links listed herein. The owners/maintainers/bloggers of this blog are not liable for any damages incurred as a result of using this guide.

Now on to the guide…

I use Plex as my main media center. I needed a way to automatically download content (TV shows and movies) and import into Plex. After several different methods here’s what finally works for me:

Rough specs of my setup: Mac Mini Intel Core Duo with an external 500GB drive.

Ingredients:

  • Plex
  • A torrent client capable of “watching” a directory for incoming torrents to start downloading, as well as the ability to move completed downloads into another directory: Transmission (mac osx version, 1.50 as of this writing)
  • An RSS feed downloader (not just a reader but something capable of actually dowloading new links): Automator
  • A program to move downloaded files into directories being watched by Plex, and name them in the correct format. This one is for TV Shows, a Movie script is below: Episode Linker
  • feedmytorrents.com: Very nice web-based method for managing which shows to subscribe to. Also allows for one-off torrents to be added.
  • mininova.org: Provides RSS feeds with links to torrent files.


Media/
  Movies/
  TV Shows/

BitTorrent/
  Completed/
  In Progress/
  Torrents/

Getting the torrent files

First download/install Automator. This adds a pref pane to system preferences where you can list which RSS feeds to monitor and configure where to download the torrent files to. You can even filter out items from an RSS feed (for example, if you had an RSS feed with everything entitled “Lost”, you may find more than just the newest episode of Lost, or even duplicates). I use feedmytorrents.com because they handle all the de-duping so my filters in Automator are left empty. I added my combined RSS feed from feedmytorrents.com, an RSS feed from mininova.org and my own personal “misc” RSS feed from feedmytorrents.com for any random things I may think of.

Once you’ve got your RSS feeds setup and auto-downloading, you may want to look in BitTorrents/Torrents/ and do a little cleanup. When an RSS feed is fetched for the first time, you may end up with many files in BitTorrents/Torrents/. Move any you don’t want to immediately download out of the way and move them back in when you’re ready.

Downloading content

Next, download and install transmission. This is a very lightweight bittorrent client with a decent webui. Configure it to auto-add anything in BitTorrent/Torrents/, download into BitTorrent/Completed/ and “keep incomplete items” in BitTorrent/In Progress/. What this means is that any torrent added to BitTorrent/Torrents/ will automatically be scanned and start downloading. While downloading, the data file(s) will be kept in BitTorrent/In Progress/. Once downloading/seeding is complete, the data file(s) will be moved to BitTorrent/Completed/. I’m not too sure, but I think the data file(s) won’t be moved until seeding is “complete” as well. For this reason, I set “seed ratio” to 0.01. You can always manually seed afterwards.


So now you’ve got content automatically downloading and being placed in BitTorrent/Completed/. But how do you get that into Plex you ask? Read on…

To move TV shows from BitTorrent/Completed/ into Media/TV Shows/, I use Episode Linker. This provides a nice GUI where you specify the folder(s) to watch and the destination folder to move shows to. In the destination folder you will end up with a structure like this:


Show Name/
  Season 1/
    Show Name - S1E01.avi
    Show Name - S1E02.avi

I changed the regexes a bit so my structure ends up like:


Show.Name/
  Season 1/
    Show.Name.S1E01.avi
    Show.Name.S1E02.avi

To move movies from BitTorrent/Completed/ into Media/Movies/, I wrote a small Applescript. It uses wget to update Plex so make sure you have that installed. Open ScriptEditor, copy the script and save into ~/Library/Scripts/Folder Action Scripts/. Then enable folder actions for BitTorrent/Completed and set that saved script as one of the actions.

(*
        This script is used to move newly downloaded files (with aXXo in the name)
        to a directory where plex will scan them into the library.

        You will need to change "/Volumes/lacie/Media/Movies" to be the full POSIX
        path to where your movie library is stored.

        This script also depends on wget being installed in order to update Plex's
        video library.
*)

on adding folder items to this_folder after receiving these_items
        repeat with this_item in these_items
                set the item_info to info for this_item

                -- This repeat checks to make sure the file is finished being
                -- copied into the directory.
                set oldSize to 0
                set newSize to size of item_info
                repeat while newSize is not equal to oldSize
                        set oldSize to size of item_info
                        delay 3
                        set newSize to size of item_info
                end repeat

                if the name of item_info contains "aXXo" then
                        try
                                set PosixPath to POSIX path of this_item
                                -- Don't forget to change the path.
                                do shell script "mv " & PosixPath & " /Volumes/lacie/Media/Movies/"
                                do shell script "wget -o /dev/null http://127.0.0.1:3000/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.updatelibrary(video) >/dev/null 2>&1"
                        on error errStr number errNum
                                if the errNum is greater than 0 then
                                        do shell script "logger " & errNum & " " & errStr
                                end if
                        end try
                end if

        end repeat
end adding folder items to

Thats it! You should now be seeing things starting to download and make their way into Plex.

The one thing I haven’t figured out yet is how to automatically remove completed torrents from transmission. For now, I just check every so often and “remove from list”. I don’t mind too much since I have a nice list of whats ready for me to watch.

Screenshots

8 Responses to “Setting up automatic torrent downloads and imports into plex”

  1. Thank you very much for writing this up. I have everything set up like you suggested and so far its working great!

    The one issue I am having is with the Applescript you wrote. I have used the exact one you have (but removed the Plex Library Update string with wget). I am just trying to get it to move the Movies from the Completed folder to my Movies folder. When Episode Linker runs, its moving TV Shows fine, and I have downloaded several -aXXo movies, so it should be seeing it. I have the script in my Folder Action Scripts and its enabled. Nothing I do seems to get it to perform any actions to move files.

    Any advice you have would be greatly appreciated. I am very new to OSX (3rd Day) so I may be overlooking something small.

    OSX v.10.5.6
    The Script is on my Mac Mini’s Hard Drive, the Completed Downloads is on my Mini1 (External Drive) drive and the Movies folder is also on Mini1.

  2. Sorry I didn’t approve the comment earlier. I didn’t get a notification for some reason. Anyhow…

    Were the movies already in the Completed folder before you setup the movie script? If so, try moving one to your mac mini hard drive, wait about 30 seconds and then move it back into the Completed folder.

    This is my first attempt at AppleScript so I’m at a loss as well. Something you can try is add after:

    set the item_info to info for this_item

    Add this line:

    do shell script “logger moving ” & this_item

    Then in /var/log/system.log you should see a line like “moving blahblah-axxo”

  3. Thank you for taking the time to respond, I will give it a try!

  4. Also, yes its for new downloads/adds to the folder. I just tried re-doing everything from start to finish, making sure the script is where it should be, and then dropped Resident Evil 1-3 -aXXo folder into my Completed Videos folder. I was not able to get the logging line to run, it would say that it expected an end of line and then it would highlight aXXo in the script, not sure why. This is what the console does when I put it in there though.

    2/26/09 10:17:05 PM com.apple.launchd[83] (com.apple.FolderActions.folders) Throttling respawn: Will start in 7 seconds

    Here is what I am using:
    (*
    This script is used to move newly downloaded files (with aXXo in the name)
    to a directory where plex will scan them into the library.

    You will need to change “/Volumes/lacie/Media/Movies” to be the full POSIX
    path to where your movie library is stored.

    This script also depends on wget being installed in order to update Plex’s
    video library.
    *)

    on adding folder items to this_folder after receiving these_items
    repeat with this_item in these_items
    set the item_info to info for this_item

    – This repeat checks to make sure the file is finished being
    – copied into the directory.
    set oldSize to 0
    set newSize to size of item_info
    repeat while newSize is not equal to oldSize
    set oldSize to size of item_info
    delay 3
    set newSize to size of item_info
    end repeat

    if the name of item_info contains “aXXo” then
    try
    set PosixPath to POSIX path of this_item
    – Don’t forget to change the path.
    do shell script “mv ” & PosixPath & ” /Volumes/Mini1/Movies/”
    on error errStr number errNum
    if the errNum is greater than 0 then
    do shell script “logger ” & errNum & ” ” & errStr
    end if
    end try
    end if

    end repeat
    end adding folder items to

    This is showing when I tried to add your suggestion:
    (*
    This script is used to move newly downloaded files (with aXXo in the name)
    to a directory where plex will scan them into the library.

    You will need to change “/Volumes/lacie/Media/Movies” to be the full POSIX
    path to where your movie library is stored.

    This script also depends on wget being installed in order to update Plex’s
    video library.
    *)

    on adding folder items to this_folder after receiving these_items
    repeat with this_item in these_items
    set the item_info to info for this_item
    do shell script “logger moving ” & this_item
    – This repeat checks to make sure the file is finished being
    – copied into the directory.
    set oldSize to 0
    set newSize to size of item_info
    repeat while newSize is not equal to oldSize
    set oldSize to size of item_info
    delay 3
    set newSize to size of item_info
    end repeat

    if the name of item_info contains “aXXo” then
    try
    set PosixPath to POSIX path of this_item
    – Don’t forget to change the path.
    do shell script “mv ” & PosixPath & ” /Volumes/Mini1/Movies/”
    on error errStr number errNum
    if the errNum is greater than 0 then
    do shell script “logger ” & errNum & ” ” & errStr
    end if
    end try
    end if

    end repeat
    end adding folder items to

    When I try to compile or run, it says Expected End of Line, but found Unknown Token, and highlights the first ” in the line you had me add.

    Thanks again, I may just have to keep poking it. :)

    How does your Folder Actions Setup application look? Mine has my Completed Videos folder, and then when you click that it shows the Episode Linker script and then your script, both checked. Is that right?

  5. oh, do you have ‘&’ or ‘&’ in the “do shell script” lines? It should be ‘&’ (no quotes)

  6. Thanks so much for this. I am only having a minor problem recreating your setup.

    It seems that the downloaded files don’t want to make it out of the
    “BitTorrent/Torrents”

    I tried to set the seed ratio to very low but it still doesn’t seem to want to move any of them. Any hints on what could be going on here?

  7. Followup to my previous post. Transmission kinda seems wierd on the applying it’s settings to torrents that have already started downloading. Kinda seems to be working now.

    Now the only thing I have to figure out is that Episode Linker and I am good to go.

    One question for you. Why Plex and not Boxee? Also does your mac mini do 720p files fairly well? What kind of connection do you have to your tv (dvi to hdmi cable)?

  8. I’ve never really looked into anything other than xbmc/plex. My mac seems to play 720p ok (I’ve haven’t done a comparison to 480 stuff). I’ve got a dvi -> hdmi adapter and then an hdmi cable to my tv.

    I’m also running eyetv and over-the-air hd content looks fine.

Discussion Area - Leave a Comment

You must be logged in to post a comment.