feat: import library from media root and stream tracks
Add a filesystem scanner that ingests supported audio files from MEDIA_ROOT into SQLite using embedded tags with filename fallbacks. Wire startup scanning, manual rescan, and authenticated audio streaming into the backend, then connect the web player to the real stream endpoint.
This commit is contained in:
@@ -4,6 +4,9 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
@@ -16,7 +19,7 @@ func Seed(ctx context.Context, database *sql.DB, cfg config.Config) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if cfg.AppEnv == "development" {
|
||||
if cfg.AppEnv == "development" && !hasMediaFiles(cfg.MediaRoot) {
|
||||
if err := seedLibrary(ctx, database); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -25,6 +28,24 @@ func Seed(ctx context.Context, database *sql.DB, cfg config.Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func hasMediaFiles(root string) bool {
|
||||
found := false
|
||||
_ = filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil || d.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch strings.ToLower(filepath.Ext(path)) {
|
||||
case ".aac", ".flac", ".m4a", ".mp3", ".ogg", ".oga", ".opus", ".wav", ".wma":
|
||||
found = true
|
||||
return fs.SkipAll
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
return found
|
||||
}
|
||||
|
||||
func seedAdmin(ctx context.Context, database *sql.DB, cfg config.Config) error {
|
||||
var count int
|
||||
if err := database.QueryRowContext(ctx, "SELECT COUNT(*) FROM users").Scan(&count); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user