Added tracklist code to replace readmp3 routine

This commit is contained in:
Jan
2019-09-26 16:03:19 +02:00
parent 20f0eb71b9
commit 88dce016de
6 changed files with 27 additions and 41 deletions

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
import time
import RPi.GPIO as GPIO

View File

@@ -1,15 +1,15 @@
v0.2.5 * Changed readmp3s routine to clockytracklist (merge)
v0.2.0 * Adjusted code for python 3
0.1.0:
v0.1.0 * added max7219 support, added signal handling
* Added additional logging messages for end of alarm
* implemented SIGINT (Ctrl-C) handling to exit gracefully
0.0.5:
* initial working version
v0.0.5 * initial working version
* show alarmtime in startup
------------------------------------------------------------
@@ -24,5 +24,5 @@ issues
todo
----
add SIGHUP handling for reload config
changes config file format to json
add SIGHUP handling for reload config and intergrate reloading of changes to tracklist or config

View File

@@ -11,16 +11,17 @@ from time import sleep,strftime
import RPi.GPIO as GPIO
import button
import signal
import clockytracklist
settings= {}
looptype=0
quit=0
print("\n +----------+\n | Clocky |\n | v0.2.0 |\n +----------+\n")
print("\n +----------+\n | Clocky |\n | v0.2.5 |\n +----------+\n")
o_configfilename = "clocky.conf"
o_defaultalarmtime = 60*13+24 # hh*60+mm
o_defaultalarmtime = 60*14+10 # hh*60+mm
o_showalarmtime=3 # time that the alarmtime shows after short press
o_showtracktime=2 # note that this is per track, so total time is 10 times longer
o_editdelaytime=3 # time it takes to qualify as longpress
@@ -51,24 +52,6 @@ def writesettings():
pickle.dump(settings, handle)
handle.close()
def readmp3list():
c=0
mp3s=[]
dirs=os.listdir('.')
for ent in os.listdir('.'):
if ent.lower().endswith(".mp3") and os.access(ent,os.R_OK):
mp3s.append(ent)
mp3s.sort()
for m in mp3s:
c+=1
if c>99: break
if c:
return(mp3s)
else:
return(0)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
looptype=0
@@ -94,7 +77,8 @@ display.SetBrightnessRaw(o_defaultbrightness)
print("")
print("reading mp3s from directory:")
allmp3s=readmp3list()
tracks=clockytracklist.ClockyTracklist("mp3",recursive=True,verbose=True)
allmp3s=tracks.tracklist
if allmp3s==0:
print("ERROR: No mp3's found!")
display.showclock(" E rr")
@@ -585,6 +569,11 @@ while quit!=True:
settings['starttrack']=track;
writesettings()
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if count % 40 == 0:
print("#")
tracks.CheckTrackList()
#------------------------------------------------------------------
if pygame.mixer.get_init():

View File

@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
from pathlib import Path
@@ -6,7 +6,7 @@ EXTENSIONS=(".mp3",".ogg",".wav",".mpa",".m4a",".flac")
class ClockyTracklist:
"""read and monitor directory with audio files"""
def __init__(self,path=".",recursive=False,verbose=False):
def __init__(self,path=".",recursive=False,sort=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
@@ -18,6 +18,8 @@ class ClockyTracklist:
exit();
self.__ReadTrackList()
if sort:
self.tracklist.sort()
if(self.__verbose):
self.ShowTrackList()

View File

@@ -1,8 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2017-18 Richard Hull and contributors
# See LICENSE.rst for details.
#!/usr/bin/env python3
import re
import time

13
tracktest.py Normal file → Executable file
View File

@@ -1,23 +1,22 @@
#!/usr/bin/python
#!/usr/bin/python3
import time
import clockytracklist
print("-------------------------------------")
print("-------------------------------------")
t1=clockytracklist.ClockyTracklist("mp3",True,True)
t1.ShowTrackList()
tl=clockytracklist.ClockyTracklist("mp3",recursive=True,sort=False,verbose=True)
tl.ShowTrackList()
print("-------------------------------------")
t2=clockytracklist.ClockyTracklist("C:\data",True,True)
t2.ShowTrackList()
for e in tl.tracklist:
print(e);
t=0
while True:
t+=1
t1.CheckTrackList()
t2.CheckTrackList()
tl.CheckTrackList()
time.sleep(1)
if(t>30):