From fd8c1381d73f30a50aef438f4983cbf844cd574d Mon Sep 17 00:00:00 2001 From: "Maxence G. de Montauzan" Date: Thu, 20 Apr 2017 00:14:30 +0200 Subject: [PATCH] Improve main loop + process --- iTunesParser.py | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/iTunesParser.py b/iTunesParser.py index c300325..b8b9a36 100644 --- a/iTunesParser.py +++ b/iTunesParser.py @@ -100,9 +100,7 @@ class ITunesParser: tracks = self._read_tracks() ret = "" - for k in tracks: - track = tracks[k] - + for _, track in tracks.items(): # Filter out any non-music if track['Track Type'] != 'File': continue @@ -157,13 +155,10 @@ class ITunesParser: self._artists[akey]['Rating'] = rating self._artists[akey]['Play Count'] += play_count - if 'Genre' not in track: - return - - # Split up the Genres - genre_parts = track['Genre'].split('/') - self._artists[akey]['Genre'] |= set(genre_parts) - return + if 'Genre' in track: + # Split up the Genres + genre_parts = track['Genre'].split('/') + self._artists[akey]['Genre'] |= set(genre_parts) def _process_album(self, track): """ @@ -198,18 +193,14 @@ class ITunesParser: self._albums[akey]['Rating'] = rating self._albums[akey]['Play Count'] += play_count - if 'Genre' not in track: - return - - # Split up the Genres - genre_parts = track['Genre'].split('/') - self._albums[akey]['Genre'] |= set(genre_parts) + if 'Genre' in track: + # Split up the Genres + genre_parts = track['Genre'].split('/') + self._albums[akey]['Genre'] |= set(genre_parts) ## Add different artists - if 'Artist' not in track: - return - self._albums[akey]['Artist'].add(track['Artist']) - return + if 'Artist' in track: + self._albums[akey]['Artist'].add(track['Artist']) def _write_artists(self): """