def read(self, device, features=[]): self.disc = libdiscid.read(device, functools.reduce( operator.or_, ( _INVERSE_FEATURES[feature] for feature in features if feature in FEATURES ), 0)) self.tracks = [ Track(self.disc, numb) for numb in range(self.disc.first_track, self.disc.last_track + 1)] return True
def load_cd_info(self): # JH - added code to query musicbrainz for disk info, build track list and times from that info # instead of the cd-discid output, if available. track_offsets = [] m.set_useragent('raspberry-pi-cdplayer', '0.2', 'https://github.com/JoeHartley3/raspberry-pi-cdplayer') try: this_disc = libdiscid.read('/dev/cdrom') except: print('DiskID could not read /dev/cdrom') self._numtracks = 0 self._track_lengths = [] self._cd_info = None return try: # A CD stub is an anonymously submitted track list that contains a disc ID, barcode, comment field, and # basic metadata like a release title and track names. ( https://wiki.musicbrainz.org/CD_Stub ) # By using cdstubs=False here, we force a ResponseError rather than try and parse the stub. Remove the # argument to enable cdstubs. self._cd_info = m.get_releases_by_discid(this_disc.id, includes=["recordings", "artists"], cdstubs=False) except m.ResponseError: print("Disk not found or database unavailable") discid = subprocess.getstatusoutput('cd-discid --musicbrainz') if discid[0] == 0: output_split = discid[1].split() self._numtracks = int(output_split[0]) track_offsets = list(map(lambda i: int(i), output_split[1:])) if self._cd_info is not None: if self._cd_info.get("disc"): self._numtracks = self._cd_info['disc']['offset-count'] track_offsets = self._cd_info['disc']['offset-list'] # Append the total time to the track_offsets track_offsets.append(int(self._cd_info['disc']['sectors'])) elif self._cd_info.get("cdstub"): pass else: # We should never actually get to this point with or without cdstubs, but let's make sure. # This is the same code as for a ResponseError above. print("Unknown disk type from MB - use track numbers") discid = subprocess.getstatusoutput('cd-discid --musicbrainz') if discid[0] == 0: output_split = discid[1].split() self._numtracks = int(output_split[0]) track_offsets = list(map(lambda i: int(i), output_split[1:])) try: self._track_lengths = list( map(lambda i, offsets=track_offsets: int((offsets[i + 1] - offsets[i]) * 1000 / 75), range(0, self._numtracks))) except: self._numtracks = 0 self._track_lengths = []
def current_disc(): """ Returns the disc information corresponding to the disc currently insterted into the default USB player. It contains among other data, the musicbrainz disc id and the number of tracks. """ try: d = cdio.Device(driver_id=pycdio.DRIVER_UNKNOWN) except IOError as err: d = None if d is not None: try: if d.get_disc_mode() == 'CD-DA': d = libdiscid.read(libdiscid.default_device()) else: d = None except: d = None return d
# if we found any info, remove first entry # since it is the album title: title = track.pop(0) print("Album: {} - {}".format(artist, title)) else: write_tags = False if write_tags and use_cdtext: get_cdtextinfo() elif write_tags and not use_cdtext: # get discid: try: disc = libdiscid.read(device) tracknum = disc.last_track except libdiscid.DiscError: print( "Disc error! Please make sure a disc is inserted and {} is the right device!" .format(device)) exit(1) # set the musicbrainz useragent_ musicbrainzngs.set_useragent("cd2mp3", "0.2", None) # needs "includes=..." to get a non-empty tracklist: try: result = musicbrainzngs.get_releases_by_discid( disc.id, includes=["artists", "recordings"]) except musicbrainzngs.ResponseError: print("No matches found on musicbrainz... Trying cd-info:")
raise parser.error("Only one of -f, -o, -w please") if options.wav: fmt = 'wav' encoding = 'wavenc' elif options.flac: fmt = 'flac' encoding = 'flacenc' from mutagen.flac import FLAC as audiofile elif options.ogg: fmt = 'oga' quality = 'quality=0.3' encoding = 'vorbisenc {} ! oggmux'.format(quality) from mutagen.oggvorbis import OggVorbis as audiofile # Get MusicBrainz info this_disc = libdiscid.read(libdiscid.default_device()) mb.set_useragent(app='get-contents', version='0.1') mb.auth(u=input('Musicbrainz username: '******'artists', 'recordings']) if release.get('disc'): this_release=release['disc']['release-list'][0] album = this_release['title'] artist = this_release['artist-credit'][0]['artist']['name'] year = this_release['date'].split('-')[0] for medium in this_release['medium-list']: for disc in medium['disc-list']: if disc['id'] == this_disc.id:
type=str) parser.add_argument('-c', '--cover-art', help='will attempt to embed the associated cover art', action='store_true') args = parser.parse_args() # Setup MusicBrainz client mb.set_useragent('Antiquarian Backups', '1.0.0') # get Username/Password creds = open('credentials', 'r').read().split('\n') mb.auth(creds[0], creds[1]) # Select the disc and retrieve the MusicBrainz discid disc = libdiscid.read(device=u'/dev/sr0') disc_id = disc.id # Collect the valuable metadata information from the discid in the MusicBrainz CDDA database try: results = mb.get_releases_by_discid(disc_id, includes=['artists', 'recordings']) except mb.musicbrainz.ResponseError as re: print( 'Error retrieving the releases data, check if the Title has a discID on musicbrainz.org' ) sys.exit(1) # save the releaseid release_id = results['disc']['release-list'][0]['id']
def test_read_None(self): try: libdiscid.read() except (DiscError, NotImplementedError): pass
def com_discid_spec_device(device_id): # return read(device=u'/dev/cdrom1') return read(device=device_id)