Created
May 5, 2017 20:36
-
-
Save blha303/d86410c59d67dc102fe286a835ec444a to your computer and use it in GitHub Desktop.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment