Plugins:Audacious

From AWN Wiki

Jump to: navigation, search

Contents

[edit] Introduction

A small Python script for use with AWN to change the icon into the cover-images of the albums played by Audacious.

[edit] Requirements

[edit] Screenshot

Here's a small screenshot of the plugin in action:

Image:Audacious-plugin.png

[edit] Downloading and installing

  1. Copy and paste the code into a file, i.e. awn-audacious.py and put it somewhere in the path
  2. Make it executable (chmod +x awn-audacious.py) and load it into background, preferably in the session autostart
  3. Now when Audacious plays a song containing a folder.jpg or folder.png in its folder, the icon will change on the launcher/task-manager

[edit] Code

awn-audacious.py

#!/usr/bin/env python

# Audacious AWN-plugin
# v. 0.7
# Tobias Hellgren <thanius at thanius dot com>
#
# CHANGES: 
# The script didn't like that audtool reported "%20" on spaces, fixed.
#
# v. 0.667: For some reason audtool sometimes reported filename starting with 'file://' which the script didn't like.
# Made a quick and dirty fix, should work now.
#
# Requires Audacious and audtool
# Dbus requires UTF-8 encoding on the folders, or else the script will crash
# The cover image must be called either 'folder.jpg' or 'folder.png'
#
# CONFIG

DEFAULT_ICON = "/usr/share/pixmaps/audacious.png"
AUDTOOL = "/usr/bin/audtool"

#------------------

import dbus
import os
import re

from subprocess import call
from time import sleep
from sys import exit

from commands import getoutput

current = ""
status = "-"
bus = dbus.SessionBus()
obj = bus.get_object("com.google.code.Awn", "/com/google/code/Awn")
awn = dbus.Interface(obj, "com.google.code.Awn")

while getoutput('pidof avant-window-navigator') != "":

	status = getoutput(AUDTOOL + ' playback-status')
	id = getoutput('xwininfo -root -children|grep player|cut -d\\" -f 1|tr -d [:space:]')

	if status == "/usr/bin/audtool: audacious server is not running!":
		awn.SetTaskIconByName ("audacious", DEFAULT_ICON)

	p = re.compile('file://')
	buffer = getoutput(AUDTOOL + ' current-song-filename')
	temp_filename = p.sub('', buffer)

	p = re.compile('%20')
	current = p.sub(' ', temp_filename)

	if len(id) == 9:

		pathname = os.path.dirname(current)
		filename = os.path.abspath(pathname)

		if os.path.exists(filename + '/folder.jpg') or os.path.exists(filename + '/folder.png'):
			if os.path.exists(filename + '/folder.jpg'):
				cover = (filename + '/folder.jpg')
			else:
				cover = (filename + '/folder.png')
		else:
			cover = DEFAULT_ICON

		if status == "playing":
			awn.SetTaskIconByXid (long(id,0), cover)
		else:
			awn.SetTaskIconByXid (long(id,0), DEFAULT_ICON)

sleep(2)

[edit] External links

Personal tools