From 0407a6f53cf055d4f46ac44d8c210b528fbc2697 Mon Sep 17 00:00:00 2001
From: Salt <rehashedsalt@cock.li>
Date: Tue, 3 Mar 2020 23:06:47 -0600
Subject: [PATCH] Almost ready to download stuff

---
 badwitch.py | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/badwitch.py b/badwitch.py
index 319c40b..560530b 100755
--- a/badwitch.py
+++ b/badwitch.py
@@ -13,6 +13,7 @@ from pathlib import Path
 import argparse
 import json
 import logging
+import pathlib
 import sys
 
 class Library:
@@ -37,6 +38,14 @@ class Library:
 
     def validate(self):
         self.load()
+        try:
+            for album, albumcontent in self.albums.items():
+                for song, songcontent in albumcontent.items():
+                    if songcontent['artist'] is None:
+                        raise Exception
+        except:
+            logging.warn('Library not valid')
+            raise Exception('Library not valid')
 
     # Download library
     def download(self, album=None):
@@ -45,6 +54,10 @@ class Library:
         else:
             print('Downloading entire library')
         for album, albumcontent in self.albums.items():
+            # God have mercy on my soul
+            artist = (next(iter(next(iter(albumcontent.values())).values())))
+            print(artist)
+            Path(Path.home() / 'Music' / artist / album).mkdir(parents=True, exist_ok=True)
             for song, songcontent in albumcontent.items():
                 logging.info('Downloaded song: ' + song + ' by ' + songcontent['artist'])
 
@@ -77,13 +90,13 @@ class BadWitch:
         # Initialize library
         libfile = self.args.library or self.dirs.user_data_dir + '/lib.json'
         lib = Library(file=libfile)
+        lib.load()
+        lib.validate()
         # Perform action
         if self.args.action == 'download':
-            lib.load()
             lib.download()
             return
         elif self.args.action == 'list':
-            lib.load()
             for album, albumcontent in lib.albums.items():
                 for song, songcontent in albumcontent.items():
                     print(album + ' - ' + song + ' by ' + songcontent['artist'])