ocarina/src/core/scan.py

78 lines
1.5 KiB
Python

# This is a simple test plugin, to make sure everything is working
__author__="bjschuma"
__date__ ="$Dec 27, 2009 8:07:18 PM$"
global name, app, type, path, opt
name = "scan"
app = "ocarina"
type = "core"
path = ""
opt = []
import tagpy
from bt.message import write
from bt.file import *
import settings
from manager import manager
#from library import *
from tools import database
from tools import extract
#from library.scan import scan
global root
# Called every time the plugin is enabled
def open():
pass
# Called every time the plugin is stopped
def close():
pass
def help():
return "Scans over a directory and attempts to add the music files"
# Performs the actual scanning
def scan(dir):
files = ls(dir)
for file in files:
path = join(dir,file)
if checkDir(path)==True:
scan(path)
else:
write(path,True)
global root
#manager.run("extract", (root,path))
extract.run((root,path))
#database.insert(path)
#self.files += [path]
# Called to scan a directory. Performs initial path expansion before traversing
def run(args=None):
if args == None:
return
space = ' '
global root
root = expandPath( space.join(args) )
database.open()
scan(root)
#count = str(database.count("files"))
count = str(database.count("artist"))
write("Library contains "+count+" artists.")
count = str(database.count("album"))
write("Library contains "+count+" albums.")
count = str(database.count("track"))
write("Library contains "+count+" tracks.")
database.close()