mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 17:35:16 +00:00
0.0.13
- Fix multiscrobbler support
This commit is contained in:
parent
67e43b8984
commit
ca7ef56326
@ -3,7 +3,7 @@ stages:
|
|||||||
- bundle
|
- bundle
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
VERSION: 0.0.10
|
VERSION: 0.0.13
|
||||||
|
|
||||||
build-go:
|
build-go:
|
||||||
image: golang:1.16.2
|
image: golang:1.16.2
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
# 0.0.13
|
||||||
|
- Fix multiscrobbler support
|
||||||
|
|
||||||
# 0.0.12
|
# 0.0.12
|
||||||
- Add client TZ support + Selectable on user page
|
- Add client TZ support + Selectable on user page
|
||||||
- Move token auth to GET ?key=XYZ for wider webhook support
|
- Move token auth to GET ?key=XYZ for wider webhook support
|
||||||
|
@ -2,7 +2,8 @@ package goscrobble
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"errors"
|
||||||
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -12,62 +13,46 @@ type MultiScrobblerInput struct {
|
|||||||
Album string `json:"album"`
|
Album string `json:"album"`
|
||||||
Track string `json:"track"`
|
Track string `json:"track"`
|
||||||
PlayedAt time.Time `json:"playDate"`
|
PlayedAt time.Time `json:"playDate"`
|
||||||
Duration string `json:"duration"`
|
Duration int `json:"duration"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseMultiScrobblerInput - Transform API data
|
// ParseMultiScrobblerInput - Transform API data
|
||||||
func ParseMultiScrobblerInput(userUUID string, data map[string]interface{}, ip net.IP, tx *sql.Tx) error {
|
func ParseMultiScrobblerInput(userUUID string, data MultiScrobblerInput, ip net.IP, tx *sql.Tx) error {
|
||||||
// Debugging
|
// Debugging
|
||||||
fmt.Printf("%+v", data)
|
artists := make([]string, 0)
|
||||||
|
albumartists := make([]string, 0)
|
||||||
|
|
||||||
// // Safety Checks
|
// Insert track artists
|
||||||
// if data["artists"] == nil {
|
for _, artist := range data.Artists {
|
||||||
// return errors.New("Missing artist data")
|
artist, err := insertArtist(artist, "", "", tx)
|
||||||
// }
|
|
||||||
|
|
||||||
// if data["album"] == nil {
|
if err != nil {
|
||||||
// return errors.New("Missing album data")
|
log.Printf("%+v", err)
|
||||||
// }
|
return errors.New("Failed to map artist: " + artist.Name)
|
||||||
|
}
|
||||||
|
artists = append(artists, artist.Uuid)
|
||||||
|
}
|
||||||
|
|
||||||
// if data["track"] == nil {
|
// Insert album if not exist
|
||||||
// return errors.New("Missing track data")
|
album, err := insertAlbum(data.Album, "", "", albumartists, tx)
|
||||||
// }
|
if err != nil {
|
||||||
|
log.Printf("%+v", err)
|
||||||
// // Insert track artists
|
return errors.New("Failed to map album")
|
||||||
// for _, artist := range data["artists"] {
|
}
|
||||||
// artist, err := insertArtist(artist.Name, "", artist.ID.String(), tx)
|
|
||||||
|
|
||||||
// if err != nil {
|
|
||||||
// log.Printf("%+v", err)
|
|
||||||
// return errors.New("Failed to map artist: " + artist.Name)
|
|
||||||
// }
|
|
||||||
// artists = append(artists, artist.Uuid)
|
|
||||||
// }
|
|
||||||
// // Insert album if not exist
|
|
||||||
// artists := []string{artist.Uuid}
|
|
||||||
// album, err := insertAlbum(fmt.Sprintf("%s", data["Album"]), fmt.Sprintf("%s", data["Provider_musicbrainzalbum"]), "", artists, tx)
|
|
||||||
// if err != nil {
|
|
||||||
// log.Printf("%+v", err)
|
|
||||||
// return errors.New("Failed to map album")
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Insert track if not exist
|
|
||||||
// length := timestampToSeconds(fmt.Sprintf("%s", data["RunTime"]))
|
|
||||||
// track, err := insertTrack(fmt.Sprintf("%s", data["Name"]), length, fmt.Sprintf("%s", data["Provider_musicbrainztrack"]), "", album.Uuid, artists, tx)
|
|
||||||
// if err != nil {
|
|
||||||
// log.Printf("%+v", err)
|
|
||||||
// return errors.New("Failed to map track")
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Insert scrobble if not exist
|
|
||||||
// timestamp := time.Now()
|
|
||||||
// fmt.Println(timestamp)
|
|
||||||
// err = insertScrobble(userUUID, track.Uuid, "jellyfin", timestamp, ip, tx)
|
|
||||||
// if err != nil {
|
|
||||||
// log.Printf("%+v", err)
|
|
||||||
// return errors.New("Failed to map track")
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Insert track if not exist
|
// Insert track if not exist
|
||||||
|
track, err := insertTrack(data.Track, data.Duration, "", "", album.Uuid, artists, tx)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("%+v", err)
|
||||||
|
return errors.New("Failed to map track")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert scrobble if not exist
|
||||||
|
err = insertScrobble(userUUID, track.Uuid, "multiscrobbler", data.PlayedAt, ip, tx)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("%+v", err)
|
||||||
|
return errors.New("Failed to map track")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -220,13 +220,7 @@ func handleResetPassword(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// serveEndpoint - API stuffs
|
// serveEndpoint - API stuffs
|
||||||
func handleIngress(w http.ResponseWriter, r *http.Request, userUuid string) {
|
func handleIngress(w http.ResponseWriter, r *http.Request, userUuid string) {
|
||||||
bodyJson, err := decodeJson(r.Body)
|
var err error
|
||||||
fmt.Println(err)
|
|
||||||
if err != nil {
|
|
||||||
throwInvalidJson(w)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ip := getUserIp(r)
|
ip := getUserIp(r)
|
||||||
tx, _ := db.Begin()
|
tx, _ := db.Begin()
|
||||||
|
|
||||||
@ -234,7 +228,14 @@ func handleIngress(w http.ResponseWriter, r *http.Request, userUuid string) {
|
|||||||
|
|
||||||
switch ingressType {
|
switch ingressType {
|
||||||
case "jellyfin":
|
case "jellyfin":
|
||||||
err := ParseJellyfinInput(userUuid, bodyJson, ip, tx)
|
bodyJson, err := decodeJson(r.Body)
|
||||||
|
fmt.Println(err)
|
||||||
|
if err != nil {
|
||||||
|
throwInvalidJson(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = ParseJellyfinInput(userUuid, bodyJson, ip, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Err? %+v", err)
|
fmt.Printf("Err? %+v", err)
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
@ -242,8 +243,18 @@ func handleIngress(w http.ResponseWriter, r *http.Request, userUuid string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
case "multiscrobbler":
|
case "multiscrobbler":
|
||||||
err := ParseMultiScrobblerInput(userUuid, bodyJson, ip, tx)
|
msInput := MultiScrobblerInput{}
|
||||||
|
err := json.NewDecoder(r.Body).Decode(&msInput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
tx.Rollback()
|
||||||
|
throwOkError(w, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = ParseMultiScrobblerInput(userUuid, msInput, ip, tx)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
throwOkError(w, err.Error())
|
throwOkError(w, err.Error())
|
||||||
return
|
return
|
||||||
@ -437,7 +448,7 @@ func deleteSpotifyLink(w http.ResponseWriter, r *http.Request, u string, v strin
|
|||||||
|
|
||||||
func fetchServerInfo(w http.ResponseWriter, r *http.Request) {
|
func fetchServerInfo(w http.ResponseWriter, r *http.Request) {
|
||||||
info := ServerInfo{
|
info := ServerInfo{
|
||||||
Version: "0.0.11",
|
Version: "0.0.13",
|
||||||
}
|
}
|
||||||
|
|
||||||
js, _ := json.Marshal(&info)
|
js, _ := json.Marshal(&info)
|
||||||
|
Loading…
Reference in New Issue
Block a user