Skip to content
Permalink
Browse files

config: Use confuse library for config management

  • Loading branch information
iamkroot committed Jan 26, 2020
1 parent 16b4322 commit 0e2582a6b97d31a63354708a72f0308e4f76b34e
Showing with 126 additions and 75 deletions.
  1. +54 −19 poetry.lock
  2. +2 −1 pyproject.toml
  3. +0 −49 sample_config.toml
  4. +50 −0 sample_config.yml
  5. +20 −6 trakt_scrobbler/config.py
@@ -53,6 +53,17 @@ version = "0.4.3"
pastel = ">=0.2.0,<0.3.0"
pylev = ">=1.3,<2.0"

[[package]]
category = "main"
description = "painless YAML configuration"
name = "confuse"
optional = false
python-versions = "*"
version = "1.0.0"

[package.dependencies]
pyyaml = "*"

[[package]]
category = "main"
description = "GuessIt - a library for guessing information from video filenames."
@@ -77,7 +88,7 @@ description = "Internationalized Domain Names in Applications (IDNA)"
name = "idna"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
version = "2.8"
version = "2.9"

[[package]]
category = "main"
@@ -127,6 +138,14 @@ optional = false
python-versions = "*"
version = "227"

[[package]]
category = "main"
description = "YAML parser and emitter for Python"
name = "pyyaml"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
version = "5.3.1"

[[package]]
category = "main"
description = "Rebulk - Define simple search patterns in bulk to perform advanced matching on any string."
@@ -149,25 +168,25 @@ description = "Python HTTP for Humans."
name = "requests"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
version = "2.22.0"
version = "2.23.0"

[package.dependencies]
certifi = ">=2017.4.17"
chardet = ">=3.0.2,<3.1.0"
idna = ">=2.5,<2.9"
chardet = ">=3.0.2,<4"
idna = ">=2.5,<3"
urllib3 = ">=1.21.1,<1.25.0 || >1.25.0,<1.25.1 || >1.25.1,<1.26"

[package.extras]
security = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)"]
security = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)"]
socks = ["PySocks (>=1.5.6,<1.5.7 || >1.5.7)", "win-inet-pton"]

[[package]]
category = "main"
description = "Python 2 and 3 compatibility utilities"
name = "six"
optional = false
python-versions = ">=2.6, !=3.0.*, !=3.1.*"
version = "1.13.0"
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"
version = "1.14.0"

[[package]]
category = "main"
@@ -182,8 +201,8 @@ category = "main"
description = "HTTP library with thread-safe connection pooling, file post, and more."
name = "urllib3"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4"
version = "1.25.7"
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4"
version = "1.25.8"

[package.extras]
brotli = ["brotlipy (>=0.6.0)"]
@@ -204,8 +223,8 @@ pypiwin32 = "*"
setuptools = "*"

[metadata]
content-hash = "ffe3fe5f761e3a86ceb2f9485a75e26f6071ed6b2e5ad4b30ff607fef31b0563"
python-versions = "^3.6"
content-hash = "1e2ab081608a04313fce7a3b4a9513dd6e75008c2bdf65bf6c68eba568715f81"
python-versions = "^3.7"

[metadata.files]
appdirs = [
@@ -231,12 +250,15 @@ clikit = [
{file = "clikit-0.4.3-py2.py3-none-any.whl", hash = "sha256:71e321b7795a2a6c4888629f43365d52db071737e668ab16861121d7dd3ada09"},
{file = "clikit-0.4.3.tar.gz", hash = "sha256:6e2d7e115e7c7b35bceb0209109935ab2f9ab50910e9ff2293f7fa0b7abf973e"},
]
confuse = [
{file = "confuse-1.0.0.tar.gz", hash = "sha256:5977c6a876b179f8c86ecaf530cc24bf00baaad028c3350b502ee6949536188c"},
]
guessit = [
{file = "guessit-3.1.0.tar.gz", hash = "sha256:2dcd3f2acaf6c1a864f903f084ddd6a6b753f3107ae864355d7c8c1e9cb205b2"},
]
idna = [
{file = "idna-2.8-py2.py3-none-any.whl", hash = "sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c"},
{file = "idna-2.8.tar.gz", hash = "sha256:c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407"},
{file = "idna-2.9-py2.py3-none-any.whl", hash = "sha256:a068a21ceac8a4d63dbfd964670474107f541babbd2250d61922f029858365fa"},
{file = "idna-2.9.tar.gz", hash = "sha256:7588d1c14ae4c77d74036e8c22ff447b26d0fde8f007354fd48a7814db15b7cb"},
]
pastel = [
{file = "pastel-0.2.0-py2.py3-none-any.whl", hash = "sha256:18b559dc3ad4ba9b8bd5baebe6503f25f36d21460f021cf27a8d889cb5d17840"},
@@ -268,25 +290,38 @@ pywin32 = [
{file = "pywin32-227-cp39-cp39-win32.whl", hash = "sha256:c054c52ba46e7eb6b7d7dfae4dbd987a1bb48ee86debe3f245a2884ece46e295"},
{file = "pywin32-227-cp39-cp39-win_amd64.whl", hash = "sha256:f27cec5e7f588c3d1051651830ecc00294f90728d19c3bf6916e6dba93ea357c"},
]
pyyaml = [
{file = "PyYAML-5.3.1-cp27-cp27m-win32.whl", hash = "sha256:74809a57b329d6cc0fdccee6318f44b9b8649961fa73144a98735b0aaf029f1f"},
{file = "PyYAML-5.3.1-cp27-cp27m-win_amd64.whl", hash = "sha256:240097ff019d7c70a4922b6869d8a86407758333f02203e0fc6ff79c5dcede76"},
{file = "PyYAML-5.3.1-cp35-cp35m-win32.whl", hash = "sha256:4f4b913ca1a7319b33cfb1369e91e50354d6f07a135f3b901aca02aa95940bd2"},
{file = "PyYAML-5.3.1-cp35-cp35m-win_amd64.whl", hash = "sha256:cc8955cfbfc7a115fa81d85284ee61147059a753344bc51098f3ccd69b0d7e0c"},
{file = "PyYAML-5.3.1-cp36-cp36m-win32.whl", hash = "sha256:7739fc0fa8205b3ee8808aea45e968bc90082c10aef6ea95e855e10abf4a37b2"},
{file = "PyYAML-5.3.1-cp36-cp36m-win_amd64.whl", hash = "sha256:69f00dca373f240f842b2931fb2c7e14ddbacd1397d57157a9b005a6a9942648"},
{file = "PyYAML-5.3.1-cp37-cp37m-win32.whl", hash = "sha256:d13155f591e6fcc1ec3b30685d50bf0711574e2c0dfffd7644babf8b5102ca1a"},
{file = "PyYAML-5.3.1-cp37-cp37m-win_amd64.whl", hash = "sha256:73f099454b799e05e5ab51423c7bcf361c58d3206fa7b0d555426b1f4d9a3eaf"},
{file = "PyYAML-5.3.1-cp38-cp38-win32.whl", hash = "sha256:06a0d7ba600ce0b2d2fe2e78453a470b5a6e000a985dd4a4e54e436cc36b0e97"},
{file = "PyYAML-5.3.1-cp38-cp38-win_amd64.whl", hash = "sha256:95f71d2af0ff4227885f7a6605c37fd53d3a106fcab511b8860ecca9fcf400ee"},
{file = "PyYAML-5.3.1.tar.gz", hash = "sha256:b8eac752c5e14d3eca0e6dd9199cd627518cb5ec06add0de9d32baeee6fe645d"},
]
rebulk = [
{file = "rebulk-2.0.0.tar.gz", hash = "sha256:1b0d526859ef3e8647f37c606d7ae7c32259e370b3f1519e4219a3ba72740aec"},
]
requests = [
{file = "requests-2.22.0-py2.py3-none-any.whl", hash = "sha256:9cf5292fcd0f598c671cfc1e0d7d1a7f13bb8085e9a590f48c010551dc6c4b31"},
{file = "requests-2.22.0.tar.gz", hash = "sha256:11e007a8a2aa0323f5a921e9e6a2d7e4e67d9877e85773fba9ba6419025cbeb4"},
{file = "requests-2.23.0-py2.py3-none-any.whl", hash = "sha256:43999036bfa82904b6af1d99e4882b560e5e2c68e5c4b0aa03b655f3d7d73fee"},
{file = "requests-2.23.0.tar.gz", hash = "sha256:b3f43d496c6daba4493e7c431722aeb7dbc6288f52a6e04e7b6023b0247817e6"},
]
six = [
{file = "six-1.13.0-py2.py3-none-any.whl", hash = "sha256:1f1b7d42e254082a9db6279deae68afb421ceba6158efa6131de7b3003ee93fd"},
{file = "six-1.13.0.tar.gz", hash = "sha256:30f610279e8b2578cab6db20741130331735c781b56053c59c4076da27f06b66"},
{file = "six-1.14.0-py2.py3-none-any.whl", hash = "sha256:8f3cd2e254d8f793e7f3d6d9df77b92252b52637291d0f0da013c76ea2724b6c"},
{file = "six-1.14.0.tar.gz", hash = "sha256:236bdbdce46e6e6a3d61a337c0f8b763ca1e8717c03b369e87a7ec7ce1319c0a"},
]
toml = [
{file = "toml-0.10.0-py2.7.egg", hash = "sha256:f1db651f9657708513243e61e6cc67d101a39bad662eaa9b5546f789338e07a3"},
{file = "toml-0.10.0-py2.py3-none-any.whl", hash = "sha256:235682dd292d5899d361a811df37e04a8828a5b1da3115886b73cf81ebc9100e"},
{file = "toml-0.10.0.tar.gz", hash = "sha256:229f81c57791a41d65e399fc06bf0848bab550a9dfd5ed66df18ce5f05e73d5c"},
]
urllib3 = [
{file = "urllib3-1.25.7-py2.py3-none-any.whl", hash = "sha256:a8a318824cc77d1fd4b2bec2ded92646630d7fe8619497b142c84a9e6f5a7293"},
{file = "urllib3-1.25.7.tar.gz", hash = "sha256:f3c5fd51747d450d4dcf6f923c81f78f811aab8205fda64b0aba34a4e48b0745"},
{file = "urllib3-1.25.8-py2.py3-none-any.whl", hash = "sha256:2f3db8b19923a873b3e5256dc9c2dedfa883e33d87c690d9c7913e1f40673cdc"},
{file = "urllib3-1.25.8.tar.gz", hash = "sha256:87716c2d2a7121198ebcb7ce7cccf6ce5e9ba539041cfbaeecfb641dc0bf6acc"},
]
win10toast = [
{file = "win10toast-0.9-py2.py3-none-any.whl", hash = "sha256:44e5afa1001de88a0ee533872231521fa67c7d144f39974089af242d9c4620a4"},
@@ -5,14 +5,15 @@ description = "Scrobbler for trakt.tv that supports VLC, Plex, MPC-HC, and MPV"
authors = ["iamkroot <kroot.patel@gmail.com>"]

[tool.poetry.dependencies]
python = "^3.6"
python = "^3.7"
requests = "^2.22.0"
guessit = "^3.1.0"
toml = "^0.10.0"
appdirs = "^1.4.3"
pywin32 = {version = "^227", platform = "win32"}
win10toast = {version = "^0.9", platform = "win32"}
cleo = "^0.7.6"
confuse = "^1.0.0"

[tool.poetry.dev-dependencies]

This file was deleted.

@@ -0,0 +1,50 @@
version: '1.0'

general:
enable_notifs: true

fileinfo:

# if defined, only files from these directories will be scrobbled
whitelist: # Keep as [] to allow all
- /path/to/Movies # linux/mac os folders
- D:\path\to\windows\folder # windows folders
- E:\TV Shows\

# custom regex to identify media information, should be posix path
include_regexes:
movie: []
episode: []

players:
monitored: [] # players to be monitored. Allowed: mpcbe, mpchc, mpv, plex, vlc

skip_interval: 5 # min percent jump to consider for scrobbling to trakt

# player specific parameters
mpcbe: # enable web interface from options
ip: localhost
port: '13579' # from Options -> Player -> Web Interface -> Listen on port (ensure it is ticked)
poll_interval: 10 # in seconds. How frequently the monitor should check for player update.

mpchc: # enable web interface from options
ip: localhost
port: '13579' # if both mpchc and mpcbe are to be monitored, then ensure that their ports are different
poll_interval: 10 # in seconds

vlc: # enable web interface from options
ip: localhost
port: '8080' # from Preferences -> All -> Input/Codecs -> HTTP Server Port
password: '' # from Preferences -> All -> Interface -> Main Interfaces -> Lua -> Lua HTTP Password
poll_interval: 10 # in seconds. How frequently the monitor should check for player update.

mpv: # enable the JSON IPC server. Either via cmd line arg (eg: --input-ipc-server=\\.\pipe\mpvpipe), or in mpv.conf file
ipc_path: \\.\pipe\mpvpipe # windows
# ipc_path: /tmp/mpvsocket # unix

plex:
ip: localhost # IP of the plex server
port: '32400'
login: ''
password: ''
poll_interval: 10 # in seconds. How frequently the monitor should check for player update.
@@ -1,10 +1,24 @@
import logging
import confuse
from app_dirs import CFG_DIR
from utils import read_toml

logger = logging.getLogger("trakt-scrobbler")
logger = logging.getLogger("trakt_scrobbler")

config = read_toml(CFG_DIR / 'config.toml')
if config is None:
logger.critical("Error while reading config file. Quitting.")
exit(1)
cfg_template = {
"version": str,
"general": {
"enable_notifs": confuse.Choice([True, False]),
},
"fileinfo": {
"whitelist": confuse.StrSeq(),
"include_regexes": {
"movie": confuse.StrSeq(),
"episode": confuse.StrSeq()
}
},
"players": dict
}

config = confuse.Configuration("trakt-scrobbler")
config.set_file(CFG_DIR / "config.yml")
config = config.get(cfg_template)

0 comments on commit 0e2582a

Please sign in to comment.
You can’t perform that action at this time.