mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-12-07 15:59:42 +00:00
Compare commits
2 Commits
da3957beb3
...
0a6292c3de
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0a6292c3de | ||
|
|
77ef0b5f05 |
@ -241,37 +241,16 @@ class YoutubeSourcedTrack extends SourcedTrack {
|
||||
required Provider provider,
|
||||
required Ref ref,
|
||||
}) async {
|
||||
final matchingResults = <YoutubeVideoInfo>[];
|
||||
final isrcResults = <YoutubeVideoInfo>[];
|
||||
final isrc = track.externalIds?.isrc;
|
||||
if (isrc != null && isrc.isNotEmpty) {
|
||||
final isrcResults = await ref
|
||||
.read(provider)
|
||||
final searchedVideos = await ref.read(provider)
|
||||
.searchVideos(isrc.toString());
|
||||
if (isrcResults.isNotEmpty) {
|
||||
for (final videoInfo in isrcResults.map(YoutubeVideoInfo.fromVideo).toList()) {
|
||||
final titleWords =
|
||||
videoInfo.title
|
||||
.toLowerCase()
|
||||
.replaceAll(RegExp(r'[^a-zA-Z0-9\s]+'), '')
|
||||
.split(RegExp(r'\s+'))
|
||||
.where((item) => item.isNotEmpty)
|
||||
.toList();
|
||||
final nameLower =
|
||||
track.name!
|
||||
.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) {
|
||||
matchingResults.add(videoInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
isrcResults.addAll(await searchedVideos
|
||||
.map<YoutubeVideoInfo>(YoutubeVideoInfo.fromVideo)
|
||||
.toList());
|
||||
}
|
||||
return matchingResults;
|
||||
return isrcResults;
|
||||
}
|
||||
|
||||
static Future<List<SiblingType>> fetchSiblings({
|
||||
@ -280,20 +259,19 @@ class YoutubeSourcedTrack extends SourcedTrack {
|
||||
}) async {
|
||||
final videoResults = <YoutubeVideoInfo>[];
|
||||
|
||||
videoResults.addAll(await fetchFromIsrc(track: track, provider: youtubeEngineProvider, ref: ref));
|
||||
videoResults.addAll(await fetchFromIsrc(
|
||||
track: track, provider: youtubeEngineProvider, ref: ref));
|
||||
|
||||
final links = await SongLinkService.links(track.id!);
|
||||
final ytLink = links.firstWhereOrNull((link) => link.platform == "youtube");
|
||||
|
||||
if (ytLink?.url != null) {
|
||||
try {
|
||||
videoResults.add(
|
||||
YoutubeVideoInfo.fromVideo(
|
||||
await ref
|
||||
.read(youtubeEngineProvider)
|
||||
.getVideo(Uri.parse(ytLink!.url!).queryParameters["v"]!),
|
||||
)
|
||||
);
|
||||
videoResults.add(YoutubeVideoInfo.fromVideo(
|
||||
await ref
|
||||
.read(youtubeEngineProvider)
|
||||
.getVideo(Uri.parse(ytLink!.url!).queryParameters["v"]!),
|
||||
));
|
||||
} on VideoUnplayableException catch (e, stack) {
|
||||
// Ignore this error and continue with the search
|
||||
AppLogger.reportError(e, stack);
|
||||
@ -302,18 +280,17 @@ class YoutubeSourcedTrack extends SourcedTrack {
|
||||
|
||||
final query = SourcedTrack.getSearchTerm(track);
|
||||
|
||||
final searchResults = await ref
|
||||
.read(youtubeEngineProvider)
|
||||
.searchVideos(query);
|
||||
final searchResults =
|
||||
await ref.read(youtubeEngineProvider).searchVideos(query);
|
||||
|
||||
if (ServiceUtils.onlyContainsEnglish(query)) {
|
||||
videoResults.addAll(
|
||||
searchResults.map(YoutubeVideoInfo.fromVideo).toList(),
|
||||
searchResults.map(YoutubeVideoInfo.fromVideo).toList(),
|
||||
);
|
||||
} else {
|
||||
videoResults.addAll(rankResults(
|
||||
searchResults.map(YoutubeVideoInfo.fromVideo).toList(),
|
||||
track,
|
||||
searchResults.map(YoutubeVideoInfo.fromVideo).toList(),
|
||||
track,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user