How to simply create a "media pool" on Linux?

Ever since I switched to (Arch) Linux, I've always loved the command line. It can often be quite amazing, I find. Back in the Windows world, you're pretty much expected to forget that such a thing even exists.

Things are different over here (particularly with Arch, I guess), and that's all for the better. Many reasons for that, one being the fantastic simplicity and power that it offers you.

Case in point, let's say you've got a bunch of external disks that you quite unimaginatively call "disk1" to "disk4" on which you store things such as movies, TV/web series and the likes.

All those data spread over many disks, and you don't necessarily know where to find what you're looking for, or you don't want to have to plug all the drives just to go through the list of what you do have (memory can be tricky).

A solution is to create what I'll call a "media pool," which is simply a folder that will "list" all you have. Say on every disk there's a folder "Movies" containing, well, movies. In our pool, we want a folder "Movies" that will "contain" all movies from all the disks.

Of course, the actual data won't be there, just symlinks. Enough for us to know what we have, and where it is. I'm not sure how you'd go and do that on Windows, but things couldn't be easier on a GNU/Linux system: a simple cp will do, since it has a flag (-s, --symbolic-link) to create symlinks instead of copying.

To do so over all disks as we want, this is all we need:

  1. #!/bin/bash
  2. for d in /media/disk?/*; do
  3.     [[ -d "$d" ]] || continue
  4.     [[ ${d:${!d} - 11} == "/lost+found" ]] && continue
  5.     cp -asR "$d" /media/pool
  6. done

Done indeed, as that is all we need.

But where is the data?

Now because cp is smart, the symlinks it'll create will be based on how you called it. Since here we're using full/absolute path names, symlinks will use the same.

Which means that we know every single symlink points to /media/disk?/... Why is that great, you ask? Because with the wonders of the command line, it couldn't be any easier to get the disk's name for a symlink/movie:

  1. readlink $SYMLINK | cut -d/ -f3

Simple as that. Probably nothing special if you've been dealing with this forever, but I always find it quite amazing how simple & easy this is. But let's not stop there...

Benefit from all this in you file manager!

Because while I like the command line, I'm also using graphical applications, and in fact I use a GUI file manager. Sometimes nothing beats opening a terminal and typing a few commands, and sometimes I like the ease & interface comfort only such a tool can provide.

And when I want to browse through my media pool, I'd like to use my file manager. But I'd like to know where my data is quite easily as well.

With donnatella, this is rather easy to do actually; Though not everything might make sense if you're not familiar with it.

First, I'll create a new arrangement for folders in /media/pool An arrangement defines things like column layout/options, and that can be made specific on a per-folder basis :


Here we define the columns to use, as well as changing a few options: column name will be made a bit smaller, we don't have a column size but use a column text instead, which will show the content of property "pool-disk"

What is that, you ask? It's a custom property we'll also have to define:

cmdline=donna-pool-disk %:n

And then we have a little script, donna-pool-disk, that will return the name of the disk(s); We're using a script because we want to support this for folders as well, but obviously this will be based on files contained within, and we'd like to support the case where those are spread across multiple disks (may not be likely for movies, but more but TV/web series).

  1. #!/bin/bash
  3. while [[ -n $1 ]]; do
  4.     file=$1
  5.     shift
  6.     if [[ -d "$file" ]]; then
  7.         disks=$(find "$file" -type l -print0 | xargs -0 readlink | \
  8.             cut -d/ -f3 | sort -u | tr $'\n' ,)
  9.         echo "$file|pool-disk|${disks:0:-1}"
  10.     else
  11.         disk=$(readlink "$file" | cut -d/ -f3)
  12.         echo "$file|pool-disk|$disk"
  13.     fi
  14. done

Et voilà!

donnatella: Browsing the media pool

Top of Page