From 0c1bf92227522a850e602607632362271fa0b730 Mon Sep 17 00:00:00 2001 From: Marekkon5 Date: Mon, 2 Nov 2020 14:39:23 +0100 Subject: [PATCH] UI Changes (by bascurtiz), improvements to matching --- beatport.py | 27 +++++++- beatporttagger.py | 8 +-- html/index.html | 126 ++++++++++++++++++++------------------ html/style.css | 153 ++++++++++++++++++++++++++++++++++++---------- requirements.txt | 3 +- tagger.py | 94 ++++++++++++++-------------- 6 files changed, 265 insertions(+), 146 deletions(-) diff --git a/beatport.py b/beatport.py index ac28205..63da5ef 100644 --- a/beatport.py +++ b/beatport.py @@ -30,11 +30,17 @@ def match_track(self, title: str, artists: list, fuzzywuzzy_ratio = 80): tracks = self.search_tracks(query) clean_title = self._clean_title(title) + #Add original mix if not mix + if '(' and ')' in title: + clean_title_om = clean_title + else: + clean_title_om = self._clean_title(title + ' (Original Mix)') clean_artists = self._clean_artists(artists) + fuzzy_matches = [] for track in tracks: #Match title - if clean_title == self._clean_title(track.title) or clean_title == self._clean_title(track.name): + if clean_title == self._clean_title(track.title) or clean_title_om == self._clean_title(track.name): #Match single artists bp_artists = [self._clean_artist(a.name) for a in track.artists] for artist in artists: @@ -46,10 +52,25 @@ def match_track(self, title: str, artists: list, fuzzywuzzy_ratio = 80): return track #No match - use fuzzywuzzy - if fuzz.token_sort_ratio(track.title, title) >= fuzzywuzzy_ratio: + fuzzy = fuzz.token_sort_ratio(track.title.replace('(Original Mix)', ''), title.replace('(Original Mix)', '')) + if fuzzy >= fuzzywuzzy_ratio: + #Fuzzy match all artists bp_artists = ','.join([a.name for a in track.artists]) if fuzz.token_sort_ratio(','.join(artists), bp_artists) >= fuzzywuzzy_ratio: - return track + fuzzy_matches.append((fuzzy, track)) + continue + #Match single exact artist + bp_artists = [self._clean_artist(a.name) for a in track.artists] + for artist in artists: + if self._clean_artist(artist) in bp_artists: + fuzzy_matches.append((fuzzy, track)) + continue + + #Get best fuzzy match + fuzzy_matches.sort(key=lambda i: i[0], reverse=True) + if len(fuzzy_matches) > 0: + return fuzzy_matches[0][1] + def _remove_special(self, input: str) -> str: specials = '.,()[] &_"' + "'" diff --git a/beatporttagger.py b/beatporttagger.py index 3eea238..5dd6abc 100644 --- a/beatporttagger.py +++ b/beatporttagger.py @@ -56,10 +56,10 @@ def update(self): window = webview.create_window( 'Beatport Tagger', 'html/index.html', - resizable=True, - width=420, - height=860, - min_size=(420, 420), + resizable=False, + width=435, + height=800, + min_size=(435, 800), js_api=JSAPI() ) diff --git a/html/index.html b/html/index.html index a973bed..2ebb144 100644 --- a/html/index.html +++ b/html/index.html @@ -13,94 +13,98 @@

Beatport Tagger

INPUT

- - + +

SETTINGS

-
-
- - +
+ +
-
- - +
+ +
-
- - +
+ +

TAGS

-
-