Skip to content
This repository
Browse code

Added support for playcounts and ratings to the importer

  • Loading branch information...
commit f7558caca29b7ff740be53bdf04013178a5781c2 1 parent 8e9ec78
Jonathan authored

Showing 1 changed file with 30 additions and 0 deletions. Show diff stats Hide diff stats

  1. +30 0 musik/library/importer.py
30 musik/library/importer.py
@@ -372,6 +372,36 @@ def readMp3MetaData(self, uri):
372 372 # TODO: conflict!
373 373 self.log.warning(u'Track website conflict for track %s: %s != %s', track, track.website, metadata['website'])
374 374
  375 + # get id3 data from the file
  376 + id3 = MP3(uri)
  377 +
  378 + # copy data to a new dict that only uses the first value of each key.
  379 + # technically this is discarding data, but most keys are only allowed
  380 + # a single value anyway, and it simplifies the following algorithm
  381 + metadata = EasygoingDictionary()
  382 + for key in id3.keys():
  383 + metadata[key] = id3[key][0]
  384 +
  385 + # play count can be stored in either the PCNT or the POPM frames.
  386 + # choose the largest of the two values as our official playcount.
  387 + playcount = 0
  388 + if metadata['PCNT'] != None and metadata['PCNT'].count != None:
  389 + playcount = int(metadata['PCNT'].count)
  390 +
  391 + if metadata['POPM'] != None and metadata['POPM'].count != None:
  392 + if int(metadata['POPM'].count) > playcount:
  393 + playcount = int(metadata['POPM'].count)
  394 +
  395 + # always take the largest playcount
  396 + if track.playcount == None or track.playcount < playcount:
  397 + track.playcount = playcount
  398 +
  399 + # rating is stored in the POPM frame
  400 + # only ever set the rating if it is currently None - we never want to overwrite a user's rating
  401 + if metadata['POPM'] != None and metadata['POPM'].rating != None:
  402 + if track.rating == None:
  403 + track.rating = int(metadata['POPM'].rating)
  404 +
375 405 return track
376 406
377 407

0 comments on commit f7558ca

Please sign in to comment.
Something went wrong with that request. Please try again.