Example ScriptΒΆ

Randomizes a list of albums (directories) and print a list of
their song files.
import glob, sys, random

# Read favorite songs list.
favs = open("favorites.txt", 'r').read().splitlines()

# Read album list (directory names) from file specified on
# command line, or from standard input if none provided.
inp = open(sys.argv[1], 'r') if len(sys.argv) > 1 else sys.stdin
albums = inp.read().splitlines()

# Shuffle list of albums.

# Print only favorite songs from each album.
for a in albums:
  songs = glob.glob(a + "/*")
  for song in songs:
    if song in favs: print song