diff --git a/badwitch.py b/badwitch.py index b79f2fb..9769158 100755 --- a/badwitch.py +++ b/badwitch.py @@ -79,7 +79,7 @@ class Library: 'format': 'bestaudio', 'postprocessors': [{ 'key': 'FFmpegExtractAudio', - 'preferredcodec': 'opus', + 'preferredcodec': 'mp3', 'preferredquality': '192' }], 'quiet': True, @@ -88,7 +88,7 @@ class Library: } with youtube_dl.YoutubeDL(ytdl_opts) as ydl: ydl.download([songcontent['source']]) - logging.info('Downloaded song: ' + song) + print('Downloaded song: ' + song) class BadWitch: # Our program @@ -103,7 +103,7 @@ class BadWitch: self.argparser.add_argument('-d', '--debug', action='store_true', help='Show even more status messages') self.argparser.add_argument('action', metavar='action', nargs='?', - choices=['download', 'list'], + choices=['download', 'edit', 'list'], help='Action to perform on the library') # Set up appdirs self.dirs = AppDirs('badwitch', 'rehashedsalt') @@ -125,6 +125,47 @@ class BadWitch: if self.args.action == 'download': lib.download() return + 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('\tAlbum: ') + in_artist = input('\tArtist: ') + if in_album not in lib.albums: + lib.albums[in_album] = {} + album = lib.albums[in_album] + try: + while True: + in_song = input('\t\tSong title: ') + in_track = input('\t\tTrack number: ') + in_source = input('\t\tSource URL: ') + # Only assign values if we gave them + if in_song not in album: + album[in_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 + for field in ['track', 'artist', 'source']: + if field not in song: + print('Critical field is empty: ' + field) + continue + except KeyboardInterrupt: + print('\n\t\tAborting, changes were not saved') + except EOFError: + album[in_song] = song + print('\n\t\tSaving changes') + 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') elif self.args.action == 'list': for album, albumcontent in lib.albums.items(): print(album)