diff --git a/main.go b/main.go
index c60295a..1a7d925 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,3 @@
-// Copyright (c) 2026 Jeremy Baxter.
-// entry point for records
-
package main
import (
@@ -19,33 +16,18 @@ const version = "0-pre"
var addr *string
var port *uint16
-var tempDir *string
-var deleteAndExit *bool
var regenerate *bool
var showVersion *bool
func main() {
addr = getopt.String('a', "0.0.0.0")
port = getopt.Uint16('p', 8000)
- tempDir = getopt.String('t', "")
- deleteAndExit = getopt.Bool('d')
regenerate = getopt.Bool('r')
showVersion = getopt.Bool('V')
if err := getopt.Getopt(nil); err != nil {
util.Die(err.Error())
}
- if len(*tempDir) != 0 {
- musicindex.TempDir = *tempDir
- }
-
- if *deleteAndExit {
- err := os.RemoveAll(musicindex.TempDir)
- if err != nil {
- util.Die("cannot remove %s: %s", musicindex.TempDir, err.Error())
- }
- os.Exit(0)
- }
if *showVersion {
fmt.Printf("records %s\n", version)
os.Exit(0)
@@ -53,20 +35,13 @@ func main() {
args := getopt.Args()
if len(args) != 1 {
- fmt.Fprintf(os.Stderr, "usage: %s [-drV] [-a address] [-p port] directory\n", os.Args[0])
+ fmt.Fprintf(os.Stderr, "usage: %s [-rV] [-a address] [-p port] directory\n", os.Args[0])
os.Exit(1)
}
mediaDir := args[0]
- {
- interactive := ""
- if util.Interactive() {
- interactive = ", running with interactive features"
- }
- log.Printf("This is records %s%s", version, interactive)
- }
-
+ log.Printf("This is records %s\n", version)
log.Println("https://git.baxters.nz/jeremy/records")
musicindex.Init(mediaDir, *regenerate)
diff --git a/musicindex/index.go b/musicindex/index.go
index 8a41d95..3c034c1 100644
--- a/musicindex/index.go
+++ b/musicindex/index.go
@@ -1,6 +1,3 @@
-// Copyright (c) 2026 Jeremy Baxter.
-// Music library indexing code
-
package musicindex
import (
@@ -116,13 +113,11 @@ func indexAlbums(artist *Artist) (albums map[string]Album) {
albums = make(map[string]Album)
for _, albumName := range entries {
- util.Iprint("\033[2K\r \033[1;36mcaching\033[0m %s - %s",
- artist.Name, albumName)
+ util.Iprint("* index %s - %s\r", artist.Name, albumName)
albumDir := artistDir + "/" + albumName
album, err := indexAlbum(artist, albumName, albumDir)
if err != nil {
- util.Iprint("\r")
log.Printf("warn: skipping inaccessible album %s: %s", albumName, err.Error())
} else {
albums[albumName] = album
diff --git a/musicindex/musicindex.go b/musicindex/musicindex.go
index b78d0ff..b70b0d3 100644
--- a/musicindex/musicindex.go
+++ b/musicindex/musicindex.go
@@ -1,5 +1,7 @@
-// Copyright (c) 2026 Jeremy Baxter.
-// In-memory album and song database
+// musicindex.go
+// Copyright (c) 2025 Jeremy Baxter.
+
+// Ephemeral music (artist, album, cover & track) index
package musicindex
diff --git a/server/pages.go b/server/pages.go
index 5bc4e72..3d21cee 100644
--- a/server/pages.go
+++ b/server/pages.go
@@ -1,6 +1,3 @@
-// Copyright (c) 2026 Jeremy Baxter.
-// HTML builders
-
package server
import (
@@ -31,8 +28,7 @@ type Page interface {
func writePage(p Page, w http.ResponseWriter) {
t, err := template.ParseFS(staticFS, "static/templates/" + p.SourceFile())
if err != nil {
- http.Error(w, "Internal server error: " + err.Error(),
- http.StatusInternalServerError)
+ http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -42,26 +38,13 @@ func writePage(p Page, w http.ResponseWriter) {
}
}
-type ErrorPage struct {
- Status string
- Reason string
-}
-
-func MakeErrorPage(status, reason string) (p ErrorPage) {
- p.Status = status
- p.Reason = reason
- return
-}
-
-func (p ErrorPage) SourceFile() string { return "error.html" }
-func (p ErrorPage) Title() string { return "" }
-func (p ErrorPage) Body() template.HTML { return template.HTML("") }
-
type IndexPage struct {
Showcase string
}
-func MakeIndexPage() (p IndexPage) {
+func MakeIndexPage() IndexPage {
+ var p IndexPage
+
albums := musicindex.Albums()
rand.Shuffle(len(albums), func(i, j int) {
albums[i], albums[j] = albums[j], albums[i]
@@ -85,11 +68,9 @@ func MakeIndexPage() (p IndexPage) {
}
b.WriteString(``)
}
-
b.WriteString(``)
p.Showcase = b.String()
-
- return
+ return p
}
func (p IndexPage) SourceFile() string { return "base.html" }
@@ -118,7 +99,8 @@ func ArtistSortOptions() []string {
return []string{"name", "albums", "songs"}
}
-func MakeArtistsPage(sortBy string) (p ArtistsPage) {
+func MakeArtistsPage(sortBy string) ArtistsPage {
+ var p ArtistsPage
var b strings.Builder
artistNames := musicindex.Artists()
@@ -153,11 +135,9 @@ func MakeArtistsPage(sortBy string) (p ArtistsPage) {
b.WriteString(fmt.Sprintf("
%d album%s, %d songs
",
albums, util.OptionalString(albums != 1, "s"), artist.Songs))
}
-
b.WriteString(``)
p.bodyHTML = b.String()
-
- return
+ return p
}
func (p ArtistsPage) SourceFile() string { return "base.html" }
@@ -213,13 +193,14 @@ func writeAlbums(b *strings.Builder, sortBy string, albums []musicindex.Album, a
b.WriteString(``)
}
-func MakeAlbumsPage(sortBy string) (p AlbumsPage) {
+func MakeAlbumsPage(sortBy string) AlbumsPage {
+ var p AlbumsPage
var b strings.Builder
writeAlbums(&b, sortBy, musicindex.Albums(), false)
p.bodyHTML = b.String()
- return
+ return p
}
func (p AlbumsPage) SourceFile() string { return "base.html" }
@@ -231,7 +212,8 @@ type ArtistPage struct {
bodyHTML string
}
-func MakeArtistPage(sortBy string, name string) (p ArtistPage) {
+func MakeArtistPage(sortBy string, name string) ArtistPage {
+ var p ArtistPage
var b strings.Builder
artist := musicindex.FindArtist(name)
@@ -242,7 +224,7 @@ func MakeArtistPage(sortBy string, name string) (p ArtistPage) {
p.Artist = artist
p.bodyHTML = b.String()
- return
+ return p
}
func (p ArtistPage) SourceFile() string { return "base.html" }
@@ -254,7 +236,8 @@ type AlbumPage struct {
bodyHTML string
}
-func MakeAlbumPage(album musicindex.Album) (p AlbumPage) {
+func MakeAlbumPage(album musicindex.Album) AlbumPage {
+ var p AlbumPage
var b strings.Builder
b.WriteString(`