rewrite _load_albums() method
This commit is contained in:
parent
76e2879fd2
commit
ba47b38960
1 changed files with 26 additions and 26 deletions
52
mcg.py
52
mcg.py
|
|
@ -353,32 +353,32 @@ class Client(Base):
|
||||||
def _load_albums(self):
|
def _load_albums(self):
|
||||||
"""Action: Perform the real update."""
|
"""Action: Perform the real update."""
|
||||||
self._albums = {}
|
self._albums = {}
|
||||||
for song in self._parse_list(self._call('listallinfo'), ['file', 'directory']):
|
# Albums
|
||||||
self._logger.debug("song: %r", song)
|
for mpdAlbum in self._parse_list(self._call('list album'), ['album']):
|
||||||
if 'file' in song:
|
albumTitle = mpdAlbum['album']
|
||||||
# Track
|
if albumTitle == "":
|
||||||
track = None
|
albumTitle = MCGAlbum.DEFAULT_ALBUM
|
||||||
if 'artist' in song and 'title' in song and 'file' in song:
|
albumHash = MCGAlbum.hash(albumTitle)
|
||||||
if 'track' not in song:
|
if hash in self._albums.keys():
|
||||||
song['track'] = None
|
album = self._albums[hash]
|
||||||
if 'time' not in song:
|
else:
|
||||||
song['time'] = 0
|
album = MCGAlbum(albumTitle, self._host, self._image_dir)
|
||||||
if 'date' not in song:
|
self._albums[albumHash] = album
|
||||||
song['date'] = None
|
self._logger.debug("album: %r", album)
|
||||||
track = MCGTrack(song['artist'], song['title'], song['track'], song['time'], song['date'], song['file'])
|
# Tracks
|
||||||
self._logger.debug("track: %r", track)
|
for mpdTrack in self._parse_list(self._call('find album ', mpdAlbum['album']), ['file']):
|
||||||
# Album
|
if 'artist' in mpdTrack and 'title' in mpdTrack and 'file' in mpdTrack:
|
||||||
if 'album' not in song:
|
trackNumber = None
|
||||||
song['album'] = MCGAlbum.DEFAULT_ALBUM
|
if 'track' in mpdTrack:
|
||||||
hash = MCGAlbum.hash(song['album'])
|
trackNumber = mpdTrack['track']
|
||||||
if hash in self._albums.keys():
|
trackTime = 0
|
||||||
album = self._albums[hash]
|
if 'time' in mpdTrack:
|
||||||
else:
|
trackTime = mpdTrack['time']
|
||||||
album = MCGAlbum(song['album'], self._host, self._image_dir)
|
trackDate = None
|
||||||
self._albums[album.get_hash()] = album
|
if 'date' in mpdTrack:
|
||||||
self._logger.debug("album: %r", album)
|
trackDate = mpdTrack['date']
|
||||||
# Add track to album
|
track = MCGTrack(mpdTrack['artist'], mpdTrack['title'], trackNumber, trackTime, trackDate, mpdTrack['file'])
|
||||||
if track:
|
self._logger.debug("track: %r", track)
|
||||||
album.add_track(track)
|
album.add_track(track)
|
||||||
self._callback(Client.SIGNAL_LOAD_ALBUMS, self._albums)
|
self._callback(Client.SIGNAL_LOAD_ALBUMS, self._albums)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue