album/track time/length

This commit is contained in:
coderkun 2013-04-30 16:26:51 +02:00
commit 7b2858292e

23
mcg.py
View file

@ -254,15 +254,19 @@ class MCGClient(MCGBase, mpd.MPDClient):
def _get_status(self): def _get_status(self):
"""Action: Perform the real status determination.""" """Action: Perform the real status determination."""
# current status # current status
self._call('noidle') #self._call('noidle')
status = self._call('status') status = self._call('status')
state = status['state'] state = status['state']
time = 0
if 'time' in status:
time = int(status['time'].split(':')[0])
volume = int(status['volume']) volume = int(status['volume'])
error = None error = None
if 'error' in status: if 'error' in status:
error = status['error'] error = status['error']
# current song # current song
self._call('noidle') #self._call('noidle')
song = self._call('currentsong') song = self._call('currentsong')
album = None album = None
pos = None pos = None
@ -279,8 +283,9 @@ class MCGClient(MCGBase, mpd.MPDClient):
pos = int(pos) - 1 pos = int(pos) - 1
except KeyError: except KeyError:
pass pass
self._state = state self._state = state
self._callback(MCGClient.SIGNAL_STATUS, state, album, pos, volume, error) self._callback(MCGClient.SIGNAL_STATUS, state, album, pos, time, volume, error)
# Playback option commants # Playback option commants
@ -347,8 +352,12 @@ class MCGClient(MCGBase, mpd.MPDClient):
def _load_albums(self): def _load_albums(self):
"""Action: Perform the real update.""" """Action: Perform the real update."""
self._albums = {}
for song in self._call('listallinfo'): for song in self._call('listallinfo'):
try: try:
if 'album' not in song:
song['album'] = 'Various'
song['date'] = 'none'
hash = MCGAlbum.hash(song['album'], song['date']) hash = MCGAlbum.hash(song['album'], song['date'])
if hash in self._albums.keys(): if hash in self._albums.keys():
album = self._albums[hash] album = self._albums[hash]
@ -418,6 +427,7 @@ class MCGAlbum:
self._host = host self._host = host
self._image_dir = image_dir self._image_dir = image_dir
self._tracks = [] self._tracks = []
self._length = 0
self._cover = None self._cover = None
self._cover_searched = False self._cover_searched = False
self._set_hash() self._set_hash()
@ -442,6 +452,7 @@ class MCGAlbum:
def add_track(self, track): def add_track(self, track):
if track not in self._tracks: if track not in self._tracks:
self._tracks.append(track) self._tracks.append(track)
self._length = self._length + track.get_time()
for artist in track.get_artists(): for artist in track.get_artists():
if artist not in self._artists: if artist not in self._artists:
self._artists.append(artist) self._artists.append(artist)
@ -454,6 +465,10 @@ class MCGAlbum:
return self._tracks return self._tracks
def get_length(self):
return self._length
def get_cover(self): def get_cover(self):
if self._cover is None and not self._cover_searched: if self._cover is None and not self._cover_searched:
self._find_cover() self._find_cover()
@ -565,7 +580,7 @@ class MCGTrack:
if type(track) is list: if type(track) is list:
track = track[0] track = track[0]
self._track = track self._track = track
self._time = time self._time = int(time)
self._file = file self._file = file