Last active 1493980561

Generates a shuffled playlist of files in a subdirectory, pops the first item from the playlist, then re-generates a new playlist when the current one is run down. Intended for use with ices

radio.py Raw
1#!/usr/bin/env python2
2from __future__ import print_function
3import sys
4from glob import glob
5from random import shuffle
6import os.path
7
8def playdir(directory):
9 def get_playlist():
10 playlist = glob("{}/*.ogg".format(directory))
11 print("Loading playlist with {} items...".format(len(playlist)), file=sys.stderr)
12 shuffle(playlist)
13 return playlist
14 if not os.path.exists("{}.lst".format(directory)):
15 with open("{}.lst".format(directory), "w") as f:
16 f.write("\n".join(get_playlist()))
17 with open("{}.lst".format(directory)) as f:
18 pl = [c.strip() for c in f.readlines() if c.strip()]
19 if len(pl) < 2:
20 pl += get_playlist()
21 curfile = pl.pop(0)
22 print(curfile)
23 print("Playing {}".format(curfile), file=sys.stderr)
24 with open("{}.lst".format(directory), "w") as f:
25 f.write("\n".join(pl))
26
27def main():
28 if len(sys.argv) < 2:
29 print("Supply directory", file=sys.stderr)
30 return 1
31 playdir(sys.argv[1])
32 return 0
33
34if __name__ == "__main__":
35 sys.exit(main())
36
z-ices.xml Raw
1<?xml version="1.0"?>
2<ices>
3 <stream>
4 <metadata>
5 <name>Stream Name</name>
6 </metadata>
7 <input>
8 <module>playlist</module>
9 <param name="type">script</param>
10 <param name="program">./radio directory</param>
11 </input>
12 <instance>
13 <password>hi there</password>
14 <mount>directory.ogg</mount>
15 </instance>
16 </stream>
17</ices>