Created an artists table, pull out artist information from each song
This commit is contained in:
parent
6ce24fae34
commit
8bc5b9e25a
|
@ -0,0 +1,85 @@
|
|||
# This is a simple test plugin, to make sure everything is working
|
||||
|
||||
__author__="bjschuma"
|
||||
__date__ ="$Dec 28, 2009 10:21:06 PM$"
|
||||
|
||||
|
||||
global name, app, type, path, opt
|
||||
name = "extract"
|
||||
app = "ocarina"
|
||||
type = "core"
|
||||
path = ""
|
||||
opt = []
|
||||
|
||||
from bt.message import write
|
||||
from tools import database
|
||||
|
||||
import re
|
||||
import tagpy
|
||||
|
||||
global goodFiles
|
||||
goodFiles = []
|
||||
|
||||
global search
|
||||
|
||||
|
||||
# Generate the search string
|
||||
def genSearch():
|
||||
global goodFiles
|
||||
global search
|
||||
search = ".*\.("
|
||||
for index,file in enumerate(goodFiles):
|
||||
if index > 0:
|
||||
search += "|"
|
||||
search += file
|
||||
search += ")"
|
||||
|
||||
|
||||
# Return true if the file is valid and false if it is not
|
||||
def validFile(filename):
|
||||
global search
|
||||
match = re.search(search,filename,re.IGNORECASE)
|
||||
if match==None:
|
||||
write(filename)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
|
||||
# Called every time the plugin is enabled
|
||||
def open():
|
||||
#goodFile = ".*\.(mp3|ogg)"
|
||||
goodFiles = ["mp3", "ogg"]
|
||||
genSearch()
|
||||
|
||||
|
||||
# Called every time the plugin is stopped
|
||||
def close():
|
||||
pass
|
||||
|
||||
|
||||
# Called when the plugin needs to perform some action
|
||||
def run(file=None):
|
||||
if file == None:
|
||||
return
|
||||
|
||||
if validFile(file) == False:
|
||||
return
|
||||
|
||||
try:
|
||||
f = tagpy.FileRef(file)
|
||||
t = f.tag()
|
||||
except:
|
||||
return
|
||||
|
||||
# Add an artist
|
||||
artist = None
|
||||
if t.artist=="":
|
||||
artist = (None,"Unknown",)
|
||||
else:
|
||||
artist = (None,t.artist,)
|
||||
#write(t.artist)
|
||||
database.insert("artist", artist )
|
||||
#database.insert("files",(file,))
|
||||
#except:
|
||||
# pass
|
|
@ -11,9 +11,12 @@ type = "core"
|
|||
path = ""
|
||||
opt = []
|
||||
|
||||
import tagpy
|
||||
|
||||
from bt.message import write
|
||||
from bt.file import *
|
||||
|
||||
from manager import manager
|
||||
#from library import *
|
||||
from tools import database
|
||||
#from library.scan import scan
|
||||
|
@ -38,7 +41,8 @@ def scan(dir):
|
|||
scan(path)
|
||||
else:
|
||||
write(path,True)
|
||||
database.insert(path)
|
||||
manager.run("extract", path)
|
||||
#database.insert(path)
|
||||
#self.files += [path]
|
||||
|
||||
|
||||
|
@ -48,10 +52,11 @@ def run(args=None):
|
|||
return
|
||||
space = ' '
|
||||
path = expandPath( space.join(args) )
|
||||
#database.open()
|
||||
database.open()
|
||||
scan(path)
|
||||
|
||||
count = str(database.count("files"))
|
||||
#count = str(database.count("files"))
|
||||
count = str(database.count("artist"))
|
||||
write("Library contains "+count+" files.")
|
||||
|
||||
database.close()
|
||||
|
|
|
@ -22,8 +22,10 @@ import sqlite3
|
|||
#c = None
|
||||
global db
|
||||
global conn
|
||||
global vals
|
||||
db = None
|
||||
conn = None
|
||||
vals = dict()
|
||||
|
||||
|
||||
# Collect all information for what to insert
|
||||
|
@ -34,7 +36,26 @@ conn = None
|
|||
|
||||
def create():
|
||||
global conn
|
||||
conn.execute("create table files (path text)")
|
||||
conn.executescript("""
|
||||
CREATE TABLE files
|
||||
(
|
||||
path TEXT PRIMARY KEY
|
||||
);
|
||||
|
||||
CREATE TABLE artist
|
||||
(
|
||||
arid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT UNIQUE
|
||||
);
|
||||
|
||||
UPDATE SQLITE_SEQUENCE SET seq = 1 WHERE name = 'artist';
|
||||
|
||||
""")
|
||||
|
||||
global vals
|
||||
vals["files"] = "?"
|
||||
vals["artist"]= "?,?"
|
||||
|
||||
|
||||
|
||||
def open():
|
||||
|
@ -60,13 +81,14 @@ def init():
|
|||
close()
|
||||
|
||||
|
||||
def insert(file):
|
||||
def insert(table, values):
|
||||
global conn
|
||||
if conn == None:
|
||||
open()
|
||||
global vals
|
||||
#c = conn.cursor()
|
||||
t = (file,)
|
||||
conn.execute('insert into files values(?)',t)
|
||||
#t = (file,)
|
||||
conn.execute('INSERT OR IGNORE INTO ' + table + ' VALUES(' + vals[table] + ')',values)
|
||||
#c.close()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue