64 lines
1.6 KiB
Python
64 lines
1.6 KiB
Python
#!/usr/bin/python
|
|
|
|
import json
|
|
import os
|
|
import time
|
|
import copy
|
|
|
|
EXTENSIONS=("mp3","ogg","wav","mpa","m4a","flac")
|
|
|
|
class ClockyTracklist:
|
|
"""read and monitor directory with audio files"""
|
|
|
|
def __init__(self,path="."):
|
|
"""do the reading"""
|
|
self.path=path
|
|
self.tracklist=[]
|
|
self.pathlist=[]
|
|
self.count=0
|
|
|
|
olddir=os.getcwd()
|
|
if(self.path != '.'):
|
|
if(not os.path.isdir(self.path)):
|
|
print("ERROR: \""+self.path+"\" is not an existing directory")
|
|
exit();
|
|
os.chdir(self.path)
|
|
|
|
for ent in os.listdir():
|
|
if ent.lower().endswith(EXTENSIONS) and os.access(ent,os.R_OK):
|
|
self.tracklist.append(ent)
|
|
self.pathlist.append(os.path.join(self.path,ent))
|
|
self.count+=1
|
|
|
|
os.chdir(olddir)
|
|
|
|
|
|
def Show(self):
|
|
"""Print the list"""
|
|
print("Tracklist.path = %s" %self.path)
|
|
print("Tracklist.count= %d" %self.count)
|
|
print("Tracks:")
|
|
for track in self.tracklist:
|
|
|
|
print (" "+track)
|
|
fn=self.path+'\\'+track
|
|
if os.access(fn,os.R_OK):
|
|
print(fn+"!")
|
|
else:
|
|
print(fn+"-")
|
|
fn=self.path+'/'+track
|
|
if os.access(fn,os.R_OK):
|
|
print(fn+"!")
|
|
else:
|
|
print(fn+"-")
|
|
|
|
print("Paths:")
|
|
for track in self.pathlist:
|
|
print (" "+track)
|
|
|
|
f=open(track,"r")
|
|
if(f):
|
|
print("OK")
|
|
f.close()
|
|
|