From 5dc8dc52e9d2f665fb418a6310642ea3c970a5d5 Mon Sep 17 00:00:00 2001 From: bjschuma Date: Sat, 30 Jan 2010 17:02:43 -0500 Subject: [PATCH] Began work on scanning / updating a library --- src/core/ct/update.py | 84 +++++++++++++++++++++++++++++++++++++++++++ src/core/library.py | 5 +++ 2 files changed, 89 insertions(+) create mode 100644 src/core/ct/update.py diff --git a/src/core/ct/update.py b/src/core/ct/update.py new file mode 100644 index 00000000..acbd9aa8 --- /dev/null +++ b/src/core/ct/update.py @@ -0,0 +1,84 @@ +#! /usr/bin/python + +# To change this template, choose Tools | Templates +# and open the template in the editor. + +__author__="bjschuma" +__date__ ="$Jan 30, 2010 3:57:53 PM$" + + +from bt import sql +from bt import needle +from bt.file import * +from bt.message import write + +import tagpy + +global total +global scanned +global added +total = 0 +added = 0 +scanned = 0 + + +def incr(path): + global total + total += 1 + + +def addtrk(path): + global added + global scanned + scanned += 1 + try: + f = tagpy.FileRef(path) + added += 1 + except: + pass + + +def scan((dir,func)): + files = ls(dir) + for file in files: + path = join(dir,file) + if checkDir(path) == True: + scan((path,func)) + else: + func(path) + + +def go(name): + global total + global added + global scanned + total = 0 + added = 0 + scanned = 0 + + sel = sql.Select("id,path","library","name='"+name+"'") + result = sel.execute().fetchall() + if result == []: + return + libid = result[0][0] + path = result[0][1] + + # Start a thread to count the total number of files to scan + totthr = needle.Needle(scan,(path,incr)) + totthr.start() + + scthr = needle.Needle(scan,(path,addtrk)) + scthr.start() + + #scan(path, incr) + #write(path) + #totthr.join() + #write(str(total) + " Files to scan") + + +def prcnt(): + global total + global scanned + global added + write( str(scanned) + " / " + str(total) ) + write( "Added " + str(added) + " tracks." ) \ No newline at end of file diff --git a/src/core/library.py b/src/core/library.py index 340bb017..0621aa5e 100644 --- a/src/core/library.py +++ b/src/core/library.py @@ -8,6 +8,7 @@ from bt import plugin from bt.file import expandPath from bt.message import write from ct import db +from ct import update class Plugin(plugin.Plugin): @@ -50,3 +51,7 @@ class Plugin(plugin.Plugin): db.listlib() elif args[0] == "remove": self.remove(args[1:]) + elif args[0] == "update": + update.go(args[1]) + elif args[0] == "prcnt": + update.prcnt()