diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 8c76eab8..157e1ebf 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -3,7 +3,7 @@ stages:
- bundle
variables:
- VERSION: 0.0.17
+ VERSION: 0.0.18
build-go:
image: golang:1.16.2
diff --git a/docs/changelog.md b/docs/changelog.md
index a6cc9de1..0b64ab50 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -1,3 +1,7 @@
+# 0.0.18
+- Add MBID/Spotify Autolinking if track exists
+- Add Genre table + .go files
+
# 0.0.17
- Add check for registration_enabled on /register endpoint
- Made songlookup check artist name as well
diff --git a/internal/goscrobble/album.go b/internal/goscrobble/album.go
index c4fa70e9..038c5d00 100644
--- a/internal/goscrobble/album.go
+++ b/internal/goscrobble/album.go
@@ -12,8 +12,8 @@ type Album struct {
Name string `json:"name"`
Desc sql.NullString `json:"desc"`
Img sql.NullString `json:"img"`
- MusicBrainzID sql.NullString `json:"mbid"`
- SpotifyID sql.NullString `json:"spotify_id"`
+ MusicBrainzID string `json:"mbid"`
+ SpotifyID string `json:"spotify_id"`
}
// insertAlbum - This will return if it exists or create it based on MBID > Name
@@ -61,6 +61,16 @@ func insertAlbum(name string, mbid string, spotifyId string, artists []string, t
return album, errors.New("Unable to fetch album!")
}
+ if album.MusicBrainzID != mbid {
+ album.MusicBrainzID = mbid
+ album.updateAlbum("mbid", mbid, tx)
+ }
+
+ if album.SpotifyID != spotifyId {
+ album.SpotifyID = spotifyId
+ album.updateAlbum("spotify_id", spotifyId, tx)
+ }
+
return album, nil
}
@@ -100,8 +110,8 @@ func (album *Album) linkAlbumToArtists(artists []string, tx *sql.Tx) error {
return err
}
-func updateAlbum(uuid string, col string, val string, tx *sql.Tx) error {
- _, err := tx.Exec("UPDATE `albums` SET `"+col+"` = ? WHERE `uuid` = UUID_TO_BIN(?,true)", val, uuid)
+func (album *Album) updateAlbum(col string, val string, tx *sql.Tx) error {
+ _, err := tx.Exec("UPDATE `albums` SET `"+col+"` = ? WHERE `uuid` = UUID_TO_BIN(?,true)", val, album.Uuid)
return err
}
diff --git a/internal/goscrobble/artist.go b/internal/goscrobble/artist.go
index 39109346..5e4331e5 100644
--- a/internal/goscrobble/artist.go
+++ b/internal/goscrobble/artist.go
@@ -11,8 +11,8 @@ type Artist struct {
Name string `json:"name"`
Desc sql.NullString `json:"desc"`
Img sql.NullString `json:"img"`
- MusicBrainzID sql.NullString `json:"mbid"`
- SpotifyID sql.NullString `json:"spotify_id"`
+ MusicBrainzID string `json:"mbid"`
+ SpotifyID string `json:"spotify_id"`
}
// insertArtist - This will return if it exists or create it based on MBID > Name
@@ -55,6 +55,16 @@ func insertArtist(name string, mbid string, spotifyId string, tx *sql.Tx) (Artis
return artist, errors.New("Unable to fetch artist!")
}
+ if artist.MusicBrainzID != mbid {
+ artist.MusicBrainzID = mbid
+ artist.updateArtist("mbid", mbid, tx)
+ }
+
+ if artist.SpotifyID != spotifyId {
+ artist.SpotifyID = spotifyId
+ artist.updateArtist("spotify_id", spotifyId, tx)
+ }
+
return artist, nil
}
@@ -80,8 +90,8 @@ func insertNewArtist(name string, mbid string, spotifyId string, tx *sql.Tx) err
return err
}
-func updateArtist(uuid string, col string, val string, tx *sql.Tx) error {
- _, err := tx.Exec("UPDATE `artists` SET `"+col+"` = ? WHERE `uuid` = UUID_TO_BIN(?,true)", val, uuid)
+func (artist *Artist) updateArtist(col string, val string, tx *sql.Tx) error {
+ _, err := tx.Exec("UPDATE `artists` SET `"+col+"` = ? WHERE `uuid` = UUID_TO_BIN(?,true)", val, artist.Uuid)
return err
}
diff --git a/internal/goscrobble/genre.go b/internal/goscrobble/genre.go
new file mode 100644
index 00000000..57468ec6
--- /dev/null
+++ b/internal/goscrobble/genre.go
@@ -0,0 +1,47 @@
+package goscrobble
+
+import (
+ "database/sql"
+ "log"
+)
+
+type Genre struct {
+ UUID string `json:"uuid"`
+ Name string `json:"name"`
+}
+
+func getGenre(uuid string) Genre {
+ var genre Genre
+ err := db.QueryRow(
+ "SELECT BIN_TO_UUID(`uuid`, true), `name` FROM `artists` WHERE `uuid` = UUID_TO_BIN(?,true)",
+ uuid).Scan(&genre.UUID, &genre.Name)
+
+ if err != nil {
+ if err != sql.ErrNoRows {
+ log.Printf("Error fetching artists: %+v", err)
+ }
+ }
+
+ return genre
+}
+
+func getGenreByName(name string) Genre {
+ var genre Genre
+ err := db.QueryRow(
+ "SELECT BIN_TO_UUID(`uuid`, true), `name` FROM `artists` WHERE `name` = ?",
+ name).Scan(&genre.UUID, &genre.Name)
+
+ if err != nil {
+ if err != sql.ErrNoRows {
+ log.Printf("Error fetching artists: %+v", err)
+ }
+ }
+
+ return genre
+}
+
+func (genre *Genre) updateGenreName(name string, value string) error {
+ _, err := db.Exec("UPDATE `genres` SET `name` = ? WHERE uuid = UUID_TO_BIN(?, true)", name, genre.UUID)
+
+ return err
+}
diff --git a/internal/goscrobble/server.go b/internal/goscrobble/server.go
index 6fabb963..c0bc1c9a 100644
--- a/internal/goscrobble/server.go
+++ b/internal/goscrobble/server.go
@@ -252,6 +252,7 @@ func handleIngress(w http.ResponseWriter, r *http.Request, userUuid string) {
err = ParseJellyfinInput(userUuid, jfInput, ip, tx)
if err != nil {
+ fmt.Println(err)
tx.Rollback()
throwOkError(w, err.Error())
return
@@ -477,7 +478,7 @@ func fetchServerInfo(w http.ResponseWriter, r *http.Request) {
}
info := ServerInfo{
- Version: "0.0.17",
+ Version: "0.0.18",
RegistrationEnabled: cachedRegistrationEnabled,
}
diff --git a/internal/goscrobble/track.go b/internal/goscrobble/track.go
index 1f3566b7..1b7ce44b 100644
--- a/internal/goscrobble/track.go
+++ b/internal/goscrobble/track.go
@@ -3,6 +3,7 @@ package goscrobble
import (
"database/sql"
"errors"
+ "fmt"
"log"
"strings"
)
@@ -13,8 +14,8 @@ type Track struct {
Length int `json:"length"`
Desc sql.NullString `json:"desc"`
Img sql.NullString `json:"img"`
- MusicBrainzID sql.NullString `json:"mbid"`
- SpotifyID sql.NullString `json:"spotify_id"`
+ MusicBrainzID string `json:"mbid"`
+ SpotifyID string `json:"spotify_id"`
}
// insertTrack - This will return if it exists or create it based on MBID > Name
@@ -24,14 +25,16 @@ func insertTrack(name string, legnth int, mbid string, spotifyId string, album s
// Try locate our track
if mbid != "" {
track = fetchTrack("mbid", mbid, tx)
+ fmt.Printf("Fetech mbid: %s", mbid)
} else if spotifyId != "" {
track = fetchTrack("spotify_id", spotifyId, tx)
+ fmt.Printf("Fetech spotify: %s", spotifyId)
}
// If it didn't match above, lookup by name
if track.Uuid == "" {
// TODO: add artist check here too
- track = fetchTrackWithArtists(name, artists, tx)
+ track = fetchTrackWithArtists(name, artists, album, tx)
}
// If we can't find it. Lets add it!
@@ -49,7 +52,7 @@ func insertTrack(name string, legnth int, mbid string, spotifyId string, album s
}
if track.Uuid == "" {
- track = fetchTrackWithArtists(name, artists, tx)
+ track = fetchTrackWithArtists(name, artists, album, tx)
}
err = track.linkTrack(album, artists, tx)
@@ -62,13 +65,23 @@ func insertTrack(name string, legnth int, mbid string, spotifyId string, album s
return track, errors.New("Unable to fetch track!")
}
+ if track.MusicBrainzID != mbid {
+ track.MusicBrainzID = mbid
+ track.updateTrack("mbid", mbid, tx)
+ }
+
+ if track.SpotifyID != spotifyId {
+ track.SpotifyID = spotifyId
+ track.updateTrack("spotify_id", spotifyId, tx)
+ }
+
return track, nil
}
func fetchTrack(col string, val string, tx *sql.Tx) Track {
var track Track
err := tx.QueryRow(
- "SELECT BIN_TO_UUID(`uuid`, true), `name`, `desc`, `img`, `mbid` FROM `tracks` WHERE `"+col+"` = ?",
+ "SELECT BIN_TO_UUID(`uuid`, true), `name`, `desc`, `img`, `mbid` FROM `tracks` WHERE `"+col+"` = ? LIMIT 1",
val).Scan(&track.Uuid, &track.Name, &track.Desc, &track.Img, &track.MusicBrainzID)
if err != nil {
@@ -80,15 +93,16 @@ func fetchTrack(col string, val string, tx *sql.Tx) Track {
return track
}
-func fetchTrackWithArtists(name string, artists []string, tx *sql.Tx) Track {
+func fetchTrackWithArtists(name string, artists []string, album string, tx *sql.Tx) Track {
var track Track
artistString := strings.Join(artists, "','")
-
err := tx.QueryRow(
"SELECT BIN_TO_UUID(`uuid`, true), `name`, `desc`, `img`, `mbid` FROM `tracks` "+
"LEFT JOIN `track_artist` ON `tracks`.`uuid` = `track_artist`.`track` "+
- "WHERE `name` = ? AND BIN_TO_UUID(`track_artist`.`artist`, true) IN ('`"+artistString+"`')",
- name).Scan(&track.Uuid, &track.Name, &track.Desc, &track.Img, &track.MusicBrainzID)
+ "LEFT JOIN `track_album` ON `tracks`.`uuid` = `track_album`.`track` "+
+ "WHERE `name` = ? AND BIN_TO_UUID(`track_artist`.`artist`, true) IN ('"+artistString+"') "+
+ "AND BIN_TO_UUID(`track_album`.`album`,true) = ? LIMIT 1",
+ name, album).Scan(&track.Uuid, &track.Name, &track.Desc, &track.Img, &track.MusicBrainzID)
if err != nil {
if err != sql.ErrNoRows {
@@ -138,8 +152,8 @@ func (track Track) linkTrackToArtists(artists []string, tx *sql.Tx) error {
return nil
}
-func updateTrack(uuid string, col string, val string, tx *sql.Tx) error {
- _, err := tx.Exec("UPDATE `tracks` SET `"+col+"` = ? WHERE `uuid` = UUID_TO_BIN(?,true)", val, uuid)
+func (track *Track) updateTrack(col string, val string, tx *sql.Tx) error {
+ _, err := tx.Exec("UPDATE `tracks` SET `"+col+"` = ? WHERE `uuid` = UUID_TO_BIN(?,true)", val, track.Uuid)
return err
}
diff --git a/migrations/11_genres.down.sql b/migrations/11_genres.down.sql
new file mode 100644
index 00000000..893e6e8c
--- /dev/null
+++ b/migrations/11_genres.down.sql
@@ -0,0 +1 @@
+DROP TABLE IF EXISTS `genres`;
\ No newline at end of file
diff --git a/migrations/11_genres.up.sql b/migrations/11_genres.up.sql
new file mode 100644
index 00000000..96d39e59
--- /dev/null
+++ b/migrations/11_genres.up.sql
@@ -0,0 +1,5 @@
+CREATE TABLE IF NOT EXISTS `genres` (
+ `uuid` BINARY(16) PRIMARY KEY,
+ `name` VARCHAR(255) NOT NULL,
+ KEY `nameLookup` (`name`)
+) DEFAULT CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;
\ No newline at end of file
diff --git a/migrations/4_mbid.up.sql b/migrations/4_mbid.up.sql
index e7627442..62a34f60 100644
--- a/migrations/4_mbid.up.sql
+++ b/migrations/4_mbid.up.sql
@@ -1,7 +1,7 @@
START TRANSACTION;
-ALTER TABLE albums ADD COLUMN `mbid` VARCHAR(36) DEFAULT NULL;
-ALTER TABLE artists ADD COLUMN `mbid` VARCHAR(36) DEFAULT NULL;
-ALTER TABLE tracks ADD COLUMN `mbid` VARCHAR(36) DEFAULT NULL;
+ALTER TABLE albums ADD COLUMN `mbid` VARCHAR(36) DEFAULT '';
+ALTER TABLE artists ADD COLUMN `mbid` VARCHAR(36) DEFAULT '';
+ALTER TABLE tracks ADD COLUMN `mbid` VARCHAR(36) DEFAULT '';
COMMIT;
diff --git a/migrations/9_spotify.up.sql b/migrations/9_spotify.up.sql
index 6c828d98..8b3e89fc 100644
--- a/migrations/9_spotify.up.sql
+++ b/migrations/9_spotify.up.sql
@@ -1,9 +1,9 @@
START TRANSACTION;
-ALTER TABLE `users` ADD COLUMN `spotify_id` VARCHAR(255) DEFAULT '';
-ALTER TABLE `albums` ADD COLUMN `spotify_id` VARCHAR(255) DEFAULT '';
-ALTER TABLE `artists` ADD COLUMN `spotify_id` VARCHAR(255) DEFAULT '';
-ALTER TABLE `tracks` ADD COLUMN `spotify_id` VARCHAR(255) DEFAULT '';
+ALTER TABLE `users` ADD COLUMN `spotify_id` VARCHAR(255) NOT NULL DEFAULT '';
+ALTER TABLE `albums` ADD COLUMN `spotify_id` VARCHAR(255) NOT NULL DEFAULT '';
+ALTER TABLE `artists` ADD COLUMN `spotify_id` VARCHAR(255) NOT NULL DEFAULT '';
+ALTER TABLE `tracks` ADD COLUMN `spotify_id` VARCHAR(255) NOT NULL DEFAULT '';
ALTER TABLE `users` ADD INDEX `spotifyLookup` (`spotify_id`);
ALTER TABLE `albums` ADD INDEX `spotifyLookup` (`spotify_id`);
diff --git a/web/src/App.css b/web/src/App.css
index 5616be07..e4ac4b25 100644
--- a/web/src/App.css
+++ b/web/src/App.css
@@ -44,6 +44,11 @@ html, body {
color: white;
}
+.pageBody {
+ padding: 20px 5px 5px 5px;
+ font-size: 16pt;
+}
+
.App-link {
color: #61dafb;
}
diff --git a/web/src/App.js b/web/src/App.js
index 4cf1fb2c..bd10e51a 100644
--- a/web/src/App.js
+++ b/web/src/App.js
@@ -3,6 +3,9 @@ import Home from './Pages/Home';
import About from './Pages/About';
import Dashboard from './Pages/Dashboard';
import Profile from './Pages/Profile';
+import Artist from './Pages/Artist';
+import Album from './Pages/Album';
+import Track from './Pages/Track';
import User from './Pages/User';
import Admin from './Pages/Admin';
import Login from './Pages/Login';
@@ -33,6 +36,9 @@ const App = () => {
All the settings
diff --git a/web/src/Pages/Track.css b/web/src/Pages/Track.css new file mode 100644 index 00000000..e69de29b diff --git a/web/src/Pages/Track.js b/web/src/Pages/Track.js new file mode 100644 index 00000000..c992cb4e --- /dev/null +++ b/web/src/Pages/Track.js @@ -0,0 +1,59 @@ +import React, { useState, useEffect } from 'react'; +import '../App.css'; +import './Track.css'; +import ScaleLoader from 'react-spinners/ScaleLoader'; +import ScrobbleTable from '../Components/ScrobbleTable' + +const Track = (route) => { + const [loading, setLoading] = useState(true); + const [profile, setProfile] = useState({}); + + let artist = false; + if (route && route.match && route.match.params && route.match.params.uuid) { + artist = route.match.params.uuid; + } else { + artist = false; + } + + useEffect(() => { + if (!artist) { + return false; + } + + // getProfile(username) + // .then(data => { + // setProfile(data); + // console.log(data) + // setLoading(false); + // }) + }, [artist]) + + if (loading) { + return ( ++
Timezone