62 lines
1.8 KiB
Python
62 lines
1.8 KiB
Python
#!/usr/bin/python
|
|
|
|
from pathlib import Path
|
|
|
|
EXTENSIONS=(".mp3",".ogg",".wav",".mpa",".m4a",".flac")
|
|
|
|
class ClockyTracklist:
|
|
"""read and monitor directory with audio files"""
|
|
def __init__(self,path=".",recursive=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
|
|
|
|
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
|
|
|
|
def ReadTrackList(self):
|
|
"""Print the list"""
|
|
path=Path(self.path)
|
|
if(not path.is_dir()):
|
|
print("ERROR: \""+self.path+"\" is not an directory")
|
|
exit();
|
|
|
|
if(self.recursive):
|
|
selection='**/*'
|
|
else:
|
|
selection='*'
|
|
for entry in path.glob(selection):
|
|
if entry.suffix in EXTENSIONS:
|
|
self.tracklist.append(entry.as_posix())
|
|
self.count+=1
|
|
|
|
|
|
def ShowTrackList(self):
|
|
"""Print the list"""
|
|
print("Tracklist:")
|
|
print(" path = %s" %self.path)
|
|
print(" recursive = %s" %self.recursive)
|
|
print(" count = %d" %self.count)
|
|
print(" tracks:")
|
|
for track in self.tracklist:
|
|
print(" "+track)
|
|
f=open(track,"r")
|
|
if(f):
|
|
f.close()
|
|
|
|
def CheckTrackList(self):
|
|
"""Check path for filechanges"""
|
|
|