diff --git a/README.md b/README.md index 1d37d49..6e6e573 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Ironic Redistribution System [![License: GNU](https://img.shields.io/badge/license-gnu-yellow.svg?style=flat-square)](http://www.gnu.org/licenses/gpl.html) [![Stars](https://img.shields.io/github/stars/kepoorhampond/irs.svg?style=flat-square)](https://github.com/kepoorhampond/irs/stargazers) -[![Build Status](https://img.shields.io/travis/kepoorhampond/irs/master.svg?style=flat-square)](https://travis-ci.org/karma-runner/karma-coverage) +[![Build Status](https://img.shields.io/travis/kepoorhampond/irs/master.svg?style=flat-square)](https://travis-ci.org/kepoorhampond/irs) [![Say Thanks](https://img.shields.io/badge/say-thanks-ff69b4.svg?style=flat-square)](https://saythanks.io/to/kepoorhampond) [![Coverage Status](http://img.shields.io/coveralls/kepoorhampond/irs.svg?style=flat-square)](https://coveralls.io/github/kepoorhampond/irs?branch=master&style=flat-square) [![PyPI](https://img.shields.io/badge/pypi-irs-blue.svg?style=flat-square)](https://pypi.python.org/pypi/irs) diff --git a/irs/cli.py b/irs/cli.py index efc443c..205ed71 100644 --- a/irs/cli.py +++ b/irs/cli.py @@ -8,6 +8,7 @@ import os # Powered by: from .ripper import Ripper from .utils import console, remove_none_values +from .config import CONFIG def main(): parser = argparse.ArgumentParser() @@ -28,7 +29,7 @@ def main(): parser.add_argument("-o", "--organize", dest="organize", action="store_true", help="Organize downloaded files.") - args = parser.parse_args() + args = parser.parse_args(sys.argv[1:] + CONFIG.get("default_flags").split(" ")) ripper_args = { "post_processors": { @@ -46,7 +47,7 @@ def main(): elif args.username and args.playlist: ripper.spotify_list("playlist", args.playlist, args.username) else: - console(Ripper()) + console(ripper) if __name__ == "__main__": main() \ No newline at end of file diff --git a/irs/config.py b/irs/config.py index 29a4fd3..35bdb5c 100644 --- a/irs/config.py +++ b/irs/config.py @@ -11,19 +11,14 @@ CONFIG = dict( default_flags = '', - # These are necessary to download Spotify playlists - client_id = '', - client_secret = '', + # You can either specify Spotify keys here, or in environment variables. + SPOTIFY_CLIENT_ID = '', + SPOTIFY_CLIENT_SECRET = '', additional_search_terms = 'lyrics', # For a custom directory. Note that `~` will not work as a shortcut in a # plain text manner. - directory = str(expanduser("~")) + "/Music", - - # If you want numbered file names - numbered_file_names = True, - - # Downloaded file names - download_file_names = False, + # TODO: Implement this into the utils arguments. + custom_directory = str(expanduser("~")) + "/Music", ) diff --git a/irs/ripper.py b/irs/ripper.py index 61307fb..3aed1d4 100644 --- a/irs/ripper.py +++ b/irs/ripper.py @@ -30,10 +30,11 @@ class Ripper: self.locations = [] self.type = None try: - client_credentials_manager = SpotifyClientCredentials(os.environ["SPOTIFY_CLIENT_ID"], os.environ["SPOTIFY_CLIENT_SECRET"]) + CLIENT_ID, CLIENT_SECRET = parse_spotify_creds(self) + client_credentials_manager = SpotifyClientCredentials(CLIENT_ID, CLIENT_SECRET) self.spotify = spotipy.Spotify(client_credentials_manager=client_credentials_manager) self.authorized = True - except spotipy.oauth2.SpotifyOauthError: + except Exception as e: self.spotify = spotipy.Spotify() self.authorized = False @@ -46,6 +47,16 @@ class Ripper: os.rename(loc, new_file_name) locations[index] = new_file_name if post_processors.get("organize") == True: + # I'd just go on believing that code this terrible doesn't exist. + # You can just close your eyes and scroll by. I'd encourage it. + # It's okay if you need to cry though. + # The rest of the code is here for you. + # It's like loving someone, + # Everyone has some flaws, but you still appreciate and embrace + # those flaws for being exclusive to them. + # And if those flaws are really enough to turn you off of them, then + # you *probably* don't really want to be with them anyways. + # Either way, it's up to you. if self.type == "album": for index, loc in enumerate(locations): mp3 = Metadata(loc) @@ -83,7 +94,7 @@ class Ripper: return locations - def find_yt_url(self, song=None, artist=None, additional_search="lyrics"): + def find_yt_url(self, song=None, artist=None, additional_search=parse_search_terms(self)): try: if not song: song = self.args["song_title"] if not artist: artist = self.args["artist"] diff --git a/irs/utils.py b/irs/utils.py index f0a74b1..a6c5fb0 100644 --- a/irs/utils.py +++ b/irs/utils.py @@ -279,4 +279,28 @@ def console(ripper): pass except KeyboardInterrupt: - sys.exit(0) \ No newline at end of file + sys.exit(0) + +#============ +# CONFIG FILE +#============ +from .config import CONFIG + +def check_sources(ripper, key, default=None, environment=False): + if ripper.args.get(key): + return ripper.args.get(key) + elif CONFIG.get(key): + return CONFIG.get(key) + elif os.environ.get(key) and environment == True: + return os.environ.get(key) + else: + return default + +def parse_spotify_creds(ripper): + CLIENT_ID = check_sources(ripper, "SPOTIFY_CLIENT_ID", environment=True) + CLIENT_SECRET = check_sources(ripper, "SPOTIFY_CLIENT_SECRET", environment=True) + return CLIENT_ID, CLIENT_SECRET + +def parse_search_terms(ripper): + search_terms = check_sources(ripper, "additional_search_terms", "lyrics") + return search_terms \ No newline at end of file