update notifications

This commit is contained in:
arcan1s 2014-08-02 18:36:12 +04:00
parent f588c9af8d
commit 03574461a9
2 changed files with 19 additions and 31 deletions

View File

@ -97,17 +97,18 @@ QString ExtendedSysMon::getAutoMpris()
{ {
if (debug) qDebug() << "[DE]" << "[getAutoMpris]"; if (debug) qDebug() << "[DE]" << "[getAutoMpris]";
QProcess command; QProcess command;
QString mpris; QString mpris;
QString cmd = QString("bash -c \"qdbus 'org.mpris.MediaPlayer2.*'\""); QString cmd = QString("bash -c \"qdbus 'org.mpris.MediaPlayer2.*'\"");
if (debug) qDebug() << "[DE]" << "[getAutoMpris]" << ":" << "Run cmd" << cmd; if (debug) qDebug() << "[DE]" << "[getAutoMpris]" << ":" << "Run cmd" << cmd;
command.start(cmd); command.start(cmd);
command.waitForFinished(-1); command.waitForFinished(-1);
QString cmdOutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()).trimmed(); QString cmdOutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()).trimmed();
mpris = cmdOutput.split(QChar('\n'))[0].split(QChar('.'))[3]; if (cmdOutput.split(QChar('\n'))[0].split(QChar('.')).count() > 3)
mpris = cmdOutput.split(QChar('\n'))[0].split(QChar('.'))[3];
if (debug) qDebug() << "[DE]" << "[getAutoMpris]" << ":" << "Player found" << mpris; if (debug) qDebug() << "[DE]" << "[getAutoMpris]" << ":" << "Player found" << mpris;
return mpris; return mpris;
} }

View File

@ -144,24 +144,15 @@ class PTMNotify:
artist = "N\\A" artist = "N\\A"
album = "N\\A" album = "N\\A"
title = "N\\A" title = "N\\A"
if (len(commands.getoutput("pgrep amarok")) > 0): if (len(commands.getoutput("pgrep mpd")) > 0):
player = "amarok"
elif (len(commands.getoutput("pgrep clementine")) > 0):
player = "clementine"
elif (len(commands.getoutput("pgrep mpd")) > 0):
player = "mpd" player = "mpd"
elif (len(commands.getoutput("pgrep qmmp")) > 0):
player = "qmmp"
else: else:
player = "" player = "mpris"
if (player == "amarok"): if (player == "mpris"):
artist = commands.getoutput("qdbus org.kde.amarok /Player GetMetadata 2> /dev/null | grep albumartist: | cut -c14-") name = commands.getoutput("qdbus 'org.mpris.MediaPlayer2.*'").split('\n')[0].split('.')[3]
album = commands.getoutput("qdbus org.kde.amarok /Player GetMetadata 2> /dev/null | grep album: | cut -c8-") artist = commands.getoutput("qdbus org.mpris." + name + " /Player GetMetadata 2> /dev/null | grep albumartist: | cut -c14-")
title = commands.getoutput("qdbus org.kde.amarok /Player GetMetadata 2> /dev/null | grep title: | cut -c8-") album = commands.getoutput("qdbus org.mpris." + name + " /Player GetMetadata 2> /dev/null | grep album: | cut -c8-")
elif (player == "clementine"): title = commands.getoutput("qdbus org.mpris." + name + " /Player GetMetadata 2> /dev/null | grep title: | cut -c8-")
artist = commands.getoutput("qdbus org.mpris.clementine /Player GetMetadata 2> /dev/null | grep albumartist: | cut -c14-")
album = commands.getoutput("qdbus org.mpris.clementine /Player GetMetadata 2> /dev/null | grep album: | cut -c8-")
title = commands.getoutput("qdbus org.mpris.clementine /Player GetMetadata 2> /dev/null | grep title: | cut -c8-")
elif (player == "mpd"): elif (player == "mpd"):
output = commands.getoutput("echo 'currentsong\nclose' | curl --connect-timeout 1 -fsm 3 telnet://localhost:6600 2> /dev/null") output = commands.getoutput("echo 'currentsong\nclose' | curl --connect-timeout 1 -fsm 3 telnet://localhost:6600 2> /dev/null")
for line in output.split("\n"): for line in output.split("\n"):
@ -171,10 +162,6 @@ class PTMNotify:
album = line.split(": ")[1] album = line.split(": ")[1]
elif (line.split(": ")[0] == "Title"): elif (line.split(": ")[0] == "Title"):
title = line.split(": ")[1] title = line.split(": ")[1]
elif (player == "qmmp"):
artist = commands.getoutput("qmmp --nowplaying '%if(%p,%p,Unknown)' 2> /dev/null")
album = commands.getoutput("qmmp --nowplaying '%if(%a,%a,Unknown)' 2> /dev/null")
title = commands.getoutput("qmmp --nowplaying '%if(%t,%t,Unknown)' 2> /dev/null")
text = text + "Artist: %s\nAlbum: %s\nTitle: %s" % (artist, album, title) text = text + "Artist: %s\nAlbum: %s\nTitle: %s" % (artist, album, title)
except: except:
text = "Something wrong" text = "Something wrong"