refactor(server/m7-353): consolidate findSidecarCover into coverart package
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/coverart"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/playevents"
|
||||
)
|
||||
@@ -143,28 +144,7 @@ func resolveAlbumCoverPath(ctx context.Context, q *dbq.Queries, album dbq.Album)
|
||||
if err != nil || len(tracks) == 0 {
|
||||
return ""
|
||||
}
|
||||
return findSidecarCover(tracks[0].FilePath)
|
||||
}
|
||||
|
||||
// sidecarNames are the conventional names for album art living next to audio
|
||||
// files. Order matches how most library tools write them — cover.* wins over
|
||||
// folder.*, and JPEG wins over PNG when both are present.
|
||||
var sidecarNames = []string{
|
||||
"cover.jpg", "cover.jpeg", "cover.png",
|
||||
"folder.jpg", "folder.jpeg", "folder.png",
|
||||
}
|
||||
|
||||
// findSidecarCover looks for a cover image in the directory containing the
|
||||
// given track file. Returns "" if no sidecar exists.
|
||||
func findSidecarCover(trackPath string) string {
|
||||
dir := filepath.Dir(trackPath)
|
||||
for _, name := range sidecarNames {
|
||||
candidate := filepath.Join(dir, name)
|
||||
if info, err := os.Stat(candidate); err == nil && !info.IsDir() {
|
||||
return candidate
|
||||
}
|
||||
}
|
||||
return ""
|
||||
return coverart.FindSidecar(filepath.Dir(tracks[0].FilePath))
|
||||
}
|
||||
|
||||
func serveImage(w http.ResponseWriter, r *http.Request, path string) {
|
||||
|
||||
Reference in New Issue
Block a user