Skip to content
Permalink
Browse files

notifier: Switch to notify-send for linux

The python-dbus package causes lots of bugs and installation errors. Now
the app uses notify-send command via a subprocess, provided via the
libnotify package.

Fixes #21
  • Loading branch information
iamkroot committed Nov 29, 2019
1 parent 6762a45 commit 65652d6c144dba755cf4b7cc4ec4de0315a5937e
Showing with 17 additions and 33 deletions.
  1. +0 −2 Pipfile
  2. +4 −21 Pipfile.lock
  3. +3 −3 README.md
  4. +10 −7 trakt_scrobbler/notifier.py
@@ -8,8 +8,6 @@ requests = "*"
guessit = "*"
pywin32 = {version = "*", sys_platform = "== 'win32'"}
win10toast = {version = "*", sys_platform = "== 'win32'"}
notify2 = {version = "*", sys_platform = "!= 'win32'"}
dbus-python = {version = "*", sys_platform = "== 'linux'"}
toml = "*"
appdirs = "*"

Some generated files are not rendered by default. Learn more.

@@ -62,9 +62,9 @@ Other player specific parameters| See sample config for the required attributes.
6. `mkdir ~/Library/Preferences/trakt-scrobbler/ && cp config.toml ~/Library/Preferences/trakt-scrobbler/`
7. Type `pipenv run python trakt_scrobbler/main.py` to start the program. You will be prompted to authorize the program to access the Trakt.tv API. Follow the steps on screen to finish the process. In the future, the script will run on computer boot, without any need for human intervention.

5. To enable notification support on Linux, the dbus libraries need to be installed (Reboot after installation).
- Arch/Manjaro: `pacman -S python-dbus`
- Ubuntu: `apt install python3-dbus`
5. To enable notification support on Linux, `libnotify` needs to be installed (Reboot after installation).
- Arch/Manjaro: `pacman -S libnotify`
- Ubuntu: `apt install libnotify-bin`

## Updating
1. Kill the currently installed app:
@@ -1,21 +1,22 @@
import logging
import sys
from utils import config

logger = logging.getLogger('trakt_scrobbler')

APP_NAME = 'Trakt Scrobbler'
enable_notifs = config['general']['enable_notifs']

if enable_notifs:
if sys.platform == 'win32':
from win10toast import ToastNotifier
toaster = ToastNotifier()
elif sys.platform == 'darwin':
import subprocess as sp
else:
import notify2
notify2.init(APP_NAME)
import subprocess as sp


def notify(body, title=APP_NAME, timeout=5, stdout=False):
global enable_notifs
if stdout or not enable_notifs:
print(title, body)
if not enable_notifs:
@@ -26,6 +27,8 @@ def notify(body, title=APP_NAME, timeout=5, stdout=False):
osa_cmd = f'display notification "{body}" with title "{title}"'
sp.run(["osascript", "-e", osa_cmd])
else:
notif = notify2.Notification(title, body)
notif.timeout = timeout * 1000
notif.show()
try:
sp.run(["notify-send", "-a", title, "-t", str(timeout * 1000), body])
except FileNotFoundError:
logger.exception("Unable to send notification")
enable_notifs = False # disable all future notifications until app restart

0 comments on commit 65652d6

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