Skip to content

Instantly share code, notes, and snippets.

@hensing
Last active August 29, 2015 14:06
Show Gist options
  • Save hensing/3f2300d56f0748aa195f to your computer and use it in GitHub Desktop.
Save hensing/3f2300d56f0748aa195f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# coding: utf-8
"""
simple notebook to patch/replace XBMC paths in MyVideo.db
infos: [howto @ wiki.xbmc.org](http://wiki.xbmc.org/index.php?title=HOW-TO:Update_SQL_databases_when_files_move)
see also [path substitution](http://wiki.xbmc.org/index.php?title=Path_substitution)
"""
__author__ = 'Henning Dickten'
import sqlite3
import glob
from os import path
# SETTINGS
dbpath = './'
old_path = r'nfs://myserver//old_path'
new_path = r'nfs://mynewserver//new_path'
# MYVIDEO.DB
#
# get latest database:
videos = glob.glob(path.join(dbpath, r'MyVideos*.db'))
videos.sort()
# get cursor:
connection = sqlite3.Connection(videos[-1])
cursor = connection.cursor()
# patch MyVideo db:
cursor.execute('UPDATE path SET strPath = REPLACE(strPath, ?, ?);', (old_path,
new_path))
cursor.execute('UPDATE movie SET c22 = REPLACE(c22, ?, ?);', (old_path,
new_path))
cursor.execute('UPDATE episode SET c18 = REPLACE(c18, ?, ?);', (old_path,
new_path))
cursor.execute('UPDATE art SET url = REPLACE(url, ?, ?);', (old_path,
new_path))
cursor.execute('UPDATE tvshow SET c16 = REPLACE(c16, ?, ?);', (old_path,
new_path))
# commit changes
connection.commit()
# TEXTURES.DB
#
# get latest database:
textures = glob.glob(path.join(dbpath, r'Textures*.db'))
textures.sort()
# get cursor:
connection = sqlite3.Connection(textures[-1])
cursor = connection.cursor()
# patch Textures.db
cursor.execute('UPDATE path SET url = REPLACE(url, ?, ?);', (old_path,
new_path))
# commit changes
connection.commit()
# MUSIC.DB
#
# get latest database
music = glob.glob(path.join(dbpath, r'MyMusic*.db'))
music.sort()
# get cursor:
connection = sqlite3.Connection(music[-1])
cursor = connection.cursor()
# patch Textures.db
cursor.execute('UPDATE path SET strPath = REPLACE(strPath, ?, ?);', (old_path,
new_path))
# commit changes
connection.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment