Skip to content

Commit 81d35ff

Browse files
committed
deadbeef_np.py 1.0: make script compatible with Python 3, drop Python 2 support
1 parent c92a480 commit 81d35ff

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

python/deadbeef_np.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21-
import commands
21+
import subprocess
2222
import weechat
2323

24+
2425
def weechat_np(data, buffer, args):
25-
read_track = commands.getoutput('deadbeef --nowplaying "%a - (%b) - %t [%@:BPS@bit / %@:BITRATE@kbps / %@:SAMPLERATE@Hz]"').split('\n')
26-
weechat.command(buffer, '/me is currently listening to: ' + read_track[1])
26+
read_track = subprocess.getoutput('deadbeef --nowplaying "%a - (%b) - %t [%@:BPS@bit / %@:BITRATE@kbps / %@:SAMPLERATE@Hz]"').split('\n')
27+
if len(read_track) > 1:
28+
weechat.command(buffer, '/me is currently listening to: ' + read_track[1])
29+
else:
30+
weechat.prnt(buffer, 'deadbeef_np: error: %s' % read_track[0])
2731
return weechat.WEECHAT_RC_OK
2832

29-
weechat.register("deadbeef_np", "mwgg", "0.9", "MIT", "Show name of the song currently played by DeaDBeeF", "", "")
33+
34+
weechat.register("deadbeef_np", "mwgg", "1.0", "MIT", "Show name of the song currently played by DeaDBeeF", "", "")
3035
weechat.hook_command("np", "Get/send now playing info.", "", "", "", "weechat_np", "")

0 commit comments

Comments
 (0)