Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_adhoc_dbus.py @ 4232:0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
fix 441
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 06 Apr 2024 12:59:50 +0200 |
parents | 50c919dfe61b |
children | 0d7bb4df2343 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
822 | 3 |
4 # SAT plugin for adding D-Bus to Ad-Hoc Commands | |
3479 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
822 | 6 |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
20 from collections import OrderedDict |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
21 import os.path |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
22 import uuid |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
23 |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
24 from twisted.internet import defer |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
25 from twisted.internet import reactor |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
26 from twisted.words.protocols.jabber import jid |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
27 from wokkel import data_form |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
28 |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
29 from libervia.backend.core.constants import Const as C |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
30 from libervia.backend.core.i18n import D_, _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
31 from libervia.backend.core.log import getLogger |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
32 |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
33 log = getLogger(__name__) |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
34 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
35 |
1542
94901070478e
plugins: added new MissingModule exceptions to plugins using third party modules
Goffi <goffi@goffi.org>
parents:
1540
diff
changeset
|
36 try: |
94901070478e
plugins: added new MissingModule exceptions to plugins using third party modules
Goffi <goffi@goffi.org>
parents:
1540
diff
changeset
|
37 from lxml import etree |
94901070478e
plugins: added new MissingModule exceptions to plugins using third party modules
Goffi <goffi@goffi.org>
parents:
1540
diff
changeset
|
38 except ImportError: |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
39 etree = None |
3028 | 40 log.warning("Missing module lxml, please download/install it from http://lxml.de/ ." |
41 "Auto D-Bus discovery will be disabled") | |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
42 |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
43 try: |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
44 import txdbus |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
45 from txdbus import client as dbus_client |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
46 except ImportError: |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
47 txdbus = None |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
48 log.warning( |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
49 "Missing module txdbus, please download/install it, auto D-Bus discovery will be " |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
50 "disabled" |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
51 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
52 |
822 | 53 |
3480
7550ae9cfbac
Renamed the project from "Salut à Toi" to "Libervia":
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
54 NS_MEDIA_PLAYER = "org.libervia.mediaplayer" |
822 | 55 FD_NAME = "org.freedesktop.DBus" |
56 FD_PATH = "/org/freedekstop/DBus" | |
57 INTROSPECT_IFACE = "org.freedesktop.DBus.Introspectable" | |
3028 | 58 MPRIS_PREFIX = "org.mpris.MediaPlayer2" |
59 CMD_GO_BACK = "GoBack" | |
60 CMD_GO_FWD = "GoFW" | |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
61 SEEK_OFFSET = 5 * 1000 * 1000 |
3028 | 62 MPRIS_COMMANDS = ["org.mpris.MediaPlayer2.Player." + cmd for cmd in ( |
63 "Previous", CMD_GO_BACK, "PlayPause", CMD_GO_FWD, "Next")] | |
64 MPRIS_PATH = "/org/mpris/MediaPlayer2" | |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
65 MPRIS_PROPERTIES = OrderedDict(( |
3028 | 66 ("org.mpris.MediaPlayer2", ( |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
67 "Identity", |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
68 )), |
3028 | 69 ("org.mpris.MediaPlayer2.Player", ( |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
70 "Metadata", |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
71 "PlaybackStatus", |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
72 "Volume", |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
73 )), |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
74 )) |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
75 MPRIS_METADATA_KEY = "Metadata" |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
76 MPRIS_METADATA_MAP = OrderedDict(( |
3028 | 77 ("xesam:title", "Title"), |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
78 )) |
822 | 79 |
80 INTROSPECT_METHOD = "Introspect" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
81 IGNORED_IFACES_START = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
82 "org.freedesktop", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
83 "org.qtproject", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
84 "org.kde.KMainWindow", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
85 ) # commands in interface starting with these values will be ignored |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
86 FLAG_LOOP = "LOOP" |
822 | 87 |
88 PLUGIN_INFO = { | |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
89 C.PI_NAME: "Ad-Hoc Commands - D-Bus", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
90 C.PI_IMPORT_NAME: "AD_HOC_DBUS", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
91 C.PI_TYPE: "Misc", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
92 C.PI_PROTOCOLS: [], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
93 C.PI_DEPENDENCIES: ["XEP-0050"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
94 C.PI_MAIN: "AdHocDBus", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
95 C.PI_HANDLER: "no", |
3028 | 96 C.PI_DESCRIPTION: _("""Add D-Bus management to Ad-Hoc commands"""), |
822 | 97 } |
98 | |
99 | |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
100 class AdHocDBus: |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
101 |
822 | 102 def __init__(self, host): |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
103 log.info(f"plugin {PLUGIN_INFO[C.PI_NAME]!r} initialization") |
822 | 104 self.host = host |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
105 if etree is not None: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
106 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
107 "ad_hoc_dbus_add_auto", |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
108 ".plugin", |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
109 in_sign="sasasasasasass", |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
110 out_sign="(sa(sss))", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
111 method=self._ad_hoc_dbus_add_auto, |
3028 | 112 async_=True, |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
113 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
114 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
115 "ad_hoc_remotes_get", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
116 ".plugin", |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
117 in_sign="s", |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
118 out_sign="a(sss)", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
119 method=self._ad_hoc_remotes_get, |
3028 | 120 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
121 ) |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
122 self._c = host.plugins["XEP-0050"] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
123 host.register_namespace("mediaplayer", NS_MEDIA_PLAYER) |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
124 self.session_con = None |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
125 |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
126 async def profile_connected(self, client): |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
127 if txdbus is not None: |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
128 if self.session_con is None: |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
129 self.session_con = await dbus_client.connect(reactor, 'session') |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
130 self.fd_object = await self.session_con.getRemoteObject(FD_NAME, FD_PATH) |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
131 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
132 self._c.add_ad_hoc_command( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
133 client, self.local_media_cb, D_("Media Players"), |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
134 node=NS_MEDIA_PLAYER, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
135 timeout=60*60*6 # 6 hours timeout, to avoid breaking remote |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
136 # in the middle of a movie |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
137 ) |
822 | 138 |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
139 async def _dbus_async_call(self, proxy, method, *args, **kwargs): |
822 | 140 """ Call a DBus method asynchronously and return a deferred |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
141 |
822 | 142 @param proxy: DBus object proxy, as returner by get_object |
143 @param method: name of the method to call | |
144 @param args: will be transmitted to the method | |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
145 @param kwargs: will be transmetted to the method, except for the following poped |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
146 values: |
822 | 147 - interface: name of the interface to use |
148 @return: a deferred | |
149 | |
150 """ | |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
151 return await proxy.callRemote(method, *args, **kwargs) |
822 | 152 |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
153 async def _dbus_get_property(self, proxy, interface, name): |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
154 return await self._dbus_async_call( |
3028 | 155 proxy, "Get", interface, name, interface="org.freedesktop.DBus.Properties") |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
156 |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
157 |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
158 async def _dbus_list_names(self): |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
159 return await self.fd_object.callRemote("ListNames") |
822 | 160 |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
161 async def _dbus_introspect(self, proxy): |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
162 return await self._dbus_async_call(proxy, INTROSPECT_METHOD, interface=INTROSPECT_IFACE) |
822 | 163 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
164 def _accept_method(self, method): |
822 | 165 """ Return True if we accept the method for a command |
166 @param method: etree.Element | |
167 @return: True if the method is acceptable | |
168 | |
169 """ | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
170 if method.xpath( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
171 "arg[@direction='in']" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
172 ): # we don't accept method with argument for the moment |
822 | 173 return False |
174 return True | |
175 | |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
176 async def _introspect(self, methods, bus_name, proxy): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
177 log.debug("introspecting path [%s]" % proxy.object_path) |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
178 assert etree is not None |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
179 introspect_xml = await self._dbus_introspect(proxy) |
822 | 180 el = etree.fromstring(introspect_xml) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
181 for node in el.iterchildren("node", "interface"): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
182 if node.tag == "node": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
183 new_path = os.path.join(proxy.object_path, node.get("name")) |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
184 new_proxy = await self.session_con.getRemoteObject( |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
185 bus_name, new_path |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
186 ) |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
187 await self._introspect(methods, bus_name, new_proxy) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
188 elif node.tag == "interface": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
189 name = node.get("name") |
822 | 190 if any(name.startswith(ignored) for ignored in IGNORED_IFACES_START): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
191 log.debug("interface [%s] is ignored" % name) |
822 | 192 continue |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
193 log.debug("introspecting interface [%s]" % name) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
194 for method in node.iterchildren("method"): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
195 if self._accept_method(method): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
196 method_name = method.get("name") |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
197 log.debug("method accepted: [%s]" % method_name) |
822 | 198 methods.add((proxy.object_path, name, method_name)) |
199 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
200 def _ad_hoc_dbus_add_auto(self, prog_name, allowed_jids, allowed_groups, allowed_magics, |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
201 forbidden_jids, forbidden_groups, flags, profile_key): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
202 client = self.host.get_client(profile_key) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
203 return self.ad_hoc_dbus_add_auto( |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
204 client, prog_name, allowed_jids, allowed_groups, allowed_magics, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
205 forbidden_jids, forbidden_groups, flags) |
822 | 206 |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
207 async def ad_hoc_dbus_add_auto(self, client, prog_name, allowed_jids=None, allowed_groups=None, |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
208 allowed_magics=None, forbidden_jids=None, forbidden_groups=None, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
209 flags=None): |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
210 bus_names = await self._dbus_list_names() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
211 bus_names = [bus_name for bus_name in bus_names if "." + prog_name in bus_name] |
822 | 212 if not bus_names: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
213 log.info("Can't find any bus for [%s]" % prog_name) |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
214 return ("", []) |
822 | 215 bus_names.sort() |
216 for bus_name in bus_names: | |
217 if bus_name.endswith(prog_name): | |
218 break | |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
219 else: |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
220 log.info(f"Can't find any command for {prog_name}") |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
221 return ("", []) |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
222 log.info(f"bus name found: {bus_name}") |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
223 proxy = await self.session_con.getRemoteObject(bus_name, "/") |
822 | 224 methods = set() |
225 | |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
226 await self._introspect(methods, bus_name, proxy) |
822 | 227 |
228 if methods: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
229 self._add_command( |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
230 client, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
231 prog_name, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
232 bus_name, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
233 methods, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
234 allowed_jids=allowed_jids, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
235 allowed_groups=allowed_groups, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
236 allowed_magics=allowed_magics, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
237 forbidden_jids=forbidden_jids, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
238 forbidden_groups=forbidden_groups, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
239 flags=flags, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
240 ) |
822 | 241 |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
242 return (str(bus_name), methods) |
822 | 243 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
244 def _add_command(self, client, adhoc_name, bus_name, methods, allowed_jids=None, |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
245 allowed_groups=None, allowed_magics=None, forbidden_jids=None, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
246 forbidden_groups=None, flags=None): |
822 | 247 if flags is None: |
248 flags = set() | |
249 | |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
250 async def d_bus_callback(client, command_elt, session_data, action, node): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
251 actions = session_data.setdefault("actions", []) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
252 names_map = session_data.setdefault("names_map", {}) |
822 | 253 actions.append(action) |
254 | |
255 if len(actions) == 1: | |
256 # it's our first request, we ask the desired new status | |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
257 status = self._c.STATUS.EXECUTING |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
258 form = data_form.Form("form", title=_("Command selection")) |
822 | 259 options = [] |
260 for path, iface, command in methods: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
261 label = command.rsplit(".", 1)[-1] |
822 | 262 name = str(uuid.uuid4()) |
263 names_map[name] = (path, iface, command) | |
264 options.append(data_form.Option(name, label)) | |
265 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
266 field = data_form.Field( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
267 "list-single", "command", options=options, required=True |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
268 ) |
822 | 269 form.addField(field) |
270 | |
271 payload = form.toElement() | |
272 note = None | |
273 | |
274 elif len(actions) == 2: | |
275 # we should have the answer here | |
276 try: | |
3028 | 277 x_elt = next(command_elt.elements(data_form.NS_X_DATA, "x")) |
822 | 278 answer_form = data_form.Form.fromElement(x_elt) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
279 command = answer_form["command"] |
1540
9a4e95c62380
plugin ad-hoc D-Bus: exception fixe + minor fixes
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
280 except (KeyError, StopIteration): |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
281 raise self._c.AdHocError(self._c.ERROR.BAD_PAYLOAD) |
822 | 282 |
283 if command not in names_map: | |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
284 raise self._c.AdHocError(self._c.ERROR.BAD_PAYLOAD) |
822 | 285 |
286 path, iface, command = names_map[command] | |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
287 proxy = await self.session_con.getRemoteObject(bus_name, path) |
822 | 288 |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
289 await self._dbus_async_call(proxy, command, interface=iface) |
822 | 290 |
291 # job done, we can end the session, except if we have FLAG_LOOP | |
292 if FLAG_LOOP in flags: | |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
293 # We have a loop, so we clear everything and we execute again the |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
294 # command as we had a first call (command_elt is not used, so None |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
295 # is OK) |
822 | 296 del actions[:] |
297 names_map.clear() | |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
298 return await d_bus_callback( |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
299 client, None, session_data, self._c.ACTION.EXECUTE, node |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
300 ) |
3028 | 301 form = data_form.Form("form", title=_("Updated")) |
302 form.addField(data_form.Field("fixed", "Command sent")) | |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
303 status = self._c.STATUS.COMPLETED |
822 | 304 payload = None |
3028 | 305 note = (self._c.NOTE.INFO, _("Command sent")) |
822 | 306 else: |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
307 raise self._c.AdHocError(self._c.ERROR.INTERNAL) |
822 | 308 |
309 return (payload, status, None, note) | |
310 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
311 self._c.add_ad_hoc_command( |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
312 client, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
313 d_bus_callback, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
314 adhoc_name, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
315 allowed_jids=allowed_jids, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
316 allowed_groups=allowed_groups, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
317 allowed_magics=allowed_magics, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
318 forbidden_jids=forbidden_jids, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
319 forbidden_groups=forbidden_groups, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
320 ) |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
321 |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
322 ## Local media ## |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
323 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
324 def _ad_hoc_remotes_get(self, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
325 return self.ad_hoc_remotes_get(self.host.get_client(profile)) |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
326 |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
327 async def ad_hoc_remotes_get(self, client): |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
328 """Retrieve available remote media controlers in our devices |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
329 @return (list[tuple[unicode, unicode, unicode]]): list of devices with: |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
330 - entity full jid |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
331 - device name |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
332 - device label |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
333 """ |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
334 found_data = await defer.ensureDeferred(self.host.find_by_features( |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
335 client, [self.host.ns_map['commands']], service=False, roster=False, |
3140 | 336 own_jid=True, local_device=True)) |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
337 |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
338 remotes = [] |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
339 |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
340 for found in found_data: |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
341 for device_jid_s in found: |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
342 device_jid = jid.JID(device_jid_s) |
4184
50c919dfe61b
plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents:
4167
diff
changeset
|
343 cmd_list = await self._c.list_commands(client, device_jid) |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
344 for cmd in cmd_list: |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
345 if cmd.nodeIdentifier == NS_MEDIA_PLAYER: |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
346 try: |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
347 result_elt = await self._c.do(client, device_jid, |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
348 NS_MEDIA_PLAYER, timeout=5) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
349 command_elt = self._c.get_command_elt(result_elt) |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
350 form = data_form.findForm(command_elt, NS_MEDIA_PLAYER) |
3014
b6abf8af87db
plugin ad-hoc D-Bus: fixed warning when no media player is found
Goffi <goffi@goffi.org>
parents:
3009
diff
changeset
|
351 if form is None: |
b6abf8af87db
plugin ad-hoc D-Bus: fixed warning when no media player is found
Goffi <goffi@goffi.org>
parents:
3009
diff
changeset
|
352 continue |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
353 mp_options = form.fields['media_player'].options |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
354 session_id = command_elt.getAttribute('sessionid') |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
355 if mp_options and session_id: |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
356 # we just want to discover player, so we cancel the |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
357 # session |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
358 self._c.do(client, device_jid, NS_MEDIA_PLAYER, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
359 action=self._c.ACTION.CANCEL, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
360 session_id=session_id) |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
361 |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
362 for opt in mp_options: |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
363 remotes.append((device_jid_s, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
364 opt.value, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
365 opt.label or opt.value)) |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
366 except Exception as e: |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
367 log.warning(_( |
3028 | 368 "Can't retrieve remote controllers on {device_jid}: " |
369 "{reason}".format(device_jid=device_jid, reason=e))) | |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
370 break |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
371 return remotes |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
372 |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
373 async def do_mpris_command(self, proxy, command): |
3028 | 374 iface, command = command.rsplit(".", 1) |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
375 if command == CMD_GO_BACK: |
3028 | 376 command = 'Seek' |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
377 args = [-SEEK_OFFSET] |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
378 elif command == CMD_GO_FWD: |
3028 | 379 command = 'Seek' |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
380 args = [SEEK_OFFSET] |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
381 else: |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
382 args = [] |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
383 return await self._dbus_async_call(proxy, command, *args, interface=iface) |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
384 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
385 def add_mpris_metadata(self, form, metadata): |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
386 """Serialise MRPIS Metadata according to MPRIS_METADATA_MAP""" |
3028 | 387 for mpris_key, name in MPRIS_METADATA_MAP.items(): |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
388 if mpris_key in metadata: |
3028 | 389 value = str(metadata[mpris_key]) |
390 form.addField(data_form.Field(fieldType="fixed", | |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
391 var=name, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
392 value=value)) |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
393 |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
394 async def local_media_cb(self, client, command_elt, session_data, action, node): |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
395 assert txdbus is not None |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
396 try: |
3028 | 397 x_elt = next(command_elt.elements(data_form.NS_X_DATA, "x")) |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
398 command_form = data_form.Form.fromElement(x_elt) |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
399 except StopIteration: |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
400 command_form = None |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
401 |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
402 if command_form is None or len(command_form.fields) == 0: |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
403 # root request, we looks for media players |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
404 bus_names = await self._dbus_list_names() |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
405 bus_names = [b for b in bus_names if b.startswith(MPRIS_PREFIX)] |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
406 if len(bus_names) == 0: |
3028 | 407 note = (self._c.NOTE.INFO, D_("No media player found.")) |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
408 return (None, self._c.STATUS.COMPLETED, None, note) |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
409 options = [] |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
410 status = self._c.STATUS.EXECUTING |
3028 | 411 form = data_form.Form("form", title=D_("Media Player Selection"), |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
412 formNamespace=NS_MEDIA_PLAYER) |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
413 for bus in bus_names: |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
414 player_name = bus[len(MPRIS_PREFIX)+1:] |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
415 if not player_name: |
3028 | 416 log.warning(_("Ignoring MPRIS bus without suffix")) |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
417 continue |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
418 options.append(data_form.Option(bus, player_name)) |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
419 field = data_form.Field( |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
420 "list-single", "media_player", options=options, required=True |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
421 ) |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
422 form.addField(field) |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
423 payload = form.toElement() |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
424 return (payload, status, None, None) |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
425 else: |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
426 # player request |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
427 try: |
3028 | 428 bus_name = command_form["media_player"] |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
429 except KeyError: |
3028 | 430 raise ValueError(_("missing media_player value")) |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
431 |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
432 if not bus_name.startswith(MPRIS_PREFIX): |
3028 | 433 log.warning(_("Media player ad-hoc command trying to use non MPRIS bus. " |
434 "Hack attempt? Refused bus: {bus_name}").format( | |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
435 bus_name=bus_name)) |
3028 | 436 note = (self._c.NOTE.ERROR, D_("Invalid player name.")) |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
437 return (None, self._c.STATUS.COMPLETED, None, note) |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
438 |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
439 try: |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
440 proxy = await self.session_con.getRemoteObject( |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
441 bus_name, MPRIS_PATH, "org.mpris.MediaPlayer2.Player" |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
442 ) |
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
443 except Exception as e: |
3028 | 444 log.warning(_("Can't get D-Bus proxy: {reason}").format(reason=e)) |
445 note = (self._c.NOTE.ERROR, D_("Media player is not available anymore")) | |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
446 return (None, self._c.STATUS.COMPLETED, None, note) |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
447 try: |
3028 | 448 command = command_form["command"] |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
449 except KeyError: |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
450 pass |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
451 else: |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
452 await self.do_mpris_command(proxy, command) |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
453 |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
454 # we construct the remote control form |
3028 | 455 form = data_form.Form("form", title=D_("Media Player Selection")) |
456 form.addField(data_form.Field(fieldType="hidden", | |
457 var="media_player", | |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
458 value=bus_name)) |
3028 | 459 for iface, properties_names in MPRIS_PROPERTIES.items(): |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
460 for name in properties_names: |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
461 try: |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
462 value = await self._dbus_get_property(proxy, iface, name) |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
463 except Exception as e: |
3028 | 464 log.warning(_("Can't retrieve attribute {name}: {reason}") |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
465 .format(name=name, reason=e)) |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
466 continue |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
467 if name == MPRIS_METADATA_KEY: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
468 self.add_mpris_metadata(form, value) |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
469 else: |
3028 | 470 form.addField(data_form.Field(fieldType="fixed", |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
471 var=name, |
3028 | 472 value=str(value))) |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
473 |
3028 | 474 commands = [data_form.Option(c, c.rsplit(".", 1)[1]) for c in MPRIS_COMMANDS] |
475 form.addField(data_form.Field(fieldType="list-single", | |
476 var="command", | |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
477 options=commands, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
478 required=True)) |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
479 |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
480 payload = form.toElement() |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
481 status = self._c.STATUS.EXECUTING |
4167
319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
482 return (payload, status, None, None) |