From 91c968e9c318e4a1968e618314ef303dcdc6d65a Mon Sep 17 00:00:00 2001 From: Salt Date: Fri, 6 Mar 2020 04:42:47 -0600 Subject: [PATCH] Allow for album metadata entries --- badwitch.py | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/badwitch.py b/badwitch.py index e406917..2d8987d 100755 --- a/badwitch.py +++ b/badwitch.py @@ -46,6 +46,8 @@ class Library: def validate(self): self.load() for album, albumcontent in self.albums.items(): + if album == 'meta': + continue for song, songcontent in albumcontent.items(): for field in ['track', 'artist', 'source']: if field not in songcontent: @@ -58,10 +60,19 @@ class Library: else: print('Downloading entire library') for album, albumcontent in self.albums.items(): + # Try to grab a metadata entry + metadata = {} + for song, songcontent in albumcontent.items(): + if song == 'meta': + metadata = self.albums['meta'] # Skip albums that don't match our criterea if targetalbum is not None and not album == targetalbum: logging.debug('Skipping album ' + album) continue + # Just skip metadata (for now) + if album == 'meta': + logging.debug('Skipping metadata entry for album ' + album) + continue # Get albumartist # Sets to Various Artists if multiple albumartist='' @@ -165,18 +176,25 @@ class BadWitch: print('\tLoaded existing album') album = lib.albums[in_album] try: + # Input metadata + if 'meta' not in album: + album['meta'] = {} + metadata = album['meta'] + meta_releaseyear = input('\tRelease year: ') + if meta_releaseyear is not '': metadata['releaseyear'] = meta_releaseyear + # Input songs while True: - in_song = input('\t\tSong title: ') + in_song = input('\t\t*Song title: ') if auto_artist is not '': in_artist = auto_artist else: - in_artist = input('\t\tArtist: ') + in_artist = input('\t\t*Artist: ') if auto_track is not -1: in_track = auto_track auto_track += 1 else: - in_track = input('\t\tTrack number: ') - in_source = input('\t\tSource URL: ') + 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] = {} @@ -187,10 +205,13 @@ class BadWitch: if in_artist is not '': song['artist'] = in_artist if in_source is not '': song['source'] = in_source # Bail if song is bad - for field in ['track', 'artist', 'source']: - if field not in song: - print('\t\tError: Critical field is empty: ' + field) - continue + 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: