diff --git a/ripcd.py b/ripcd.py index 68ffefd..1b1190e 100755 --- a/ripcd.py +++ b/ripcd.py @@ -37,6 +37,12 @@ class TocProtocol(asyncio.SubprocessProtocol): values = m.groupdict() self.toc.album = values.get('album') self.toc.artist = values.get('artist') + elif line.startswith('CDINDEX'): + try: + discid = line.split(':', 1)[1].strip() + except ValueError: + continue + self.toc.discid = discid elif line.startswith('Track'): try: title = line.split(':', 1)[1].strip().strip("'") @@ -55,6 +61,7 @@ class TableOfContents(object): ) def __init__(self): + self.discid = None self.artist = None self.album = None self.tracks = [] @@ -68,7 +75,7 @@ class TableOfContents(object): cmd.extend(( '--info-only', '--no-infofile', - '--verbose-level', 'titles', + '--verbose-level', 'catalog,titles', '--quiet', '--silent-scsi', )) @@ -162,19 +169,8 @@ class Track(object): @asyncio.coroutine -def fetch_album_art(): +def fetch_album_art(discid): loop = asyncio.get_event_loop() - try: - with open('audio.cdindex') as f: - tree = yield from loop.run_in_executor(None, etree.parse, f) - except OSError as e: - sys.stderr.write('Could not read CD index: {}\n'.format(e)) - return - try: - discid = tree.xpath('//DiskId/Id')[0].text - except IndexError: - sys.stderr.write('Missing disc ID in CD index\n') - return headers = { 'Accept': 'application/json', @@ -269,10 +265,11 @@ def rip_cd(args): toc = yield from TableOfContents.from_device(args.device) print('Found CD: {} by {}'.format(toc.album, toc.artist)) yield from rip_info(args.device) - tasks = [ - loop.create_task(fetch_album_art()), - loop.create_task(rip_tracks(args.device, args.num_encoders)), - ] + tasks = [] + if toc.discid: + tasks.append(loop.create_task(fetch_album_art(toc.discid))) + tasks.append(loop.create_task(rip_tracks(args.device, args.codec, + args.num_encoders))) yield from asyncio.wait(tasks) if args.cleanup: cleanup()