Dirk Meyer wrote:
> Please also report how long it takes to get the results if it is
> longer than 5 seconds after the drive has read the disc. If it takes
> longer, please look into /var/log/messages if there are reading
> problems reported from the kernel. 

I hoped that was a problem with my VCD (I have only one, and that is
full of images, no video). The problem was that I tried to read 6 MB
from the device, but you can't read that much from a VCD. Please try
the new version in this mail please. There should be no messages in
/var/log/messages about I/O errors anymore and every disc should be
detected in less than 5 secs.


Dischi

#!/usr/bin/env python

import re
import sys
import os

from fcntl import ioctl


# taken from cdrom.py so we don't need to import cdrom.py
CDROM_DRIVE_STATUS=0x5326
CDSL_CURRENT=( (int ) ( ~ 0 >> 1 ) )
CDS_DISC_OK=4
CDROM_DISC_STATUS=0x5327
CDS_AUDIO=100
CDS_MIXED=105
CDROM_SELECT_SPEED=0x5322

device = sys.argv[1]

try:
    fd = os.open(device, os.O_RDONLY | os.O_NONBLOCK)
    s = ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT)
except:
    # maybe we need to close the fd if ioctl fails, maybe
    # open fails and there is no fd
    try:
        os.close(fd)
    except:
        pass
    print 'no disc or broken disc in drive'
    sys.exit(0)


s = ioctl(fd, CDROM_DISC_STATUS)
if s == CDS_AUDIO or s == CDS_MIXED:
    print 'This is an AUDIO CD'
    sys.exit(0)
    


os.close(fd)




f = open(device,'rb')

f.seek(0x0000832d)
id = f.read(16)
f.seek(32808, 0)
label = f.read(32)
m = re.match("^(.*[^ ]) *$", label)
if m:
    label = m.group(1)
else:
    label = ''

# print id
# print label

buffer = f.read(50000)

if buffer.find('SVCD') > 0 and buffer.find('TRACKS.SVD') > 0 and \
       buffer.find('ENTRIES.SVD') > 0:
    print 'This is a SVCD'

elif buffer.find('INFO.VCD') > 0 and buffer.find('ENTRIES.VCD') > 0:
    print 'This is a VCD'

elif buffer.find('UDF') > 0:
    # this may be a DVD, check deeper
    buffer += f.read(550000)
    if buffer.find('VIDEO_TS') > 0 and buffer.find('VIDEO_TS.IFO') > 0 and \
           buffer.find('OSTA UDF Compliant') > 0:
        print 'This is a DVD'

    else:
        print 'Sorry no DVD/VCD/SVCD/AUDIOCD here, must be a normal disc'

else:
    print 'Sorry no DVD/VCD/SVCD/AUDIOCD here, must be a normal disc'

f.close()
-- 
Customer: I'm running Windows '98 
Tech: Yes. 
Customer: My computer isn't working now. 
Tech: Yes, you said that.

Reply via email to