added ChecktTrackList
This commit is contained in:
@@ -6,33 +6,27 @@ EXTENSIONS=(".mp3",".ogg",".wav",".mpa",".m4a",".flac")
|
||||
|
||||
class ClockyTracklist:
|
||||
"""read and monitor directory with audio files"""
|
||||
def __init__(self,path=".",recursive=False):
|
||||
def __init__(self,path=".",recursive=False,verbose=False):
|
||||
"""Read (current or supplied) path for all audio files. Add recursive=True to check all subdirectories too"""
|
||||
self.recursive=recursive
|
||||
self.path=path
|
||||
self.tracklist=[]
|
||||
self.count=0
|
||||
self.__verbose=verbose
|
||||
|
||||
p=Path(self.path)
|
||||
if(not p.is_dir()):
|
||||
print("ERROR: \""+path+"\" is not an directory")
|
||||
exit();
|
||||
|
||||
if(self.recursive):
|
||||
selection='**/*'
|
||||
else:
|
||||
selection='*'
|
||||
for Q in p.glob(selection):
|
||||
if Q.suffix in EXTENSIONS: #and os.access(Q,os.R_OK):
|
||||
self.tracklist.append(Q.as_posix())
|
||||
self.count+=1
|
||||
self.__ReadTrackList()
|
||||
if(self.__verbose):
|
||||
self.ShowTrackList()
|
||||
|
||||
def ReadTrackList(self):
|
||||
"""Print the list"""
|
||||
|
||||
def __ReadTrackList(self):
|
||||
"""do the actual reading"""
|
||||
self.tracklist=[]
|
||||
self.count=0
|
||||
path=Path(self.path)
|
||||
if(not path.is_dir()):
|
||||
print("ERROR: \""+self.path+"\" is not an directory")
|
||||
exit();
|
||||
|
||||
if(self.recursive):
|
||||
selection='**/*'
|
||||
@@ -59,4 +53,19 @@ class ClockyTracklist:
|
||||
|
||||
def CheckTrackList(self):
|
||||
"""Check path for filechanges"""
|
||||
|
||||
newtracklist=[]
|
||||
newcount=0
|
||||
|
||||
newpath=Path(self.path)
|
||||
if(self.recursive):
|
||||
selection='**/*'
|
||||
else:
|
||||
selection='*'
|
||||
for newentry in newpath.glob(selection):
|
||||
if newentry.suffix in EXTENSIONS:
|
||||
newtracklist.append(newentry.as_posix())
|
||||
newcount+=1
|
||||
if(newcount != self.count) or (newtracklist != self.tracklist):
|
||||
self.__ReadTrackList()
|
||||
if(self.__verbose):
|
||||
print("Changes in filenames or number of files detected! Re-read tracklist.")
|
||||
|
||||
Reference in New Issue
Block a user