0. Why might this be neccessary
Well, I collect quite a lot of Movies, and recently my hard-disks were full, so I bought a new one. But my Antec-Case only has slots for two hard-disks, so I had to swap one out to make room for the bigger one. The problem here was that I was merging two partitions, so movies which were previoulsy in /media/hd1/ now resided in /media/hd2. Of course XBMC could not find them any more. Of course I could've done a Library-Cleanup and a Rescan, but that would have downloaded about 300 movie-infos again.
A word of warning before we begin: This will directly alter your XBMC-Database. If you screw up, no one will be able to help you and you will have to delete your database and start over from the beginning.
You also should exit out of XBMC before beginning.
Also, this guide is probably not very beginner-friendly. Basic knowledge of Linux and XBMC is required.
First of all, I'll be using these example values, which correspond to the actual move I made.
Original path to the movies: /media/hd2/Movies/
New path: /media/hd1/Movies
There will be three steps to this:
- Move the Media-Files
- Change the Paths in the Database
- Change Thumbnail-Cache
For the second part, I used "SQLite Manager", an addon for Firefox. For the third part, I created a tool to simplify the process.
2. Move the Files
Nothing magical about that, just do a simple mv to move all your Files to the new location.
[clou@maia ~]$ mv /media/hd2/Movies/* /media/hd1/Movies
3. Fix the Database
The devs have done a great job designing the Video-Database, so this is not a very difficult tast. Before getting into the Database itself, be sure to create a new Video-Source in the GUI pointing to our new directory.
Now open up the MyVideos34.db (in .xbmc/userdata/Database) in SQLite Manager. I recommend creating a backup.
Select the table "path" on the left and switch to "Browse & Search" on the right. You now need to find the entries for both your old movie-path and your new movie-path. We are especialle interested in the "idPath"-numbers.
My numbers were: /media/hd1/Movies: 9, /media/hd2/Movies: 6
Uploaded with ImageShack.us
Now go to the table "files". XBMC stores filenames seperately from their paths, which is a good thing for us here. We need to change the "idPath"-column from the value of our old path to our new path. Change to "Execute SQL" and enter the following:
UPDATE files SET idPath=[newPath] WHERE idPath=[oldPath]
All the file entries who previously had the old path assigned to them should now have the new path. Save the database and quit SQLite manager.
You should now be able to start any movie in XBMC again. But the thumbnails of your moved movies will be missing.
4. Renaming the Thumbnails
The reason for the cover-images not showing up is that they are saved in a format dependend on the location of the files. They all are in .xbmc/userdata/Thumbnails/Video. You can open any .tbn file with your favourite image-viewer to see them. So because we changed the paths, XBMC is not able to find the images. We need to correct that.
I wrote a tool to make this process a little easiert. It works as follows:
- Input a list of ABSOLUTE paths to movie-files in their NEW location
- Input old location and new location
- The tool will calculate the name of the thumbnail for every file in the old location
- and output a shellscript to rename these thumbnails to correspond to the new location
I "borrowed" the algorithm directly from the XBMC-source, so the calculation will always be equal to the one xbmc does.
Use the tool like this
find /media/hd1/Movies -type f | ./hashcalc /media/hd2 /media/hd1 > move.sh
Of course, adjust the values to your actual folders. To find out more about the syntax, start the tool without any parameters.
It should create a file move.sh with a lot of mv-commands, like this
# Rename thumbnail for /media/hd4/Movies/Blow.mkv
mv c/cf8361f3.tbn c/cd9cde5a.tbn
As you can see, the paths are already prepended with the first character, as in the Thumbnails folder. So copy the script to .xbmc/userdata/Thumbnails/Video, make it executable and run it. If you had other movies in your new video-path that were never in your old path, some operations will fail, but that is expected and does not do any harm.
XBMC should now be able to display all thumbnails and start all movies just like before the move. Congratulations
The tool: http://rapidshare.com/files/429406112/hashcalc.tar.gz