Doc + Album Rating Computed

This commit is contained in:
2017-04-20 00:33:20 +02:00
parent fd8c1381d7
commit 92c4901992

View File

@@ -1,9 +1,13 @@
#!/usr/bin/env python
"""
--> Parse library and just do JSON adapted for Elasticsearch
Parse iTunes library and produce JSON adapted files to send to Elasticsearch
iTunes Graph Parser
Rating note:
For albums and artists data, 'Rating' is the average rate for *all* songs in the album or of the artist.
So, if in an album, 10 songs are evaluated and 2 not evaluated, 'Rating' will be the sum of rate divided by 12.
TODO: Add informations to store number of evaluated songs, and 'Rating' for evaluated song.
Parses an iTunes library XML file and generates a JSON file
for use in the D3.js JavaScript library.
@@ -74,7 +78,6 @@ class ITunesParser:
Note: process_songs do a process_artists and process_albums...
This method suck.
"""
ret = self._process_songs()
self._write_artists()
@@ -85,7 +88,7 @@ class ITunesParser:
def _read_tracks(self):
"""
Read library and return Tracks part
Read library and return Tracks key of dict
"""
plist = plistlib.load(open(self.library_file, 'rb'))
return plist['Tracks']
@@ -145,10 +148,9 @@ class ITunesParser:
}
# Compute information
rating = track['Rating'] if 'Rating' in track else 0
# TODO If no Rating, don't take 0
play_count = track['Play Count'] if 'Play Count' in track else 0
rating = track['Rating'] if 'Rating' in track else 0
rating = self.calc_rating(rating, self._artists[akey]['Rating'], self._artists[akey]['Track Count'])
self._artists[akey]['Track Count'] += 1
@@ -182,11 +184,9 @@ class ITunesParser:
}
# Compute information
rating = track['Rating'] if 'Rating' in track else 0
# TODO Use Album Rating
# TODO If no Rating, don't take 0
play_count = track['Play Count'] if 'Play Count' in track else 0
rating = track['Rating'] if 'Rating' in track else 0
rating = self.calc_rating(rating, self._albums[akey]['Rating'], self._albums[akey]['Track Count'])
self._albums[akey]['Track Count'] += 1
@@ -198,10 +198,13 @@ class ITunesParser:
genre_parts = track['Genre'].split('/')
self._albums[akey]['Genre'] |= set(genre_parts)
## Add different artists
if 'Artist' in track:
self._albums[akey]['Artist'].add(track['Artist'])
if 'Album Rating' in track:
self._albums[akey]['Album Rating'] = track['Album Rating']
self._albums[akey]['Album Rating Computed'] = True
def _write_artists(self):
"""
Write artists data to another JSON file