ocarina/src/core/extract.py

86 lines
1.4 KiB
Python

# 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