Fork me on GitHub

Plex & Trakt: A Scrobbling Love Story

Plex & Trakt: A Scrobbling Love Story

I love my AppleTV2. Not because you can purchase movies and TV shows online, wait a heap of time for them to buffer, then watch them disappear from your library the next day. Nope. But because the little black box can be jailbroken and turned into the beast it should of been.

Now this isn’t a jailbreak tutorial, unlike the iPhone tuts I’ve written in the past. Otherwise this post would be obsolete before I push the publish button. Instead I’m going to show you how to pair up Plex Media Center’s awesomeness with Trakt’s wickedness so you can follow what you’ve watched, get recommendations and follow trends, all automatically through a scrobbling script.

First of all I will assume you have Plex Media Centre installed on the machine that you are going to scrobble from (this post isn’t at all specific to AppleTV, as the scrobble script analyses Plex Media Centre’s log files). I will also assume you have the libraries set up on your media centre and that you have happily enjoyed viewing content from the server before. Now lastly you will need a Trakt.tv account. They’re free, and damn simple to get so head over to Trakt.tv and set up an account.

Now with all the fluff out of the way lets get started. Ensure the media server is set up and running. Next we’ll clone down the scrobbling script created by Tester22, who seems to be all about the automated torrent and workflow scripts for mac. Open up Terminal.app and:

cd ~/Library/
git clone https://github.com/voidet/Plex-Trakt-Scrobbler.git plextrakt
cd plextrakt

What did we just do here? Well we copied down a running git repository from tester22 of which we will work with now. Next up we need to enter our Trakt.tv username and password:

mv config_sample.ini config.ini
vi config.ini

We moved the sample config.ini to the appropriate config.ini file the scrobble script is expecting. You should now see something like:

[Trakt]
username = your_username
password = your_password

[Optional]
log_path =

We will ignore the log_path for now, but change your_username and your_password to the trait username and password you signed up with. You are using the text editor vim, so if you need a hand look up the shortcuts. But for a quick help, press i to change the cursor to insert text, escape to get pointer back, and shift + zz to save and close. That should be all you need.

With that done we need to test the script. Back in terminal (with vim closed and your config all sorted) run:

python script.py

Now when I first ran this I had some issues, namely with element_tree and simple_json. Quite simply, they weren’t installed. So if you have these issues, lets install them! Back in terminal:

curl -O http://effbot.org/media/downloads/elementtree-1.2.6-20050316.tar.gz
tar xzf elementtree-1.2.6-20050316.tar.gz
cd elementtree-1.2.6-20050316
sudo python setup.py install

Now that’s element tree sorted. Let’s get simple JSON also:

cd ../
curl -O http://pypi.python.org/packages/source/s/simplejson/simplejson-2.3.2.tar.gz#md5=0863e016f682f06ead07dd9efad95194
tar xzf simplejson-2.3.2.tar.gz
cd simplejson-2.3.2
sudo python setup.py install

You should be all sorted now. So let’s try the scrobbling script again:

cd ~/Library/plextrakt
python script.py

If all’s well, which I hope it is, you should see some output put to the screen:

Started monitoring a MacOSX running 10.7.2 with PMS Version 0.9.5.2-bf472e4
This plugin is in version 0.1 and is monitoring the log at /Users/voidet/Library/Logs/Plex Media Server.log
additional data is collected from PMS running at http://localhost:32400/ and reported to trakt.tv with username voidet.

That’s right, my username is voidet. If you don’t see something like this, you borked it, or your setup is not entirely…. set, up. Leave a comment and I’ll try help you figure it out.

So you have the scrobbler running, awesome! But what if you reboot, how do we get this going automatically again. Well let’s add this into a LaunchAgent and call it a day. In terminal do this:

vi ~/Library/LaunchAgents/tv.trakt.plist

Next up, press “i” and paste this in:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
	<dict>
		<key>KeepAlive</key>
			<true/>
		<key>Label</key>
			<string>tv.trakt.plist</string>
		<key>ProgramArguments</key>
			<array>
			<string>/usr/bin/python</string>
			<string>/Users/USERNAME_HERE/Library/plextrakt/script.py</string>
			</array>
		<key>RunAtLoad</key>
			<true/>
	</dict>
</plist>

Ensure you change USERNAME_HERE to be the home directory name of your user. For me, it is voidet. To save press escape then shift + zz. Saved and ready to load, on load…

launchctl load -w ~/Library/LaunchAgents/tv.trakt.plist

Reboot and start watching some TV shows or Movies, because they should start coming into Trakt.tv website where you can start getting great recommendations. Big thanks to Tester22 for they’re amazing work, and merging my pull request, also to the hard work of Trakt team and Plex hackers to get Plex on my AppleTV2!

Posted by voidet

Categorised under Python, Technology
Bookmark the permalink or leave a trackback.

4 Comments

  1. Great article, although you need to change the following:

    tar xzf simplejson-2.3.2.tar.gz

    should read:

    tar xzf simplejson-2.3.2.tar.gz#md5=0863e016f682f06ead07dd9efad95194

    February 20, 2012 @ 2:54 am
  2. Thanks for the idiot-proof guide. Even someone like me who is vaguely familiar with GitHub was able to follow it!

    I am having a problem getting it to submit though. Any idea what might be wrong?

    Here’s what its reporting back: (I have changed the ‘password’ string to password)


    Started monitoring a MacOSX running 10.7.3 with PMS Version 0.9.5.2-bf472e4
    This plugin is in version 0.1 and is monitoring the log at /Users/saltedlolly/Library/Logs/Plex Media Server.log
    additional data is collected from PMS running at http://localhost:32400/ and reported to trakt.tv with username saltedlolly.

    Progress on 62776 is 155844 ms
    0
    percent 0
    Found the episode The Lost Music of Rajasthan from 2011, lets make a call to trakt.tv
    Make a call with this data: username=saltedlolly&password=password&media_center_version=0.9.5.2-bf472e4&plugin_version=0.1&title=The+Lost+Music+of+Rajasthan&year=2011&duration=61&progress=4.0&season=18&tvdb_id=74910&episode=5
    Traceback (most recent call last):
    File "script.py", line 170, in
    add_to_trakt(type, title, year, int(float(duration)/60000), percent, guid)
    File "script.py", line 112, in add_to_trakt
    result = urllib2.urlopen(req)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 392, in open
    response = self._open(req, data)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 410, in _open
    '_open', req)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 370, in _call_chain
    result = func(*args)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1186, in http_open
    return self.do_open(httplib.HTTPConnection, req)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1161, in do_open
    raise URLError(err)
    urllib2.URLError:

    It is timing out but I have no diea why. I able to access the Trakt website from my browser no problem?!?!

    February 22, 2012 @ 3:06 am
  3. Cool! Will check it out!

    March 10, 2012 @ 1:46 am
  4. If you are a Linux user, you can use this /etc/init.d script to initialize the script:

    https://gist.github.com/2199084

    March 26, 2012 @ 5:07 am

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

or