import sys

def parseDisc(device):
    f = open(device)
    try:
        # read CD-XA001 at byte 1024 in sector 16
        f.seek(2048*16 + 1024, 0)
        if f.read(8) != 'CD-XA001':
            raise IOError('CD-XA001 not found')
        # read VIDEO_CD at sector 150
        f.seek(2048*150, 0)
        if f.read(8) != 'VIDEO_CD':
            raise IOError('VIDEO_CD not found')
        # read some bytes of the ISO9660 part to guess VCD or SVCD
        f.seek(2048*16, 0)
        iso9660 = f.read(2048*16)
        if iso9660.find('MPEGAV') > 0:
            print 'VCD'
        elif iso9660.find('SVCD') > 0 or iso9660.find('MPEG2') > 0:
            print 'SVCD'
        else:
            raise IOError('Unable to detect video format')
    finally:
        f.close()

try:
    parseDisc(sys.argv[1])
except Exception, e:
    print e
    print 'No VCD or SVCD'

