Having recently bought a WDTV HD Live to replace my Xbox (with XBMC) I decided to look into setting up a UPnP service on my Ubuntu headless server.
sudo apt-get install mediatomb
This will get mediatomb installed, and should set it up as a service. You can stop/start/restart it with:
sudo /etc/init.d/mediatomb stop|start
Next you need to change the config.xml for MediaTomb. This is located at /etc/mediatomb/config.xml
sudo gedit /etc/mediatomb/config.xml
- Set the name of your server in the config. This is near the top under the element <name>.
- By default (and this point stumped me for a bit) it won't use import.js to import your videos/music/photos. Instead it will just use the MediaTomb default (which for movies I didn't find very good). If you search for "virtual-layout" and change its attribute "type", from "builtin" to "js", this will cause import.js to be used.
- Under the <server> element, add <pc-directory upnp-hide="yes"/>. This hides the annoying PC Directory folder that will otherwise show up when you view your UPnP service.
Next you'll want to edit the "import.js" file that defines how your media is imported. This is located at /usr/share/mediatomb/js/import.js.
sudo gedit /usr/share/mediatomb/js/import.js
Here's my import.js file. I've only changed the "addVideo" function so far. The code (if you're a developer) should be reasonably easy to read. With all of the above set, restart your MediaTomb service
sudo /etc/init.d/mediatomb stop
sudo /etc/init.d/mediatomb start
* note you can try "restart" but I've had issues with it.
You should now be able to go to the web interface for MediaTomb (http://localhost:49152/), then under the "File System" section add any folders, setup filesystem watchers etc... If you're running the service on your local machine, "Inotify" is probably the better way of getting Mediatomb to watch any folders for updates. However, using Inotify won't work remotely. For example, I ssh onto my server, and often move files around which don't get picked up by Inotify.
Set it watching any folders you choose, then wait a minute or two for Mediatomb to import all the data. You can check what the import looks like in the web interface, under the "Database" section.
sudo gedit /etc/default/mediatomb
Make sure at the top you have the line - NO_START="no".
Also, if you're running Ubuntu it has a bit of a bug, whereby Mediatomb is started before NetworkManager and fails to start as it can't find a working network device. I found the following lines fixed this (moved it back in terms of load order):
sudo update-rc.d -f mediatomb remove
sudo update-rc.d mediatomb defaults 99
This fix was taken from the Mediatomb wiki FAQ (about 1/4 down the page). You should now have a fully functional UPnP server up and running!