Created
October 18, 2009 11:21
-
-
Save MrElendig/212637 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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.PIPE) | |
info, err = pipe.communicate() | |
except OSError as e: | |
weechat.prnt(buffer, '{0}Zomg something went wrong: {1}'.format(weechat.prefix('error'), e)) | |
if err: # ssh or moc spit out some error. Let's pring it and return. | |
weechat.prnt(buffer, '{0}Zomg something went wrong: {1}'.format(weechat.prefix('error'), err)) | |
return weechat.WEECHAT_RC_OK | |
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