Steven Smith revised this gist . Go to revision
2 files changed, 52 insertions
radio.py(file created)
| @@ -0,0 +1,35 @@ | |||
| 1 | + | #!/usr/bin/env python2 | |
| 2 | + | from __future__ import print_function | |
| 3 | + | import sys | |
| 4 | + | from glob import glob | |
| 5 | + | from random import shuffle | |
| 6 | + | import os.path | |
| 7 | + | ||
| 8 | + | def 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 | + | ||
| 27 | + | def 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 | + | ||
| 34 | + | if __name__ == "__main__": | |
| 35 | + | sys.exit(main()) | |
z-ices.xml(file created)
| @@ -0,0 +1,17 @@ | |||
| 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> | |