mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-12-08 08:17:31 +00:00
Compare commits
2 Commits
4277c5af47
...
3bf85e07cd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3bf85e07cd | ||
|
|
4441d6cb59 |
@ -75,7 +75,7 @@ extension TrackSimpleExtensions on TrackSimple {
|
||||
final spotify = ref.read(spotifyProvider);
|
||||
return await spotify.invoke((api) => api.tracks.get(id!));
|
||||
} catch (e, stack) {
|
||||
// Ignore errors and create the track locally
|
||||
// Ignore this error and create the Track locally
|
||||
AppLogger.reportError(e, stack);
|
||||
|
||||
Track track = Track();
|
||||
|
||||
@ -54,8 +54,8 @@ class AlbumCard extends HookConsumerWidget {
|
||||
|
||||
Future<List<Track>> fetchAllTrack() async {
|
||||
if (album.tracks != null && album.tracks!.isNotEmpty) {
|
||||
return await Future.wait(
|
||||
album.tracks!.map((track) => track.asTrack(album, ref)));
|
||||
return Future.wait(
|
||||
album.tracks!.map((track) => track.asTrack(album, ref)).toList());
|
||||
}
|
||||
await ref.read(albumTracksProvider(album).future);
|
||||
return ref.read(albumTracksProvider(album).notifier).fetchAll();
|
||||
|
||||
@ -33,7 +33,7 @@ class AlbumTracksNotifier extends AutoDisposeFamilyPaginatedAsyncNotifier<Track,
|
||||
final tracks = await spotify.invoke(
|
||||
(api) => api.albums.tracks(arg.id!).getPage(limit, offset),
|
||||
);
|
||||
final List<Track> items = await Future.wait(tracks.items?.map((e) => e.asTrack(arg, ref)) ?? []);
|
||||
final List<Track> items = await Future.wait(tracks.items?.map((e) => e.asTrack(arg, ref)).toList() ?? []);
|
||||
|
||||
return (
|
||||
items: items,
|
||||
|
||||
@ -248,31 +248,30 @@ class YoutubeSourcedTrack extends SourcedTrack {
|
||||
.read(provider)
|
||||
.searchVideos(isrc.toString());
|
||||
if (searchedVideos.isNotEmpty) {
|
||||
isrcResults.addAll(searchedVideos
|
||||
.map<YoutubeVideoInfo>(YoutubeVideoInfo.fromVideo)
|
||||
.map((YoutubeVideoInfo videoInfo) {
|
||||
final ytWords =
|
||||
videoInfo.title
|
||||
.toLowerCase()
|
||||
.replaceAll(RegExp(r'[^a-zA-Z0-9\s]+'), '')
|
||||
.split(RegExp(r'\s+'))
|
||||
.where((item) => item.isNotEmpty);
|
||||
final spWords =
|
||||
track.name!
|
||||
.toLowerCase()
|
||||
.replaceAll(RegExp(r'\((.*)\)'), '')
|
||||
.replaceAll(RegExp(r'[^a-zA-Z0-9\s]+'), '')
|
||||
.split(RegExp(r'\s+'))
|
||||
.where((item) => item.isNotEmpty);
|
||||
// Word match to filter out unrelated results
|
||||
final matchCount =
|
||||
ytWords.where((word) => spWords.contains(word)).length;
|
||||
if (matchCount > spWords.length ~/ 2) {
|
||||
return videoInfo;
|
||||
}
|
||||
return null;
|
||||
isrcResults.addAll(await Future.wait(
|
||||
searchedVideos
|
||||
.map<YoutubeVideoInfo>(YoutubeVideoInfo.fromVideo)
|
||||
.map((YoutubeVideoInfo videoInfo) async {
|
||||
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();
|
||||
if (titleWords.any((word) => nameLower.contains(word))) {
|
||||
return videoInfo;
|
||||
}
|
||||
).whereType<YoutubeVideoInfo>().toList());
|
||||
return null;
|
||||
}
|
||||
)).then((s) => s.whereType<YoutubeVideoInfo>().toList()));
|
||||
}
|
||||
}
|
||||
return isrcResults;
|
||||
@ -293,9 +292,11 @@ class YoutubeSourcedTrack extends SourcedTrack {
|
||||
try {
|
||||
videoResults.add(
|
||||
YoutubeVideoInfo.fromVideo(
|
||||
await ref.read(youtubeEngineProvider)
|
||||
.getVideo(Uri.parse(ytLink!.url!).queryParameters["v"]!)
|
||||
));
|
||||
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);
|
||||
@ -304,12 +305,13 @@ 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(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user