[LINUX] HOW-TO move files in your Library to another location without Rescraping
#1
Hi everyone. As I could not find anything about this topic I figured it out myself and am now writing a little guide. Maybe it will be useful to someone. The method still requires a lot of "manual" operations. If there is some interest, I might automate it further with a python script or something.

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.

1. Prerequisites
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:
  1. Move the Media-Files
  2. Change the Paths in the Database
  3. 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.
Code:
[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
Image

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:
Code:
UPDATE files SET idPath=[newPath] WHERE idPath=[oldPath]
And replace [newPath] with the id of your new path (in my case, 9) and [oldPath] with the id of the old path (6 in my case). Then press "Run SQL".
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:
  1. Input a list of ABSOLUTE paths to movie-files in their NEW location
  2. Input old location and new location
  3. The tool will calculate the name of the thumbnail for every file in the old location
  4. 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
Code:
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
Code:
# 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.

5. Conclusion
XBMC should now be able to display all thumbnails and start all movies just like before the move. Congratulations Wink

The tool: http://rapidshare.com/files/429406112/hashcalc.tar.gz
Reply
#2
There is info on here as I wrote something similar its also in the wiki but nice to see a way to get thumbnails to show again Smile

Although you could have just exported your library to separate files and then xbmc wouldn't have needed to download any info just add local artwork and nfo's
Reply
#3
Cool, I must've searched for the wrong terms Wink
Exporting would have been an option, but I don't really like the idea of creating hundreds of little files in my movies-folder. I like it neat and clean =)
Reply
#4
Clou42 - I just wanted to say thanks for posting this tool. I intend to give it a try in the next few days to help me switch from using the smb protocol to a local nfs mounted filesystem.

Re: the posts above, I believe that 'just' exporting your library would cause you to lose watched/unwatched status, date added to the library, etc., which I would very much like to preserve when making this change.
------------------------------------------
Dharma Quick Setup Guide:
XBMC tips on the TechNazgul Blog
------------------------------------------
Reply
#5
Thank you very much, this is exactly what I was looking for!

But this is a linux script, and I was using previously XBMC under Windows, with files locally and not shared on the network.
Now I want to move XBMC to my new AppleTV2, si I will be sharing my files through smb.

I can export and import my database with no problem, changing the sources.xml too, but the thumbnail won't display. I don't want to rescrap again cause I really have a poor internet connection (and I may need to do this again later, as I am planning to use NFS in the future).

My question is: if I load my linux VMWare image, would I be able to make the necessary changes ? ie: from "E:\Movies\Movie1.avi" to "smb://Computer/Movies/Movie1.avi"

If I understand your explanations well, it should as I just need the old path to be an input value. I don't want to install XBMC on my Linux vmware so I will just move the necessary files in it.
Reply
#6
For the benefit of future Googlers who land here, I thought I'd post back a link to the solution I found for moving your XBMC libraries without losing your thumbnails.

I did try to use the scripts posted above but ultimately could not get it to work. The script generates a list of files to move and rename, but I couldn't get them to generate the XBMC hash correctly for the filename. This was most likely my mistake, but I ultimately gave up and found another solution.

@Roums - check out this post and let me know if you have questions on how I accomplished the library move without losing thumbnails.
------------------------------------------
Dharma Quick Setup Guide:
XBMC tips on the TechNazgul Blog
------------------------------------------
Reply
#7
Roums Wrote:My question is: if I load my linux VMWare image, would I be able to make the necessary changes ? ie: from "E:\Movies\Movie1.avi" to "smb://Computer/Movies/Movie1.avi"

I think so, although you should be comfortable with linux, because you will not be able to use the "find" command from above in your case.
You need to create a text-file with the paths to all your files in the smb://-format, one on each line.
Then use
Code:
cat newpaths.txt | ./hashcalc "E:\Movies\" "smb://Computer/Movies/" > move.sh
(With oldpaths.txt of course being the text file with all the new URLs)
Reply
#8
Like more people I bought a new hdd and moved my HD movies to the new drive. Updating the video library was easy but the thumb problem is harder to fix.

In the first place, why is XBMC not reloading the images from the web when there there is no thumbnail cache? It would make cleaning and moving way easier, just delete the thumbs and database and let XBMC do the work. Although a automated process when changing the source to a new location would be more user-friendly.

But for me, I run Windows with XBMC 10.0 r35647 and the movies and databases are local. The library part was easy. To make the thumbs work again I tried to remove the thumb db and the thumb folder without success. Second attempt I used this post. This kind of worked but I made some changes in selecting other than the default thumb/fanart for some movies. So some are still broken or use the default images Sad Is there a way to really rename the thumbs so they match again? Or am I really doomed to rescan and manually change the images again?
Reply
#9
Septillion, FWIW, the post on technazgul completely replaced all thumbs/fanart for me without a single broken one remaining when done. Sorry it didn't work for you. Sad
------------------------------------------
Dharma Quick Setup Guide:
XBMC tips on the TechNazgul Blog
------------------------------------------
Reply
#10
Hi There.

I hope anybody is still reading this post. Can anyone reupload the hashcalc tool from the original post?
The rapidshare link is dead.

Thank you in advance!
Reply
#11
Question 
Is this still the best way of moving the fanart, summaries etc for the xbmc database? I have a mythbuntu htpc with xbmc 13.1 that has all the info which has also been edited when the scraper pulled the wrong info. I am about to get an android box (probox2 ex) for another room. The options seem to be the OP, upnp, or maybe there is an addon that will do this. What would be the most up-to-date method?
Reply
#12
This is a great tutorial. But does it work for latest versions?

Check

http://forum.kodi.tv/showthread.php?tid=303536

-J
Reply

Logout Mark Read Team Forum Stats Members Help
[LINUX] HOW-TO move files in your Library to another location without Rescraping1