def open(device=None, flags=None): # Allow this function to be called with no arguments, # specifying that we should call cdrom.open() with # no arguments. if device == None: return cdrom.open() elif flags == None: return cdrom.open(device) else: return cdrom.open(device, flags)
def getCDTracks(self, device): import cdrom try: if device: device = cdrom.open(device) else: device = cdrom.open() (first, last) = cdrom.toc_header(device) cdtracks = [] for i in range(first, last+1): cdtracks.append([sopranoGlobals.TRACKPB, "Track " + str(i), 3, 'cdda://' + str(i) ]) return cdtracks except: return [[sopranoGlobals.TRACKPB, "No Audio CD Found", 3, '' ]]
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()
def getCDTracks(self, device): import cdrom try: if device: device = cdrom.open(device) else: device = cdrom.open() (first, last) = cdrom.toc_header(device) cdtracks = [] for i in range(first, last + 1): cdtracks.append([ sopranoGlobals.TRACKPB, "Track " + str(i), 3, 'cdda://' + str(i) ]) return cdtracks except: return [[sopranoGlobals.TRACKPB, "No Audio CD Found", 3, '']]
def __track_times(self): device = cdrom.open() first, last = cdrom.toc_header(device) tr_times = [] for trk in range(first, last + 1): if trk > 1: minu, sec = cdrom.toc_entry(device, trk)[0:2] total = (minu * 60) + sec old_m, old_s = cdrom.toc_entry(device, trk - 1)[0:2] old_t = (old_m * 60) + old_s total -= old_t tr_times.append(total) return tr_times
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]
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 ]
config.readfp(config_file) config_file.close default_track_name = config.get('playlist', 'default_track_name') previous_name = config.get('playlist', 'previous_name') playlist_name = config.get('playlist', 'playlist_name') playlist_path = config.get('playlist', 'playlist_path') cddb_path = config.get('playlist', 'cddb_path') mpd_port = config.get('mpd', 'port') except: print("Error in configuration file") sys.exit(-1) playlist_fullpath = os.path.join(playlist_path, playlist_name) # Gets track lengths device = cdrom.open() try: (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.)
import sys import os from fcntl import ioctl import struct import cdrom from CDROM import * # --- fd = cdrom.open('/dev/cdrom', os.O_RDONLY) # --- tochdr_fmt = 'BB' tochdr = struct.pack(tochdr_fmt, 0, 0) tochdr = ioctl(fd, CDROMREADTOCHDR, tochdr) start, end = struct.unpack(tochdr_fmt, tochdr) #--- tocentry_fmt = 'BBBix' addr_fmt = 'BBB' + 'x' * (struct.calcsize('i') - 3) for trnum in range(start, end + 1) + [CDROM_LEADOUT]: tocentry = struct.pack(tocentry_fmt, trnum, 0, CDROM_MSF, 0) tocentry = ioctl(fd, CDROMREADTOCENTRY, tocentry) track, adrctrl, format, addr = struct.unpack(tocentry_fmt, tocentry) minute, second, fraction = struct.unpack(addr_fmt, struct.pack('i', addr)) print "%3d: %2d:%02d.%02d" \ % (track, minute, second, fraction)
print("config file", config_file) default_track_name = config.get('playlist', 'default_track_name') previous_name = config.get('playlist', 'previous_name') playlist_name = config.get('playlist', 'playlist_name') playlist_path = config.get('playlist', 'playlist_path') cddb_path = config.get('playlist', 'cddb_path') mpd_port = config.get('mpd', 'port') except: print("Error in configuration file") sys.exit(-1) playlist_fullpath = os.path.join(playlist_path, playlist_name) print(playlist_fullpath) # Gets track lengths device = cdrom.open("/dev/sr0") #cambiar esta linea con el nombre del cdrom try: (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.)
import sys import os from fcntl import ioctl import struct import cdrom from CDROM import * # --- fd = cdrom.open("/dev/cdrom", os.O_RDONLY) # --- tochdr_fmt = "BB" tochdr = struct.pack(tochdr_fmt, 0, 0) tochdr = ioctl(fd, CDROMREADTOCHDR, tochdr) start, end = struct.unpack(tochdr_fmt, tochdr) # --- tocentry_fmt = "BBBix" addr_fmt = "BBB" + "x" * (struct.calcsize("i") - 3) for trnum in range(start, end + 1) + [CDROM_LEADOUT]: tocentry = struct.pack(tocentry_fmt, trnum, 0, CDROM_MSF, 0) tocentry = ioctl(fd, CDROMREADTOCENTRY, tocentry) track, adrctrl, format, addr = struct.unpack(tocentry_fmt, tocentry) minute, second, fraction = struct.unpack(addr_fmt, struct.pack("i", addr)) print "%3d: %2d:%02d.%02d" % (track, minute, second, fraction)