format the project

This commit is contained in:
Tony Crisci
2020-01-14 19:59:15 -05:00
parent 8bcc3658d4
commit 917cf6e1dc
6 changed files with 30 additions and 16 deletions

View File

@@ -12,29 +12,35 @@ gi.require_version('Notify', '0.7')
from gi.repository import Notify from gi.repository import Notify
Notify.init("Media Player") Notify.init("Media Player")
notification = Notify.Notification.new(""); notification = Notify.Notification.new("")
from urllib.parse import urlparse, unquote from urllib.parse import urlparse, unquote
from pathlib import Path from pathlib import Path
from gi.repository import GdkPixbuf from gi.repository import GdkPixbuf
import os.path import os.path
def notify(player): def notify(player):
metadata = player.props.metadata; metadata = player.props.metadata
keys = metadata.keys() keys = metadata.keys()
if 'xesam:artist' in keys and 'xesam:title' in keys: if 'xesam:artist' in keys and 'xesam:title' in keys:
notification.update(metadata['xesam:title'], metadata['xesam:artist'][0]) notification.update(metadata['xesam:title'],
path = Path(unquote(urlparse(metadata['xesam:url']).path)).parent / "cover.jpg"; metadata['xesam:artist'][0])
path = Path(unquote(urlparse(
metadata['xesam:url']).path)).parent / "cover.jpg"
if os.path.exists(path): 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.set_image_from_pixbuf(image)
notification.show(); notification.show()
def on_play(player, status, manager): def on_play(player, status, manager):
notify(player); notify(player)
def on_metadata(player, metadata, manager): def on_metadata(player, metadata, manager):
notify(player); notify(player)
def init_player(name): def init_player(name):
player = Playerctl.Player.new_from_name(name) player = Playerctl.Player.new_from_name(name)
@@ -43,9 +49,11 @@ def init_player(name):
manager.manage_player(player) manager.manage_player(player)
notify(player) notify(player)
def on_name_appeared(manager, name): def on_name_appeared(manager, name):
init_player(name) init_player(name)
manager.connect('name-appeared', on_name_appeared) manager.connect('name-appeared', on_name_appeared)
for name in manager.props.player_names: for name in manager.props.player_names:

View File

@@ -25,6 +25,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "playerctl-common.h" #include "playerctl-common.h"
#include "playerctl-formatter.h" #include "playerctl-formatter.h"

View File

@@ -18,6 +18,7 @@
*/ */
#include "playerctl-common.h" #include "playerctl-common.h"
#include <glib.h> #include <glib.h>
#include <stdio.h> #include <stdio.h>
#include <strings.h> #include <strings.h>

View File

@@ -1,8 +1,10 @@
#include "playerctl/playerctl-formatter.h" #include "playerctl/playerctl-formatter.h"
#include <assert.h> #include <assert.h>
#include <glib.h> #include <glib.h>
#include <inttypes.h> #include <inttypes.h>
#include <playerctl/playerctl-player.h> #include <playerctl/playerctl-player.h>
#include "playerctl/playerctl-common.h" #include "playerctl/playerctl-common.h"
#define LENGTH(array) (sizeof array / sizeof array[0]) #define LENGTH(array) (sizeof array / sizeof array[0])

View File

@@ -18,8 +18,10 @@
*/ */
#include "playerctl/playerctl-player-manager.h" #include "playerctl/playerctl-player-manager.h"
#include <gio/gio.h> #include <gio/gio.h>
#include <glib-object.h> #include <glib-object.h>
#include "playerctl/playerctl-common.h" #include "playerctl/playerctl-common.h"
#include "playerctl/playerctl-player-name.h" #include "playerctl/playerctl-player-name.h"
#include "playerctl/playerctl-player.h" #include "playerctl/playerctl-player.h"

View File

@@ -17,17 +17,17 @@
* Copyright © 2014, Tony Crisci and contributors. * Copyright © 2014, Tony Crisci and contributors.
*/ */
#include <gio/gio.h>
#include <glib-object.h>
#include <string.h>
#include <playerctl/playerctl-enum-types.h>
#include <playerctl/playerctl-player-manager.h>
#include "playerctl-common.h"
#include "playerctl-generated.h"
#include "playerctl-player.h" #include "playerctl-player.h"
#include <gio/gio.h>
#include <glib-object.h>
#include <playerctl/playerctl-enum-types.h>
#include <playerctl/playerctl-player-manager.h>
#include <stdint.h> #include <stdint.h>
#include <string.h>
#include "playerctl-common.h"
#include "playerctl-generated.h"
#define LENGTH(array) (sizeof array / sizeof array[0]) #define LENGTH(array) (sizeof array / sizeof array[0])