From 7909c587e79f1ed872416b460b57e3570db1b998 Mon Sep 17 00:00:00 2001 From: Salt Date: Tue, 3 Mar 2020 18:39:04 -0600 Subject: [PATCH] Do a whole helluvalotta work --- badwitch.py | 99 +++++++++++++++++++++++++++++++++++------------- requirements.txt | 2 +- venv.sh | 1 + 3 files changed, 75 insertions(+), 27 deletions(-) diff --git a/badwitch.py b/badwitch.py index 9be1144..8bcce43 100755 --- a/badwitch.py +++ b/badwitch.py @@ -8,52 +8,99 @@ # Distributed under terms of the MIT license. # +from appdirs import AppDirs +from pathlib import Path import argparse +import json import sys class Library: - # A big thing full of songs - def __init__(self): + # A thing full of albums + def __init__(self, file, albums={}): + self.albums = albums + self.file = file + + # Load from file + def load(self, file): + with open(self.file, 'r+') as libfd: + libfd.seek(0) return -class Song: - # An item with metadata and a source - def __init__(self, title, source): - self.title = title or 'Untitled song' - self.source = source or '' + # Save to file + def save(self): + with open(self.file, 'w+') as libfd: + libfd.seek(0) + json.dump(self.albums, libfd, indent='\t') + return + + def download(self): + for album in self.albums: + return class BadWitch: # Our program def __init__(self): # Set up arguments self.argparser = argparse.ArgumentParser(description='Manage a declarative music library through YouTube scraping') - self.argparser.add_argument('action', metavar='action', nargs='+', - choices=['download', 'add', 'remove'], + self.argparser.add_argument('action', metavar='action', nargs=1, + choices=['download', 'add', 'remove', 'list', 'test'], help='Action to perform on the library') self.argparser.add_argument('-l', '--library', metavar='f', nargs=1, help='Override default library file with this one') self.argparser.add_argument('-v', '--verbose', action='store_true', help='Show more status messages') + # Set up appdirs + self.dirs = AppDirs('badwitch', 'rehashedsalt') + Path(self.dirs.user_data_dir).mkdir(parents=True, exist_ok=True) def execute(self): self.args = self.argparser.parse_args() - if self.args.verbose: - print(self.args.config) - print(self.args.downloadall) - print(self.args.verbose) - - def load(self, library): - # Load a library as an object - return - - def add(self, song): - # Add a song to the library - return - - def remove(self): - # Use keyword arguments here - # Remove a song based on criterea - return + # Initialize library + libfile = self.args.library[0] or self.dirs.user_data_dir + '/lib.json' + lib = Library(file=libfile) + # Perform action + for action in self.args.action: + if action == 'download': + return + elif action == 'add': + return + 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) + return + elif action == 'test': + # Set up a test album + lib.albums['Bad Witch'] = { + 'Shit Mirror': { + 'artist': 'Nine Inch Nails', + 'source': 'https://www.youtube.com/watch?v=yeqjz5mXrLQ' + }, + 'Ahead of Ourselves': { + 'artist': 'Nine Inch Nails', + 'source': 'https://www.youtube.com/watch?v=4Ab1O-i4ep4' + }, + 'Play the Goddamned Part': { + 'artist': 'Nine Inch Nails', + 'source': 'https://www.youtube.com/watch?v=85UgvBkMfr8' + }, + 'God Break Down the Door': { + 'artist': 'Nine Inch Nails', + 'source': 'https://www.youtube.com/watch?v=eeJ_DzRJUI4' + }, + 'I\'m Not From This World': { + 'artist': 'Nine Inch Nails', + 'source': 'https://www.youtube.com/watch?v=9fjbcSUSt9w' + }, + 'Over and Out': { + 'artist': 'Nine Inch Nails', + 'source': 'https://www.youtube.com/watch?v=h-XlN3N2fis' + } + } + lib.save() + return badwitch = BadWitch() badwitch.execute() diff --git a/requirements.txt b/requirements.txt index 7683147..f1265fe 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -PyQt5==5.9.2 +appdirs>=1.4.3 diff --git a/venv.sh b/venv.sh index f1b630a..e2cba02 100755 --- a/venv.sh +++ b/venv.sh @@ -6,6 +6,7 @@ # Distributed under terms of the MIT license. # +[ -d ./venv ] || python3 -m venv venv [ -r ./venv/bin/activate ] || exit 1 . ./venv/bin/activate printf "Spawned a terminal within the venv\n"