XBMC is an awesome media center solution but when you’re using it all over your house your library updates and watched-media lists get out of sync. Read on as we show how to keep all your media centers on the same page.
Note: This how-to guide was originally published in September of 2011 and detailed how to set up whole-house media syncing for XBMC “Dharma” 10.0. We’ve updated the guide for the newer, more user-friendly MySQL integration included in XBMC “Eden” 11.0.
Why Should I Care and Who Is This Guide For?
XBMC has a built-in library system and it keeps track of media you’ve already watched. Unfortunately these things happen, in the default configuration, at the local level. If you have an XBMC unit in your living room and in your bedroom those two installations of XBMC don’t talk to each other.
As a result if you watch some of your TV shows in the living room and some in the bedroom then the marked-as-watched function in XBMC will only show you what you watched on that specific television set. The pause/resume and bookmark functions are also local. If you pause a movie or set a bookmark to hold your place there is no way to access those things unless you’re sitting at the same media center you created them with.
Wouldn’t it be nice if you could stop watching a movie in the living room and resume watching it in the proper location somewhere else in the house? Wouldn’t it be awesome to not have to sit there and wait for each library to update but instead to have it load the library from a central location ensuring all your media is up to date and in sync? It sure would be pretty awesome and we’re going to show you how to do it with free tools.
Before we get to that, however, let’s clear up who will benefit from this the most and who can skip over it.
You should skip this project if…
- You only have one installation of XBMC in your house.
- You store your media on a local HDD attached to your XBMC installations and do not share that media across the network.
- You do not have an always-on (or nearly always on) desktop, HTPC, or server.
- You are running XBMC on the original Xbox hardware—only modern HTPC-based versions of XBMC are compatible with this technique.
You should take advantage of this project if…
- You have multiple installations of XBMC in your house.
- You store your media in a central location like a file server, always-on desktop, or a primary media center.
- You have a computer, such as the aforementioned media server, that is on whenever you’re watching media.
How Does It Work and What Do I Need?
The core of the synchronization magic we’re about to undertake is a MySQL database. Don’t panic if you’ve never used one before! While some of the HTG staff are old database pros I will confess to using MySQL for one thing and one thing alone—managing my media collection.
Follow along closely and you should have no problems. What we’re going to do is install a free version of MySQL database server, create a user account on the MySQL server, and then instruct XBMC to start writing and reading all its library entries to a database on the MySQL server. From that point forward when XBMC checks to see if you’ve seen a specific TV show episode or movie, paused media, or set a bookmark, it won’t just be answering for the specific media center you’re standing in front of but whether you’ve done those things anywhere in the house.
So what do you need for this project? You’ll need the following:
- More than one media center with XBMC installed (version 11.0 or above)
- A free copy of MySQL Community Server (version 5.5 as of this tutorial)
- An always on or nearly always on machine to run the MySQL server on.
You can install the MySQL server on any computer that will be consistently on while you’re using the media centers. In our case we’re going to install it directly to the media server itself as this means that anytime the media is available to our XBMC clients the database is too.
Note: Even if you followed along with our previous guide and have MySQL installed, please take a moment to read over the MySQL configuration section again as key settings have changed in both the configuration of the MySQL server and the settings in XBMC.
Installing and Configuring MySQL for XBMC
For this tutorial we will be installing MySQL on a media server running Windows Home Server. Our installation instructions should match for any version of Windows. For other operating systems please consult the MySQL 5.5 Manual.
The installation of MySQL is straight forward. Simply download the server installation app and run it. Accept the license agreement and, once it finishes installing, make sure “Launch the MySQL Instance Configuration Wizard” is checked before clicking Finish.
The MySQL configuration wizard will launch and present you with the option to select between Detailed and Standard Configuration. Select Standard Configuration and click Next.
On the next screen check Install As Windows Service, name it MySQL—or, if you’re running multiple MySQL servers for some purpose, give it a unique name—and check Launch the MySQL Server Automatically to ensure the MySQL server is always on when you need it.
On the next screen check Modify Security Settings, plug in a new root password, and check Enable root access from remote machines. Click through to the final screen and then click Execute to modify the database. Click finish to close the configuration wizard.
Now it’s time to create a user account on the MySQL server for your media centers. Previous versions of XBMC had a MySQL implementation that required you to manually create databases for every profile’s music and video libraries. XBMC Eden does away with the over-fiddly database creation sequence and handles 90% of the database creation tasks internally. To that end, we no longer need to create multiple databases with multiple users, we simply need to create a single user account on the MySQL server for all of our XBMC units to use.
Let’s get started creating that single user account. Run the MySQL console; you should have an entry for it in your Start Menu if not look in the fire up the command prompt and paste in:
C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql.exe" "--defaults-file=C:\Program Files\MySQL\MySQL Server 5.5\my.ini" "-uroot" "-p"
When the console opens enter the password you created in the previous step. You’ll then find yourself at the MySQL server prompt.
At the prompt type the following to create a user on the database server:
CREATE USER 'xbmc' IDENTIFIED BY 'xbmc';
GRANT ALL ON *.* TO 'xbmc';
The first quoted portion is the username and the second quoted portion is the password. While identical login/passwords are generally a huge security no-no in this case we’re comfortable using a matching pair for the sake of simplicity. A MySQL database, on a private server, that tracks which episodes of Dexter you’ve watched is hardly a high risk installation.
At this point you’re done! Compared to the prior versions of XBMC that required multiple database creations, database edits, and other tweaks, the setup is a veritable walk in the park now. We’d recommend keep the command prompt open for the MySQL server, however, as we’re going to check in later and take a peek at the databases once XBMC has created them for us.
We have one final step before going to configure XBMC. Make sure that Port 3306 (the MySQL server port) is open on the firewall of the machine you’ve installed MySQL onto. By default the Windows installer should open the port automatically but you’re going to save yourself a headache later on by double checking that now.
Configuring XBMC to Communicate with the MySQL Database
By default XBMC uses an internal SQLite database. In order for XBMC to communicate effectively across your home network we need to instruct it to use an external MySQL database. Before we get to that step, however, you’ll need to make an executive decision regarding whether or not you’re going to scrap your library and start fresh or backup and restore it.
If this is a brand new installation of XBMC and you’re configuring everything fresh you can simply skip to the next step. If you wish to save your existing library data you will need to export your library. From within your XBMC installation You’ll need to go to System –> Settings –> Video and System –> Settings –> Video and, at the bottom of the menu, select Export to export your library file. You should only export the library files from one machine on your network. Pick the machine with the most up to date libraries. When you are done configuring XBMC to accept the MySQL databases you will then repeat the above steps and choose to Import the libraries. Everyone else will just run a new scan on their media directories to repopulate the library.
Once you’ve backed up the library (or opted to not worry about it and start from scratch) you’re ready to start configuring. The specific file we’re interested in the the advancedsettings.xml. By default this file does not exist (although it is possible that, during the installation process, XBMC created one for you to deal with specific configuration issues). If the advancedsettings.xml file exists it will be in the following location, based on your OS:
Windows XP – C:\Documents and Settings\[username]\Application Data\XBMC\
Windows 7/Vista – C:\Users\[username]\AppData\Roaming\XBMC\
Linux/XBMC Live – $HOME/.xbmc/userdata
Mac OS X – /Users/[username]/Library/Application Support/XBMC/userdata
Check in that folder. Is there an advancedsettings.xml file there? Yes? Open it up. No? You’ll need to open a text editor and create one. Regardless of whether you’re editing the existing one or create a new one, cut and paste the following text into the file (note: if there is already some entries in your advancedsettings.xml file, leave those in place!):
Edit the above text to reflect the IP address of your server on your LAN and the username/password of your MySQL database. The <name> </name> section is very important and should reflect the specific database you want XBMC to create for that profile. For example, in my house we have three profiles: Adults, Kids, and Test for adult movies and television shows, kid-friendly movies and television shows, and a third profile for tinkering around with XBMC add-ons and other tweaks.
If you are using multiple profiles you need to create a unique advancedsettings.xml file for each profile. Edit advancedsettings.xml file separately and then place it in the /profiles/[profile name]/ folder—a subdirectory of the folder noted for your OS in the step above. The master profile’s advancedsettings.xml file goes in the root folder, the other profiles all go in /profiles/[profile name]/.
Again, you must have a unique settings file for each profile. This means that on each of the multiple XBMC units in my home there are the three aforementioned profiles (Adults, Kids, and Test), each with a copy of the advancedsettings.xml file for the three profiles on each machine.
Once you have created the file and placed it in the proper directory, it’s time to reboot your XBMC for the new file to load. Once you reboot, you’ll need to either import your library or rescan your sources to begin populating the MySQL database. Do that now.
Once you’ve imported your library and/or done your initial scan, you can hop over to your MySQL command prompt and check to make sure XBMC created and populated the databases.
At the mySQL comment prompt type in:
It will output all the databases currently on the MySQL server. You should see, at minimum, at least the following databases: information_schema, mysql, and performance_scheme, as these are part of the MySQL installation itself. The default database names for XBCM Eden are myvideo18 and mymusic60, any custom naming you’ve done will yield custom database names, like adultsvideo60 or the like.
If you should ever accidently create a database via the <name> </name> parameter that you wish to remove from your MySQL server, you can use the following command:
DROP DATABASE databasename;
Empty databases take up hardly any space and won’t negatively impact the performance of your syncing system, but it’s nice to keep things tidy.
When your libraries are imported and/or done scanning, you can do a simple check to see if XBMC is properly communicating with the database. Return to the MySQL command prompt and, to check on whether or not your movies and television shows are in the database, type the following commands (replacing databasename with the name of your video database):
SELECT COUNT(*) from databasename.movie;
SELECT COUNT(*) from databasename.tvshow;
Each query will return the total number of movies and television shows, respectively, contained in your library (according to the the MySQL database). See the screenshot above for an example of a query into the TV show count. If the number of entries is zero there is a problem somewhere along the line. Here’s is a quick trouble shooting checklist of common mistakes:
- Did you copy the advancedsettings.xml file to each machine for each profile?
- If you’re having problem with a sub-profile’s database, did you place the advancedsettings.xml file in /profiles/[profile name] ?
- Did you use the GRANT ALL command to give the XBMC account access to the MySQL server?
- Are all your shares defined as Samba shares (//somehost/sharefolder) and not local shares (c:\media files\)? MySQL doesn’t play nice with the \ symbol found in local share names.
- Did you open port 3306 on the MySQL host machine?
- Are your sources valid and scannable when you remove the advancedsettings.xml file and revert to the local database? If not, you’ll need to troubleshoot your sources independently of your MySQL problems.
If you’ve checked these things and it’s still not working the way it should, go to Settings -> System -> Debugging and turn on the logging feature. Checking the logs will help you find exactly where things are going wrong because, from the XBMC GUI, it’s not always apparent what is going on behind the scenes.
If everything looks good and your SELECT COUNT query pans out, that means you’re ready to start taking advantage of the cross-media-center syncing. Let’s take a peek at what that looks like.
XBMC Syncing Across Multiple Machines
One of the first changes you’ll want to make, if you haven’t already toggled this setting to begin with, is to alter what XBMC does in response to you pressing play on a file. By default XBMC simply plays the file from the beginning. Since we now have an XBMC system that remembers our place across multiple machines, we want XBMC to prompt us.
Navigate to Settings –> Video –> File Lists and set the Default select action to Choose. We want XBMC to ask us what to do when we’re opening a file instead of automatically playing it from the start.
Now that we’ve flipped that toggle it’s time to play around with XBMC and see how we can resume play and check our watched files across the network at multiple XBMC consoles.
We’re going to navigate to our directory of HDTV demo reels and mark one as watched, set a bookmark in another, and watch and pause the third reel. Then we’re going to leave the office and go into the living room and check the three files to ensure XBMC has properly flagged the first, bookmarked the second, and can resume the third. Here are snapshots of each action:
Now, when we travel to another XBMC console, we can take a peek at what each one of these things looks like. Let’s check to see that our first file has been marked as watched:
Excellent, there it is with a check mark beside it. The remote XBMC console is aware the file has been watched.
What about bookmarks? Did the bookmarks carry across via the database too? Let’s check and see if the action our action packed scene with the fire breather and rugby player is still bookmarked:
Looking good so far. Finally let’s check to make sure that the video we paused in our office will resume in the correct location (1:13) when we select it in the living room:
Success! Simply pausing/stopping the movie file in the office was enough to mark it in the database and prompt us to resume from that location when we returned to the file at the remote location.
From this point forward you’ll be able to check what movie and TV shows you’ve watched, where you left off, and what bookmarks you set, from anywhere within your house. Your media and associated libraries will be up to date regardless of where you are—no more fussing with manually syncing your library contents again!