(scripts) Put Bit rate (min & avg) in albums
Calc avg Bit Rate for a album Rename average calc function
This commit is contained in:
@@ -154,7 +154,7 @@ class ITunesParser:
|
||||
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'])
|
||||
rating = self.calc_average(rating, self._artists[akey]['Rating'], self._artists[akey]['Track Count'])
|
||||
|
||||
self._artists[akey]['Track Count'] += 1
|
||||
self._artists[akey]['Rating'] = rating
|
||||
@@ -190,6 +190,8 @@ class ITunesParser:
|
||||
'Rating': 0,
|
||||
'Genre': set(),
|
||||
'Artist': set(),
|
||||
'Avg Bit Rate': track['Bit Rate'],
|
||||
'Min Bit Rate': track['Bit Rate'],
|
||||
# 'Album Artist': '',
|
||||
'Total Time': 0
|
||||
}
|
||||
@@ -198,10 +200,16 @@ class ITunesParser:
|
||||
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'])
|
||||
rating = self.calc_average(rating, self._albums[akey]['Rating'], self._albums[akey]['Track Count'])
|
||||
|
||||
total_time = track['Total Time'] if 'Total Time' in track else 0
|
||||
|
||||
if self._albums[akey]['Min Bit Rate'] > track['Bit Rate']:
|
||||
self._albums[akey]['Min Bit Rate'] = track['Bit Rate']
|
||||
|
||||
avg_bitrate = self.calc_average(track['Bit Rate'], self._albums[akey]['Avg Bit Rate'], self._albums[akey]['Track Count'])
|
||||
self._albums[akey]['Avg Bit Rate'] = avg_bitrate
|
||||
|
||||
self._albums[akey]['Track Count'] += 1
|
||||
self._albums[akey]['Rating'] = rating
|
||||
self._albums[akey]['Play Count'] += play_count
|
||||
@@ -223,11 +231,11 @@ class ITunesParser:
|
||||
self._albums[akey]['Album Artist'] = track['Album Artist']
|
||||
|
||||
@classmethod
|
||||
def calc_rating(cls, added_value, current_rating, count):
|
||||
def calc_average(cls, added_value, current_value, nb_values):
|
||||
"""
|
||||
Calculate average rating from a current rating, a rating value to add and the number of elements
|
||||
Calculate average value from a current value, a value to add and the number of values
|
||||
"""
|
||||
return (current_rating * count + added_value) / (count + 1)
|
||||
return (current_value * nb_values + added_value) / (nb_values + 1)
|
||||
|
||||
@classmethod
|
||||
def calc_id(cls, key):
|
||||
@@ -271,6 +279,7 @@ class WriteElsJson:
|
||||
for _, album in albums.items():
|
||||
persistent_id = album['Persistent ID']
|
||||
album['Rating'] = round(album['Rating'])
|
||||
album['Avg Bit Rate'] = round(album['Avg Bit Rate'])
|
||||
|
||||
json_track_index = {
|
||||
"index": {"_index": ITunesParser.ALBUM_INDEX, "_id": persistent_id}
|
||||
|
||||
Reference in New Issue
Block a user