Skip to content

Instantly share code, notes, and snippets.

@MrElendig
Created October 18, 2009 11:09
Show Gist options
  • Save MrElendig/212634 to your computer and use it in GitHub Desktop.
Save MrElendig/212634 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import weechat
import subprocess
import os.path
weechat.register('SMNP',
'Mion',
'0.1',
'AGPL3',
'ssh + moc now playing script',
'',
'')
SERVER = 'noire' # change this to your remote server
FORMAT = '%file' # change this to whatever format you want, see mocp(1)
def format(s):
s = os.path.basename(s)
s = s.rsplit('.', 1)[0]
return s
def main(data, buffer, args):
try:
pipe = subprocess.Popen(['ssh', SERVER, 'mocp', '-Q', FORMAT],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout
info = pipe.readline()
pipe.close()
except OSError as e:
weechat.prnt(buffer, '{0}Zomg something went wrong: {1}'.format(weechat.prefix('error'), e))
info = format(info) # comment out this if you use something else than '%file' as the FORMAT
com = u'/me is now playing: {0}'.format(info)
weechat.command(buffer, com)
return weechat.WEECHAT_RC_OK
weechat.hook_command('smnp',
'Displays the current playing song from moc from a remote server',
'',
'',
'',
'main',
'')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment