From d782ce8c48f43cf88524c79f7daa6ace553ec6f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Fri, 24 May 2019 00:05:17 +0200 Subject: [PATCH] change tagging logic (>.8 acoustid trumps all; >.4 acoustid fallback) --- delojza.py | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/delojza.py b/delojza.py index 57291de..a75d37c 100755 --- a/delojza.py +++ b/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))