60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
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))
|
|
}
|