Move prompt to its own function
This commit is contained in:
parent
42d4edabb7
commit
89e28db59b
138
badwitch.py
138
badwitch.py
@ -277,76 +277,14 @@ class BadWitch:
|
||||
# Perform action
|
||||
if self.args.action == 'download':
|
||||
lib.download()
|
||||
return
|
||||
if self.args.action == 'gui':
|
||||
qapp = QApplication(sys.argv)
|
||||
gui = BadWitchGUI(self, lib)
|
||||
sys.exit(qapp.exec_())
|
||||
elif self.args.action == 'edit':
|
||||
print('Bad Witch interactive $ibrary editor')
|
||||
print('^C to abort, ^D to finish changes')
|
||||
print('Loaded library ' + lib.file)
|
||||
try:
|
||||
while True:
|
||||
in_album = input('\t*Album: ')
|
||||
auto_artist = input('\tArtist (leave blank to assign per song): ')
|
||||
auto_track = int(input('\tStarting track number (leave blank to assign per song): ') or -1)
|
||||
if in_album not in lib.albums:
|
||||
lib.albums[in_album] = {}
|
||||
else:
|
||||
print('\tLoaded existing album')
|
||||
album = lib.albums[in_album]
|
||||
try:
|
||||
# Input metadata
|
||||
if 'meta' not in album:
|
||||
album['meta'] = {}
|
||||
metadata = album['meta']
|
||||
# Metadata fields sorted in order of popularity... ish
|
||||
for field in ['genre', 'publisher', 'release_date', 'composer']:
|
||||
in_value = input('\t' + field + ': ')
|
||||
if in_value is not '': metadata[field] = in_value
|
||||
# Input songs
|
||||
while True:
|
||||
in_song = input('\t\t*Song title: ')
|
||||
if auto_artist is not '':
|
||||
in_artist = auto_artist
|
||||
else:
|
||||
in_artist = input('\t\t*Artist: ')
|
||||
if auto_track is not -1:
|
||||
in_track = auto_track
|
||||
auto_track += 1
|
||||
else:
|
||||
in_track = input('\t\t*Track number: ')
|
||||
in_source = input('\t\t*Source URL: ')
|
||||
# Only assign values if we gave them
|
||||
if in_song not in album:
|
||||
album[in_song] = {}
|
||||
else:
|
||||
print('\t\tLoaded existing song')
|
||||
song = album[in_song]
|
||||
if in_track is not '': song['track'] = int(in_track)
|
||||
if in_artist is not '': song['artist'] = in_artist
|
||||
if in_source is not '': song['source'] = in_source
|
||||
# Bail if song is bad
|
||||
if in_song in ['meta']:
|
||||
print('\t\tError: Song title collides with a reserved field: ' + in_song)
|
||||
continue
|
||||
if '' in [in_song, in_track, in_artist, in_source]:
|
||||
print('\t\tError: A critical field was empty')
|
||||
continue
|
||||
album[in_song] = song
|
||||
except KeyboardInterrupt:
|
||||
print('\n\t\tAborting, changes were not saved')
|
||||
except EOFError:
|
||||
album[in_song] = song
|
||||
print('\n\t\tChanges cached, ^D again to save')
|
||||
lib.albums[in_album] = album
|
||||
lib.save()
|
||||
except KeyboardInterrupt:
|
||||
print('\n\tAborting, changes were not saved')
|
||||
except EOFError:
|
||||
lib.save()
|
||||
print('\n\tSaving changes')
|
||||
print('Closing library')
|
||||
self.prompt(lib)
|
||||
return
|
||||
elif self.args.action == 'list':
|
||||
for album, albumcontent in lib.albums.items():
|
||||
print(album)
|
||||
@ -356,8 +294,78 @@ class BadWitch:
|
||||
print('\t' + str(songcontent['track'])
|
||||
+ ' - ' + song
|
||||
+ ' by ' + songcontent['artist'])
|
||||
return
|
||||
else:
|
||||
print('Nothing to do')
|
||||
return
|
||||
|
||||
def prompt(self, lib):
|
||||
print('Bad Witch interactive $ibrary editor')
|
||||
print('^C to abort, ^D to finish changes')
|
||||
print('Loaded library ' + lib.file)
|
||||
try:
|
||||
while True:
|
||||
in_album = input('\t*Album: ')
|
||||
auto_artist = input('\tArtist (leave blank to assign per song): ')
|
||||
auto_track = int(input('\tStarting track number (leave blank to assign per song): ') or -1)
|
||||
if in_album not in lib.albums:
|
||||
lib.albums[in_album] = {}
|
||||
else:
|
||||
print('\tLoaded existing album')
|
||||
album = lib.albums[in_album]
|
||||
try:
|
||||
# Input metadata
|
||||
if 'meta' not in album:
|
||||
album['meta'] = {}
|
||||
metadata = album['meta']
|
||||
# Metadata fields sorted in order of popularity... ish
|
||||
for field in ['genre', 'publisher', 'release_date', 'composer']:
|
||||
in_value = input('\t' + field + ': ')
|
||||
if in_value is not '': metadata[field] = in_value
|
||||
# Input songs
|
||||
while True:
|
||||
in_song = input('\t\t*Song title: ')
|
||||
if auto_artist is not '':
|
||||
in_artist = auto_artist
|
||||
else:
|
||||
in_artist = input('\t\t*Artist: ')
|
||||
if auto_track is not -1:
|
||||
in_track = auto_track
|
||||
auto_track += 1
|
||||
else:
|
||||
in_track = input('\t\t*Track number: ')
|
||||
in_source = input('\t\t*Source URL: ')
|
||||
# Only assign values if we gave them
|
||||
if in_song not in album:
|
||||
album[in_song] = {}
|
||||
else:
|
||||
print('\t\tLoaded existing song')
|
||||
song = album[in_song]
|
||||
if in_track is not '': song['track'] = int(in_track)
|
||||
if in_artist is not '': song['artist'] = in_artist
|
||||
if in_source is not '': song['source'] = in_source
|
||||
# Bail if song is bad
|
||||
if in_song in ['meta']:
|
||||
print('\t\tError: Song title collides with a reserved field: ' + in_song)
|
||||
continue
|
||||
if '' in [in_song, in_track, in_artist, in_source]:
|
||||
print('\t\tError: A critical field was empty')
|
||||
continue
|
||||
album[in_song] = song
|
||||
except KeyboardInterrupt:
|
||||
print('\n\t\tAborting, changes were not saved')
|
||||
except EOFError:
|
||||
album[in_song] = song
|
||||
print('\n\t\tChanges cached, ^D again to save')
|
||||
lib.albums[in_album] = album
|
||||
lib.save()
|
||||
except KeyboardInterrupt:
|
||||
print('\n\tAborting, changes were not saved')
|
||||
except EOFError:
|
||||
lib.save()
|
||||
print('\n\tSaving changes')
|
||||
print('Closing library')
|
||||
return
|
||||
|
||||
badwitch = BadWitch()
|
||||
badwitch.execute()
|
||||
|
Loading…
x
Reference in New Issue
Block a user