Skip to content

Monthly Archives: February 2015

minidlna rescan

I’m using minidlna on my server to serve media to the whole house.

It works, but I’ve never gotten it to auto update the media library, even though inotify is enabled.

So far I’ve just logged in on the server and run (I’m using arch linux):
/usr/bin/minidlnad -R && systemctl restart minidlna

This approach sucks for several reasons:
1) I actually need to do something to make it register new content
2) The WAF factor is at an all-time low.

Instead I’ve made this little script, to solve my problems:

#!/bin/bash

#check that minidlna is not being used!
wget http://localhost:8200 -O /tmp/minidlna_index.html 2> /dev/null

isOpen=`grep ‘
-1 connections currently open
‘ /tmp/minidlna_index.html`

if [ -n “$isOpen” ]; then
#minidlna can be updated – if needed

# list files monitored by minidlna
ls -l /mnt/dlnamedia/* > /tmp/minidlna_rescan_dir_list_new

#If you want to force a minidlna rescan on the first run of this script, comment out this if block!
if [ ! -f /tmp/minidlna_rescan_dir_list ]; then
mv /tmp/minidlna_rescan_dir_list_new /tmp/minidlna_rescan_dir_list
#echo “minidlna dir list does not exist.”;
exit;
fi

filesDiff=`diff /tmp/minidlna_rescan_dir_list /tmp/minidlna_rescan_dir_list_new`

if [ -n “$filesDiff” ]; then
#echo “dir lists don’t match – rescan!”
mv /tmp/minidlna_rescan_dir_list_new /tmp/minidlna_rescan_dir_list
/usr/bin/minidlnad -R && systemctl restart minidlna
fi

#else
#echo “minidlna is in use! – skipping rescan”
fi

and I’ve then added this script to crontab:

crontab -e
0,15,30,45 * * * * /root/my_scripts/minidlna_rescan.sh

It runs four times pr. hour.

First it checks if minidlna is in use, if so nothing is done.
Then it checks if some files changed in watched directory, if so, it will restart the minidlna service and force a rescan.

You’ll need to change the /mnt/dlnamedia/ path to match your system (the media directory path(s) in minidlna.conf).
Also, if minidlna runs on a different port then 8200, you’ll need to change that as well.
The path set in crontab (/root/my_scripts/minidlna_rescan.sh) should match the path to where you put this script.

It works quite well for my purpose, though still not the optimal solution. Maybe it will be useful for someone else as well.