I’ve been looking for this for ages, but never found it anywhere. I have minidlna scan my media directories for any new files, but whenever I move a directory into my media, minidlna always shows it as empty.

It turns out that this is because it does get notified about the new directory, but doesn’t scan the containing media inside it. The solution was pretty simple, just touch every file after adding them. Here’s how to do this for all your legal downloads with Deluge:

#!/usr/bin/env python
import sys
import os
import subprocess

def walkdir(root):
    for path, subdirs, files in os.walk(root):
        for name in files:
            yield(os.path.join(path, name))


if __name__ == "__main__":
    torrent_id = sys.argv[1]
    torrent_name = sys.argv[2]
    torrent_path = sys.argv[3]

    # Touch files so minidlna sees them.
    for filename in walkdir(os.path.join(torrent_path, torrent_name)):
        subprocess.call(["/usr/bin/touch", filename])

Feel free to adapt the above to your own use, it’s released under the MIT license.