Check if a file is a valid audio file type before attempting to scan
This commit is contained in:
parent
4d419dea8b
commit
05f09dfdfb
|
@ -13,16 +13,47 @@ from bt.file import *
|
|||
from bt.message import write
|
||||
|
||||
import tagpy
|
||||
import re
|
||||
|
||||
global total
|
||||
global scanned
|
||||
global added
|
||||
global root
|
||||
global goodFiles
|
||||
global search
|
||||
|
||||
global libid
|
||||
|
||||
total = 0
|
||||
added = 0
|
||||
scanned = 0
|
||||
root = ""
|
||||
goodFiles = ["ogg", "mp3"]
|
||||
|
||||
|
||||
# Generate search string (allows adding to goodFiles later)
|
||||
def genSearch():
|
||||
global goodFiles
|
||||
global search
|
||||
search = ".*\.("
|
||||
for index,file in enumerate(goodFiles):
|
||||
if index > 0:
|
||||
search += "|"
|
||||
search += file
|
||||
search += ")"
|
||||
|
||||
genSearch()
|
||||
|
||||
|
||||
|
||||
# Test if the file extension is in goodFiles
|
||||
def testPath(path):
|
||||
global search
|
||||
match = re.search(search,path,re.IGNORECASE)
|
||||
if match == None:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
|
||||
def incr(path):
|
||||
|
@ -75,6 +106,7 @@ def instrk(arid, alid, title, length, path):
|
|||
def addtrk(path):
|
||||
global added
|
||||
global scanned
|
||||
|
||||
scanned += 1
|
||||
try:
|
||||
f = tagpy.FileRef(path)
|
||||
|
@ -98,7 +130,8 @@ def scan((dir,func)):
|
|||
if checkDir(path) == True:
|
||||
scan((path,func))
|
||||
else:
|
||||
func(path)
|
||||
if testPath(path) == True:
|
||||
func(path)
|
||||
|
||||
|
||||
def go(name):
|
||||
|
|
Loading…
Reference in New Issue