Skip to content

Commit

Permalink
allow selecting a CD drive from the command line
Browse files Browse the repository at this point in the history
Add -d/--drive command-line option to arver and arver-discinfo. The new
option allows selecting the CD drive to read the TOC from.

The implementation follows the path of least resistance: get_disc_info()
was changed to accept two arguments instead of one, and its internal
logic became more complicated.

This should be simplified in the long run. Refactoring should also take
into account creating DiscInfo object with -t/--track-lengths option.
  • Loading branch information
arcctgx committed Jul 11, 2024
1 parent 4de0bd8 commit 9b857d0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion arver/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Main ARver package."""

APPNAME = 'ARver'
VERSION = 'v1.4.0.dev1'
VERSION = 'v1.4.0.dev2'
URL = 'https://github.com/arcctgx/ARver'
17 changes: 12 additions & 5 deletions arver/arver_discinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ def _parse_args():
derived from MusicBrainz disc ID. Fetch and display AccurateRip data
of the disc.""")

parser.add_argument('-i',
'--disc-id',
metavar='disc_id',
help='get disc TOC from MusicBrainz by disc ID')
toc_source = parser.add_mutually_exclusive_group()

toc_source.add_argument('-d',
'--drive',
metavar='device_path',
help='read disc TOC from a CD in specified drive (e.g. /dev/sr0)')

toc_source.add_argument('-i',
'--disc-id',
metavar='disc_id',
help='get disc TOC from MusicBrainz by disc ID query')

parser.add_argument('-v', '--version', action='version', version=version_string())

Expand All @@ -28,7 +35,7 @@ def _parse_args():

def main():
args = _parse_args()
disc = get_disc_info(args.disc_id)
disc = get_disc_info(args.drive, args.disc_id)

if disc is None:
print('Failed to get disc info, exiting.')
Expand Down
7 changes: 6 additions & 1 deletion arver/arver_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def _parse_args():

toc_source = parser.add_mutually_exclusive_group()

toc_source.add_argument('-d',
'--drive',
metavar='device_path',
help='read disc TOC from a CD in specified drive (e.g. /dev/sr0)')

toc_source.add_argument('-i',
'--disc-id',
metavar='disc_id',
Expand Down Expand Up @@ -87,7 +92,7 @@ def main():
if args.track_lengths:
disc = DiscInfo.from_track_lengths(rip.track_frames(), args.pregap_length, args.data_length)
else:
disc = get_disc_info(args.disc_id)
disc = get_disc_info(args.drive, args.disc_id)

if disc is None:
print('Failed to get disc info, exiting.')
Expand Down
31 changes: 18 additions & 13 deletions arver/disc/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,21 +384,26 @@ def fetch_accuraterip_data(self) -> None:
self.accuraterip_data = fetcher.fetch()


def get_disc_info(disc_id: Optional[str]) -> Optional[DiscInfo]:
def get_disc_info(drive: Optional[str], disc_id: Optional[str]) -> Optional[DiscInfo]:
"""
Helper function for obtaining disc information.
If disc_id is None read CD TOC from the CD in drive.
Otherwise get TOC from specified MusicBrainz disc ID.
"""
if disc_id is None:
disc_info = DiscInfo.from_cd()
else:
disc_info = DiscInfo.from_disc_id(disc_id)
Helper function for obtaining DiscInfo object.
if disc_info is None:
if disc_id is None:
drive | disc ID | TOC source
--------|---------|------------------
None | None | default device
defined | None | specified device
None | defined | disc ID query
"""
if (drive is None and disc_id is None) or drive is not None:
disc_info = DiscInfo.from_cd(drive)
if disc_info is None:
print('Could not read disc. Is there a CD in the drive?')
else:
return disc_info

if disc_id is not None:
disc_info = DiscInfo.from_disc_id(disc_id)
if disc_info is None:
print(f'Could not look up disc ID "{disc_id}", is it correct?')
return disc_info

return disc_info
return None

0 comments on commit 9b857d0

Please sign in to comment.