flacfetch 0.37.1__tar.gz → 0.37.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flacfetch-0.37.1/flacfetch.egg-info → flacfetch-0.37.2}/PKG-INFO +1 -1
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/core/matching.py +12 -2
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/providers/gazelle.py +99 -43
- {flacfetch-0.37.1 → flacfetch-0.37.2/flacfetch.egg-info}/PKG-INFO +1 -1
- {flacfetch-0.37.1 → flacfetch-0.37.2}/pyproject.toml +1 -1
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_gazelle.py +56 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_matching.py +12 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/ARCHITECTURE.md +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/LICENSE +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/MANIFEST.in +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/PLAN.md +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/README.md +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/__init__.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/api/__init__.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/api/auth.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/api/main.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/api/models.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/api/routes/__init__.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/api/routes/cache.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/api/routes/config.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/api/routes/credentials.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/api/routes/download.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/api/routes/health.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/api/routes/search.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/api/routes/spotify.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/api/routes/torrents.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/api/services/__init__.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/api/services/credential_check.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/api/services/disk_manager.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/api/services/download_manager.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/api/services/health_check.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/api/services/search_cache.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/api/services/secret_manager_utils.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/api/services/spotify_budget.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/core/album_match.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/core/categorize.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/core/config.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/core/interfaces.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/core/log.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/core/manager.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/core/models.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/credential_keeper/__init__.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/credential_keeper/__main__.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/credential_keeper/browser.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/credential_keeper/google_login.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/credential_keeper/keeper.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/credential_keeper/librespot.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/credential_keeper/probe.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/credential_keeper/refresh_request.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/credential_keeper/spotify.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/credential_keeper/youtube.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/downloaders/spotify.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/downloaders/torrent.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/downloaders/torrent_coordinator.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/downloaders/youtube.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/interface/cli.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/interface/cli_remote.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/providers/ops.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/providers/red.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/providers/spotify.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch/providers/youtube.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch.egg-info/SOURCES.txt +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch.egg-info/dependency_links.txt +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch.egg-info/entry_points.txt +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch.egg-info/requires.txt +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/flacfetch.egg-info/top_level.txt +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/requirements.txt +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/setup.cfg +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/setup.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/_route_paths.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_album_search.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_api_auth.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_api_config.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_api_deep_health.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_api_health_ytdlp.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_api_integration.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_api_models.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_api_routes.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_api_services.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_cache_api.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_cli_cookies.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_cli_remote.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_cookie_refresh_request.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_core.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_credential_keeper.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_keeper_leaves_youtube.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_keeper_probe.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_logging.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_manager.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_models.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_ops.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_provider_errors.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_red.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_search_api.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_spotify.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_spotify_budget.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_torrent_coordinator.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_torrent_downloader.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_torrent_shared_album.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_transcode_hf_noise.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_youtube.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_youtube_cookies.py +0 -0
- {flacfetch-0.37.1 → flacfetch-0.37.2}/tests/test_youtube_provider.py +0 -0
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import re
|
|
2
2
|
from difflib import SequenceMatcher
|
|
3
3
|
|
|
4
|
+
# Straight, curly and backtick apostrophes. People type "lets" / "dont" without
|
|
5
|
+
# them while release files say "Let's" / "Don’t", so matching ignores them.
|
|
6
|
+
_APOSTROPHES = re.compile(r"['\u2018\u2019`]")
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _strip_apostrophes(text: str) -> str:
|
|
10
|
+
return _APOSTROPHES.sub("", text)
|
|
11
|
+
|
|
4
12
|
|
|
5
13
|
def clean_filename(filename: str) -> str:
|
|
6
14
|
# Remove file extension
|
|
@@ -9,6 +17,8 @@ def clean_filename(filename: str) -> str:
|
|
|
9
17
|
# Remove track numbers like "01 - ", "01. ", "1-", "A1 "
|
|
10
18
|
filename = re.sub(r'^(\d{1,3}[ .-]+)+', '', filename)
|
|
11
19
|
filename = re.sub(r'^[A-D]\d{1,2}[ .-]+', '', filename)
|
|
20
|
+
# Scene-style names use underscores for spaces ("lets_get_retarded")
|
|
21
|
+
filename = filename.replace('_', ' ')
|
|
12
22
|
# Remove " - " separators which might remain
|
|
13
23
|
filename = filename.replace(' - ', ' ')
|
|
14
24
|
return filename.strip()
|
|
@@ -18,8 +28,8 @@ def calculate_match_score(track_title: str, filename: str) -> float:
|
|
|
18
28
|
Returns a score 0.0 - 1.0 indicating how well the filename matches the track title.
|
|
19
29
|
1.0 = Exact match (ignoring case/punctuation)
|
|
20
30
|
"""
|
|
21
|
-
cleaned_name = clean_filename(filename).lower()
|
|
22
|
-
target = track_title.lower()
|
|
31
|
+
cleaned_name = _strip_apostrophes(clean_filename(filename).lower())
|
|
32
|
+
target = _strip_apostrophes(track_title.lower())
|
|
23
33
|
|
|
24
34
|
# Exact match check
|
|
25
35
|
if cleaned_name == target:
|
|
@@ -34,6 +34,27 @@ ALBUM_SEARCH_MAX_GROUPS = 3
|
|
|
34
34
|
# Quotes: ' (apostrophe breaks searches like "I'm With You")
|
|
35
35
|
SPHINX_SPECIAL_CHARS = frozenset(r'()|\\-@~&<>!"/*$^=?:[],.;\'')
|
|
36
36
|
|
|
37
|
+
# Curly apostrophes split words in the tracker index just like straight ones.
|
|
38
|
+
APOSTROPHE_LIKE_CHARS = frozenset('\u2018\u2019`')
|
|
39
|
+
|
|
40
|
+
# Contractions people type without the apostrophe ("lets get it started").
|
|
41
|
+
# The tracker index splits "Let's" into "let" + "s", so the filelist search for
|
|
42
|
+
# "lets" finds nothing; the fallback search spells these out as "let s".
|
|
43
|
+
# Only words that are not also ordinary words (so no "ill", "well", "were").
|
|
44
|
+
APOSTROPHE_LESS_CONTRACTIONS = {
|
|
45
|
+
"aint": "ain t", "arent": "aren t", "cant": "can t", "couldnt": "couldn t",
|
|
46
|
+
"couldve": "could ve", "didnt": "didn t", "doesnt": "doesn t", "dont": "don t",
|
|
47
|
+
"hadnt": "hadn t", "hasnt": "hasn t", "havent": "haven t", "hes": "he s",
|
|
48
|
+
"heres": "here s", "im": "i m", "isnt": "isn t", "its": "it s", "ive": "i ve",
|
|
49
|
+
"lets": "let s", "mustnt": "mustn t", "shes": "she s", "shouldnt": "shouldn t",
|
|
50
|
+
"shouldve": "should ve", "thats": "that s", "theres": "there s", "theyd": "they d",
|
|
51
|
+
"theyll": "they ll", "theyre": "they re", "theyve": "they ve", "wasnt": "wasn t",
|
|
52
|
+
"weve": "we ve", "werent": "weren t", "whats": "what s", "wheres": "where s",
|
|
53
|
+
"whos": "who s", "wont": "won t", "wouldnt": "wouldn t", "wouldve": "would ve",
|
|
54
|
+
"yall": "y all", "youd": "you d", "youll": "you ll", "youre": "you re",
|
|
55
|
+
"youve": "you ve",
|
|
56
|
+
}
|
|
57
|
+
|
|
37
58
|
|
|
38
59
|
class GazelleProvider(Provider):
|
|
39
60
|
"""Base class for Gazelle-based private music trackers.
|
|
@@ -161,7 +182,7 @@ class GazelleProvider(Provider):
|
|
|
161
182
|
are NOT modified - Sphinx handles these via charset_table and ngram_chars.
|
|
162
183
|
"""
|
|
163
184
|
sanitized = query
|
|
164
|
-
for char in SPHINX_SPECIAL_CHARS:
|
|
185
|
+
for char in SPHINX_SPECIAL_CHARS | APOSTROPHE_LIKE_CHARS:
|
|
165
186
|
sanitized = sanitized.replace(char, ' ')
|
|
166
187
|
|
|
167
188
|
# Collapse multiple spaces into one
|
|
@@ -170,6 +191,19 @@ class GazelleProvider(Provider):
|
|
|
170
191
|
logger.debug(f"Sanitized filelist query: '{query}' -> '{sanitized}'")
|
|
171
192
|
return sanitized
|
|
172
193
|
|
|
194
|
+
@staticmethod
|
|
195
|
+
def _expand_contractions(sanitized_title: str) -> Optional[str]:
|
|
196
|
+
"""Spell out apostrophe-less contractions the way the index stores them.
|
|
197
|
+
|
|
198
|
+
"lets get retarded" -> "let s get retarded". Returns None when the title
|
|
199
|
+
has none, so the caller knows there is no fallback search to run.
|
|
200
|
+
"""
|
|
201
|
+
words = sanitized_title.split()
|
|
202
|
+
expanded = [APOSTROPHE_LESS_CONTRACTIONS.get(w.lower(), w) for w in words]
|
|
203
|
+
if expanded == words:
|
|
204
|
+
return None
|
|
205
|
+
return " ".join(expanded)
|
|
206
|
+
|
|
173
207
|
def _find_best_target_file(self, file_list_str: str, track_title: str) -> tuple[Optional[str], Optional[int], float]:
|
|
174
208
|
"""Find the best matching file in a torrent's file list.
|
|
175
209
|
|
|
@@ -1062,57 +1096,79 @@ class GazelleProvider(Provider):
|
|
|
1062
1096
|
# Sanitize the filelist query to remove Sphinx special operators
|
|
1063
1097
|
sanitized_title = self._sanitize_filelist_query(query.title) if query.title else ""
|
|
1064
1098
|
|
|
1099
|
+
try:
|
|
1100
|
+
releases = self._search_browse_filelist(query, sanitized_title)
|
|
1101
|
+
# "lets" only finds files that also drop the apostrophe (often a
|
|
1102
|
+
# stray compilation), never the album's "Let's", so always search
|
|
1103
|
+
# the spelled-out form too and merge.
|
|
1104
|
+
expanded = self._expand_contractions(sanitized_title)
|
|
1105
|
+
if expanded:
|
|
1106
|
+
logger.info(f"{self.name}: also searching contraction form '{expanded}'")
|
|
1107
|
+
seen = {r.source_id for r in releases}
|
|
1108
|
+
try:
|
|
1109
|
+
extra = self._search_browse_filelist(query, expanded)
|
|
1110
|
+
except Exception as e:
|
|
1111
|
+
# Never lose the first search's matches to the extra one.
|
|
1112
|
+
logger.warning(f"{self.name}: contraction search failed, keeping first results: {e}")
|
|
1113
|
+
extra = []
|
|
1114
|
+
for r in extra:
|
|
1115
|
+
if r.source_id not in seen:
|
|
1116
|
+
seen.add(r.source_id)
|
|
1117
|
+
releases.append(r)
|
|
1118
|
+
return releases
|
|
1119
|
+
except requests.RequestException as e:
|
|
1120
|
+
logger.error(f"Connection error to {self.name}: {e}")
|
|
1121
|
+
return []
|
|
1122
|
+
except Exception as e:
|
|
1123
|
+
logger.exception(f"Unexpected error in {self.name}Provider: {e}")
|
|
1124
|
+
return []
|
|
1125
|
+
|
|
1126
|
+
def _search_browse_filelist(self, query: TrackQuery, filelist: str) -> list[Release]:
|
|
1127
|
+
"""One browse by artist + filelist words, then file lists for the top groups."""
|
|
1065
1128
|
params = {
|
|
1066
1129
|
"action": "browse",
|
|
1067
1130
|
"artistname": query.artist,
|
|
1068
|
-
"filelist":
|
|
1131
|
+
"filelist": filelist,
|
|
1069
1132
|
"format": "FLAC"
|
|
1070
1133
|
}
|
|
1071
1134
|
|
|
1072
1135
|
logger.debug(f"Searching {self.name} with params: {params}")
|
|
1073
1136
|
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
logger.debug(f"Found {len(ordered_group_ids)} groups in {self.name} response")
|
|
1137
|
+
ordered_group_ids, token_eligibility = self._browse(params)
|
|
1138
|
+
logger.debug(f"Found {len(ordered_group_ids)} groups in {self.name} response")
|
|
1077
1139
|
|
|
1078
|
-
|
|
1140
|
+
limited_group_ids = ordered_group_ids[:self.search_limit]
|
|
1079
1141
|
|
|
1080
|
-
|
|
1081
|
-
|
|
1142
|
+
if len(ordered_group_ids) > self.search_limit:
|
|
1143
|
+
logger.info(f"Limiting detailed fetch to top {self.search_limit} groups (out of {len(ordered_group_ids)} found)")
|
|
1082
1144
|
|
|
1083
|
-
|
|
1145
|
+
logger.info(f"Fetching details for up to {len(limited_group_ids)} groups to resolve file lists...")
|
|
1084
1146
|
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
except requests.RequestException as e:
|
|
1114
|
-
logger.error(f"Connection error to {self.name}: {e}")
|
|
1115
|
-
return []
|
|
1116
|
-
except Exception as e:
|
|
1117
|
-
logger.exception(f"Unexpected error in {self.name}Provider: {e}")
|
|
1118
|
-
return []
|
|
1147
|
+
releases = []
|
|
1148
|
+
excellent_found = False
|
|
1149
|
+
groups_fetched = 0
|
|
1150
|
+
|
|
1151
|
+
for gid in limited_group_ids:
|
|
1152
|
+
# Rate limit: sleep before each request
|
|
1153
|
+
time.sleep(1.1)
|
|
1154
|
+
|
|
1155
|
+
group_releases = self._fetch_group_details(gid, query.title, token_eligibility)
|
|
1156
|
+
releases.extend(group_releases)
|
|
1157
|
+
groups_fetched += 1
|
|
1158
|
+
|
|
1159
|
+
# Check for early termination
|
|
1160
|
+
if self.early_termination and not excellent_found:
|
|
1161
|
+
for r in group_releases:
|
|
1162
|
+
if (r.seeders and r.seeders >= self.early_termination_seeders and
|
|
1163
|
+
r.release_type in self.early_termination_release_types):
|
|
1164
|
+
excellent_found = True
|
|
1165
|
+
logger.info(f"Found excellent result: {r.artist} - {r.title} ({r.seeders} seeders, {r.release_type})")
|
|
1166
|
+
break
|
|
1167
|
+
|
|
1168
|
+
# If we found an excellent result, fetch a few more groups then stop
|
|
1169
|
+
if excellent_found and groups_fetched >= min(5, len(limited_group_ids)):
|
|
1170
|
+
logger.info(f"Early termination: stopping after {groups_fetched} groups (found excellent result)")
|
|
1171
|
+
break
|
|
1172
|
+
|
|
1173
|
+
logger.info(f"Total matching tracks parsed from {self.name}: {len(releases)}")
|
|
1174
|
+
return releases
|
|
@@ -1080,3 +1080,59 @@ class TestDownloadBudget:
|
|
|
1080
1080
|
p.fetch_artifact_by_id("42")
|
|
1081
1081
|
ledger = p._load_download_ledger("42")
|
|
1082
1082
|
assert [r["kind"] for r in ledger["requests"]] == ["token"]
|
|
1083
|
+
|
|
1084
|
+
|
|
1085
|
+
class TestContractionFallback:
|
|
1086
|
+
"""Apostrophe-less contractions ("lets") miss the tracker index, which stores "let s"."""
|
|
1087
|
+
|
|
1088
|
+
@pytest.fixture
|
|
1089
|
+
def provider(self):
|
|
1090
|
+
return ConcreteGazelleProvider(api_key="test", base_url="https://test.example", cache_subdir="test")
|
|
1091
|
+
|
|
1092
|
+
@pytest.mark.parametrize("title,expected", [
|
|
1093
|
+
("lets get retarded", "let s get retarded"),
|
|
1094
|
+
("Dont Stop Believin", "don t Stop Believin"),
|
|
1095
|
+
("Im Yours", "i m Yours"),
|
|
1096
|
+
("Hello", None),
|
|
1097
|
+
("well ill be there", None),
|
|
1098
|
+
])
|
|
1099
|
+
def test_expand_contractions(self, provider, title, expected):
|
|
1100
|
+
assert provider._expand_contractions(title) == expected
|
|
1101
|
+
|
|
1102
|
+
def test_curly_apostrophe_sanitized(self, provider):
|
|
1103
|
+
assert provider._sanitize_filelist_query("Let’s Get It Started") == "Let s Get It Started"
|
|
1104
|
+
|
|
1105
|
+
def test_also_searches_expanded_title_and_merges(self, provider, monkeypatch):
|
|
1106
|
+
from flacfetch.core.models import TrackQuery
|
|
1107
|
+
comp, album, dup = MagicMock(source_id="1"), MagicMock(source_id="2"), MagicMock(source_id="1")
|
|
1108
|
+
calls = []
|
|
1109
|
+
|
|
1110
|
+
def fake(query, filelist):
|
|
1111
|
+
calls.append(filelist)
|
|
1112
|
+
return [comp] if filelist == "lets get retarded" else [album, dup]
|
|
1113
|
+
|
|
1114
|
+
monkeypatch.setattr(provider, "_search_browse_filelist", fake)
|
|
1115
|
+
result = provider._search_browse(TrackQuery(artist="black eyed peas", title="lets get retarded"))
|
|
1116
|
+
assert calls == ["lets get retarded", "let s get retarded"]
|
|
1117
|
+
assert result == [comp, album]
|
|
1118
|
+
|
|
1119
|
+
def test_expanded_search_failure_keeps_first_results(self, provider, monkeypatch):
|
|
1120
|
+
import requests
|
|
1121
|
+
|
|
1122
|
+
from flacfetch.core.models import TrackQuery
|
|
1123
|
+
comp = MagicMock(source_id="1")
|
|
1124
|
+
|
|
1125
|
+
def fake(query, filelist):
|
|
1126
|
+
if filelist == "let s get retarded":
|
|
1127
|
+
raise requests.Timeout("slow tracker")
|
|
1128
|
+
return [comp]
|
|
1129
|
+
|
|
1130
|
+
monkeypatch.setattr(provider, "_search_browse_filelist", fake)
|
|
1131
|
+
assert provider._search_browse(TrackQuery(artist="x", title="lets get retarded")) == [comp]
|
|
1132
|
+
|
|
1133
|
+
def test_no_retry_without_contractions(self, provider, monkeypatch):
|
|
1134
|
+
from flacfetch.core.models import TrackQuery
|
|
1135
|
+
calls = []
|
|
1136
|
+
monkeypatch.setattr(provider, "_search_browse_filelist", lambda q, f: calls.append(f) or [])
|
|
1137
|
+
assert provider._search_browse(TrackQuery(artist="x", title="Hello")) == []
|
|
1138
|
+
assert calls == ["Hello"]
|
|
@@ -27,3 +27,15 @@ def test_no_match():
|
|
|
27
27
|
score = calculate_match_score("Tonight", "Tomorrow.flac")
|
|
28
28
|
assert score < 0.5
|
|
29
29
|
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_apostrophe_less_title_matches_contraction():
|
|
33
|
+
# Typed "lets", the file says "Let's" (straight or curly)
|
|
34
|
+
assert calculate_match_score("lets get retarded", "05 - Let's Get Retarded.flac") == 1.0
|
|
35
|
+
assert calculate_match_score("lets get retarded", "05 - Let’s Get Retarded.flac") == 1.0
|
|
36
|
+
assert calculate_match_score("Let's Get Retarded", "05 - Lets Get Retarded.flac") == 1.0
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_underscored_scene_filename_matches():
|
|
40
|
+
score = calculate_match_score("lets get retarded", "306-black_eyed_peas-lets_get_retarded.flac")
|
|
41
|
+
assert score > 0.6
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|