diff --git a/examples/notify.py b/examples/notify.py index 7aab398..265b8c8 100755 --- a/examples/notify.py +++ b/examples/notify.py @@ -12,29 +12,35 @@ gi.require_version('Notify', '0.7') from gi.repository import Notify Notify.init("Media Player") -notification = Notify.Notification.new(""); +notification = Notify.Notification.new("") from urllib.parse import urlparse, unquote from pathlib import Path from gi.repository import GdkPixbuf import os.path + def notify(player): - metadata = player.props.metadata; + metadata = player.props.metadata keys = metadata.keys() if 'xesam:artist' in keys and 'xesam:title' in keys: - notification.update(metadata['xesam:title'], metadata['xesam:artist'][0]) - path = Path(unquote(urlparse(metadata['xesam:url']).path)).parent / "cover.jpg"; + notification.update(metadata['xesam:title'], + metadata['xesam:artist'][0]) + path = Path(unquote(urlparse( + metadata['xesam:url']).path)).parent / "cover.jpg" if os.path.exists(path): - image = GdkPixbuf.Pixbuf.new_from_file(str(path)); + image = GdkPixbuf.Pixbuf.new_from_file(str(path)) notification.set_image_from_pixbuf(image) - notification.show(); + notification.show() + def on_play(player, status, manager): - notify(player); + notify(player) + def on_metadata(player, metadata, manager): - notify(player); + notify(player) + def init_player(name): player = Playerctl.Player.new_from_name(name) @@ -43,9 +49,11 @@ def init_player(name): manager.manage_player(player) notify(player) + def on_name_appeared(manager, name): init_player(name) + manager.connect('name-appeared', on_name_appeared) for name in manager.props.player_names: diff --git a/playerctl/playerctl-cli.c b/playerctl/playerctl-cli.c index 4333c24..585f0e2 100644 --- a/playerctl/playerctl-cli.c +++ b/playerctl/playerctl-cli.c @@ -25,6 +25,7 @@ #include #include #include + #include "playerctl-common.h" #include "playerctl-formatter.h" diff --git a/playerctl/playerctl-common.c b/playerctl/playerctl-common.c index ce25f34..111e1ff 100644 --- a/playerctl/playerctl-common.c +++ b/playerctl/playerctl-common.c @@ -18,6 +18,7 @@ */ #include "playerctl-common.h" + #include #include #include diff --git a/playerctl/playerctl-formatter.c b/playerctl/playerctl-formatter.c index 2e025ae..439e886 100644 --- a/playerctl/playerctl-formatter.c +++ b/playerctl/playerctl-formatter.c @@ -1,8 +1,10 @@ #include "playerctl/playerctl-formatter.h" + #include #include #include #include + #include "playerctl/playerctl-common.h" #define LENGTH(array) (sizeof array / sizeof array[0]) diff --git a/playerctl/playerctl-player-manager.c b/playerctl/playerctl-player-manager.c index 589f16a..9460bf1 100644 --- a/playerctl/playerctl-player-manager.c +++ b/playerctl/playerctl-player-manager.c @@ -18,8 +18,10 @@ */ #include "playerctl/playerctl-player-manager.h" + #include #include + #include "playerctl/playerctl-common.h" #include "playerctl/playerctl-player-name.h" #include "playerctl/playerctl-player.h" diff --git a/playerctl/playerctl-player.c b/playerctl/playerctl-player.c index 3df2090..0282e4c 100644 --- a/playerctl/playerctl-player.c +++ b/playerctl/playerctl-player.c @@ -17,17 +17,17 @@ * Copyright © 2014, Tony Crisci and contributors. */ -#include -#include -#include - -#include -#include -#include "playerctl-common.h" -#include "playerctl-generated.h" #include "playerctl-player.h" +#include +#include +#include +#include #include +#include + +#include "playerctl-common.h" +#include "playerctl-generated.h" #define LENGTH(array) (sizeof array / sizeof array[0])