Hi,

I want to find out if a disc is a DVD/VCD/SVCD or not _without_
mounting the disc. I wrote a small program to test it. It's attached
to the mail. Please test it with some DVD/VCD/SVCD of you. Also try
Audio CDs, no CDs and normal CDs, too.

Just start the script with the device as parameter, e.g.
./check_disc /dev/dvd

If I have 100% the correct results I will integrate this into mmpython
which will be our media detector in the future. Please don't only
report failures, also positive results. Send reports to me
([EMAIL PROTECTED]) to avoid a flood of mails on this list.

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. 


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(600000)

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'

elif 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'

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

f.close()
-- 
Never put off until tomorrow what you can do the day after.

Reply via email to