Change how next ids are generated in extract.py, correct for names with
apostrophes in them
This commit is contained in:
parent
cbdf7d9dba
commit
947aa73411
|
@ -52,16 +52,4 @@ def run(args=None):
|
||||||
l = len(args)
|
l = len(args)
|
||||||
if args[0] == "library":
|
if args[0] == "library":
|
||||||
library(args[1:])
|
library(args[1:])
|
||||||
#name = "Default"
|
|
||||||
#root = ""
|
|
||||||
#if l >= 2:
|
|
||||||
# name = args[1]
|
|
||||||
#if l >= 3:
|
|
||||||
# space = ' '
|
|
||||||
# root = expandPath( space.join(args[2:]) )
|
|
||||||
#database.open()
|
|
||||||
#database.insert('library',(name,root) )
|
|
||||||
#database.close()
|
|
||||||
#if not root=="":
|
|
||||||
# manager.run("scan",[root])
|
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,14 @@ def close():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def findId(table,name):
|
||||||
|
result = database.select("id",table,"name=\'"+name.replace("\'","\'\'")+"\'").fetchone()
|
||||||
|
if result == None:
|
||||||
|
return database.count(table),False
|
||||||
|
return result[0],True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Called when the plugin needs to perform some action
|
# Called when the plugin needs to perform some action
|
||||||
def run(file=None):
|
def run(file=None):
|
||||||
if file == None:
|
if file == None:
|
||||||
|
@ -73,24 +81,21 @@ def run(file=None):
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
artists = settings.get("artists")
|
|
||||||
|
|
||||||
# Find artist information
|
# Find artist information
|
||||||
artist = t.artist
|
artist = t.artist#.replace("\'","\'\'")
|
||||||
if artist == "":
|
if artist == "":
|
||||||
artist = "Unknown Artist"
|
artist = "Unknown Artist"
|
||||||
|
|
||||||
# If artist does not exist yet, insert into database
|
arid,inserted = findId("artist",artist)
|
||||||
if (artist in artists.keys())==False:
|
if inserted == False:
|
||||||
arid = database.count("artist")
|
|
||||||
database.insert("artist", (arid, artist) )
|
database.insert("artist", (arid, artist) )
|
||||||
artists[artist] = arid
|
|
||||||
else:
|
|
||||||
arid = artists[artist]
|
|
||||||
|
|
||||||
album = t.album
|
album = t.album#.replace("\'","\'\'")
|
||||||
if album == "":
|
if album == "":
|
||||||
album = "Unknown Album"
|
album = "Unknown Album"
|
||||||
|
|
||||||
alid = database.count("album")
|
#alid = database.count("album")
|
||||||
database.insert("album", (alid, album) )
|
alid,inserted = findId("album",album)
|
||||||
|
if inserted == False:
|
||||||
|
database.insert("album", (alid, album) )
|
||||||
|
#database.commit()
|
||||||
|
|
|
@ -54,13 +54,14 @@ def run(args=None):
|
||||||
space = ' '
|
space = ' '
|
||||||
path = expandPath( space.join(args) )
|
path = expandPath( space.join(args) )
|
||||||
|
|
||||||
settings.set("artists",dict())
|
|
||||||
database.open()
|
database.open()
|
||||||
scan(path)
|
scan(path)
|
||||||
|
|
||||||
#count = str(database.count("files"))
|
#count = str(database.count("files"))
|
||||||
count = str(database.count("artist"))
|
count = str(database.count("artist"))
|
||||||
write("Library contains "+count+" files.")
|
write("Library contains "+count+" artists.")
|
||||||
|
count = str(database.count("album"))
|
||||||
|
write("Library contains "+count+" albums.")
|
||||||
|
|
||||||
database.close()
|
database.close()
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ def create():
|
||||||
|
|
||||||
CREATE TABLE library
|
CREATE TABLE library
|
||||||
(
|
(
|
||||||
libid INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
name TEXT UNIQUE,
|
name TEXT UNIQUE,
|
||||||
path TEXT UNIQUE
|
path TEXT UNIQUE
|
||||||
);
|
);
|
||||||
|
@ -85,6 +85,13 @@ def close():
|
||||||
conn = None
|
conn = None
|
||||||
|
|
||||||
|
|
||||||
|
def commit():
|
||||||
|
global conn
|
||||||
|
if conn == None:
|
||||||
|
return
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
global db
|
global db
|
||||||
db = join(settings.get("ocarina"),"ocarina.db")
|
db = join(settings.get("ocarina"),"ocarina.db")
|
||||||
|
@ -119,6 +126,10 @@ def select(select,table,where=None):
|
||||||
statement = 'select '+select+' from '+table
|
statement = 'select '+select+' from '+table
|
||||||
if not (where==None):
|
if not (where==None):
|
||||||
statement += ' where '+where
|
statement += ' where '+where
|
||||||
print statement
|
#print statement
|
||||||
result = execute(statement)
|
try:
|
||||||
return result
|
result = execute(statement)
|
||||||
|
return result
|
||||||
|
except:
|
||||||
|
print statement
|
||||||
|
return None
|
Loading…
Reference in New Issue
Block a user