From c49387bd2d64781517893616b62817c79cd11d66 Mon Sep 17 00:00:00 2001 From: Seungmin Kim <8457324+ehfd@users.noreply.github.com> Date: Sat, 29 Mar 2025 03:48:05 -0700 Subject: [PATCH] fix: revise filter for ISRC search --- lib/services/sourced_track/sources/youtube.dart | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/services/sourced_track/sources/youtube.dart b/lib/services/sourced_track/sources/youtube.dart index 12c0d885..193bdc0d 100644 --- a/lib/services/sourced_track/sources/youtube.dart +++ b/lib/services/sourced_track/sources/youtube.dart @@ -251,19 +251,18 @@ class YoutubeSourcedTrack extends SourcedTrack { .map((YoutubeVideoInfo videoInfo) { final ytWords = videoInfo.title .toLowerCase() - .replaceAll(RegExp(r'[^a-zA-Z0-9\s]+'), '') - .split(RegExp(r'\s+')) + .replaceAll(RegExp(r'[^\p{L}\p{N}\p{Z}]+', unicode: true), '') + .split(RegExp(r'\p{Z}+', unicode: true)) .where((item) => item.isNotEmpty); final spWords = track.name! .toLowerCase() - .replaceAll(RegExp(r'\((.*)\)'), '') - .replaceAll(RegExp(r'[^a-zA-Z0-9\s]+'), '') - .split(RegExp(r'\s+')) + .replaceAll(RegExp(r'[^\p{L}\p{N}\p{Z}]+', unicode: true), '') + .split(RegExp(r'\p{Z}+', unicode: true)) .where((item) => item.isNotEmpty); - // Word match to filter out unrelated results - final matchCount = - ytWords.where((word) => spWords.contains(word)).length; - if (matchCount > spWords.length ~/ 2) { + // Single word and duration match with 3 second tolerance + if (ytWords.any((word) => spWords.contains(word)) && + (videoInfo.duration - track.duration!) + .abs().inMilliseconds <= 3000) { return videoInfo; } return null;