Almost ready to download stuff
This commit is contained in:
		
							
								
								
									
										17
									
								
								badwitch.py
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								badwitch.py
									
									
									
									
									
								
							@@ -13,6 +13,7 @@ from pathlib import Path
 | 
				
			|||||||
import argparse
 | 
					import argparse
 | 
				
			||||||
import json
 | 
					import json
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
 | 
					import pathlib
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Library:
 | 
					class Library:
 | 
				
			||||||
@@ -37,6 +38,14 @@ class Library:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def validate(self):
 | 
					    def validate(self):
 | 
				
			||||||
        self.load()
 | 
					        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
 | 
					    # Download library
 | 
				
			||||||
    def download(self, album=None):
 | 
					    def download(self, album=None):
 | 
				
			||||||
@@ -45,6 +54,10 @@ class Library:
 | 
				
			|||||||
        else:
 | 
					        else:
 | 
				
			||||||
            print('Downloading entire library')
 | 
					            print('Downloading entire library')
 | 
				
			||||||
        for album, albumcontent in self.albums.items():
 | 
					        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():
 | 
					            for song, songcontent in albumcontent.items():
 | 
				
			||||||
                logging.info('Downloaded song: ' + song + ' by ' + songcontent['artist'])
 | 
					                logging.info('Downloaded song: ' + song + ' by ' + songcontent['artist'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -77,13 +90,13 @@ class BadWitch:
 | 
				
			|||||||
        # Initialize library
 | 
					        # Initialize library
 | 
				
			||||||
        libfile = self.args.library or self.dirs.user_data_dir + '/lib.json'
 | 
					        libfile = self.args.library or self.dirs.user_data_dir + '/lib.json'
 | 
				
			||||||
        lib = Library(file=libfile)
 | 
					        lib = Library(file=libfile)
 | 
				
			||||||
 | 
					        lib.load()
 | 
				
			||||||
 | 
					        lib.validate()
 | 
				
			||||||
        # Perform action
 | 
					        # Perform action
 | 
				
			||||||
        if self.args.action == 'download':
 | 
					        if self.args.action == 'download':
 | 
				
			||||||
            lib.load()
 | 
					 | 
				
			||||||
            lib.download()
 | 
					            lib.download()
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
        elif self.args.action == 'list':
 | 
					        elif self.args.action == 'list':
 | 
				
			||||||
            lib.load()
 | 
					 | 
				
			||||||
            for album, albumcontent in lib.albums.items():
 | 
					            for album, albumcontent in lib.albums.items():
 | 
				
			||||||
                for song, songcontent in albumcontent.items():
 | 
					                for song, songcontent in albumcontent.items():
 | 
				
			||||||
                    print(album + ' - ' + song + ' by ' + songcontent['artist'])
 | 
					                    print(album + ' - ' + song + ' by ' + songcontent['artist'])
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user