Solved How To copy song ratings to new database. (export doesn't work)
#3
Unfortunately that didn't work for me. I went ahead and wrote a python script to do what I needed. I also went ahead and populated the lastplayed and iTimesPlayed:

Code:
#! /usr/bin/env python

#
# Script populates the ratings, iTimesPlayed, lastplayed field in a XBMC music
# database (new) with the values from another XBMC music database (old).  This
# was written to save my ratings from an old database that was corrupt and would
# not export when I upgraded from Eden to Gotham.
# assumes same episode title and base filename (NOT fully qualified filename)

import sqlite3

olddb = "MyMusic18.db"
newdb = "MyMusic46.db"

old_con = sqlite3.connect(olddb)
new_con = sqlite3.connect(newdb)
new_con.text_factory = str
old_con.text_factory = str
oldc = old_con.cursor()
newc = new_con.cursor()
newc.execute("""select idSong,strPath,strFileName from song natural left outer join path""")
newdata = newc.fetchall()
for row in newdata:
        print "processing song ", row[0]
        print "file: " + row[1] + row[2]
        oldc.execute('SELECT rating,iTimesPlayed,lastplayed from song natural left outer join path where strPath = ? and strFileName = ?', (row[1], row[2]))
        old=oldc.fetchall()
        if len(old)==0:
                print "No matching file in old database!!"
        else:
                if old[0][2] is None:
                        print "Populating the song rating = " + old[0][0] + " and iTimesPlayed = ",  old[0][1]
                else:
                        print "Populating the song rating = " + old[0][0] + " last played = " + old[0][2] + " and iTimesPlayed = ",  old[0][1]

                newc.execute('UPDATE song SET rating = ? WHERE idSong = ?', (old[0][0], row[0]))
                newc.execute('UPDATE song SET iTimesPlayed = ? WHERE idSong = ?', (old[0][1], row[0]))
                newc.execute('UPDATE song SET lastplayed = ? WHERE idSong = ?', (old[0][2], row[0]))
                print "Success"
                print
oldc.close()
newc.close()
Reply


Messages In This Thread
RE: Need sql kungfu, trying to rescue my music ratings. - by ikiller - 2014-05-09, 02:37
Logout Mark Read Team Forum Stats Members Help
How To copy song ratings to new database. (export doesn't work)1