Skip to content

Instantly share code, notes, and snippets.

@hensing
Last active August 29, 2015 14:06

Revisions

  1. hensing revised this gist Sep 23, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion update_xbmc_db.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/usr/bin/env python
    # coding: utf-8
    """
    simple notebook to patch XBMC paths in MyVideo.db
    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)
    """
  2. hensing created this gist Sep 23, 2014.
    76 changes: 76 additions & 0 deletions update_xbmc_db.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,76 @@
    #!/usr/bin/env python
    # coding: utf-8
    """
    simple notebook to patch 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()