Kodi Community Forum

Full Version: How to change path in MyVideos60.db
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I wanted to move my library from a local disk to Synology NAS server. Data transfer is easy, but how do you change the database to point to the new resource?

I have a lot of experience with SQL databases so I could write a script, but maybe someone has developed a solution to this problem.
no other option?
just do it with SQL if you can, that is the easiest way.
(2012-10-05, 22:44)Geraldziu Wrote: [ -> ]Hi,

I wanted to move my library from a local disk to Synology NAS server. Data transfer is easy, but how do you change the database to point to the new resource?

Unless they changed the SQL guts the problem will be more with the thumbnails then the file paths. The crc32 calc of the entire video file path is used as the name of the thumbnail so if you change the path the thumbnail file names are no longer correct. I do a lot of moving and found it easier to use the Watched status import/export addon. Basically export watched statues, move files, clean library, edit sources, rescan then import watched statuses. Below is (not mine) a bash script that changes the file locations and thumbnail caches. It should give you an idea of what needs to be done.

#!/bin/bash
#
# Create copies of xbmc video library database and thumbnails
# with adjusted path names of all referenced video files.
#
# Usage: ./copyprofile.sh SED SRC DST...
#
# SED sed script to filter path names, e.g. "s/\/mnt\/pub/smb:\/\/srv\/pub/"
# SRC source dir containing .xbmc/ to be used as master profile
# DST destination dir(s) where cloned .xbmc/ profiles will pe placed
#
# Required packages: sqlite3 libdigest-crc-perl
#

sed=$1
src=$2
shift 2
dst=("$@")

videodb=/home/ken/.xbmc/userdata/Profiles/FileMover/Database/MyVideos34.db
vthumbs=/home/ken/.xbmc/userdata/Profiles/FileMover/Thumbnails/Video
vfanart=/home/ken/.xbmc/userdata/Profiles/FileMover/Thumbnails/Video/Fanart

set -e

videofiles()
{
sqlite3 $1 "
SELECT strPath FROM path;
SELECT strPath||strFilename FROM files
JOIN path ON files.idPath = path.idPath;
SELECT strPath||strFilename||'episode'||c13 FROM episode
JOIN files ON episode.idFile = files.idFile
JOIN path ON files.idPath = path.idPath;
SELECT 'season'||strPath||'season '||c12 FROM episode
JOIN tvshowlinkepisode ON episode.idEpisode = tvshowlinkepisode.idEpisode
JOIN tvshowlinkpath ON tvshowlinkepisode.idShow = tvshowlinkpath.idShow
JOIN path ON tvshowlinkpath.idPath = path.idPath
GROUP BY tvshowlinkepisode.idShow,c12;
SELECT 'season'||strPath||'* all seasons' FROM tvshow
JOIN tvshowlinkpath ON tvshow.idShow = tvshowlinkpath.idShow
JOIN path ON tvshowlinkpath.idPath = path.idPath;
SELECT 'season'||strPath||'specials' FROM tvshow
JOIN tvshowlinkpath ON tvshow.idShow = tvshowlinkpath.idShow
JOIN path ON tvshowlinkpath.idPath = path.idPath;
SELECT 'videodb://1/7/'||idSet||'/' FROM sets;"
}

thumbcrc()
{
perl -mDigest::CRC=crc -ne'chomp; printf "%08x\n",crc(lc,32,-1,0,0,79764919)'
}

thumbcopy()
{
[ ! -e $1 ] || ( mkdir -p $2 && cp --preserve=timestamps $1 $2/$3 )
}

tmp=$(mktemp -d)
mkdir -p $tmp/$(dirname $videodb)
sqlite3 $src/$videodb .dump | sqlite3 $tmp/tmp.db
sqlite3 $tmp/tmp.db .dump | sed "$sed" | sqlite3 $tmp/$videodb

videofiles $tmp/tmp.db | sed "p;$sed" | thumbcrc | while read a && read b
do
thumbcopy "$src/$vthumbs/${a::1}/${a}.tbn" "$tmp/$vthumbs/${b::1}" "${b}.tbn"
thumbcopy "$src/$vfanart/${a}.tbn" "$tmp/$vfanart" "${b}.tbn"
done

for d in "${dst[@]}"
do
cp -r --preserve=timestamps $tmp/.xbmc $d/
[ "$(id -u)" == "0" ] && chown -R $(stat -c %U:%G $d) $d/.xbmc
done

rm -r $tmp/.xbmc/ $tmp/tmp.db
rmdir $tmp