change tagging logic (>.8 acoustid trumps all; >.4 acoustid fallback)
This commit is contained in:
parent
2027b80fb6
commit
d782ce8c48
1 changed files with 24 additions and 21 deletions
45
delojza.py
45
delojza.py
|
@ -109,23 +109,18 @@ class DelojzaBot:
|
|||
artist = None
|
||||
source = None
|
||||
|
||||
if 'track' in info:
|
||||
title = info['track']
|
||||
if 'artist' in info:
|
||||
artist = info['artist']
|
||||
best_acoustid_score = 0
|
||||
|
||||
if 'track' in info or 'artist' in info:
|
||||
source = "supplied metadata"
|
||||
|
||||
if title is None or artist is None and self.acoustid_key:
|
||||
if self.acoustid_key:
|
||||
try:
|
||||
self.logger.debug("Requesting AcoustID for {}".format(filepath))
|
||||
results = sorted(acoustid.match(self.acoustid_key, filepath), key=itemgetter(0), reverse=True)
|
||||
if len(results) > 0:
|
||||
score, rid, aid_title, aid_artist = results[0]
|
||||
if score > .8:
|
||||
if score > .4:
|
||||
title = aid_title
|
||||
artist = aid_artist
|
||||
best_acoustid_score = score
|
||||
source = "AcoustID ({}%)".format(round(score * 100))
|
||||
except acoustid.NoBackendError:
|
||||
self.logger.warning("chromaprint library/tool not found")
|
||||
|
@ -134,19 +129,28 @@ class DelojzaBot:
|
|||
except acoustid.WebServiceError as exc:
|
||||
self.logger.warning("web service request failed: {}".format(exc.message))
|
||||
|
||||
if title is None and artist is None and '-' in info.get("title", ""):
|
||||
split = info['title'].split("-")
|
||||
artist = split[0]
|
||||
title = split[1]
|
||||
source = "fallback (artist - title)"
|
||||
if best_acoustid_score < .8:
|
||||
if 'track' in info:
|
||||
title = info['track']
|
||||
if 'artist' in info:
|
||||
artist = info['artist']
|
||||
|
||||
if title is None and 'title' in info:
|
||||
title = info['title']
|
||||
source = "full title fallback"
|
||||
if 'track' in info or 'artist' in info:
|
||||
source = "supplied metadata"
|
||||
|
||||
if 'soundcloud' in info.get("extractor", "") and artist is None:
|
||||
artist = info['uploader']
|
||||
source = "soundcloud \"fallback\""
|
||||
if title is None and artist is None and '-' in info.get("title", ""):
|
||||
split = info['title'].split("-")
|
||||
artist = split[0]
|
||||
title = split[1]
|
||||
source = "fallback (artist - title)"
|
||||
|
||||
if title is None and 'title' in info:
|
||||
title = info['title']
|
||||
source = "full title fallback"
|
||||
|
||||
if 'soundcloud' in info.get("extractor", "") and artist is None:
|
||||
artist = info['uploader']
|
||||
source = "soundcloud \"fallback\""
|
||||
|
||||
artist = artist.strip() if artist else None
|
||||
title = title.strip() if title else None
|
||||
|
@ -332,7 +336,6 @@ class DelojzaBot:
|
|||
if len(file_urls) > 0:
|
||||
self.handle(file_urls, message, hashtags, self.download_raw)
|
||||
|
||||
# noinspection PyBroadException
|
||||
def tg_handle_rest(self, bot, update):
|
||||
self.handle_tg_message(update.message, bot, self.get_hashtags(update.message))
|
||||
|
||||
|
|
Loading…
Reference in a new issue