Almost ready to download stuff
This commit is contained in:
parent
83f79a0d4a
commit
0407a6f53c
17
badwitch.py
17
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'])
|
||||
|
Loading…
Reference in New Issue
Block a user