mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-12-08 00:17:29 +00:00
Compare commits
2 Commits
a98e47a474
...
2341e5ca06
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2341e5ca06 | ||
|
|
50d729f8a0 |
@ -242,28 +242,30 @@ class YoutubeSourcedTrack extends SourcedTrack {
|
|||||||
}) async {
|
}) async {
|
||||||
List<SiblingType> siblings = [];
|
List<SiblingType> siblings = [];
|
||||||
|
|
||||||
final isrc = track.externalIds?.isrc.toString();
|
final isrc = track.externalIds?.isrc;
|
||||||
if (isrc != null && isrc.isNotEmpty) {
|
if (isrc != null && isrc.isNotEmpty) {
|
||||||
final isrcResults =
|
final isrcResults =
|
||||||
await ref.read(youtubeEngineProvider).searchVideos(isrc);
|
await ref.read(youtubeEngineProvider).searchVideos(isrc.toString());
|
||||||
if (isrcResults.isNotEmpty) {
|
if (isrcResults.isNotEmpty) {
|
||||||
final rankedResults = rankResults(
|
final rankedResults = rankResults(
|
||||||
isrcResults.map(YoutubeVideoInfo.fromVideo).toList(), track);
|
isrcResults.map(YoutubeVideoInfo.fromVideo).toList(), track);
|
||||||
final matchingResults = <YoutubeVideoInfo>[];
|
final matchingResults = <YoutubeVideoInfo>[];
|
||||||
for (final video in rankedResults) {
|
for (final video in rankedResults) {
|
||||||
final titleWords = video.title
|
final titleWords = video.title
|
||||||
.replaceAll(RegExp(r'\((.*)\)'), '')
|
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
|
.replaceAll(RegExp(r'[^a-zA-Z0-9\s]+'), '')
|
||||||
.split(RegExp(r'\s+'))
|
.split(RegExp(r'\s+'))
|
||||||
|
.where((item) => item.isNotEmpty)
|
||||||
.toList();
|
.toList();
|
||||||
final nameLower = track.name!
|
final nameLower = track.name!
|
||||||
.replaceAll(RegExp(r'\((.*)\)'), '')
|
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
|
.replaceAll(RegExp(r'[^a-zA-Z0-9\s]+'), '')
|
||||||
.split(RegExp(r'\s+'))
|
.split(RegExp(r'\s+'))
|
||||||
|
.where((item) => item.isNotEmpty)
|
||||||
.toList();
|
.toList();
|
||||||
final matchCount =
|
final matchCount =
|
||||||
titleWords.where((word) => nameLower.contains(word)).length;
|
titleWords.where((word) => nameLower.contains(word)).length;
|
||||||
if (matchCount >= nameLower.length) {
|
if (matchCount > nameLower.length / 2) {
|
||||||
matchingResults.add(video);
|
matchingResults.add(video);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -322,18 +324,16 @@ class YoutubeSourcedTrack extends SourcedTrack {
|
|||||||
.mapIndexed((index, info) => toSiblingType(index, info, ref)),
|
.mapIndexed((index, info) => toSiblingType(index, info, ref)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return await (() async {
|
|
||||||
// Deduplicate siblings by info.id, keeping the first occurrence
|
final seenIds = <String>{};
|
||||||
final seenIds = <String>{};
|
// Deduplicate siblings by info.id, keeping the first occurrence
|
||||||
final uniqueSiblings = <SiblingType>[];
|
return await Future.wait(siblings.map((sibling) async {
|
||||||
for (final sibling in siblings) {
|
if (!seenIds.contains(sibling.info.id)) {
|
||||||
if (!seenIds.contains(sibling.info.id)) {
|
seenIds.add(sibling.info.id);
|
||||||
seenIds.add(sibling.info.id);
|
return sibling;
|
||||||
uniqueSiblings.add(sibling);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return uniqueSiblings;
|
return null;
|
||||||
})();
|
})).then((s) => s.whereType<SiblingType>().toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user