initial commit

This commit is contained in:
Jeremy Baxter 2026-01-04 23:33:46 +13:00
commit 32a57cc050
12 changed files with 1169 additions and 0 deletions

60
main.go Normal file
View file

@ -0,0 +1,60 @@
package main
import (
"fmt"
"log"
"os"
"github.com/pborman/getopt"
"git.baxters.nz/jeremy/records/musicindex"
"git.baxters.nz/jeremy/records/server"
"git.baxters.nz/jeremy/records/util"
)
const version = "0-pre"
var addr *string
var port *uint16
var showVersion *bool
func main() {
addr = getopt.String('a', "0.0.0.0")
port = getopt.Uint16('p', 8000)
showVersion = getopt.Bool('V')
if err := getopt.Getopt(nil); err != nil {
util.Die(err.Error())
}
if *showVersion {
fmt.Printf("records %s\n", version)
os.Exit(0)
}
args := getopt.Args()
if len(args) != 1 {
fmt.Fprintf(os.Stderr, "usage: %s [-V] [-a address] [-p port] directory\n", os.Args[0])
os.Exit(1)
}
mediaDir := args[0]
log.Printf("This is records %s\n", version)
log.Println("https://git.baxters.nz/jeremy/records")
musicindex.Init(mediaDir)
var artistCount, albumCount, songCount int
artistCount = len(musicindex.Artists())
albumCount = 0
songCount = 0
for _, album := range musicindex.Albums() {
songCount += len(album.TrackFiles)
albumCount++
}
log.Printf("indexed %d artists, %d albums and %d songs\n",
artistCount, albumCount, songCount);
server.RunOn(fmt.Sprintf("%s:%d", *addr, *port))
}