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
|
from bt.message import write
|
||||||
|
|
||||||
import tagpy
|
import tagpy
|
||||||
|
import re
|
||||||
|
|
||||||
global total
|
global total
|
||||||
global scanned
|
global scanned
|
||||||
global added
|
global added
|
||||||
global root
|
global root
|
||||||
|
global goodFiles
|
||||||
|
global search
|
||||||
|
|
||||||
global libid
|
global libid
|
||||||
|
|
||||||
total = 0
|
total = 0
|
||||||
added = 0
|
added = 0
|
||||||
scanned = 0
|
scanned = 0
|
||||||
root = ""
|
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):
|
def incr(path):
|
||||||
|
@ -75,6 +106,7 @@ def instrk(arid, alid, title, length, path):
|
||||||
def addtrk(path):
|
def addtrk(path):
|
||||||
global added
|
global added
|
||||||
global scanned
|
global scanned
|
||||||
|
|
||||||
scanned += 1
|
scanned += 1
|
||||||
try:
|
try:
|
||||||
f = tagpy.FileRef(path)
|
f = tagpy.FileRef(path)
|
||||||
|
@ -98,7 +130,8 @@ def scan((dir,func)):
|
||||||
if checkDir(path) == True:
|
if checkDir(path) == True:
|
||||||
scan((path,func))
|
scan((path,func))
|
||||||
else:
|
else:
|
||||||
func(path)
|
if testPath(path) == True:
|
||||||
|
func(path)
|
||||||
|
|
||||||
|
|
||||||
def go(name):
|
def go(name):
|
||||||
|
|
Loading…
Reference in New Issue