mirror of
https://github.com/cooperhammond/irs.git
synced 2024-12-22 17:35:28 +00:00
Almost finished implementing a new config file
This commit is contained in:
parent
4cdd9f4ca7
commit
03949be7ab
|
@ -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)
|
[![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)
|
[![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)
|
[![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)
|
[![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)
|
[![PyPI](https://img.shields.io/badge/pypi-irs-blue.svg?style=flat-square)](https://pypi.python.org/pypi/irs)
|
||||||
|
|
|
@ -8,6 +8,7 @@ import os
|
||||||
# Powered by:
|
# Powered by:
|
||||||
from .ripper import Ripper
|
from .ripper import Ripper
|
||||||
from .utils import console, remove_none_values
|
from .utils import console, remove_none_values
|
||||||
|
from .config import CONFIG
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
@ -28,7 +29,7 @@ def main():
|
||||||
parser.add_argument("-o", "--organize", dest="organize", action="store_true", help="Organize downloaded files.")
|
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 = {
|
ripper_args = {
|
||||||
"post_processors": {
|
"post_processors": {
|
||||||
|
@ -46,7 +47,7 @@ def main():
|
||||||
elif args.username and args.playlist:
|
elif args.username and args.playlist:
|
||||||
ripper.spotify_list("playlist", args.playlist, args.username)
|
ripper.spotify_list("playlist", args.playlist, args.username)
|
||||||
else:
|
else:
|
||||||
console(Ripper())
|
console(ripper)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
|
@ -11,19 +11,14 @@ CONFIG = dict(
|
||||||
default_flags = '',
|
default_flags = '',
|
||||||
|
|
||||||
|
|
||||||
# These are necessary to download Spotify playlists
|
# You can either specify Spotify keys here, or in environment variables.
|
||||||
client_id = '',
|
SPOTIFY_CLIENT_ID = '',
|
||||||
client_secret = '',
|
SPOTIFY_CLIENT_SECRET = '',
|
||||||
|
|
||||||
additional_search_terms = 'lyrics',
|
additional_search_terms = 'lyrics',
|
||||||
|
|
||||||
# For a custom directory. Note that `~` will not work as a shortcut in a
|
# For a custom directory. Note that `~` will not work as a shortcut in a
|
||||||
# plain text manner.
|
# plain text manner.
|
||||||
directory = str(expanduser("~")) + "/Music",
|
# TODO: Implement this into the utils arguments.
|
||||||
|
custom_directory = str(expanduser("~")) + "/Music",
|
||||||
# If you want numbered file names
|
|
||||||
numbered_file_names = True,
|
|
||||||
|
|
||||||
# Downloaded file names
|
|
||||||
download_file_names = False,
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -30,10 +30,11 @@ class Ripper:
|
||||||
self.locations = []
|
self.locations = []
|
||||||
self.type = None
|
self.type = None
|
||||||
try:
|
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.spotify = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
|
||||||
self.authorized = True
|
self.authorized = True
|
||||||
except spotipy.oauth2.SpotifyOauthError:
|
except Exception as e:
|
||||||
self.spotify = spotipy.Spotify()
|
self.spotify = spotipy.Spotify()
|
||||||
self.authorized = False
|
self.authorized = False
|
||||||
|
|
||||||
|
@ -46,6 +47,16 @@ class Ripper:
|
||||||
os.rename(loc, new_file_name)
|
os.rename(loc, new_file_name)
|
||||||
locations[index] = new_file_name
|
locations[index] = new_file_name
|
||||||
if post_processors.get("organize") == True:
|
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":
|
if self.type == "album":
|
||||||
for index, loc in enumerate(locations):
|
for index, loc in enumerate(locations):
|
||||||
mp3 = Metadata(loc)
|
mp3 = Metadata(loc)
|
||||||
|
@ -83,7 +94,7 @@ class Ripper:
|
||||||
|
|
||||||
return locations
|
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:
|
try:
|
||||||
if not song: song = self.args["song_title"]
|
if not song: song = self.args["song_title"]
|
||||||
if not artist: artist = self.args["artist"]
|
if not artist: artist = self.args["artist"]
|
||||||
|
|
26
irs/utils.py
26
irs/utils.py
|
@ -279,4 +279,28 @@ def console(ripper):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
sys.exit(0)
|
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
|
Loading…
Reference in a new issue