added ChecktTrackList
This commit is contained in:
@@ -6,33 +6,27 @@ EXTENSIONS=(".mp3",".ogg",".wav",".mpa",".m4a",".flac")
|
|||||||
|
|
||||||
class ClockyTracklist:
|
class ClockyTracklist:
|
||||||
"""read and monitor directory with audio files"""
|
"""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"""
|
"""Read (current or supplied) path for all audio files. Add recursive=True to check all subdirectories too"""
|
||||||
self.recursive=recursive
|
self.recursive=recursive
|
||||||
self.path=path
|
self.path=path
|
||||||
self.tracklist=[]
|
self.__verbose=verbose
|
||||||
self.count=0
|
|
||||||
|
|
||||||
p=Path(self.path)
|
p=Path(self.path)
|
||||||
if(not p.is_dir()):
|
if(not p.is_dir()):
|
||||||
print("ERROR: \""+path+"\" is not an directory")
|
print("ERROR: \""+path+"\" is not an directory")
|
||||||
exit();
|
exit();
|
||||||
|
|
||||||
if(self.recursive):
|
self.__ReadTrackList()
|
||||||
selection='**/*'
|
if(self.__verbose):
|
||||||
else:
|
self.ShowTrackList()
|
||||||
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
|
|
||||||
|
|
||||||
def ReadTrackList(self):
|
|
||||||
"""Print the list"""
|
def __ReadTrackList(self):
|
||||||
|
"""do the actual reading"""
|
||||||
|
self.tracklist=[]
|
||||||
|
self.count=0
|
||||||
path=Path(self.path)
|
path=Path(self.path)
|
||||||
if(not path.is_dir()):
|
|
||||||
print("ERROR: \""+self.path+"\" is not an directory")
|
|
||||||
exit();
|
|
||||||
|
|
||||||
if(self.recursive):
|
if(self.recursive):
|
||||||
selection='**/*'
|
selection='**/*'
|
||||||
@@ -59,4 +53,19 @@ class ClockyTracklist:
|
|||||||
|
|
||||||
def CheckTrackList(self):
|
def CheckTrackList(self):
|
||||||
"""Check path for filechanges"""
|
"""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.")
|
||||||
|
|||||||
20
tracktest.py
20
tracktest.py
@@ -1,12 +1,26 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import time
|
||||||
import clockytracklist
|
import clockytracklist
|
||||||
|
|
||||||
print("-------------------------------------")
|
print("-------------------------------------")
|
||||||
print("-------------------------------------")
|
print("-------------------------------------")
|
||||||
tl=clockytracklist.ClockyTracklist("mp3",True)
|
t1=clockytracklist.ClockyTracklist("mp3",True,True)
|
||||||
tl.ShowTrackList()
|
t1.ShowTrackList()
|
||||||
print("-------------------------------------")
|
print("-------------------------------------")
|
||||||
t2=clockytracklist.ClockyTracklist("C:\data",True)
|
t2=clockytracklist.ClockyTracklist("C:\data",True,True)
|
||||||
t2.ShowTrackList()
|
t2.ShowTrackList()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
t=0
|
||||||
|
while True:
|
||||||
|
t+=1
|
||||||
|
t1.CheckTrackList()
|
||||||
|
t2.CheckTrackList()
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
if(t>30):
|
||||||
|
break
|
||||||
|
print(t)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user