radio.py
· 1.1 KiB · Python
Raw
#!/usr/bin/env python2
from __future__ import print_function
import sys
from glob import glob
from random import shuffle
import os.path
def playdir(directory):
def get_playlist():
playlist = glob("{}/*.ogg".format(directory))
print("Loading playlist with {} items...".format(len(playlist)), file=sys.stderr)
shuffle(playlist)
return playlist
if not os.path.exists("{}.lst".format(directory)):
with open("{}.lst".format(directory), "w") as f:
f.write("\n".join(get_playlist()))
with open("{}.lst".format(directory)) as f:
pl = [c.strip() for c in f.readlines() if c.strip()]
if len(pl) < 2:
pl += get_playlist()
curfile = pl.pop(0)
print(curfile)
print("Playing {}".format(curfile), file=sys.stderr)
with open("{}.lst".format(directory), "w") as f:
f.write("\n".join(pl))
def main():
if len(sys.argv) < 2:
print("Supply directory", file=sys.stderr)
return 1
playdir(sys.argv[1])
return 0
if __name__ == "__main__":
sys.exit(main())
| 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()) |
| 36 |
z-ices.xml
· 374 B · XML
Raw
<?xml version="1.0"?>
<ices>
<stream>
<metadata>
<name>Stream Name</name>
</metadata>
<input>
<module>playlist</module>
<param name="type">script</param>
<param name="program">./radio directory</param>
</input>
<instance>
<password>hi there</password>
<mount>directory.ogg</mount>
</instance>
</stream>
</ices>
| 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> |