summaryrefslogtreecommitdiff
path: root/clSong.py
blob: d2111d79ae25f4c5646dafcf0cbf13a1c22431f1 (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
class Song:
	"""The Song class offers an abstraction of a song."""
	_data=None

	def __init__(self, data):
		self._data=data
		if 'id' in self._data:
			self._data['id']=int(self._data['id'])

	def getID(self):
		"""Get the ID."""
		return self.getTag('id', '-1')
	
	def getTitle(self):
		"""Get the title."""
		return self.getTag('title', self._data['file'])

	def getArtist(self):
		"""Get the artist."""
		return self.getTag('artist', self._data['file'])

	def getTrack(self):
		"""Get the track."""
		return self.getTag('track')

	def getAlbum(self):
		"""Get the album."""
		return self.getTag('album')

	def getFilepath(self):
		"""Get the filepath."""
		return self._data['file']

	def __str__(self):
		return "%s - %s [%s]" % (self.getTag('artist'), self.getTag('title'), self.getTag('album'))

	def getTag(self, tag, default=''):
		"""Get a tag. If it doesn't exist, return $default."""
		if tag in self._data:
			return self._data[tag]
		if tag=='song':
			return self

		return default