Plugin ‘mpv’ para Weechat
Voy a darle un poco de publicidad a un script que hicimos mi buen amigo ‘teraflops‘ y yo y que muy gentilmente la gente de Weechat lo ha añadido a la lista de scripts oficiales instalables desde el propio Weechat.
El script es un ‘now playing’ (otro más por si no había ya bastantes 😀 ) para mpv. El funcionamiento es bien sencillo, basta con lanzar MPV sobre un socket Linux y desde weechat escribir ‘/mpv‘. Es configurable, si tienes instalado el plugin ‘iset‘, también oficial, bastaría con hacer ‘/iset mpv‘ para acceder a sus opciones.
Para lanzar MPV a través del socket (viene en la cabecera del script):
mpv --input-ipc-server=/ruta/al/socket tu_fichero_de_audio_o_video
La ruta al socket Linux la puedes modificar con ‘/iset‘, por defecto teraflops la puso en ‘/tmp/mpvsocket‘.
Tengo que decir que la gran idea y la forma en la que el núcleo central coge los metadatos de MPV fue de teraflops, yo tan solo me limité a poner las 3 funciones y el diccionario necesarios para que Weechat registre el plugin correctamente.
Aquí tienes el enlace a la página de weechat donde está el script.
Casi me lo dejo atrás… Cuando hicimos el script no tuvimos en cuenta que también se pueden reproducir emisoras Icecast con MPV, y el script no lo contemplaba. Por mi parte he hecho unas modificaciones al script que aún estoy probando. A ver si esta semana lo subimos para que los responsables de Weechat lo añadan.
""" mpv.py author: teraflops <cprieto.ortiz@gmail.com> contributor: nashgul <m.alcocer1978@gmail.com> desc: Sends your current mpv track to the current buffer usage: /mpv note: you have to run this way: mpv --input-ipc-server=/tmp/mpvsocket license: The Beer-ware License version: 0.2 """ import weechat import subprocess from json import loads MPV = { 'SCRIPT_NAME' : 'mpv', 'SCRIPT_COMMAND' : 'mpv', 'default_options' : { 'message' : '/me is now watching: ', 'mpv_socket' : '/tmp/mpvsocket' }, } def set_default_options(): for option, default_value in MPV['default_options'].items(): if not weechat.config_is_set_plugin(option): weechat.config_set_plugin(option, default_value) def reload_options_cb(data, option, value): MPV[option.split('.')[-1]] = value return weechat.WEECHAT_RC_OK def load_options(): for option in MPV['default_options'].keys(): MPV[option] = weechat.config_get_plugin(option) def mpv_msg(world,world_eol,userdata): try: output = subprocess.check_output("echo \'{ \"command\": [\"get_property\", \"metadata\"] }\' | socat - %s" % MPV['mpv_socket'], shell=True) output_short = subprocess.check_output("echo \'{ \"command\": [\"get_property\", \"media-title\"] }\' | socat - %s" % MPV['mpv_socket'], shell=True) metadata = loads(output.decode('utf8')) metadata_short = loads(output_short.decode('utf8')) if 'ALBUM' not in metadata['data']: title = metadata_short['data'].encode('utf-8') message = '%s' % MPV['message'] + title weechat.command(weechat.current_buffer(), message) return weechat.WEECHAT_RC_OK if 'ALBUM' in metadata['data']: title = metadata['data']['TITLE'].encode('utf-8') artist = metadata['data']['ARTIST'].encode('utf-8') album = metadata['data']['ALBUM'].encode('utf-8') np = artist + ' ' + title message = '%s' % MPV['message'] + np if 'icy-url' in metadata['data']: station = '%s - %s' %(metadata['data']['icy-url'],metadata['data']['icy-name']) message = message + ' (( icecast radio: ' + station + ' ))' weechat.command(weechat.current_buffer(), message) return weechat.WEECHAT_RC_OK else: return weechat.WEECHAT_RC_ERROR except: weechat.prnt('', '%s: mpv socket not properly configurated or mpv is not running' % MPV['SCRIPT_NAME']) return weechat.WEECHAT_RC_ERROR weechat.register(MPV['SCRIPT_NAME'], "llua", "0.1", "The Beer-ware License", "Now Playing for mpv", "", "") set_default_options() load_options() weechat.hook_config('plugins.var.python.' + MPV['SCRIPT_NAME'] + '.*', 'reload_options_cb', '') weechat.hook_command(MPV['SCRIPT_COMMAND'], "Now Watching", "", "/%s" % MPV['SCRIPT_COMMAND'], "", "mpv_msg", "")
Pongo una capturilla de cómo funciona…
Comentarios recientes