Skip to content

Commit eaef590

Browse files
committed
fix: revise filter for ISRC search
1 parent 8a7f5c4 commit eaef590

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

lib/services/sourced_track/sources/youtube.dart

+6-7
Original file line numberDiff line numberDiff line change
@@ -251,19 +251,18 @@ class YoutubeSourcedTrack extends SourcedTrack {
251251
.map((YoutubeVideoInfo videoInfo) {
252252
final ytWords = videoInfo.title
253253
.toLowerCase()
254-
.replaceAll(RegExp(r'[^a-zA-Z0-9\s]+'), '')
254+
.replaceAll(RegExp(r'(?:\p{L}\p{Mn}*|\p{N}|\s)+', unicode: true), '')
255255
.split(RegExp(r'\s+'))
256256
.where((item) => item.isNotEmpty);
257257
final spWords = track.name!
258258
.toLowerCase()
259-
.replaceAll(RegExp(r'\((.*)\)'), '')
260-
.replaceAll(RegExp(r'[^a-zA-Z0-9\s]+'), '')
259+
.replaceAll(RegExp(r'(?:\p{L}\p{Mn}*|\p{N}|\s)+', unicode: true), '')
261260
.split(RegExp(r'\s+'))
262261
.where((item) => item.isNotEmpty);
263-
// Word match to filter out unrelated results
264-
final matchCount =
265-
ytWords.where((word) => spWords.contains(word)).length;
266-
if (matchCount > spWords.length ~/ 2) {
262+
// Single word and duration match with 3 second tolerance
263+
if (ytWords.any((word) => spWords.contains(word)) &&
264+
(videoInfo.duration - track.duration!)
265+
.abs().inMilliseconds <= 3000) {
267266
return videoInfo;
268267
}
269268
return null;

0 commit comments

Comments
 (0)