def _search_tokens(song_name, song_list): """Search song in the cache based on simple each word matching.""" song_name = remove_punct( remove_stopwords( remove_multiple_spaces(unidecode(song_name)).lower() )) tokens1 = song_name.split() cached_songs = song_list res = [] for song in cached_songs: song_back = song name = song.track_name.lower() # If there is a part like (featuring ..) or any extra data # we should remove it as it doesn't aid the search name = re.sub(r'\([^)]*\)', '', name) name = remove_stopwords(name) name = remove_punct(name) name = remove_multiple_spaces(name) name = unidecode(name) tokens2 = name.split() match = check_keywords(tokens1, tokens2) if match: dist = compute_jaccard(tokens1, tokens2) if dist >= preconfig.CONFIG().SEARCH_SENSITIVITY: res.append((song_back, dist)) res = sorted(res, key=lambda x: x[1], reverse=True) # Return w/o the dist values for i in range(0, len(res)): res[i] = res[i][0] return res
def setData(SONG_INFO, is_quiet, song_path, datatype='mp3', choice=None): """Add the metadata to the song.""" # Some providers need extra daa from other endpoints, # this is where we define which need it and where to get # it from logger.debug(choice) option = _get_option(SONG_INFO, is_quiet, choice) logger.debug(option) if option != '~': song = SONG_INFO[option] get_more_data_dict = preconfig.CONFIG().GET_EXTRA_DATA # Try to check if the song object has an attribute provider # Deezer has it but other objects don't have it. # If the provider is present then fetch extra data accordingly if hasattr(song, 'provider') and song.provider in get_more_data_dict: song = get_more_data_dict.get(song.provider, lambda _: None)(song) if datatype == 'mp3': img_added = set_MP3_data( song, song_path, ) elif datatype == 'm4a': img_added = set_M4A_data( song, song_path, ) elif datatype == 'opus': img_added = set_OPUS_data(song, song_path) # Show the written stuff in a better format prepend.PREPEND(1) print('================================') print(' || YEAR: ' + song.release_date) print(' || TITLE: ' + song.track_name) print(' || ARTIST: ' + song.artist_name) print(' || ALBUM: ' + song.collection_name) print(' || GENRE: ' + song.primary_genre_name) print(' || TRACK NO: ' + str(song.track_number)) if img_added: print(' || ALBUM COVER ADDED') prepend.PREPEND(1) print('================================') # Otherwise, the user has opted to enter metadata manually. else: logger.debug('The user is manually entering metadata ...') return option