1st test of track stuff

This commit is contained in:
Jan
2019-09-25 12:32:18 +02:00
parent 930a517982
commit 3edf9ba34c
2 changed files with 70 additions and 0 deletions

63
clockytracklist.py Normal file
View File

@@ -0,0 +1,63 @@
#!/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()

7
tracktest.py Normal file
View File

@@ -0,0 +1,7 @@
#!/usr/bin/python
import clockytracklist
tl=clockytracklist.ClockyTracklist("mp3")
tl.Show()