Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
poezio
poezio
Commits
4deee7cb
Commit
4deee7cb
authored
Mar 11, 2013
by
mathieui
Browse files
Implement user-tune publishing in the mpd plugin (
#1840
)
parent
71c35eb2
Changes
2
Hide whitespace changes
Inline
Side-by-side
doc/en/plugins/mpd_client.txt
View file @
4deee7cb
...
...
@@ -38,6 +38,9 @@ port = 6600
password = password if necessary
---------------------------------------------------------------------
To enable link:http://xmpp.org/extensions/xep-0118.html[User tune]
publishing, you also have to set the _broadcast_ option to _true_.
Usage
-----
...
...
plugins/mpd_client.py
View file @
4deee7cb
...
...
@@ -5,6 +5,48 @@ from common import shell_split
from
os.path
import
basename
as
base
import
tabs
import
mpd
import
threading
from
select
import
select
from
time
import
sleep
class
UpdateThread
(
threading
.
Thread
):
"""
Background thread that awaits mpd changes
"""
def
__init__
(
self
,
plugin
,
xmpp
):
threading
.
Thread
.
__init__
(
self
)
self
.
plugin
=
plugin
self
.
xmpp
=
xmpp
self
.
alive
=
False
self
.
c
=
mpd
.
MPDClient
()
def
run
(
self
,
*
args
,
**
kwargs
):
self
.
alive
=
True
while
self
.
alive
:
try
:
self
.
c
.
connect
(
host
=
self
.
plugin
.
config
.
get
(
'host'
,
'localhost'
),
port
=
self
.
plugin
.
config
.
get
(
'port'
,
'6600'
))
password
=
self
.
plugin
.
config
.
get
(
'password'
,
''
)
if
password
:
self
.
c
.
password
(
password
)
self
.
c
.
send_idle
()
select
([
self
.
c
],
[],
[])
self
.
c
.
fetch_idle
()
status
=
self
.
c
.
status
()
if
status
[
'state'
]
==
'play'
and
self
.
alive
:
song
=
self
.
c
.
currentsong
()
self
.
xmpp
.
plugin
[
'xep_0118'
].
publish_tune
(
artist
=
song
.
get
(
'artist'
),
length
=
song
.
get
(
'time'
),
title
=
song
.
get
(
'title'
),
track
=
song
.
get
(
'track'
),
block
=
False
)
self
.
c
.
disconnect
()
except
:
pass
finally
:
try
:
self
.
c
.
disconnect
()
except
:
pass
sleep
(
8
)
class
Plugin
(
BasePlugin
):
def
init
(
self
):
...
...
@@ -14,6 +56,15 @@ class Plugin(BasePlugin):
help
=
'Sends a message showing the current song of an MPD instance. If full is provided, the message is more verbose.'
,
short
=
'Send the MPD status'
,
completion
=
self
.
completion_mpd
)
if
self
.
config
.
get
(
'broadcast'
,
'true'
).
lower
()
!=
'false'
:
self
.
core
.
xmpp
.
register_plugin
(
'xep_0118'
)
self
.
thread
=
UpdateThread
(
plugin
=
self
,
xmpp
=
self
.
core
.
xmpp
)
self
.
thread
.
start
()
def
cleanup
(
self
):
self
.
thread
.
alive
=
False
self
.
thread
.
c
.
disconnect
()
self
.
core
.
xmpp
.
plugin
[
'xep_0118'
].
stop
(
block
=
False
)
def
command_mpd
(
self
,
args
):
args
=
shell_split
(
args
)
...
...
@@ -27,13 +78,12 @@ class Plugin(BasePlugin):
album
=
current
.
get
(
'album'
,
'Unknown album'
)
title
=
current
.
get
(
'title'
,
base
(
current
.
get
(
'file'
,
'Unknown title'
)))
s
=
'%s - %s (%s)'
%
(
artist
,
title
,
album
)
if
'full'
in
args
:
if
'elapsed'
in
current
and
'time'
in
current
:
current_time
=
float
(
c
.
status
()[
'elapsed'
])
p
ou
rcent
age
=
int
(
current_time
/
float
(
current
[
'time'
])
*
10
)
s
+=
'
\x19
2}[
\x19
1}'
+
'-'
*
(
p
ou
rcent
age
-
1
)
+
'
\x19
3}+'
+
'
\x19
1}'
+
'-'
*
(
10
-
p
ou
rcent
age
-
1
)
+
'
\x19
2}]
\x19
o'
p
e
rcent
s
=
int
(
current_time
/
float
(
current
[
'time'
])
*
10
)
s
+=
'
\x19
2}[
\x19
1}'
+
'-'
*
(
p
e
rcent
s
-
1
)
+
'
\x19
3}+'
+
'
\x19
1}'
+
'-'
*
(
10
-
p
e
rcent
s
-
1
)
+
'
\x19
2}]
\x19
o'
if
not
self
.
api
.
send_message
(
'%s'
%
(
s
,)):
self
.
api
.
information
(
'Cannot send result (%s)'
%
s
,
'Error'
)
...
...
louiz’
@louiz
mentioned in issue
#2056 (closed)
·
Aug 21, 2018
mentioned in issue
#2056 (closed)
mentioned in issue #2056
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment