Changed status format; added host argument; documented arguments;

fixed code for missing frame argument.
This commit is contained in:
Guido van Rossum 1992-04-15 16:38:38 +00:00
parent b108e976a4
commit f4be726da2
1 changed files with 30 additions and 21 deletions

View File

@ -1,15 +1,23 @@
# Read CD audio data from the SCSI CD player and send it as UDP # Read CD audio data from the SCSI CD player and send it as UDP
# packets to "readcd.py" on another host. # packets to "recvcd.py" on another host.
# Option: #
# "-l" lists track info and quits. # Usage: python sendcd.py [options] host [track | minutes seconds [frames]]
# "-s" displays status and quits. #
# Options:
# "-l" list track info and quit.
# "-s" display status and quit.
#
# Arguments:
# host host to send the audio data to (required unless -l or -s).
# track track number where to start; alternatively,
# min sec [frames] absolute address where to start;
# default is continue at current point according to status.
import cd import cd
import sys import sys
from socket import * from socket import *
import getopt import getopt
HOST = 'voorn.cwi.nl' # The host where readcd.py is run
PORT = 50505 # Must match the port in readcd.py PORT = 50505 # Must match the port in readcd.py
def main(): def main():
@ -31,10 +39,15 @@ def main():
prstatus(player) prstatus(player)
return return
if not args:
sys.stderr.write('usage: ' + sys.argv[0] + ' host [track]\n')
sys.exit(2)
host, args = args[0], args[1:]
sys.stdout.write('waiting for socket... ') sys.stdout.write('waiting for socket... ')
sys.stdout.flush() sys.stdout.flush()
port = socket(AF_INET, SOCK_DGRAM) port = socket(AF_INET, SOCK_DGRAM)
port.connect(HOST, PORT) port.connect(host, PORT)
print 'socket connected' print 'socket connected'
parser = cd.createparser() parser = cd.createparser()
@ -52,7 +65,7 @@ def main():
[min, sec, frame] = args[:3] [min, sec, frame] = args[:3]
else: else:
[min, sec] = args [min, sec] = args
frame = 0 frame = '0'
min, sec, frame = eval(min), eval(sec), eval(frame) min, sec, frame = eval(min), eval(sec), eval(frame)
print 'Seek to', triple(min, sec, frame) print 'Seek to', triple(min, sec, frame)
dummy = player.seek(min, sec, frame) dummy = player.seek(min, sec, frame)
@ -61,7 +74,7 @@ def main():
print 'Seek to track', track print 'Seek to track', track
dummy = player.seektrack(track) dummy = player.seektrack(track)
else: else:
min, sec, frame = player.getstatus()[5:8] min, sec, frame = player.getstatus()[3]
print 'Try to seek back to', triple(min, sec, frame) print 'Try to seek back to', triple(min, sec, frame)
try: try:
player.seek(min, sec, frame) player.seek(min, sec, frame)
@ -87,11 +100,8 @@ def prtrackinfo(player):
except RuntimeError: except RuntimeError:
break break
for i in range(len(info)): for i in range(len(info)):
start_min, start_sec, start_frame, \ start, total = info[i]
total_min, total_sec, total_frame = info[i] print 'Track', zfill(i+1), triple(start), triple(total)
print 'Track', zfill(i+1), \
triple(start_min, start_sec, start_frame), \
triple(total_min, total_sec, total_frame)
def audiocallback(port, type, data): def audiocallback(port, type, data):
## sys.stdout.write('#') ## sys.stdout.write('#')
@ -117,25 +127,24 @@ def controlcallback(arg, type, data):
statedict = ['ERROR', 'NODISK', 'READY', 'PLAYING', 'PAUSED', 'STILL'] statedict = ['ERROR', 'NODISK', 'READY', 'PLAYING', 'PAUSED', 'STILL']
def prstatus(player): def prstatus(player):
state, track, min, sec, frame, abs_min, abs_sec, abs_frame, \ state, track, curtime, abstime, totaltime, first, last, \
total_min, total_sec, total_frame, first, last, scsi_audio, \ scsi_audio, cur_block, dummy = player.getstatus()
cur_block, dum1, dum2, dum3 = player.getstatus()
print 'Status:', print 'Status:',
if 0 <= state < len(statedict): if 0 <= state < len(statedict):
print statedict[state] print statedict[state]
else: else:
print state print state
print 'Track: ', track print 'Track: ', track
print 'Time: ', triple(min, sec, frame) print 'Time: ', triple(curtime)
print 'Abs: ', triple(abs_min, abs_sec, abs_frame) print 'Abs: ', triple(abstime)
print 'Total: ', triple(total_min, total_sec, total_frame) print 'Total: ', triple(totaltime)
print 'First: ', first print 'First: ', first
print 'Last: ', last print 'Last: ', last
print 'SCSI: ', scsi_audio print 'SCSI: ', scsi_audio
print 'Block: ', cur_block print 'Block: ', cur_block
print 'Future:', (dum1, dum2, dum3) print 'Future:', dummy
def triple(a, b, c): def triple((a, b, c)):
return zfill(a) + ':' + zfill(b) + ':' + zfill(c) return zfill(a) + ':' + zfill(b) + ':' + zfill(c)
def zfill(n): def zfill(n):