From b3bd9c616b746313cce0276392c6c00f2117b90b Mon Sep 17 00:00:00 2001
From: Salt <rehashedsalt@cock.li>
Date: Tue, 3 Mar 2020 19:14:38 -0600
Subject: [PATCH] Basic functional library parsing

---
 badwitch.py | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/badwitch.py b/badwitch.py
index 8bcce43..d5a0af2 100755
--- a/badwitch.py
+++ b/badwitch.py
@@ -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