blacktwin / JBOPS

Just a Bunch Of Plex Scripts
1.64k stars 305 forks source link

[Req] Config file instead of modifying all the scripts #37

Closed Mirabis closed 5 years ago

Mirabis commented 6 years ago

Hi,

is it possible to have it read a config file in the same or root directory of the repo? That way we can enter:

PLEXPY_APIKEY
PLEXPY_URL

and it will use it for all scripts in use

blacktwin commented 6 years ago

Yeah I've been thinking about that.

mescon commented 6 years ago

+1 on this one. Whenever I do git pull I have to do a whole dance to get everything set up properly again.

samip5 commented 6 years ago

@mescon I have already made the PR request for this, but time will tell if it will be merged. I hope so though.

blacktwin commented 6 years ago

The original intent of making this repo was to better organize my scripts that were gists. Gist doesn't notify the author when comments are made and searching to find the correct page the script was on was becoming a pain. The gists were all one off scripts that I thought people would just download and run. After moving to Github, I didn't really think people would grab/pull them all, just one or two.

To setup the config it would need to be able to allow the scripts to work without the config file to allow people who just grab one or two to not have a problem. if config: use config, else: use whats in the script.

Also once Tautulli is out of Beta then I'll be looking at all the scripts and either remove or update them to better fit Tautulli. So I don't think there is a point in updating all the scripts now if I'm just going to remove some (maybe most) of them.

samip5 commented 6 years ago

@blacktwin Ah, gotcha. :)

mescon commented 6 years ago

@blacktwin Much appreciated :-) I think your little scripts have become essential to having peace of mind on my server!

samip5 commented 6 years ago

@blacktwin Could you take a look at my PR (#42)?

blacktwin commented 6 years ago

@samip5 Check out the config-update branch. Specifically the kill_stream.py

TAUTULLI_URL = os.getenv('TAUTULLI_URL', TAUTULLI_FALLBACK_URL)
TAUTULLI_APIKEY = os.getenv('TAUTULLI_APIKEY', TAUTULLI_FALLBACK_APIKEY)

Tautulli now uses environmental variables. So with anything being executed by the script notification agent from Tautulli will allow you to pull the URL and APIKEY when the script is ran. With that I think I'm going to be using the terminate_session API call from Tautulli instead of using the plexapi library to do it.

For anything else that would be using the plexapi, the plexapi has it's own configuration file method. Load it once and done. Just import the config module and call what you want.

from plexapi.server import CONFIG
PLEX_URL = CONFIG.data['auth'].get('server_baseurl')
PLEX_TOKEN = CONFIG.data['auth'].get('server_token')

The configuration file that the plexapi will use can hold anything so I think that would be the better way to go about it.