ripcd: Read disc ID from TOC
When the verbose level of `icedax` contains `catalog`, the disc ID is printed to stdout. This is a faster and simpler method compared to parsing the CD index XML document.master
parent
3694f177df
commit
27d13532ea
31
ripcd.py
31
ripcd.py
|
@ -37,6 +37,12 @@ class TocProtocol(asyncio.SubprocessProtocol):
|
||||||
values = m.groupdict()
|
values = m.groupdict()
|
||||||
self.toc.album = values.get('album')
|
self.toc.album = values.get('album')
|
||||||
self.toc.artist = values.get('artist')
|
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'):
|
elif line.startswith('Track'):
|
||||||
try:
|
try:
|
||||||
title = line.split(':', 1)[1].strip().strip("'")
|
title = line.split(':', 1)[1].strip().strip("'")
|
||||||
|
@ -55,6 +61,7 @@ class TableOfContents(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.discid = None
|
||||||
self.artist = None
|
self.artist = None
|
||||||
self.album = None
|
self.album = None
|
||||||
self.tracks = []
|
self.tracks = []
|
||||||
|
@ -68,7 +75,7 @@ class TableOfContents(object):
|
||||||
cmd.extend((
|
cmd.extend((
|
||||||
'--info-only',
|
'--info-only',
|
||||||
'--no-infofile',
|
'--no-infofile',
|
||||||
'--verbose-level', 'titles',
|
'--verbose-level', 'catalog,titles',
|
||||||
'--quiet',
|
'--quiet',
|
||||||
'--silent-scsi',
|
'--silent-scsi',
|
||||||
))
|
))
|
||||||
|
@ -162,19 +169,8 @@ class Track(object):
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def fetch_album_art():
|
def fetch_album_art(discid):
|
||||||
loop = asyncio.get_event_loop()
|
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 = {
|
headers = {
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
|
@ -269,10 +265,11 @@ def rip_cd(args):
|
||||||
toc = yield from TableOfContents.from_device(args.device)
|
toc = yield from TableOfContents.from_device(args.device)
|
||||||
print('Found CD: {} by {}'.format(toc.album, toc.artist))
|
print('Found CD: {} by {}'.format(toc.album, toc.artist))
|
||||||
yield from rip_info(args.device)
|
yield from rip_info(args.device)
|
||||||
tasks = [
|
tasks = []
|
||||||
loop.create_task(fetch_album_art()),
|
if toc.discid:
|
||||||
loop.create_task(rip_tracks(args.device, args.num_encoders)),
|
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)
|
yield from asyncio.wait(tasks)
|
||||||
if args.cleanup:
|
if args.cleanup:
|
||||||
cleanup()
|
cleanup()
|
||||||
|
|
Loading…
Reference in New Issue