mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-12-07 07:49:43 +00:00
Compare commits
2 Commits
2341e5ca06
...
a98e47a474
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a98e47a474 | ||
|
|
045c865904 |
@ -242,30 +242,28 @@ class YoutubeSourcedTrack extends SourcedTrack {
|
||||
}) async {
|
||||
List<SiblingType> siblings = [];
|
||||
|
||||
final isrc = track.externalIds?.isrc;
|
||||
final isrc = track.externalIds?.isrc.toString();
|
||||
if (isrc != null && isrc.isNotEmpty) {
|
||||
final isrcResults =
|
||||
await ref.read(youtubeEngineProvider).searchVideos(isrc.toString());
|
||||
await ref.read(youtubeEngineProvider).searchVideos(isrc);
|
||||
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 / 2) {
|
||||
if (matchCount >= nameLower.length) {
|
||||
matchingResults.add(video);
|
||||
}
|
||||
}
|
||||
@ -324,16 +322,18 @@ class YoutubeSourcedTrack extends SourcedTrack {
|
||||
.mapIndexed((index, info) => toSiblingType(index, info, ref)),
|
||||
));
|
||||
}
|
||||
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
})).then((s) => s.whereType<SiblingType>().toList());
|
||||
return uniqueSiblings;
|
||||
})();
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Loading…
Reference in New Issue
Block a user