Below is the script for the Simpsons Shuffler. Make sure to replace the two lines in [square brackets] with the appropriate paths.


#!/usr/bin/python

import RPi.GPIO as GPIO
import time
import os
import random

buttonPin = 17

directory = "[put the path to your directory of simpsons episodes here]"

GPIO.setmode(GPIO.BCM)
GPIO.setup(buttonPin, GPIO.IN)

def playEpisode():
    episode = random.choice(os.listdir(directory))
    cmd = "nohup omxplayer -b -o hdmi "+"'"+directory+episode+"' &"
    os.system('killall omxplayer.bin')
    os.system(cmd)

try:

    GPIO.wait_for_edge(buttonPin, GPIO.FALLING)
    playEpisode()

    #point this to the location of this file
    os.system('sudo python [path to this script]')

except KeyboardInterrupt:  
    GPIO.cleanup()