MP3 jukebox for RH62 Linux

Will Ware wware at world.std.com
Wed Aug 30 14:34:54 EDT 2000


#!/usr/bin/python
"""MP3 Jukebox, runs on Red Hat 6.2 systems"""

import os, sys, random, time, string

pid = 0

files = [ ]
p = os.popen('find ' + os.getcwd() + ' -name "*.mp3"')
for x in p.readlines():
    files.append(x[:-1])
p.close()

while 1:
    try:
        childRunning = 0
        if pid != 0:
            p = os.popen("ps ax | grep mpg123")
            for x in p.readlines():
                x = string.split(x)
                if pid == eval(x[0]) and x[2] == 'S':
                    childRunning = 1
                    break
            p.close()
        if not childRunning:
            file = random.choice(files)
            print file
            pid = os.fork()
            if pid == 0:
                # child process plays the tune
                os.close(1)
                os.close(2)
                player = '/usr/bin/mpg123'
                os.execv(player, [player, file])
        time.sleep(2)
    except KeyboardInterrupt:
        if pid != 0:
            os.kill(pid, 9)
            pid = 0
        sys.stdout.write('N for a different tune, anything else to quit: ')
        sys.stdout.flush()
        another = string.upper(sys.stdin.readline()[0]) == 'N'
        if not another:
            sys.exit(0)

-- 
# - - - - - - - - - - - - - - - - - - - - - - - -
# Resistance is futile. Capacitance is efficacious.
# Will Ware	email:    wware @ world.std.com



More information about the Python-list mailing list