Smörgåsbord

Ambachtelijk bereide beschouwingen.

Just finished up a 0.1 version of a LIRC (Linux Infrared Control) plugin for the Exaile media player. Now you can use your remote with Exaile efficiently. The plugin is in the public repository and is called Lircaile.
I haven’t touched Python much as of yet, but I’m pleased with it: it appears to be a consistent language. Well, here’s my 0.1 effort. I desperately wanted to have some fun with introspection, but I have the feeling the nested exception logic is a bit… unusual.

Update #20110222: Updated the inline code preview below to 0.3.0.

# A LIRC plugin for Exaile. Depends on pylirc from http://sourceforge.net/projects/pylirc/
# Copyright (C) 2009-2011 Wicher Minnaard, http://smorgasbord.gavagai.nl / wicher@gavagai.eu
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
 
import pylirc, logging, threading, select
 
LIRCAILE = None
 
def enable(exaile):
  _enable(None, exaile, None)
 
def _enable(eventname, exaile, nothing):
  global LIRCAILE
  LIRCAILE = Lircaile(exaile)
 
def disable(exaile):
  pylirc.exit()
 
 
class Lircaile():
 
  def __init__(self, exaile):
    self.exaile = exaile
    self.logger = logging.getLogger(__name__)
    sock_fd = pylirc.init('lircaile')
    waitlirc = threading.Thread(target=self.wait_lircevent, args=(sock_fd,), name='Thread-lircaile-waitlirc')
    waitlirc.daemon = True
    waitlirc.start()
 
 
  def wait_lircevent(self,sock_fd):
    while True:
      """Pops all queued signals off of the LIRC queue and hands them to
      handleCode() for further processing."""
      select.select([sock_fd],[],[])
      try:
        [code] = pylirc.nextcode()
        self.handleCode(*code.split())
      except TypeError:
        pass #empty queue
 
 
  def handleCode(self, command, *arg):
    """Takes LIRC signals and uses introspection to try to find appropriate 
    exaile functions to call based on the name of the signal. """
    if (command == 'chvol'):
      self.exaile.player.set_volume(self.exaile.player.get_volume() + float(arg[0]))
    elif (command == 'seek'):
      self.exaile.player.seek((self.exaile.player.get_position()/1000000000) + float(arg[0]))
    else:
      func = None
      # Look for a matching playlist function
      try:
        func = getattr(self.exaile.queue, command)
      except AttributeError:
        # No? Then look for a matching player function
        try:
          func = getattr(self.exaile.player, command)
        except AttributeError:
          # No? Then we're out of options
          self.logger.warning('No function to handle the "%s" LIRC event' % command)
      if callable(func):
        func()

Tags: , , , , ,

9 Responses to “LIRC plugin for Exaile”

  1. LIRC en Archlinux « Archlinux Xz

    [...] de audio simple y similar a amarok pero escrito en GTK, gracias a un plugin que encontré en una entrada de este blog, podemos configurarlo de manera sencilla para que funcione con lirc, simplemente descargamos el [...]

  2. Camille Bissuel

    Hi, and thanks for this plugin !
    I’ve just tested it today, and it works great.

    However, I can’t figure out how to get the exaile function list I could put in “config =” in an .lircrc file.

    The basic sample help, and I can find some obvious function like “stop”, but an exaustive list would be great…

    Can you help me with that, or indicate how to obtain it ?

    Thanks a lot,
    yagraph

    Wicher Reply:

    The details are in handleCode(). If you define ‘config=yadda’ in your ~/.lircrc, then lircaile will look for a function ‘yadda()’ in the exaile.queue object, and subsequently in the exaile.player object.

    The exaile.queue object is, on my machine, an instance of PlayQueue as found in /usr/lib64/exaile/xl/player/queue.py. The exaile.player object maps to NormalPlayer in /usr/lib64/exaile/xl/player/engine_normal.py.

    An exhaustive list would therefore contain all functions in these classes, of which few make sense to map a remote button to ;-)

    Camille Bissuel Reply:

    Thanks Wicher,

    you’re right, there’s a lot of functions, and really few make sense to use with a remote button ;)
    I searched around files you mention, and others, but couldn’t find anything more relevent than what your sample provided (except “stop”).

    To say it short : I look for a way to
    = seek forward and rewind (I tried with “seek +10″, “position +10″, “scroll +10″, with no success).
    = toogle the three button above play and stop : track randomness, toogle repeat playback, and dynamic tracks adding…
    but I do not feel it’s possible actually, and I can’t find than in python files.

    If you have any idea, I would be pleased to hear it, that’s my last request, I promise !

    Wicher Reply:

    There actually is a seek() in engine_normal.py, but it takes an absolute position. I added seeking support in lircaile 0.3.0, check my repo.

    If you have any idea, I would be pleased to hear it, that’s my last request, I promise !

    I absolutely don’t mind hearing from you, that’s what the comment form is for ;-)
    Please test 0.3.0.

  3. Camille Bissuel

    Thanks a lot Wicher, I didn’t expect you to do custom dev for me ;)

    Sadly, I can’t install your latest version, for some reason…
    Adding the plugin with Exaile Preference menu, I obtain :
    “Plugin file installation failed !” “PLugin archive is not in the correct format”
    I updated Exaile to 0.3.2.1 to be sure, but no more result (Xubuntu 10.10 64 bits install).

    Do I miss something, or there is some bug in your package ?
    Cheers

    Wicher Reply:

    I seem to have zipped where I should’ve targz’ed.

    Camille Bissuel Reply:

    Ok, its works, and it rocks, thanks again !

    just a detail : maybe you should use a config of seek “+5″ instead of “+10″ : a value of 5 give a 10 seconds jump, which is fine for my tests.

  4. Wicher

    just a detail : maybe you should use a config of seek “+5″ instead of “+10″ : a value of 5 give a 10 seconds jump, which is fine for my tests.

    That’s a quirk in your lirc setup. You might solve it by twiddling the repeat and delay parameters in your ~/.lircrc, check the docs.

Leave a Reply

Got an account? This would be an excellent time to log in!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

© 2009-2011 Wicher Minnaard | electronic mail | theme: righteously modified "dark strict"