summaryrefslogtreecommitdiff
path: root/totem/zeitgeist_plugin.py
blob: 4cf6c20b0c13cfa0e230a9fba74a814dee53eff5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import totem

class Zeitgeist(totem.Plugin):
	def __init__ (self):
		totem.Plugin.__init__(self)
		self.totem_object = None
		self.null_metadata = {"year" : "", "tracknumber" : "", "location" : "",
			"title" : "", "album" : "", "time" : "", "genre" : "", "artist" : "", "uri" : ""}
		self.old_metadata = self.null_metadata.copy()
		self.current_uri = None
		self.last_metadata = None
		self.current_metadata = self.null_metadata.copy()
		self.counter = 0

	def activate (self, totem_object):
		self.totem_object = totem_object
		self.totem_object.connect("file-opened", self.handle_opened)
		self.totem_object.connect("file-closed", self.handle_closed)
		self.totem_object.connect("metadata-updated", self.do_update_metadata)

	def deactivate (self, totem):
		print "deactivate"

	def do_update_metadata(self, totem, artist, title, album, num):
		self.current_metadata = self.null_metadata.copy()
		if title:
			self.current_metadata["title"] = title
		if artist:
			self.current_metadata["artist"] = artist
		if album:
			self.current_metadata["album"] = album
		if self.current_uri:
			self.current_metadata["uri"] = self.current_uri
		self.counter += 1
		if self.counter == 8:
			self.counter = 0
			self.inform_opened()
			self.last_metadata = self.current_metadata

	def handle_opened(self, totem, uri):
		self.current_uri = uri
	def handle_closed(self, totem):
		self.inform_closed()

	def inform_opened(self):
		print "OPENED"
		print self.current_metadata
		print "--------------------"

	def inform_closed(self):
		print "CLOSED"
		print self.last_metadata
		print "--------------------"