Skip to content

Telling Boxee Box you’ve watched a file after moving it

Like many of you, I occasionally reorganize my collection of digital video according to my whims of the moment. Unfortunately, this means that my Boxee Box, which I mostly love, now has no idea whether I’ve watched a particular video or not, since it keys off the path of the file. This is particularly annoying when I’m in the middle of a season of TV and decide to move it to a different directory, since I then have to remember which episode I was on.

Now I have a solution, in the form of a very hacky little python script. I had to root my Boxee to accomplish this feat, mostly just to get root access to its database of watched files, but that’s easy to do. My first inclination was to write a python script that edited the database using a proper API, but after an hour of frustrated searching I couldn’t find a way to invoke the python interpreter on the Boxee from the command line. It’s probably in there somewhere, but I’ve given up looking. Instead, I came up with one of my favorite recent hacks: telnet from the NAS (DNS-323) hosting the file to the Boxee and issue SQL commands to the sqlite3 command line tool. It looks like this:

import telnetlib

mnt_prefix = "/mnt/HD_b2"  # NAS root path
smb_prefix = "smb://NETWORKSTORE/Volume_2" # SMB share root path, which Boxee understands
HOST = "" # local IP address of the Boxee Box
sqlite = '/data/hack/bin/sqlite3 -interactive '
db_path = '/data/.boxee/UserData/profiles/zachm/Database/boxee_user_catalog.db' # your path will vary
sqlite_cmd = sqlite + db_path

# Transfers any watched boxee status between the src and dest locations
def move_watched_status(src, dest):
  src = string.replace(src, mnt_prefix, smb_prefix)
  dest = string.replace(dest, mnt_prefix, smb_prefix)

  tn = telnetlib.Telnet(HOST, 2323)

  tn.read_until("Password: ")
  tn.write('secret' + "\n")  # this is the default telnet password when you root the boxee

  count_rows = "select count(*) from watched where strPath = '" + src + "';"

  tn.write(sqlite_cmd + "\n")
  tn.read_until('sqlite> ')
  tn.write(count_rows + '\n')
  row_count = tn.read_until('sqlite> ').split('\n')[1]
  if row_count:
    insert = "insert into watched (strPath, iPlayCount, iLastPlayed, fPositionInSeconds) select '%s', iPlayCount, iLastPlayed, fPositionInSeconds from watched where strPath = '%s';" % (dest, src)
    tn.write(insert + '\n')
    tn.read_until('sqlite> ')


What I particularly like about this solution is that it just automates exactly what I would do if I were doing this manually, telnetting into the Boxee and running some SQL commands. The fact that I was forced into this solution by the limitations of the environment makes it even more satisfying.

I would submit this little solution back to the Boxee hacks project, except that it seems to be mostly dead. Anyone feel like picking it up?

Posted in Coding.

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK

or, reply to this post via trackback.