-
Notifications
You must be signed in to change notification settings - Fork 98
/
rndplay.py
49 lines (43 loc) · 1.45 KB
/
rndplay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Plays mp3 files found under sys.argv[1] one by one, randomly.
# Meant to simulate a radio.
import glob, os, random, sys, threading, numpy as np, datetime
import select, kutil
if __name__ == "__main__":
fout = open("/tmp/rndplay.out","w")
while True:
print ("Music Dir", sys.argv[1])
os.chdir(sys.argv[1])
list = glob.glob("*.m*") + glob.glob("*.webm*")
print (list)
print ('\n')
#idx = util.my_random(len(list))
idx = util.my_random2(len(list))
print ("# of songs", len(list),)
"song idx selected", idx,
"song", list[idx]
fout.write(str(list[idx]) + "\n")
fout.flush()
print ('\n')
#cmd = "/usr/bin/ffplay -nodisp '%s'" % list[idx]
cmd = 'mplayer "%s" ' % list[idx]
print (cmd)
os.system(cmd)
print ("Delete? (Press d for delete)...")
k=""
def input():
global k
i = 0
while i < 1:
i = i + 1
r,w,x = select.select([sys.stdin.fileno()],[],[],2)
if len(r) != 0:
k =sys.stdin.readline()
T = threading.Thread(target=input)
T.setDaemon(1)
T.start()
T.join(1) # wait for [arg] seconds
print ("\n>>>>>>>>>" + k)
if 'd' in k:
print ("deleting ===================> " + list[idx])
cmd = "rm '%s'" % list[idx]
os.system(cmd)