Basic functional library parsing
This commit is contained in:
parent
7909c587e7
commit
b3bd9c616b
14
badwitch.py
14
badwitch.py
@ -21,9 +21,10 @@ class Library:
|
|||||||
self.file = file
|
self.file = file
|
||||||
|
|
||||||
# Load from file
|
# Load from file
|
||||||
def load(self, file):
|
def load(self):
|
||||||
with open(self.file, 'r+') as libfd:
|
with open(self.file, 'r+') as libfd:
|
||||||
libfd.seek(0)
|
libfd.seek(0)
|
||||||
|
self.albums = json.load(libfd)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Save to file
|
# Save to file
|
||||||
@ -56,7 +57,9 @@ class BadWitch:
|
|||||||
def execute(self):
|
def execute(self):
|
||||||
self.args = self.argparser.parse_args()
|
self.args = self.argparser.parse_args()
|
||||||
# Initialize library
|
# 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)
|
lib = Library(file=libfile)
|
||||||
# Perform action
|
# Perform action
|
||||||
for action in self.args.action:
|
for action in self.args.action:
|
||||||
@ -67,9 +70,10 @@ class BadWitch:
|
|||||||
elif action == 'remove':
|
elif action == 'remove':
|
||||||
return
|
return
|
||||||
elif action == 'list':
|
elif action == 'list':
|
||||||
for album in lib.albums:
|
lib.load()
|
||||||
for song in lib.songs:
|
for album, albumcontent in lib.albums.items():
|
||||||
print(song.title + ' by ' + song.artist + ', released ' + song.releasedate)
|
for song, songcontent in albumcontent.items():
|
||||||
|
print(album + ' - ' + song + ' by ' + songcontent['artist'])
|
||||||
return
|
return
|
||||||
elif action == 'test':
|
elif action == 'test':
|
||||||
# Set up a test album
|
# Set up a test album
|
||||||
|
Loading…
x
Reference in New Issue
Block a user