Script: Refresh the Fritz!Mediaserver DLNA Index of the Fritz!Box 6360 Cable

Some of AVM’s Fritz!Box routers allow connecting a USB device and use this device as a network attached storage (NAS) via Samba/SMB in the local network. In combination with the fact that the NAS can also be accessed from the Internet via FTP, and the multimedia files can be streamed to a TV via the Fritz!Mediaserver (using DLNA), it makes a pretty basic home entertainment system. I use it to automatically copy videos (YouTube, etc.) to the NAS from my virtual server, and then watch these with my Samsung Smart TV. It’s not as great as XBMC, but it works for now.

Unfortunately, the Fritz!Mediaserver (DLNA server) does not automatically refresh the index when media files are added via Samba/SMB or FTP (only if they are added via their web interface Fritz!NAS). It can be refreshed manually via the interface on fritz.box/storage/settings.lua. But, since I like to automate things, I made a little helper to automatically refresh the index.

Only once: Download and configure the Script

Setting up the script is easy. Just download and configure the Fritz!Box DLNA index refresh script. If you haven’t already, install the PHP command line interpreter:

sudo apt-get install php5-cli
wget https://heckel.io/uploads/2012/12/fritzbox-md5-2.1-BROKEN.js.php
wget https://heckel.io/uploads/2012/12/fritzbox-dlna-refresh
chmod +x fritzbox-dlna-refresh
vi fritzbox-dlna-refresh

Now update the configuration (esp. your Fritz!Box router password) and run the script.

Side note (not relevant for the setup): If you’re wondering why an external MD5 library is necessary to run this script, here’s the answer. The Fritz!Box 6360 uses Paul Johnston’s MD5 JavaScript library (version 2.1). Unfortunately, this version of the library is broken and the MD5 hash it returns is wrong – in other words: md5(“123”) != hex_md5(“123”). So I had to translate the library from JavaScript to PHP. The resulting library can be found is at fritzbox-md5-2.1-BROKEN.js.php.

Running the script

The output of the script should look something like this:

./fritzbox-dlna-refresh 
[GET login.lua     ] Retrieving login page and challenge ... challenge is 63dbb3af, calculated response is 63dbb3af-e8d4c113f2b5a73c80d5df7488d7bd84
[POST login.lua    ] Logging in ... Successful, SID is ece4927d0b7b58c6
[POST settings.lua ] Refreshing NAS DB 1 ... Done.

Of course this script also needs to be manually triggered somehow. But setting up a cronjob on you laptop or home server shouldn’t be a problem…

I hope this helped a little!