Hatena::ブログ(Diary)

nozzy123nozzyの日記

2011-05-02

Write totem plugin.

16:56

I recently prefer totem-2.30 on debian sid to listen music.However totem seems lack of an ability which notifies the music title to GNOME notification area.

Then ,I decided to write the plugin to notify the meta-data (included title,artist,etc...) of music. I found using python make it very easy task! So I memorize here.

1) mkdir ~/.local/share/totem/plugins/metadata_notifier

2) cd ~/.local/share/totem/plugins/metadata_notifier

3) put the following source, named as "metadata_notifier.py"

## Metadata  notify plugin
## Author nozzy123nozzy <nozzy123nozzy_at_gmail_dot_com>
## Copyright: nozzy123nozzy
## License: GPL
 
import totem
import pynotify

class metadata_notifier(totem.Plugin):
	def __init__(self):
		totem.Plugin.__init__(self)
		self.notifier_ident="Totem Metadata notification"
		pynotify.init(self.notifier_ident)
		self.old_notify_string=""

	def activate(self,totem):
		totem.connect("metadata-updated", self.do_metadata)

	def deactivate(self,totem):
		pynotify.uninit();

	def do_metadata(self, totem, artist, title, album, num):
		notify_string=""
		if artist:
			notify_string+=artist+"\n"
		if title:
			notify_string+=title+"\n"
		if album:
			notify_string+=album+"\n"
		if len(notify_string) != 0:
			if totem.is_playing() and \
				(notify_string != self.old_notify_string):
				self.do_notify(notify_string)
				self.old_notify_string=notify_string

	def do_notify(self, notify_string):
		notify=pynotify.Notification("Totem",notify_string,"/usr/share/pixmaps/totem.xpm")
		notify.set_timeout(10000)
		notify.show()

4) put the plugin definition named as "metadata_notifier.totem-plugin",

[Totem Plugin]
Loader=python
Module=metadata_notifier
IAge=1
Name=Metadata Notifier
Description=Plugin for sending notification of currently playing music to gnome nitifier daemon.
Author=nozzy123nozzy <nozzy123nozzy_at_gmail_dot_com>
Copyright=nozzy123nozzy
Website=http://d.hatena.ne.jp/nozzy123nozzy/

5) aptitude install python-notify

6) invoke totem.

7) select menu of plugins.

8) 'Metadata Notifier' is shown. Then, put check-mark on it.

9) start play music.

If music data has meta-data, it is shown on notification area on GNOME desktop,

like below,

f:id:nozzy123nozzy:20110502172451j:image

Tips:

[1] If meta-data has some cp932(or shift-jis) code, putting 'GST_TAG_ENCODING=CP932' to your environmental variable is covenient.It can help show the correct Japanese titles,artists.

Have fun!

トラックバック - http://d.hatena.ne.jp/nozzy123nozzy/20110502/1304322969