mirror of
https://github.com/markuryy/shark.git
synced 2025-12-13 12:01:01 +00:00
feat(db): add tracks table and lyric scan caching
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
import { readDir, exists, readFile } from '@tauri-apps/plugin-fs';
|
||||
import { parseBuffer } from 'music-metadata';
|
||||
import type { AudioFormat } from '$lib/types/track';
|
||||
import { upsertTrack, getTracksWithoutLyrics, type DbTrack } from '$lib/library/database';
|
||||
|
||||
export interface TrackWithoutLyrics {
|
||||
path: string;
|
||||
@@ -116,6 +117,7 @@ async function scanDirectoryForMissingLyrics(
|
||||
|
||||
/**
|
||||
* Scan the music library for tracks without .lrc files
|
||||
* Results are cached in the database
|
||||
*/
|
||||
export async function scanForTracksWithoutLyrics(
|
||||
musicFolderPath: string,
|
||||
@@ -129,9 +131,43 @@ export async function scanForTracksWithoutLyrics(
|
||||
|
||||
await scanDirectoryForMissingLyrics(musicFolderPath, results);
|
||||
|
||||
// Save results to database
|
||||
if (onProgress) {
|
||||
onProgress(results.length, results.length, 'Caching results...');
|
||||
}
|
||||
|
||||
for (const track of results) {
|
||||
await upsertTrack({
|
||||
path: track.path,
|
||||
title: track.title,
|
||||
artist: track.artist,
|
||||
album: track.album,
|
||||
duration: Math.round(track.duration),
|
||||
format: track.format,
|
||||
has_lyrics: false
|
||||
});
|
||||
}
|
||||
|
||||
if (onProgress) {
|
||||
onProgress(results.length, results.length, `Found ${results.length} tracks without lyrics`);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load cached tracks without lyrics from database
|
||||
*/
|
||||
export async function loadCachedTracksWithoutLyrics(): Promise<TrackWithoutLyrics[]> {
|
||||
const dbTracks = await getTracksWithoutLyrics();
|
||||
|
||||
return dbTracks.map((track: DbTrack) => ({
|
||||
path: track.path,
|
||||
filename: track.path.split('/').pop() || track.path,
|
||||
title: track.title,
|
||||
artist: track.artist,
|
||||
album: track.album,
|
||||
duration: track.duration,
|
||||
format: track.format as AudioFormat
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user