usr bin python coding utf-8 HOST localhost PORT 6600 Port global oldm

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/python
# -*- coding: utf-8 -*-
HOST = "" # localhost
PORT = 6600 # Port
global oldm,oldmus
oldm=oldmus=""
import socket,string,time,os
#Getting string with songname
def get(s):
artist=album=title=""
for i in s.split("\n"):
if i.startswith("Artist:"):
artist=i.replace("Artist: ","",1)
if i.startswith("Album:"):
album=i.replace("Album: ","",1)
if i.startswith("Title: "):
title=i.replace("Title: ","",1)
if i.startswith("file: "):
file=i.replace("file: ","",1)
if artist==title=="":
return file
else:
# return artist+": "+album+" - "+title
return artist + " - " + title
#Getting gajim status
def get_gajim():
f=os.popen("gajim-remote get_status")
return f.read().replace("\n","")
#Getting status-message
def getm_gajim():
f=os.popen("gajim-remote get_status_message")
return "\""+f.read().replace("\n","")+"\""
#Setting status
def set_gajim(s=""):
global oldm,oldmus
if s=="":
if oldmus!="":
o=getm_gajim()
if o!=oldmus:
oldm=o
s=oldm
oldmus=""
else:
return
else:
if s==oldmus:
return
else:
o=getm_gajim()
if o!=oldmus:
oldm=o
oldmus=s
os.putenv("MUSIC", s)
y=os.popen("echo $MUSIC")
s=y.read()
f=os.popen("gajim-remote change_status "+get_gajim()+" "+s)
#Playing status (play/pause/...)
def status(s):
for i in s.split("\n"):
if i.startswith("state:"):
return i.replace("state: ","",1)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((HOST, PORT))
sock.recv(1024) #Zeroing...
try:
while 1:
sock.send("status\n")
if status(sock.recv(1024)) == "play":
sock.send("currentsong\n")
s=sock.recv(1024)
s="\"♫ "+get(s)+"\""
set_gajim(s)
else:
set_gajim()
time.sleep(1)
except KeyboardInterrupt:
set_gajim()
sock.send("close")
sock.close()
print "-----------------------\nExiting..."