Cleaner args
This commit is contained in:
parent
b3bd9c616b
commit
d59cd47f36
101
badwitch.py
101
badwitch.py
@ -41,15 +41,17 @@ class Library:
|
|||||||
class BadWitch:
|
class BadWitch:
|
||||||
# Our program
|
# Our program
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Set up arguments
|
# Flags and arguments
|
||||||
self.argparser = argparse.ArgumentParser(description='Manage a declarative music library through YouTube scraping')
|
self.argparser = argparse.ArgumentParser(
|
||||||
self.argparser.add_argument('action', metavar='action', nargs=1,
|
description='Manage a declarative music library through YouTube scraping')
|
||||||
choices=['download', 'add', 'remove', 'list', 'test'],
|
self.argparser.add_argument('-l', '--library', metavar='f', nargs='?',
|
||||||
help='Action to perform on the library')
|
|
||||||
self.argparser.add_argument('-l', '--library', metavar='f', nargs=1,
|
|
||||||
help='Override default library file with this one')
|
help='Override default library file with this one')
|
||||||
self.argparser.add_argument('-v', '--verbose', action='store_true',
|
self.argparser.add_argument('-v', '--verbose', action='store_true',
|
||||||
help='Show more status messages')
|
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
|
# Set up appdirs
|
||||||
self.dirs = AppDirs('badwitch', 'rehashedsalt')
|
self.dirs = AppDirs('badwitch', 'rehashedsalt')
|
||||||
Path(self.dirs.user_data_dir).mkdir(parents=True, exist_ok=True)
|
Path(self.dirs.user_data_dir).mkdir(parents=True, exist_ok=True)
|
||||||
@ -57,54 +59,51 @@ class BadWitch:
|
|||||||
def execute(self):
|
def execute(self):
|
||||||
self.args = self.argparser.parse_args()
|
self.args = self.argparser.parse_args()
|
||||||
# Initialize library
|
# Initialize library
|
||||||
libfile = self.dirs.user_data_dir + '/lib.json'
|
libfile = self.args.library or self.dirs.user_data_dir + '/lib.json'
|
||||||
if self.args.library is not None:
|
|
||||||
libfile = self.args.library[0]
|
|
||||||
lib = Library(file=libfile)
|
lib = Library(file=libfile)
|
||||||
# Perform action
|
# Perform action
|
||||||
for action in self.args.action:
|
if self.args.action == 'download':
|
||||||
if action == 'download':
|
return
|
||||||
return
|
elif self.args.action == 'add':
|
||||||
elif action == 'add':
|
return
|
||||||
return
|
elif self.args.action == 'remove':
|
||||||
elif action == 'remove':
|
return
|
||||||
return
|
elif self.args.action == 'list':
|
||||||
elif action == 'list':
|
lib.load()
|
||||||
lib.load()
|
for album, albumcontent in lib.albums.items():
|
||||||
for album, albumcontent in lib.albums.items():
|
for song, songcontent in albumcontent.items():
|
||||||
for song, songcontent in albumcontent.items():
|
print(album + ' - ' + song + ' by ' + songcontent['artist'])
|
||||||
print(album + ' - ' + song + ' by ' + songcontent['artist'])
|
return
|
||||||
return
|
elif self.args.action == 'test':
|
||||||
elif action == 'test':
|
# Set up a test album
|
||||||
# Set up a test album
|
lib.albums['Bad Witch'] = {
|
||||||
lib.albums['Bad Witch'] = {
|
'Shit Mirror': {
|
||||||
'Shit Mirror': {
|
'artist': 'Nine Inch Nails',
|
||||||
'artist': 'Nine Inch Nails',
|
'source': 'https://www.youtube.com/watch?v=yeqjz5mXrLQ'
|
||||||
'source': 'https://www.youtube.com/watch?v=yeqjz5mXrLQ'
|
},
|
||||||
},
|
'Ahead of Ourselves': {
|
||||||
'Ahead of Ourselves': {
|
'artist': 'Nine Inch Nails',
|
||||||
'artist': 'Nine Inch Nails',
|
'source': 'https://www.youtube.com/watch?v=4Ab1O-i4ep4'
|
||||||
'source': 'https://www.youtube.com/watch?v=4Ab1O-i4ep4'
|
},
|
||||||
},
|
'Play the Goddamned Part': {
|
||||||
'Play the Goddamned Part': {
|
'artist': 'Nine Inch Nails',
|
||||||
'artist': 'Nine Inch Nails',
|
'source': 'https://www.youtube.com/watch?v=85UgvBkMfr8'
|
||||||
'source': 'https://www.youtube.com/watch?v=85UgvBkMfr8'
|
},
|
||||||
},
|
'God Break Down the Door': {
|
||||||
'God Break Down the Door': {
|
'artist': 'Nine Inch Nails',
|
||||||
'artist': 'Nine Inch Nails',
|
'source': 'https://www.youtube.com/watch?v=eeJ_DzRJUI4'
|
||||||
'source': 'https://www.youtube.com/watch?v=eeJ_DzRJUI4'
|
},
|
||||||
},
|
'I\'m Not From This World': {
|
||||||
'I\'m Not From This World': {
|
'artist': 'Nine Inch Nails',
|
||||||
'artist': 'Nine Inch Nails',
|
'source': 'https://www.youtube.com/watch?v=9fjbcSUSt9w'
|
||||||
'source': 'https://www.youtube.com/watch?v=9fjbcSUSt9w'
|
},
|
||||||
},
|
'Over and Out': {
|
||||||
'Over and Out': {
|
'artist': 'Nine Inch Nails',
|
||||||
'artist': 'Nine Inch Nails',
|
'source': 'https://www.youtube.com/watch?v=h-XlN3N2fis'
|
||||||
'source': 'https://www.youtube.com/watch?v=h-XlN3N2fis'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
lib.save()
|
}
|
||||||
return
|
lib.save()
|
||||||
|
return
|
||||||
|
|
||||||
badwitch = BadWitch()
|
badwitch = BadWitch()
|
||||||
badwitch.execute()
|
badwitch.execute()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user