feat: add library scanning mechanic
This commit is contained in:
@@ -177,4 +177,41 @@ public class Seeder
|
||||
return migrationSuccess;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the library needs a full rescan
|
||||
/// </summary>
|
||||
/// <returns>True if full rescan is needed</returns>
|
||||
/// <exception cref="MissingFieldException">Thrown when either last library state, path to music library or cache is unknown</exception>
|
||||
public async Task<bool> ScanPrefetchAsync()
|
||||
{
|
||||
bool scanNecessary = false;
|
||||
Global? lastLibraryState = await db.Globals.FirstOrDefaultAsync(g => g.Key == "libraryState");
|
||||
Global? libraryPath = await db.Globals.FirstOrDefaultAsync(g => g.Key == "musicLibraryPath");
|
||||
Global? cachePath = await db.Globals.FirstOrDefaultAsync(g => g.Key == "musicThumbnailPath");
|
||||
|
||||
if (libraryPath is null || cachePath is null || lastLibraryState is null)
|
||||
{
|
||||
throw new MissingFieldException("[Error] Missing libraryState, musicLibraryPath, musicThumbnailPath. Please rerun the setup wizard with `Shadow setupWizard`.");
|
||||
}
|
||||
LibraryWatcher lw = new(libraryPath.Value!, [cachePath.Value!], db);
|
||||
|
||||
// Get library contents
|
||||
List<string> currentLibraryStateList = await lw.GetAllMultimediaAsync();
|
||||
// Compute their hash
|
||||
string currentLibraryStateString = string.Join("\n", currentLibraryStateList);
|
||||
string currentLibraryState = MetadataExtractor.GetStringMD5(currentLibraryStateString);
|
||||
|
||||
// Compare against last known library state
|
||||
if (currentLibraryState != lastLibraryState.Value)
|
||||
scanNecessary = true;
|
||||
|
||||
// The contents changed? Initiate a full rescan, then call LibraryWatcher.
|
||||
if (scanNecessary)
|
||||
await lw.PerformFullScanAsync();
|
||||
// State seems identical? Launch just the LibraryWatcher.
|
||||
// TODO: lw.Watch()...
|
||||
|
||||
return scanNecessary;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user