mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-22 08:25:14 +00:00
0.0.24
- Spotify will now add images on scrobble - Renamed /api/v1/track to tracks to bypass blocklists... (uBlock :()
This commit is contained in:
parent
07bce0ebc2
commit
b1de018b27
@ -3,7 +3,7 @@ stages:
|
|||||||
- bundle
|
- bundle
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
VERSION: 0.0.23
|
VERSION: 0.0.24
|
||||||
|
|
||||||
build-go:
|
build-go:
|
||||||
image: golang:1.16.2
|
image: golang:1.16.2
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
# 0.0.24
|
||||||
|
- Spotify will now add images on scrobble
|
||||||
|
- Renamed /api/v1/track to tracks to bypass blocklists... (uBlock :()
|
||||||
|
|
||||||
# 0.0.23
|
# 0.0.23
|
||||||
- Get top tracks pulling correctly :)
|
- Get top tracks pulling correctly :)
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ type Album struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// insertAlbum - This will return if it exists or create it based on MBID > Name
|
// insertAlbum - This will return if it exists or create it based on MBID > Name
|
||||||
func insertAlbum(name string, mbid string, spotifyId string, artists []string, tx *sql.Tx) (Album, error) {
|
func insertAlbum(name string, mbid string, spotifyId string, artists []string, img string, tx *sql.Tx) (Album, error) {
|
||||||
album := Album{}
|
album := Album{}
|
||||||
|
|
||||||
// Try locate our album
|
// Try locate our album
|
||||||
@ -33,7 +33,7 @@ func insertAlbum(name string, mbid string, spotifyId string, artists []string, t
|
|||||||
|
|
||||||
// If we can't find it. Lets add it!
|
// If we can't find it. Lets add it!
|
||||||
if album.UUID == "" {
|
if album.UUID == "" {
|
||||||
err := insertNewAlbum(&album, name, mbid, spotifyId, tx)
|
err := insertNewAlbum(&album, name, mbid, spotifyId, img, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return album, errors.New("Failed to insert album")
|
return album, errors.New("Failed to insert album")
|
||||||
}
|
}
|
||||||
@ -60,6 +60,13 @@ func insertAlbum(name string, mbid string, spotifyId string, artists []string, t
|
|||||||
album.updateAlbum("spotify_id", spotifyId, tx)
|
album.updateAlbum("spotify_id", spotifyId, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if album.Img == "" {
|
||||||
|
if img != "" {
|
||||||
|
album.Img = img
|
||||||
|
album.updateAlbum("img", img, tx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return album, nil
|
return album, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,14 +85,15 @@ func getAlbumByCol(col string, val string, tx *sql.Tx) Album {
|
|||||||
return album
|
return album
|
||||||
}
|
}
|
||||||
|
|
||||||
func insertNewAlbum(album *Album, name string, mbid string, spotifyId string, tx *sql.Tx) error {
|
func insertNewAlbum(album *Album, name string, mbid string, spotifyId string, img string, tx *sql.Tx) error {
|
||||||
album.UUID = newUUID()
|
album.UUID = newUUID()
|
||||||
album.Name = name
|
album.Name = name
|
||||||
album.MusicBrainzID = mbid
|
album.MusicBrainzID = mbid
|
||||||
album.SpotifyID = spotifyId
|
album.SpotifyID = spotifyId
|
||||||
|
album.Img = img
|
||||||
|
|
||||||
_, err := tx.Exec("INSERT INTO `albums` (`uuid`, `name`, `mbid`, `spotify_id`) "+
|
_, err := tx.Exec("INSERT INTO `albums` (`uuid`, `name`, `mbid`, `spotify_id`, `img`) "+
|
||||||
"VALUES (UUID_TO_BIN(?, true),?,?,?)", album.UUID, album.Name, album.MusicBrainzID, album.SpotifyID)
|
"VALUES (UUID_TO_BIN(?, true),?,?,?,?)", album.UUID, album.Name, album.MusicBrainzID, album.SpotifyID, album.Img)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ type Artist struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// insertArtist - This will return if it exists or create it based on MBID > Name
|
// insertArtist - This will return if it exists or create it based on MBID > Name
|
||||||
func insertArtist(name string, mbid string, spotifyId string, tx *sql.Tx) (Artist, error) {
|
func insertArtist(name string, mbid string, spotifyId string, img string, tx *sql.Tx) (Artist, error) {
|
||||||
artist := Artist{}
|
artist := Artist{}
|
||||||
|
|
||||||
// Try locate our artist
|
// Try locate our artist
|
||||||
@ -33,7 +33,7 @@ func insertArtist(name string, mbid string, spotifyId string, tx *sql.Tx) (Artis
|
|||||||
|
|
||||||
// If we can't find it. Lets add it!
|
// If we can't find it. Lets add it!
|
||||||
if artist.UUID == "" {
|
if artist.UUID == "" {
|
||||||
err := insertNewArtist(&artist, name, mbid, spotifyId, tx)
|
err := insertNewArtist(&artist, name, mbid, spotifyId, img, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error inserting artist: %+v", err)
|
log.Printf("Error inserting artist: %+v", err)
|
||||||
return artist, errors.New("Failed to insert artist")
|
return artist, errors.New("Failed to insert artist")
|
||||||
@ -44,7 +44,7 @@ func insertArtist(name string, mbid string, spotifyId string, tx *sql.Tx) (Artis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates these values if we match earlier!M
|
// Updates these values if we have the data!
|
||||||
if artist.MusicBrainzID == "" {
|
if artist.MusicBrainzID == "" {
|
||||||
if artist.MusicBrainzID != mbid {
|
if artist.MusicBrainzID != mbid {
|
||||||
artist.MusicBrainzID = mbid
|
artist.MusicBrainzID = mbid
|
||||||
@ -59,6 +59,13 @@ func insertArtist(name string, mbid string, spotifyId string, tx *sql.Tx) (Artis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if artist.Img == "" {
|
||||||
|
if img != "" {
|
||||||
|
artist.Img = img
|
||||||
|
artist.updateArtist("img", img, tx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return artist, nil
|
return artist, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,14 +84,15 @@ func getArtistByCol(col string, val string, tx *sql.Tx) Artist {
|
|||||||
return artist
|
return artist
|
||||||
}
|
}
|
||||||
|
|
||||||
func insertNewArtist(artist *Artist, name string, mbid string, spotifyId string, tx *sql.Tx) error {
|
func insertNewArtist(artist *Artist, name string, mbid string, spotifyId string, img string, tx *sql.Tx) error {
|
||||||
artist.UUID = newUUID()
|
artist.UUID = newUUID()
|
||||||
artist.Name = name
|
artist.Name = name
|
||||||
artist.MusicBrainzID = mbid
|
artist.MusicBrainzID = mbid
|
||||||
artist.SpotifyID = spotifyId
|
artist.SpotifyID = spotifyId
|
||||||
|
artist.Img = img
|
||||||
|
|
||||||
_, err := tx.Exec("INSERT INTO `artists` (`uuid`, `name`, `mbid`, `spotify_id`) "+
|
_, err := tx.Exec("INSERT INTO `artists` (`uuid`, `name`, `mbid`, `spotify_id`, `img`) "+
|
||||||
"VALUES (UUID_TO_BIN(?, true),?,?,?)", artist.UUID, artist.Name, artist.MusicBrainzID, artist.SpotifyID)
|
"VALUES (UUID_TO_BIN(?, true),?,?,?,?)", artist.UUID, artist.Name, artist.MusicBrainzID, artist.SpotifyID, artist.Img)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ func ParseJellyfinInput(userUUID string, jf JellyfinRequest, ip net.IP, tx *sql.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Insert artist if not exist
|
// Insert artist if not exist
|
||||||
artist, err := insertArtist(jf.Artist, jf.ProviderMusicbrainzartist, "", tx)
|
artist, err := insertArtist(jf.Artist, jf.ProviderMusicbrainzartist, "", "", tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%+v", err)
|
log.Printf("%+v", err)
|
||||||
return errors.New("Failed to map artist")
|
return errors.New("Failed to map artist")
|
||||||
@ -80,7 +80,7 @@ func ParseJellyfinInput(userUUID string, jf JellyfinRequest, ip net.IP, tx *sql.
|
|||||||
|
|
||||||
// Insert album if not exist
|
// Insert album if not exist
|
||||||
artists := []string{artist.UUID}
|
artists := []string{artist.UUID}
|
||||||
album, err := insertAlbum(jf.Album, jf.ProviderMusicbrainzalbum, "", artists, tx)
|
album, err := insertAlbum(jf.Album, jf.ProviderMusicbrainzalbum, "", artists, "", tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%+v", err)
|
log.Printf("%+v", err)
|
||||||
return errors.New("Failed to map album")
|
return errors.New("Failed to map album")
|
||||||
|
@ -32,7 +32,7 @@ func ParseMultiScrobblerInput(userUUID string, data MultiScrobblerRequest, ip ne
|
|||||||
|
|
||||||
// Insert track artists
|
// Insert track artists
|
||||||
for _, artist := range data.Artists {
|
for _, artist := range data.Artists {
|
||||||
artist, err := insertArtist(artist, "", "", tx)
|
artist, err := insertArtist(artist, "", "", "", tx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%+v", err)
|
log.Printf("%+v", err)
|
||||||
@ -42,7 +42,7 @@ func ParseMultiScrobblerInput(userUUID string, data MultiScrobblerRequest, ip ne
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Insert album if not exist
|
// Insert album if not exist
|
||||||
album, err := insertAlbum(data.Album, "", "", albumartists, tx)
|
album, err := insertAlbum(data.Album, "", "", albumartists, "", tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%+v", err)
|
log.Printf("%+v", err)
|
||||||
return errors.New("Failed to map album")
|
return errors.New("Failed to map album")
|
||||||
|
@ -145,7 +145,13 @@ func ParseSpotifyInput(userUUID string, data spotify.RecentlyPlayedItem, client
|
|||||||
|
|
||||||
// Insert track artists
|
// Insert track artists
|
||||||
for _, artist := range data.Track.Artists {
|
for _, artist := range data.Track.Artists {
|
||||||
artist, err := insertArtist(artist.Name, "", artist.ID.String(), tx)
|
fullArtist, err := client.GetArtist(artist.ID)
|
||||||
|
img := ""
|
||||||
|
if len(fullArtist.Images) > 0 {
|
||||||
|
img = fullArtist.Images[0].URL
|
||||||
|
}
|
||||||
|
|
||||||
|
artist, err := insertArtist(artist.Name, "", artist.ID.String(), img, tx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%+v", err)
|
log.Printf("%+v", err)
|
||||||
@ -163,7 +169,13 @@ func ParseSpotifyInput(userUUID string, data spotify.RecentlyPlayedItem, client
|
|||||||
|
|
||||||
// Insert album artists
|
// Insert album artists
|
||||||
for _, artist := range fulltrack.Album.Artists {
|
for _, artist := range fulltrack.Album.Artists {
|
||||||
albumartist, err := insertArtist(artist.Name, "", artist.ID.String(), tx)
|
fullArtist, err := client.GetArtist(artist.ID)
|
||||||
|
img := ""
|
||||||
|
if len(fullArtist.Images) > 0 {
|
||||||
|
img = fullArtist.Images[0].URL
|
||||||
|
}
|
||||||
|
|
||||||
|
albumartist, err := insertArtist(artist.Name, "", artist.ID.String(), img, tx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%+v", err)
|
log.Printf("%+v", err)
|
||||||
@ -173,7 +185,11 @@ func ParseSpotifyInput(userUUID string, data spotify.RecentlyPlayedItem, client
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Insert album if not exist
|
// Insert album if not exist
|
||||||
album, err := insertAlbum(fulltrack.Album.Name, "", fulltrack.Album.ID.String(), albumartists, tx)
|
albumImage := ""
|
||||||
|
if len(fulltrack.Album.Images) > 0 {
|
||||||
|
albumImage = fulltrack.Album.Images[0].URL
|
||||||
|
}
|
||||||
|
album, err := insertAlbum(fulltrack.Album.Name, "", fulltrack.Album.ID.String(), albumartists, albumImage, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%+v", err)
|
log.Printf("%+v", err)
|
||||||
return errors.New("Failed to map album")
|
return errors.New("Failed to map album")
|
||||||
@ -197,3 +213,7 @@ func ParseSpotifyInput(userUUID string, data spotify.RecentlyPlayedItem, client
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (track *Track) updateImageFromSpotify() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -50,12 +50,12 @@ func HandleRequests(port string) {
|
|||||||
// No Auth
|
// No Auth
|
||||||
v1.HandleFunc("/stats", limitMiddleware(handleStats, lightLimiter)).Methods("GET")
|
v1.HandleFunc("/stats", limitMiddleware(handleStats, lightLimiter)).Methods("GET")
|
||||||
v1.HandleFunc("/profile/{username}", limitMiddleware(getProfile, lightLimiter)).Methods("GET")
|
v1.HandleFunc("/profile/{username}", limitMiddleware(getProfile, lightLimiter)).Methods("GET")
|
||||||
v1.HandleFunc("/artist/top/{uuid}", limitMiddleware(getArtists, lightLimiter)).Methods("GET")
|
v1.HandleFunc("/artists/top/{uuid}", limitMiddleware(getArtists, lightLimiter)).Methods("GET")
|
||||||
v1.HandleFunc("/artist/{uuid}", limitMiddleware(getArtist, lightLimiter)).Methods("GET")
|
v1.HandleFunc("/artists/{uuid}", limitMiddleware(getArtist, lightLimiter)).Methods("GET")
|
||||||
v1.HandleFunc("/album/top/{uuid}", limitMiddleware(getArtists, lightLimiter)).Methods("GET")
|
v1.HandleFunc("/albums/top/{uuid}", limitMiddleware(getArtists, lightLimiter)).Methods("GET")
|
||||||
v1.HandleFunc("/album/{uuid}", limitMiddleware(getAlbum, lightLimiter)).Methods("GET")
|
v1.HandleFunc("/albums/{uuid}", limitMiddleware(getAlbum, lightLimiter)).Methods("GET")
|
||||||
v1.HandleFunc("/track/top/{uuid}", limitMiddleware(getTracks, lightLimiter)).Methods("GET")
|
v1.HandleFunc("/tracks/top/{uuid}", limitMiddleware(getTracks, lightLimiter)).Methods("GET")
|
||||||
v1.HandleFunc("/track/{uuid}", limitMiddleware(getTrack, lightLimiter)).Methods("GET")
|
v1.HandleFunc("/tracks/{uuid}", limitMiddleware(getTrack, lightLimiter)).Methods("GET")
|
||||||
|
|
||||||
v1.HandleFunc("/register", limitMiddleware(handleRegister, heavyLimiter)).Methods("POST")
|
v1.HandleFunc("/register", limitMiddleware(handleRegister, heavyLimiter)).Methods("POST")
|
||||||
v1.HandleFunc("/login", limitMiddleware(handleLogin, standardLimiter)).Methods("POST")
|
v1.HandleFunc("/login", limitMiddleware(handleLogin, standardLimiter)).Methods("POST")
|
||||||
@ -665,7 +665,7 @@ func getServerInfo(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
info := ServerInfo{
|
info := ServerInfo{
|
||||||
Version: "0.0.23",
|
Version: "0.0.24",
|
||||||
RegistrationEnabled: cachedRegistrationEnabled,
|
RegistrationEnabled: cachedRegistrationEnabled,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ func StartBackgroundWorkers() {
|
|||||||
endTicker := make(chan bool)
|
endTicker := make(chan bool)
|
||||||
|
|
||||||
hourTicker := time.NewTicker(time.Hour)
|
hourTicker := time.NewTicker(time.Hour)
|
||||||
minuteTicker := time.NewTicker(time.Duration(1) * time.Minute)
|
minuteTicker := time.NewTicker(time.Duration(60) * time.Second)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
|
@ -292,7 +292,7 @@ export const getServerInfo = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const getArtist = (uuid) => {
|
export const getArtist = (uuid) => {
|
||||||
return axios.get(process.env.REACT_APP_API_URL + "artist/" + uuid).then(
|
return axios.get(process.env.REACT_APP_API_URL + "artists/" + uuid).then(
|
||||||
(data) => {
|
(data) => {
|
||||||
return data.data;
|
return data.data;
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
@ -301,7 +301,7 @@ export const getArtist = (uuid) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getAlbum = (uuid) => {
|
export const getAlbum = (uuid) => {
|
||||||
return axios.get(process.env.REACT_APP_API_URL + "album/" + uuid).then(
|
return axios.get(process.env.REACT_APP_API_URL + "albums/" + uuid).then(
|
||||||
(data) => {
|
(data) => {
|
||||||
return data.data;
|
return data.data;
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
@ -310,7 +310,7 @@ export const getAlbum = (uuid) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getTrack = (uuid) => {
|
export const getTrack = (uuid) => {
|
||||||
return axios.get(process.env.REACT_APP_API_URL + "track/" + uuid).then(
|
return axios.get(process.env.REACT_APP_API_URL + "tracks/" + uuid).then(
|
||||||
(data) => {
|
(data) => {
|
||||||
return data.data;
|
return data.data;
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
@ -319,7 +319,7 @@ export const getTrack = (uuid) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getTopTracks = (uuid) => {
|
export const getTopTracks = (uuid) => {
|
||||||
return axios.get(process.env.REACT_APP_API_URL + "track/top/" + uuid).then(
|
return axios.get(process.env.REACT_APP_API_URL + "tracks/top/" + uuid).then(
|
||||||
(data) => {
|
(data) => {
|
||||||
return data.data;
|
return data.data;
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user