Basic functional library parsing

This commit is contained in:
Salt 2020-03-03 19:14:38 -06:00
parent 7909c587e7
commit b3bd9c616b

View File

@ -21,9 +21,10 @@ class Library:
self.file = file
# Load from file
def load(self, file):
def load(self):
with open(self.file, 'r+') as libfd:
libfd.seek(0)
self.albums = json.load(libfd)
return
# Save to file
@ -56,7 +57,9 @@ class BadWitch:
def execute(self):
self.args = self.argparser.parse_args()
# Initialize library
libfile = self.args.library[0] or self.dirs.user_data_dir + '/lib.json'
libfile = self.dirs.user_data_dir + '/lib.json'
if self.args.library is not None:
libfile = self.args.library[0]
lib = Library(file=libfile)
# Perform action
for action in self.args.action:
@ -67,9 +70,10 @@ class BadWitch:
elif action == 'remove':
return
elif action == 'list':
for album in lib.albums:
for song in lib.songs:
print(song.title + ' by ' + song.artist + ', released ' + song.releasedate)
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':
# Set up a test album