mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-12-08 08:17:31 +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 Provider provider,
|
||||||
required Ref ref,
|
required Ref ref,
|
||||||
}) async {
|
}) async {
|
||||||
final matchingResults = <YoutubeVideoInfo>[];
|
final isrcResults = <YoutubeVideoInfo>[];
|
||||||
final isrc = track.externalIds?.isrc;
|
final isrc = track.externalIds?.isrc;
|
||||||
if (isrc != null && isrc.isNotEmpty) {
|
if (isrc != null && isrc.isNotEmpty) {
|
||||||
final isrcResults = await ref
|
final searchedVideos = await ref.read(provider)
|
||||||
.read(provider)
|
|
||||||
.searchVideos(isrc.toString());
|
.searchVideos(isrc.toString());
|
||||||
if (isrcResults.isNotEmpty) {
|
isrcResults.addAll(await searchedVideos
|
||||||
for (final videoInfo in isrcResults.map(YoutubeVideoInfo.fromVideo).toList()) {
|
.map<YoutubeVideoInfo>(YoutubeVideoInfo.fromVideo)
|
||||||
final titleWords =
|
.toList());
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return matchingResults;
|
return isrcResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<List<SiblingType>> fetchSiblings({
|
static Future<List<SiblingType>> fetchSiblings({
|
||||||
@ -280,20 +259,19 @@ class YoutubeSourcedTrack extends SourcedTrack {
|
|||||||
}) async {
|
}) async {
|
||||||
final videoResults = <YoutubeVideoInfo>[];
|
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 links = await SongLinkService.links(track.id!);
|
||||||
final ytLink = links.firstWhereOrNull((link) => link.platform == "youtube");
|
final ytLink = links.firstWhereOrNull((link) => link.platform == "youtube");
|
||||||
|
|
||||||
if (ytLink?.url != null) {
|
if (ytLink?.url != null) {
|
||||||
try {
|
try {
|
||||||
videoResults.add(
|
videoResults.add(YoutubeVideoInfo.fromVideo(
|
||||||
YoutubeVideoInfo.fromVideo(
|
await ref
|
||||||
await ref
|
.read(youtubeEngineProvider)
|
||||||
.read(youtubeEngineProvider)
|
.getVideo(Uri.parse(ytLink!.url!).queryParameters["v"]!),
|
||||||
.getVideo(Uri.parse(ytLink!.url!).queryParameters["v"]!),
|
));
|
||||||
)
|
|
||||||
);
|
|
||||||
} on VideoUnplayableException catch (e, stack) {
|
} on VideoUnplayableException catch (e, stack) {
|
||||||
// Ignore this error and continue with the search
|
// Ignore this error and continue with the search
|
||||||
AppLogger.reportError(e, stack);
|
AppLogger.reportError(e, stack);
|
||||||
@ -302,18 +280,17 @@ class YoutubeSourcedTrack extends SourcedTrack {
|
|||||||
|
|
||||||
final query = SourcedTrack.getSearchTerm(track);
|
final query = SourcedTrack.getSearchTerm(track);
|
||||||
|
|
||||||
final searchResults = await ref
|
final searchResults =
|
||||||
.read(youtubeEngineProvider)
|
await ref.read(youtubeEngineProvider).searchVideos(query);
|
||||||
.searchVideos(query);
|
|
||||||
|
|
||||||
if (ServiceUtils.onlyContainsEnglish(query)) {
|
if (ServiceUtils.onlyContainsEnglish(query)) {
|
||||||
videoResults.addAll(
|
videoResults.addAll(
|
||||||
searchResults.map(YoutubeVideoInfo.fromVideo).toList(),
|
searchResults.map(YoutubeVideoInfo.fromVideo).toList(),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
videoResults.addAll(rankResults(
|
videoResults.addAll(rankResults(
|
||||||
searchResults.map(YoutubeVideoInfo.fromVideo).toList(),
|
searchResults.map(YoutubeVideoInfo.fromVideo).toList(),
|
||||||
track,
|
track,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user