Cleaner args
This commit is contained in:
parent
b3bd9c616b
commit
d59cd47f36
29
badwitch.py
29
badwitch.py
@ -41,15 +41,17 @@ class Library:
|
||||
class BadWitch:
|
||||
# Our program
|
||||
def __init__(self):
|
||||
# Set up arguments
|
||||
self.argparser = argparse.ArgumentParser(description='Manage a declarative music library through YouTube scraping')
|
||||
self.argparser.add_argument('action', metavar='action', nargs=1,
|
||||
choices=['download', 'add', 'remove', 'list', 'test'],
|
||||
help='Action to perform on the library')
|
||||
self.argparser.add_argument('-l', '--library', metavar='f', nargs=1,
|
||||
# Flags and arguments
|
||||
self.argparser = argparse.ArgumentParser(
|
||||
description='Manage a declarative music library through YouTube scraping')
|
||||
self.argparser.add_argument('-l', '--library', metavar='f', nargs='?',
|
||||
help='Override default library file with this one')
|
||||
self.argparser.add_argument('-v', '--verbose', action='store_true',
|
||||
help='Show more status messages')
|
||||
# Subparsers
|
||||
self.argparser.add_argument('action', metavar='action', nargs='?',
|
||||
choices=['download', 'add', 'remove', 'list', 'test'],
|
||||
help='Action to perform on the library')
|
||||
# Set up appdirs
|
||||
self.dirs = AppDirs('badwitch', 'rehashedsalt')
|
||||
Path(self.dirs.user_data_dir).mkdir(parents=True, exist_ok=True)
|
||||
@ -57,25 +59,22 @@ class BadWitch:
|
||||
def execute(self):
|
||||
self.args = self.argparser.parse_args()
|
||||
# Initialize library
|
||||
libfile = self.dirs.user_data_dir + '/lib.json'
|
||||
if self.args.library is not None:
|
||||
libfile = self.args.library[0]
|
||||
libfile = self.args.library or self.dirs.user_data_dir + '/lib.json'
|
||||
lib = Library(file=libfile)
|
||||
# Perform action
|
||||
for action in self.args.action:
|
||||
if action == 'download':
|
||||
if self.args.action == 'download':
|
||||
return
|
||||
elif action == 'add':
|
||||
elif self.args.action == 'add':
|
||||
return
|
||||
elif action == 'remove':
|
||||
elif self.args.action == 'remove':
|
||||
return
|
||||
elif action == 'list':
|
||||
elif self.args.action == 'list':
|
||||
lib.load()
|
||||
for album, albumcontent in lib.albums.items():
|
||||
for song, songcontent in albumcontent.items():
|
||||
print(album + ' - ' + song + ' by ' + songcontent['artist'])
|
||||
return
|
||||
elif action == 'test':
|
||||
elif self.args.action == 'test':
|
||||
# Set up a test album
|
||||
lib.albums['Bad Witch'] = {
|
||||
'Shit Mirror': {
|
||||
|
Loading…
x
Reference in New Issue
Block a user