Compare commits

..

2 Commits

Author SHA1 Message Date
Seungmin Kim
3bf85e07cd
Merge 4441d6cb59 into 0ec9f3535b 2025-03-26 04:43:08 +00:00
Seungmin Kim
4441d6cb59 Add ISRC track search for YouTube 2025-03-25 21:42:58 -07:00
4 changed files with 36 additions and 34 deletions

View File

@ -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();

View File

@ -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();

View File

@ -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,

View File

@ -248,31 +248,30 @@ class YoutubeSourcedTrack extends SourcedTrack {
.read(provider)
.searchVideos(isrc.toString());
if (searchedVideos.isNotEmpty) {
isrcResults.addAll(searchedVideos
isrcResults.addAll(await Future.wait(
searchedVideos
.map<YoutubeVideoInfo>(YoutubeVideoInfo.fromVideo)
.map((YoutubeVideoInfo videoInfo) {
final ytWords =
.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);
final spWords =
.where((item) => item.isNotEmpty)
.toList();
final nameLower =
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) {
.where((item) => item.isNotEmpty)
.toList();
if (titleWords.any((word) => nameLower.contains(word))) {
return videoInfo;
}
return null;
}
).whereType<YoutubeVideoInfo>().toList());
)).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(