YetAnotherNerd / whatlastgenre

Improve genre metadata of audio files based on tags from various music sites.
http://yetanothernerd.github.io/whatlastgenre
MIT License
78 stars 20 forks source link

Division by 0 error #7

Closed erqzor closed 8 years ago

erqzor commented 8 years ago

Hello,

First, a great thanks for your script ! It's quite the amazing solution i've ever searched for.

I've started the script with -vnr on my directory and everything is running fine until i encounter an error.

[MP3] artist=None, album=Entourage, date=2007 (14 artists)
Discogs  album  got 21 of 24 tags for 'entourage'
MBrainz  album  got  1 of  1 tags for 'entourage'
prefilter 13 of 15 results by year
WhatCD   album  got  2 of  4 tags for 'entourage'
MBrainz  artist got  4 of  5 tags for 'common'
WhatCD   artist got  1 of  1 tags for 'common'
MBrainz  artist got    no    tags for 'kevin michael'
WhatCD   artist got 10 of 15 tags for 'kevin michael'
Traceback (most recent call last):
  File "whatlastgenre", line 24, in <module>
    main()
  File "/Users/mp/Downloads/whatlastgenre-master/wlg/whatlastgenre.py", line 761, in main
    work_directory(wlg, path)
  File "/Users/mp/Downloads/whatlastgenre-master/wlg/whatlastgenre.py", line 688, in work_directory
    genres, release = wlg.query_album(metadata)
  File "/Users/mp/Downloads/whatlastgenre-master/wlg/whatlastgenre.py", line 196, in query_album
    tags = taglib.score(results[0]['tags'], query.score)
  File "/Users/mp/Downloads/whatlastgenre-master/wlg/whatlastgenre.py", line 376, in score
    tags = {k: v / max_ for k, v in tags.iteritems()}
  File "/Users/mp/Downloads/whatlastgenre-master/wlg/whatlastgenre.py", line 376, in <dictcomp>
    tags = {k: v / max_ for k, v in tags.iteritems()}
ZeroDivisionError: float division by zero

I've suspected a time that there was no tags attached to the artist and a value got a 0 but i don't know how to check/understand/debug.

Thanks again for your amazing work.

Osx Yosemite / Python 2.7

YetAnotherNerd commented 8 years ago

this happens because musicbrainz returns a negative score for one tag of the artist 'flo rida' - query:

"tags": [
  {
    "count": 0,
    "name": "electro"
  },
  {
    "count": 0,
    "name": "hip hop"
  },
  {
    "count": 0,
    "name": "electropop"
  },
  {
    "count": 0,
    "name": "southern hip hop"
  },
  {
    "count": 0,
    "name": "dance-pop"
  },
  {
    "count": 0,
    "name": "pop rap"
  },
  {
    "count": 0,
    "name": "hip house"
  },
  {
    "count": -1,
    "name": "hip hop rnb and dance hall"
  },
  {
    "count": 0,
    "name": "a filk artist"
  }
]

(and therefore, even though there are values, the highest value is 0)

never encountered negative scores from dataproviders before, so here is the fix, ty for reporting :)

erqzor commented 8 years ago

Thanks for your quick fix and answer.

But i still have the same error :/

YetAnotherNerd commented 8 years ago

-1 might still be cached, can you try with -u argument? (just call with -u for that specific album, no need to do in a full rerun)

erqzor commented 8 years ago

It works <3 :+1: :+1: