diff --git a/.gitignore b/.gitignore index a8215b4..a3d38b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -lastfm-data -spotify-data +imports diff --git a/README.md b/README.md index 96e67bd..44b5f74 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,30 @@ -# muzi - -Self hosted music listening statistics +# Muzi +## Self-hosted music listening statistics ### Dependencies - PostgreSQL -### Spotify Import Instructions (for testing and development): -- Navigate to the muzi project root dir -- Create a folder called "spotify-data" -- Inside the new "spotify-data" folder create a folder called "zip" -- Place all zip archives that you obtained from Spotify in this folder. -- Ensure the PostgreSQL server is running locally on port 5432. -- Run muzi.go -- All Spotify tracks that have > 20 second playtime will congregate into the muzi PostgreSQL database +### Installation Instructions (for testing and development) \[Only Supports Spotify Imports ATM\]: +1. Clone the repo:
```git clone https://github.com/riwiwa/muzi``` +2. Copy over all zip archives obtained from Spotify into the ```imports/spotify-data/zip/``` directory. +3. Ensure PostgreSQL is installed and running locally on port 5432. +4. Run the app with:
```go run main.go``` +5. Navigate to ```localhost:1234/history``` to see your sorted listening history. +6. Comment out ```importsongs.ImportSpotify()``` from ```main.go``` to prevent the app's attempts to import the Spotify data again -### plans: -- Ability to import all listening statistics and scrobbles from lastfm, spotify, apple music -- daily, weekly, monthly, yearly, lifetime presets for listening reports -- ability to specify a certain point in time from one datetime to another to list data -- grid maker (3x3-10x10) -- multi artist scrobbling -- ability to change artist image -- webUI -- ability to "sync" scrobbles (send from a device to the server) -- live scrobbling to the server -- batch scrobble editor +### Roadmap: +- Ability to import all listening statistics and scrobbles from: \[In Progress\] + - lastfm + - spotify \[Complete\] + - apple music + +- WebUI \[In Progress\] + - Full listening history with time \[Functional\] + - Daily, weekly, monthly, yearly, lifetime presets for listening reports + - Ability to specify a certain point in time from one datetime to another to list data + - Grid maker (3x3-10x10) + - Ability to change artist image +- Multi artist scrobbling +- Ability to "sync" offline scrobbles (send from a device to the server) +- Live scrobbling to the server +- Batch scrobble editor diff --git a/importsongs/importsongs.go b/importsongs/importsongs.go index f853a34..7cee95d 100644 --- a/importsongs/importsongs.go +++ b/importsongs/importsongs.go @@ -31,7 +31,6 @@ func TableExists(name string, conn *pgx.Conn) bool { func DbExists() bool { conn, err := pgx.Connect(context.Background(), "postgres://postgres:postgres@localhost:5432/muzi") if err != nil { - fmt.Fprintf(os.Stderr, "Cannot connect to muzi database: %v\n", err) return false } defer conn.Close(context.Background()) @@ -152,8 +151,8 @@ func AddDirToDB(path string, platform int) { } func ImportSpotify() { - path := filepath.Join(".", "spotify-data", "zip") - targetBase := filepath.Join(".", "spotify-data", "extracted") + path := filepath.Join(".", "imports", "spotify", "zip") + targetBase := filepath.Join(".", "imports", "spotify", "extracted") entries, err := os.ReadDir(path) if err != nil { panic(err) diff --git a/main.go b/main.go index f680a4b..ade7be8 100644 --- a/main.go +++ b/main.go @@ -1,10 +1,73 @@ package main import ( - //"muzi/importsongs" + "errors" + "fmt" + "muzi/importsongs" "muzi/web" + "os" ) +func dbCheck() error { + if !importsongs.DbExists() { + err := importsongs.CreateDB() + if err != nil { + fmt.Fprintf(os.Stderr, "Error creating muzi DB: %v\n", err) + return err + } + } + return nil +} + +func dirCheck(path string) error { + + _, err := os.Stat(path) + if err != nil { + if errors.Is(err, os.ErrNotExist) { + os.MkdirAll(path, os.ModePerm) + } else { + fmt.Fprintf(os.Stderr, "Error checking dir: %s: %v\n", path, err) + return err + } + } + + return nil +} + func main() { + dirImports := "./imports/" + + dirSpotify := "./imports/spotify/" + dirSpotifyZip := "./imports/spotify/zip/" + dirSpotifyExt := "./imports/spotify/extracted/" + + dirLastFM := "./imports/lastfm/" + + err := dirCheck(dirImports) + if err != nil { + return + } + err = dirCheck(dirSpotify) + if err != nil { + return + } + err = dirCheck(dirSpotifyZip) + if err != nil { + return + } + err = dirCheck(dirSpotifyExt) + if err != nil { + return + } + err = dirCheck(dirLastFM) + if err != nil { + return + } + err = dbCheck() + if err != nil { + return + } + + //importsongs.ImportSpotify() web.Start() } diff --git a/web/web.go b/web/web.go index 14c9bbf..3aee950 100644 --- a/web/web.go +++ b/web/web.go @@ -143,11 +143,13 @@ func tmp(w http.ResponseWriter, r *http.Request) { } func Start() { + addr := ":1234" r := chi.NewRouter() r.Use(middleware.Logger) r.Get("/static/style.css", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./static/style.css") }) r.Get("/history", tmp) - http.ListenAndServe(":1234", r) + fmt.Printf("WebUI starting on %s\n", addr) + http.ListenAndServe(addr, r) }