SEARCH

How-To Geek

How to Sync Your Media Across Your Entire House with XBMC

2011-09-27_160436

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?

xbmcreq

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

2011-09-16_154349

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.

2011-09-16_160713

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.

2011-09-16_160759

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.

2011-09-27_143648a

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

2011-09-27_161137

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!):

<advancedsettings>
<videodatabase>
<type>mysql</type>
<host>192.168.1.120</host>
<port>3306</port>
<user>xbmc</user>
<pass>xbmc</pass>
<name>profilenameherevideo</name>
</videodatabase>

<musicdatabase>
<type>mysql</type>
<host>192.168.1.120</host>
<port>3306</port>
<user>xbmc</user>
<pass>xbmc</pass>
<name>profilenameheremusic</name>
</musicdatabase>
</advancedsettings>

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 profileThis 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:

SHOW DATABASES;

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

2011-09-27_160436

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.

2011-09-27_153735

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:

xbmc1a

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:

2011-09-27_155639

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:

2011-09-27_155823

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:

2011-09-27_155722

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!

 

 

 

 

Jason Fitzpatrick is warranty-voiding DIYer and all around geek. When he's not documenting mods and hacks he's doing his best to make sure a generation of college students graduate knowing they should put their pants on one leg at a time and go on to greatness, just like Bruce Dickinson. You can follow him on if you'd like.

  • Published 04/3/12

Comments (37)

  1. Durban

    Oh snap!!! How simple was that!!! Revolutionary … Bloody revolutionary!

  2. TheClaus

    I do this on my AppleTV2s that I have jailbreaked and running XBMC on them. Though there is a bug that causes db wipes with ATV2 so I have 2 mysql users. One that has SELECT access on everything except bookmarks and files which have GRANT ALL. That way I can still pause and resume in different rooms and also marked as watched.

    It works great and combined with Amahi Storage Pooling it makes for one bad arse library of media goodness.

  3. Adam

    I’m about to start this but I am wondering is it possible to run mysql from my router itself? I have an asus rt-n16 running Tomato Firmware v1.28.9054 MIPSR2-beta K26 USB Ext. Since tomato is based off of linux I’m hoping i can use that to host it all so I can have a central server (which is where i store all my media) and that way we can turn any pc on, open xbmc and go from there without making sure my one is on

  4. Psybernoid

    @Adam
    I wouldn’t even go there.
    MySQL databases require more CPU power than the average router could provide.

  5. Veovis Muad'dib

    Got it done, but note that when I was doing this over ssh to my Ubuntu machine, I was required to replace all symbols such as ‘ myself. They looked correct, but would not work, popping up syntax errors until I replaced them myself.

    TL;DR: Don’t copy and paste.

  6. Jason Fitzpatrick

    @TheClaus: Would you care to expand upon your setup/configuration? I think that would greatly assist any AppleTV users who come across this tutorial.

    @Adam: Out of curiosity I did a little digging. It turns outs that there *is* a MySQL package for Tomato firmware (specifically it’s an optware package for TomatoUSB).

    Here are a couple forum posts that mention it:

    http://tomatousb.org/forum/t-292257/
    http://tomatousb.org/forum/t-319292/

    My big concern would be storage space (the MySQL files on my Windows server take up about 80MB total, perhaps the router version is better optimized) first and processing power second. Maybe the demands on the CPU would be pretty low given the nature of the database we’re building here but I can’t speak to that with any authority.

    @Veovis: Indeed… many a time I’ve been thwarted by cut/paste.

  7. Cambo

    @Adam

    I agree with the other posters- running a database off a router is not a great idea. The CPU’s are slow, and you’ll eventually run out of space on it. Not to mention, probably burning it out quickly.

    PC’s cost very little to run 24/7, so I’d be more inclined to put it on a Windows/Linux machine instead. Unlimited storage and much better CPU power.

  8. A

    I like how this article tells you whether or not it’s pertinent to your needs or not.

  9. Adam

    For Windows the advancedsettings file does not go in the root folder of xbmc. It goes in the userdata folder. So it should read C:\Users\[username]\AppData\Roaming\XBMC\userdata
    And for everyone else. thanks for the suggestions. I’ll just stick to having the database on my pc. It’s pretty much always no anyway

  10. Rob

    I’ve been running this setup for a while. Got the idea off a post @ lifehacker. I’ve got to say, this was the single most impressive thing I’ve done w/ xbmc. Having libraries, and auto-scrobblers, and skins is cool, but pausing and picking backup in another room is AWESOME.

    Currently SQL and the Actual LVM storage sits on an old dual core 3.0ghz AMD machine, w/ 4 gigs of ram. Everything that serves or watches is gigabit wired. Its possible to get the same thing (movie/music) playing in multiple rooms of the house @ the same time, but I found usability problems with it…. remote wouldn’t work on main tv… which was a killer.

    I think I missed the steps about the audio database before, so I’m going to give this a shot!
    Long live XBMC!

  11. Chef_

    I do this with my setup, 3 HTPC XBMC Installs and I take it one step further. I have the profile information stored on a share on the server and I point all installs to the same folder. That way when I update the skin or a setting on one, all three get the setting at next start. Customize once, enjoy many.

  12. Adam

    Ok I’ve got this up and running and it’s great. Next step. how would I create a whole new library on a different profile? So I can set up a list of movies, etc that are kid friendly and still get the room to room portability

  13. shaf

    Chef, how do you do that….with all 3 ….how do you point the profile to a shared folder?

    thanks

  14. Adam

    Never mind, figured it out… it’s real simple and I’m a twit :P

  15. sti25impreza

    I had tried this back when Lifehacker posted on it but never got it working. Decided to try it again using these instructions but am running into the same issue I did months ago. Everything goes fine until I import stuff into XBMC, its supposed to automatically be populating the database but it isnt. When I run the SELECT COUNT(*) from xbmc_video.tvshow; command I get an error stating the table does not exist. Seems XBMC cant communicate with the database. All my settings are correct, I have quadruple checked them. Anyone have any ideas or experiencing the same issue?

    My XBMC install and my sql database are on the same machine FYI. Tried disabling the firewall and even changing the IP address to use 127.0.0.1 but to no avail.

  16. TODAYinTECH

    This does not work for me. I am able to connect to the database from my xboxes and export the database. But pausing or bookmarking never update the database. I configured the skin to allow me to choose whether to start from the beginning or resume.

  17. scunner

    same issue as sti25impreza.

  18. shellshock

    @sti25impreza & scunner

    I think that the stated path to the advancedsettings.xml file in is wrong (for Windows 7). It works for me, if I put the file in the following directory:
    C:\Users\[username]\AppData\Roaming\XBMC\userdata

  19. akira6968

    If the author reads this, I humbly request you add a small bit of text to this line in your “Stuff people frequently screw up” section…

    (currently says)
    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.

    “This includes mapped network drives, they will not work. Your sources must be defined using SMB!”

    you only mentioned local not working, and I guess mapped drives look local to XBMC or whatever, but to a noob like me I missed it because my Z:/ drive isn’t local… and of course I never remember which slash is used where, so I didn’t catch that either.

    The library I had locally was set up with mapped drives, then exported, then imported with the MySQL running. It got most of the content, but not all, which really threw me off. Then it wouldn’t scan for new content, or allow me to set content, or anything. Only played content…

    Dunno if I should start all over, or if it will fill in the gaps. Either way, this is now uber-awesome, and thank you for the guide!!!!!!!!!!!!!

  20. andriajohn

    Good to know about the How to Sync Your Media Across Your Entire House with XBMC

  21. Citrus Rain

    I hope it becomes compatible with Google TV… all the aVida app does is look at the directories of whatever XBMC has episode information on.

    XBMC or VLC… whatever comes first. (That unofficial build of VLC is not for Honeycomb)

  22. Vinh

    An issue I ran into is that I created the 2 db’s, xbmc_video and xbmc_audio. This caused XBMC to not autocreate the proper db’s. I deleted the db’s and it worked properly.

    DROP DATABASE xbmc_audio;
    DROP DATABASE xbmc_video;

    I’m using Zend Community Edition (free) for MySQL (and apache\PHP) with PHPMyAdmin for DB management. Convenient optimized way to have Apache\PHP\MySQL.
    http://www.zend.com/en/products/server-ce/downloads

  23. jamesjoseph

    Thanks for giving the more information about the How to Sync The Media Across Your Entire House with XBMC

  24. grellanl

    This is a lot of work. How about you just use Plex instead? Only one server/database to manage, it remembers your resume points, has clients for Mac/Windows/iOS/Android.

  25. Set271

    Thanks HTG. Why, just the other day I realized I have enough parts hanging around in boxes to build a server which I could transfer all my movies, tv shows, music, and data archives to. And, then, this article pops out of your site. Awesomeness abounds here!

  26. Elove7300

    I read this and it sounds great but I didn’t see any distinct direction on how to sync this to my ATV2. Did I just miss it? I tried importing the video file library but it wont over a network I guess it has to be local to the ATV2. Any suggestions

  27. press_DUCK

    FYI:

    CREATE USER ‘xbmc’ IDENTIFIED BY ‘xbmc’;

    GRANT ALL ON *.* TO ‘xbmc’;

    The single quotes in these commands all need to be an apostrophe to work, trying to copy and paste into the command window will return an error if, like me, you are disinclined to type.

  28. awraynor

    My WHS 2011 Server already has Microsoft SQL Server 2008 server running. Can I complete this with that SQL install, or do I need the free MySQL Community Edition? Just trying to limit the SQL installs if possible? Oh, and trying to use a jailbroken ATV2 with it.

  29. Dave

    Thanks for the article! I’ve got this mostly set up, but am running into some issues on my remote machines. I’ve got the libraries set up using SMB share paths on the media centre that also runs MySQL, and the database is populating correctly. I can play the videos and everything shows up as it should. However, when I try to access the library from another machine I can still see all of my videos in the library but without posters, covers, or fanart, and when I try to play a video I get a “video not found” error. Any ideas what might be causing this?

  30. Tom

    hello Dave:

    I’m have a similar problem. i’ve posted here: http://goo.gl/8n5id

    If you manage to find a fix would you mind sharing?

  31. guest

    @shellshock that worked for me. thanks!

  32. Learnfrom Mymistakes

    With regards to the count statement in MySQL, you need to connect to your database first.
    Do the following to see if it works without the double quotation marks – dont forget the semicolon at the end of each statement. Also at times Mysql does not work well with spaces so when you create your user profile do it without a space. I had issues in mysql doing the databasename with a space, “Master uservideo60″ was creating issues but masteruservideo60 did not. — I also copied the sources.xml find from the main xbmc computer, this way I did not have to rewrite or search for new sources on my other three htpc. The only issue I am having even though I am using a gig home network is a little latency due to the amount of movies, TV shows, and music (4,000 movies, 12000 tv episodes, 22,000 songs- wont mention how many artists). So I have to optimize my tables daily. Hope these few tidbits help. By the way Lifehacker — excellent blog!

    “show databases;”
    “connect yourvideodatabasename;” –> for example mine is “connect masteruservideo60″
    “SELECT COUNT(*) from yourdatabasename.movie;” —> for example mine is “SELECT COUNT(*) from masteruservideo60.movie;”

  33. bezdancing

    Hi, thanks for the great guide!

    I have one small problem though. The remote machine will display the video synopsis but it will not show thumbs or fan-art. Everything else works perfectly, I can start and resume videos on either machine I can even read what the video is about, I just can’t get thumbs. Has anyone had a similar problem?

  34. Amber

    I set this up last night (Vista, Win7 and XbmcUbuntu boxes) and it is the best thing ever.

    One note: the correct settings xml file location on my systems was never exactly where the tutorial stated it should be, but I was able to figure out where XBMC thought it should be by looking at the log file. Easy peasy!

  35. ttr

    use dropbox instead

  36. zebraitis

    @ ttr :

    Dropbox is not an option for some. reason: my thumbnails subdirectory is already over 2 gig.

  37. Kevin Barrett

    I’ve got “Mark as watched” and bookmarks working, but not pause. In fact, I can’t seem to replicate the “Resume from 1:13″ (or whatever time) screenshot at all. And that’s without switching to another machine. Is there a setting or something I’m missing? I do have the “Choose” option turned on in Play Lists. Thanks!

Enter Your Email Here to Get Access for Free:

Go check your email!