I have been thinking for a while about virtual VDR directories
holding symbolic links to recordings that are stored elsewhere
using different sort criteria.

I have been a VDR user since 2000
and I have recorded a lot since then (9245 recordings),
so some kind of structure is required to find things quickly.

For example, I have top level folders for various genres in my
/video directory. So far, I decide after recording and cutting
into which folder I move the recording.

It might be better to have them all on one big RAID and
create symbolic links in /video, so I can find an action comedy
both in /video/Action and in /video/Comedy.

Regarding the genre, I have managed without that feature.
However, many German TV stations are now broadcasting
in HD, sometimes with 5.1 surround sound.
It is really hard to find these high quality recordings directly
among my 9245 recordings.

So I have written a little Python tool that creates "virtual"
recordings in a different folder structure from my "real"
recordings using symbolic links.
This is done by creating top level folders /video/Surround,
/video/HD, /video/Surround+HD and linking matching
recordings into these keeping the original folder structure

Maybe somebody else finds this useful, so I am attaching
the code. It only considers recordings that are cut
(having a % in the name). Please note that the tool
removes any existing folders /video/Surround,
/video/HD, /video/Surround+HD before re-creating them.
Use at your own risk.


import os
import shutil
import sys

video_dir = "/video"

def linkto(root, name):

   components = []
   for root_component in root.split('/')[2:]:
      if root_component.startswith('%'):
   source = os.path.join(video_dir, '/'.join(components))
   target = os.path.join(video_dir, name, '/'.join(components))
   target_parent = os.path.join(video_dir, name, '/'.join(components[:-1]))
   if not os.path.exists(target_parent):
   os.symlink(source, target)

for subdir in ("Surround", "HD", "Surround+HD"):
   path = os.path.join(video_dir, subdir)
   if os.path.exists(path):

surround_dirs = []
hd_dirs = []
surround_hd_dirs = []
for root, dummy_dirs, files in os.walk(video_dir, followlinks=True):
   if '%' in root and ("info" in files or "info.vdr" in files):
      surround = False
      hd = False
      for line in open(os.path.join(root, "info" if "info" in files else "info.vdr")):
         if line.startswith("X "):
            if " 5.1" in line:
               surround = True
            elif "high definition Video" in line:
               hd = True
      if surround:
      if hd:
      if surround and hd:

for root in surround_dirs:
   linkto(root, "Surround")
for root in hd_dirs:
   linkto(root, "HD")
for root in surround_hd_dirs:
   linkto(root, "Surround+HD")
vdr mailing list

Reply via email to