Compare commits

..

2 Commits

Author SHA1 Message Date
Seungmin Kim
2341e5ca06
Merge 50d729f8a0 into 0ec9f3535b 2025-03-24 15:48:28 +00:00
Seungmin Kim
50d729f8a0 Add ISRC track search for YouTube 2025-03-24 08:48:18 -07:00

View File

@ -242,28 +242,30 @@ class YoutubeSourcedTrack extends SourcedTrack {
}) async {
List<SiblingType> siblings = [];
final isrc = track.externalIds?.isrc.toString();
final isrc = track.externalIds?.isrc;
if (isrc != null && isrc.isNotEmpty) {
final isrcResults =
await ref.read(youtubeEngineProvider).searchVideos(isrc);
await ref.read(youtubeEngineProvider).searchVideos(isrc.toString());
if (isrcResults.isNotEmpty) {
final rankedResults = rankResults(
isrcResults.map(YoutubeVideoInfo.fromVideo).toList(), track);
final matchingResults = <YoutubeVideoInfo>[];
for (final video in rankedResults) {
final titleWords = video.title
.replaceAll(RegExp(r'\((.*)\)'), '')
.toLowerCase()
.replaceAll(RegExp(r'[^a-zA-Z0-9\s]+'), '')
.split(RegExp(r'\s+'))
.where((item) => item.isNotEmpty)
.toList();
final nameLower = track.name!
.replaceAll(RegExp(r'\((.*)\)'), '')
.toLowerCase()
.replaceAll(RegExp(r'[^a-zA-Z0-9\s]+'), '')
.split(RegExp(r'\s+'))
.where((item) => item.isNotEmpty)
.toList();
final matchCount =
titleWords.where((word) => nameLower.contains(word)).length;
if (matchCount >= nameLower.length) {
if (matchCount > nameLower.length / 2) {
matchingResults.add(video);
}
}
@ -322,18 +324,16 @@ class YoutubeSourcedTrack extends SourcedTrack {
.mapIndexed((index, info) => toSiblingType(index, info, ref)),
));
}
return await (() async {
// Deduplicate siblings by info.id, keeping the first occurrence
final seenIds = <String>{};
final uniqueSiblings = <SiblingType>[];
for (final sibling in siblings) {
if (!seenIds.contains(sibling.info.id)) {
seenIds.add(sibling.info.id);
uniqueSiblings.add(sibling);
}
final seenIds = <String>{};
// Deduplicate siblings by info.id, keeping the first occurrence
return await Future.wait(siblings.map((sibling) async {
if (!seenIds.contains(sibling.info.id)) {
seenIds.add(sibling.info.id);
return sibling;
}
return uniqueSiblings;
})();
return null;
})).then((s) => s.whereType<SiblingType>().toList());
}
@override