Example #1
0
	def __init__(self):
	
		self.error = None
		cdaudio = cdrom.open()
		print "CD: ", cdaudio

		try:
			first, last = cdrom.toc_header(cdaudio)
			print "toc_header: ", first, last
			self.is_audio_cd = True
		except:
			print "No CD"
			disc_id = None
			self.is_audio_cd = False
			raise

		# Legge la TOC del disco
		if self.is_audio_cd:
			frames = []
			for i in range(first, last + 1):
				print cdrom.toc_entry(cdaudio, i)
				(m, s, frame) = cdrom.toc_entry(cdaudio, i)
				frames.append(m*60*75 + s*75 + frame)
			m, s, frame = cdrom.leadout(cdaudio)
			frames.append(m*60*75 + s*75 + frame)
			
			# Ordina i dati della TOC nel formato adatto a MusicBrainz
			self.__MB_full_toc = [first, last, frames[-1]] + frames[:-1]
			# Numero di tracce
			self.__num_tracks = last
		cdaudio.close()
Example #2
0
    def isDisc(self, device):
        type = None
        if DiscInfo.isDisc(self, device) != 2:
            return 0
        
        # brute force reading of the device to find out if it is a VCD
        f = open(device,'rb')
        f.seek(32768, 0)
        buffer = f.read(60000)
        f.close()

        if buffer.find('SVCD') > 0 and buffer.find('TRACKS.SVD') > 0 and \
               buffer.find('ENTRIES.SVD') > 0:
            type = 'SVCD'

        elif buffer.find('INFO.VCD') > 0 and buffer.find('ENTRIES.VCD') > 0:
            type = 'VCD'

        else:
            return 0

        # read the tracks to generate the title list
        device = open(device)
        (first, last) = cdrom.toc_header(device)

        lmin = 0
        lsec = 0

        num = 0
        for i in range(first, last + 2):
            if i == last + 1:
                min, sec, frames = cdrom.leadout(device)
            else:
                min, sec, frames = cdrom.toc_entry(device, i)
            if num:
                vi = mediainfo.VideoInfo()
                # XXX add more static information here, it's also possible
                # XXX to scan for more informations like fps
                # XXX Settings to MPEG1/2 is a wild guess, maybe the track
                # XXX isn't playable at all (e.g. the menu)
                if type == 'VCD':
                    vi.codec = 'MPEG1'
                else:
                    vi.codec = 'MPEG2'
                vi.length = (min-lmin) * 60 + (sec-lsec)
                self.tracks.append(vi)
            num += 1
            lmin, lsec = min, sec
        device.close()
        return 1
Example #3
0
    def isDisc(self, device):
        type = None
        if DiscInfo.isDisc(self, device) != 2:
            return 0

        # brute force reading of the device to find out if it is a VCD
        f = open(device, 'rb')
        f.seek(32768, 0)
        buffer = f.read(60000)
        f.close()

        if buffer.find('SVCD') > 0 and buffer.find('TRACKS.SVD') > 0 and \
               buffer.find('ENTRIES.SVD') > 0:
            type = 'SVCD'

        elif buffer.find('INFO.VCD') > 0 and buffer.find('ENTRIES.VCD') > 0:
            type = 'VCD'

        else:
            return 0

        # read the tracks to generate the title list
        device = open(device)
        (first, last) = cdrom.toc_header(device)

        lmin = 0
        lsec = 0

        num = 0
        for i in range(first, last + 2):
            if i == last + 1:
                min, sec, frames = cdrom.leadout(device)
            else:
                min, sec, frames = cdrom.toc_entry(device, i)
            if num:
                vi = mediainfo.VideoInfo()
                # XXX add more static information here, it's also possible
                # XXX to scan for more informations like fps
                # XXX Settings to MPEG1/2 is a wild guess, maybe the track
                # XXX isn't playable at all (e.g. the menu)
                if type == 'VCD':
                    vi.codec = 'MPEG1'
                else:
                    vi.codec = 'MPEG2'
                vi.length = (min - lmin) * 60 + (sec - lsec)
                self.tracks.append(vi)
            num += 1
            lmin, lsec = min, sec
        device.close()
        return 1
Example #4
0
def disc_id(device):
    (first, last) = cdrom.toc_header(device)

    track_frames = []
    checksum = 0

    for i in range(first, last + 1):
        (min, sec, frame) = cdrom.toc_entry(device, i)
        checksum = checksum + cddb_sum(min * 60 + sec)
        track_frames.append(min * 60 * 75 + sec * 75 + frame)

    (min, sec, frame) = cdrom.leadout(device)
    track_frames.append(min * 60 * 75 + sec * 75 + frame)

    total_time = (track_frames[-1] / 75) - (track_frames[0] / 75)

    discid = ((checksum % 0xff) << 24 | total_time << 8 | last)

    return [discid, last] + track_frames[:-1] + [track_frames[-1] / 75]
Example #5
0
def disc_id(device):
    device = cdrom.open(device)
    (first, last) = cdrom.toc_header(device)

    track_frames = []
    checksum = 0
    
    for i in range(first, last + 1):
	(min, sec, frame) = cdrom.toc_entry(device, i)
	checksum = checksum + cddb_sum(min*60 + sec)
	track_frames.append(min*60*75 + sec*75 + frame)

    (min, sec, frame) = cdrom.leadout(device)
    track_frames.append(min*60*75 + sec*75 + frame)

    total_time = (track_frames[-1] / 75) - (track_frames[0] / 75)
	       
    discid = ((long(checksum) % 0xff) << 24 | total_time << 8 | last)
    cdrom.close(device)
    return [discid, last] + track_frames[:-1] + [ track_frames[-1] / 75 ]
Example #6
0
    (first, num_tracks) = cdrom.toc_header(device)
except:
    print("no medium found")
    sys.exit(-1)

track_length = []  # track_length in seconds
track_limits = []
track_prefix = []
track_title = []
disk_title = []

for i in range(num_tracks):
    (min, sec, frame) = cdrom.toc_entry(device, i + 1)
    track_limits.append(60 * min + sec + frame / 75.)

(min, sec, frame) = cdrom.leadout(device)
track_limits.append(60 * min + sec + frame / 75.)

for i in range(num_tracks):
    track_length.append(track_limits[i + 1] - track_limits[i])
    track_prefix.append("%02d. " % (i + 1))
    track_title.append(track_prefix[i] + default_track_name)

status2 = 0
disc_id = DiscID.disc_id(device)
cddb_id = hex(disc_id[0])[2:]  # magic id string

# looks for cd in local database
cddb_fullpath = cddb_path + cddb_id
cddb_local = False
if os.path.exists(cddb_fullpath):
Example #7
0
    def isDisc(self, device):
        if discinfo.DiscInfo.isDisc(self, device) != 1:
            return 0
        
        disc_id = DiscID.disc_id(device)
        if mmpython.USE_NETWORK:
            try:
                (query_stat, query_info) = CDDB.query(disc_id)
            except:
                # Oops no connection
                query_stat = 404
        else:
            query_stat = 404


        if query_stat == 210 or query_stat == 211:
            # set this to success
            query_stat = 200

            for i in query_info:
                if i['title'] != i['title'].upper():
                    query_info = i
                    break
            else:
                query_info = query_info[0]

        elif query_stat != 200:
            _debug("failure getting disc info, status %i" % query_stat)

        if query_stat == 200:
            qi = query_info['title'].split('/')
            self.artist = qi[0].strip()
            self.title = qi[1].strip()
            for type in ('title', 'artist'):
                if getattr(self, type) and getattr(self, type)[0] in ('"', '\'') \
                       and getattr(self, type)[-1] in ('"', '\''):
                    setattr(self, type, getattr(self, type)[1:-1])
            (read_stat, read_info) = CDDB.read(query_info['category'], 
                                               query_info['disc_id'])
            # id = disc_id + number of tracks
            #self.id = '%s_%s' % (query_info['disc_id'], disc_id[1])

            if read_stat == 210:
                for i in range(0, disc_id[1]):
                    mi = mediainfo.MusicInfo()
                    mi.title = read_info['TTITLE' + `i`]
                    mi.album = self.title
                    mi.artist = self.artist
                    mi.genre = query_info['category']
                    mi.codec = 'PCM'
                    mi.samplerate = 44.1
                    mi.trackno = i+1
                    mi.trackof = disc_id[1]
                    self.tracks.append(mi)
                    for type in ('title', 'album', 'artist', 'genre'):
                        if getattr(mi, type) and getattr(mi, type)[0] in ('"', '\'') \
                           and getattr(mi, type)[-1] in ('"', '\''):
                            setattr(mi, type, getattr(mi, type)[1:-1])
            else:
                _debug("failure getting track info, status: %i" % read_stat)
                # set query_stat to somthing != 200
                query_stat = 400
            

        if query_stat != 200:
            _debug("failure getting disc info, status %i" % query_stat)
            self.no_caching = 1
            for i in range(0, disc_id[1]):
                mi = mediainfo.MusicInfo()
                mi.title = 'Track %s' % (i+1)
                mi.codec = 'PCM'
                mi.samplerate = 44.1
                mi.trackno = i+1
                mi.trackof = disc_id[1]
                self.tracks.append(mi)
                
                
        # read the tracks to generate the title list
        device = open(device)
        (first, last) = cdrom.toc_header(device)

        lmin = 0
        lsec = 0

        num = 0
        for i in range(first, last + 2):
            if i == last + 1:
                min, sec, frames = cdrom.leadout(device)
            else:
                min, sec, frames = cdrom.toc_entry(device, i)
            if num:
                self.tracks[num-1].length = (min-lmin)*60 + (sec-lsec)
            num += 1
            lmin, lsec = min, sec
        device.close()

        # correct bad titles for the tracks, containing also the artist
        for t in self.tracks:
            if not self.artist or not t.title.startswith(self.artist):
                break
        else:
            for t in self.tracks:
                t.title = t.title[len(self.artist):].lstrip('/ \t-_')

        # correct bad titles for the tracks, containing also the title
        for t in self.tracks:
            if not self.title or not t.title.startswith(self.title):
                break
        else:
            for t in self.tracks:
                t.title = t.title[len(self.title):].lstrip('/ \t-_')
        return 1