give & take lists

published: 2015-09-09 15:17:10, updated: 2017-11-12 16:28:37
comparing movies with friends

So far, using hdd-indexer, you can indentify what movies are present on the disk, get their metadata, browse using this metadata. So you know what’s the highest rated movie you have, or what’s the latest movie you have. Great. But what happens when you meet up with a friend, and there’s exchanging of movies? You both ask each other what movies are present that you don’t have, find the movie files amongst all the (if) randomly named and arranged folders, and then copy them one by one. Too much repetition. So I decided to see if I can get hdd-indexer can do something about it.

I came up with the simple concept of give/take lists, which show a two-column list of movies that

If you’ve studied (and remember!) a little bit of math (set theory, to be precise) you can see that the the above two conditions are nothing but an application of set difference. Let’s say that X is the set of movies on your disk, and Y is the set of movies on your friends’ disk. Then by set theory, we have:

The assumption here, is that all objects in X and Y are similar, or can be compared to see if they exist in either set. Which means, that the format in which movies are stored, or indexed on both disks must be the same (or it will involve more work to first convert them both in to a common format). Once we get a set of movies, it’s trivial to calculate the set difference in any programming language. If you’re not an aware programmer, I hope the pesudocode is self-explanatory.

function set_difference(X, Y):

var difference = list() # empty list

for x in X:

if x not in Y:

difference.add( x )

return difference

Once we calculate this difference, we get a list of movies to give and take. This eases a part of the transaction - finding which movies should be exchanged. There’s still the other parts that need to be addressed: copying movie files. To make this possible, we need to understand what happens when movies are exchanged. The files containing these movies are copied directly to the disk, if available, or else to a temporary location (to be copied to the disk later). In both cases, it’s a copy-file operation that can be automated using a script.\

Since hdd-indexer is aware of the file paths of movies indexed in its database, the creation of such a script is trivial.```

function copy_script(movie_list, target_folder):

var script = list() # empty list

for movie in movie_list:

# cp for *NIX, copy for WINDOWS

# shell command

script.append(“copy movie_list to target_folder”)

Depending on the platform, the command to copy changes. Fortunately, this trivial differences are taken care of because hdd-indexer uses python, which offers libraries that do the work on all platforms. So we merely have to tell the script that we want a file copied from one path to another.

After copying, the part that does not figure in the movie exchange - adding these files to hdd-indexer comes up. There’s always the easiest way to simply copy the files in the movie folder on disk, and let hdd-indexer detect them and download their metadata. But to make things more challenging, and better, we can export the metadata along with the copied files. Hdd-indexer can simply create a file called, say, get_list.json that will contain a list of all movie files that have been copied, and their metadata. Now you can simply import this file in to hdd-indexer, and it knows what movie files to add along with their metadata.

There, a simple example of exchanging movies between friends gets another feature added to hdd-indexer!