diff --git a/README.md b/README.md index 0e19094..1ba759a 100644 --- a/README.md +++ b/README.md @@ -16,13 +16,15 @@ A tool to download your music with metadata. It uses [Spotify](https://www.spoti Works with Python 2 and 3. -## Install +## Install and Setup ``` $ sudo pip install irs +$ irs --setup ``` **You will need to have some Spotify tokens, the instructions to set them up are [here](https://github.com/kepoorhampond/irs#spotify-tokens).** + ## Demo and Usages This is a demo of the CLI displayling its features: diff --git a/irs/__init__.py b/irs/__init__.py index d25d2a7..e5a642b 100644 --- a/irs/__init__.py +++ b/irs/__init__.py @@ -1 +1,20 @@ -from .ripper import Ripper \ No newline at end of file +import os +import argparse +from .setup_binaries import setup + +parser = argparse.ArgumentParser() + +parser.add_argument("-S", "--setup", dest="setup", help="Setup IRS", + action="store_true") + +args = parser.parse_args() + +if args.setup: + setup() + exit(0) +elif not os.path.isdir(os.path.expanduser("~/.irs")): + print("Please run `irs --setup` to install the youtube-dl and \ +ffmpeg binaries.") +else: + from .ripper import Ripper + Ripper # PyLinter reasons diff --git a/irs/config.py b/irs/config.py index cdb7108..b72fbc4 100644 --- a/irs/config.py +++ b/irs/config.py @@ -1,9 +1,13 @@ import sys from os import path +if path.isfile(path.expanduser("~/.irs/config_.py")): + sys.path.append(path.expanduser("~/.irs")) # Add config to path -sys.path.append(path.expanduser("~/.irs")) # Add config to path + import config_ # from "~/.irs/config_.py" -import config_ # from "~/.irs/config_.py" - -CONFIG = config_.CONFIG + CONFIG = config_.CONFIG +else: + config = open("irs/config_preset", "r").read() + print(config) + CONFIG = eval(config) diff --git a/irs/ripper.py b/irs/ripper.py index 8993190..14417a9 100644 --- a/irs/ripper.py +++ b/irs/ripper.py @@ -12,6 +12,7 @@ sys.path.append(os.path.expanduser("~/.irs/bin/youtube-dl")) # Powered by: import youtube_dl # Locally imported from the binary + import spotipy from spotipy.oauth2 import SpotifyClientCredentials diff --git a/irs/setup_binaries.py b/irs/setup_binaries.py new file mode 100644 index 0000000..1e68581 --- /dev/null +++ b/irs/setup_binaries.py @@ -0,0 +1,12 @@ +import ydl_binaries +from shutil import copyfile +import os + + +def setup(): + ydl_binaries.download_ffmpeg("~/.irs/bin") + ydl_binaries.update_ydl("~/.irs/bin") + + config_file = os.path.expanduser("~/.irs/config_.py") + if not os.path.isfile(config_file): + copyfile("irs/config_preset", config_file) diff --git a/setup.py b/setup.py index 6b28529..7b7aa4e 100644 --- a/setup.py +++ b/setup.py @@ -1,39 +1,4 @@ from setuptools import setup -from setuptools.command.develop import develop -from setuptools.command.install import install - - -class PostDevelopCommand(develop): - """Post-installation for development mode.""" - def run(self): - # PUT YOUR PRE-INSTALL SCRIPT HERE or CALL A FUNCTION - develop.run(self) - # PUT YOUR POST-INSTALL SCRIPT HERE or CALL A FUNCTION - - -class PostInstallCommand(install): - """Post-installation for installation mode.""" - def run(self): - install.run(self) # Actually install the module and dependencies - - try: - import ydl_binaries - except ImportError: - import pip - pip.main(['install', "ydl-binaries"]) - - import ydl_binaries - from os import path - from shutil import copyfile - - print("\n\nDownloading Dependencies:\n") - ydl_binaries.download_ffmpeg("~/.irs/bin") - ydl_binaries.update_ydl("~/.irs/bin") - - config_file = path.expanduser("~/.irs/config_.py") - if not path.isfile(config_file): - copyfile("irs/config_preset", config_file) - setup( name = 'irs', @@ -54,8 +19,4 @@ setup( entry_points = { 'console_scripts': ['irs = irs.cli:main'], }, - cmdclass = { - 'develop': PostDevelopCommand, - 'install': PostInstallCommand, - }, )