From 4a5498866caa65bd8ff662274f03e19c73408ac5 Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 25 Sep 2019 17:11:51 +0200 Subject: [PATCH] added ChecktTrackList --- clockytracklist.py | 43 ++++++++++++++++++++++++++----------------- tracktest.py | 20 +++++++++++++++++--- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/clockytracklist.py b/clockytracklist.py index d0470e6..37137a8 100644 --- a/clockytracklist.py +++ b/clockytracklist.py @@ -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""" - \ No newline at end of file + 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.") diff --git a/tracktest.py b/tracktest.py index 4bee807..6885c38 100644 --- a/tracktest.py +++ b/tracktest.py @@ -1,12 +1,26 @@ #!/usr/bin/python +import time import clockytracklist print("-------------------------------------") print("-------------------------------------") -tl=clockytracklist.ClockyTracklist("mp3",True) -tl.ShowTrackList() +t1=clockytracklist.ClockyTracklist("mp3",True,True) +t1.ShowTrackList() print("-------------------------------------") -t2=clockytracklist.ClockyTracklist("C:\data",True) +t2=clockytracklist.ClockyTracklist("C:\data",True,True) t2.ShowTrackList() + + +t=0 +while True: + t+=1 + t1.CheckTrackList() + t2.CheckTrackList() + time.sleep(1) + + if(t>30): + break + print(t) +