Skip to content

Commit

Permalink
feat(song): lyrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Topvennie committed Nov 28, 2024
1 parent 6415eba commit 25e8579
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 163 deletions.
1 change: 1 addition & 0 deletions config/development.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ port = 3000
[song]
spotify_api = "https://api.spotify.com/v1"
spotify_account = "https://accounts.spotify.com/api/token"
lrclib_api = "https://lrclib.net/api"

[tap]
api = "https://tap.zeus.gent"
Expand Down
23 changes: 23 additions & 0 deletions db/migrations/20241128115057_alter_song_table_add_lyrics.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- +goose Up
-- +goose StatementBegin
ALTER TABLE song
ADD COLUMN album TEXT NOT NULL;

ALTER TABLE song
ADD COLUMN lyrics_type TEXT;

ALTER TABLE song
ADD COLUMN lyrics TEXT;
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
ALTER TABLE song
DROP COLUMN isrc_id;

ALTER TABLE song
DROP COLUMN lyrics;

ALTER TABLE song
DROP COLUMN common_id;
-- +goose StatementEnd
25 changes: 3 additions & 22 deletions db/queries/song.sql
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
-- CRUD

-- name: GetAllSongs :many
SELECT *
FROM song;

-- name: GetSongByID :one
SELECT *
FROM song
WHERE id = ?;

-- name: CreateSong :one
INSERT INTO song (title, spotify_id, duration_ms)
VALUES (?, ?, ?)
INSERT INTO song (title, album, spotify_id, duration_ms, lyrics_type, lyrics)
VALUES (?, ?, ?, ?, ?, ?)
RETURNING *;

-- name: CreateSongHistory :one
Expand Down Expand Up @@ -39,16 +30,6 @@ INSERT INTO song_artist_genre (artist_id, genre_id)
VALUES (?, ?)
RETURNING *;

-- name: UpdateSong :one
UPDATE song
SET title = ?, spotify_id = ?, duration_ms = ?
WHERE id = ?
RETURNING *;

-- name: DeleteSong :execrows
DELETE FROM song
WHERE id = ?;


-- Other

Expand Down Expand Up @@ -79,7 +60,7 @@ FROM song_artist
WHERE name = ?;

-- name: GetLastSongFull :many
SELECT s.title AS song_title, s.spotify_id, s.duration_ms, a.name AS artist_name, g.genre AS genre
SELECT s.title AS song_title, s.spotify_id, s.album, s.duration_ms, s.lyrics_type, s.lyrics, a.name AS artist_name, g.genre AS genre
FROM song_history sh
JOIN song s ON sh.song_id = s.id
LEFT JOIN song_artist_song sa ON s.id = sa.song_id
Expand Down
52 changes: 24 additions & 28 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ module github.com/zeusWPI/scc
go 1.23.1

require (
github.com/NimbleMarkets/ntcharts v0.1.2
github.com/charmbracelet/bubbletea v0.25.0
github.com/charmbracelet/lipgloss v1.0.0
github.com/disintegration/imaging v1.6.2
github.com/go-playground/validator/v10 v10.22.1
github.com/gocolly/colly v1.2.0
github.com/gofiber/contrib/fiberzap v1.0.2
github.com/gofiber/fiber/v2 v2.52.5
github.com/joho/godotenv v1.5.1
github.com/lucasb-eyer/go-colorful v1.2.0
github.com/mattn/go-sqlite3 v1.14.24
github.com/spf13/viper v1.19.0
go.uber.org/zap v1.27.0

)

Expand All @@ -23,65 +30,54 @@ require (
github.com/charmbracelet/bubbles v0.18.0 // indirect
github.com/charmbracelet/x/ansi v0.4.2 // indirect
github.com/containerd/console v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/kennygrant/sanitize v1.2.4 // indirect
github.com/klauspost/compress v1.17.2 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/lrstanley/bubblezone v0.0.0-20240125042004-b7bafc493195 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect
github.com/temoto/robotstxt v1.1.2 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.51.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/image v0.11.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/term v0.24.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)

require (
github.com/NimbleMarkets/ntcharts v0.1.2
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-playground/validator/v10 v10.22.1
github.com/gocolly/colly v1.2.0
github.com/gofiber/contrib/fiberzap v1.0.2
github.com/gofiber/fiber/v2 v2.52.5
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-sqlite3 v1.14.24
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/temoto/robotstxt v1.1.2 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.51.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/term v0.24.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
11 changes: 3 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,8 @@ github.com/kennygrant/sanitize v1.2.4 h1:gN25/otpP5vAsO2djbMhF/LQX6R7+O1TB4yv8Nz
github.com/kennygrant/sanitize v1.2.4/go.mod h1:LGsjYYtgxbetdg5owWB2mpgUL6e2nfw2eObZ0u0qvak=
github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4=
github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
Expand Down Expand Up @@ -172,9 +169,8 @@ golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 h1:hVwzHzIUGRjiF7EcUjqNxk3NCfkPxbDKRdnNE1Rpg0U=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.11.0 h1:ds2RoQvBvYTiJkwpSFDwCcDFNX7DqjL2WsUgTNk0Ooo=
golang.org/x/image v0.11.0/go.mod h1:bglhjqbqVuEb9e9+eNR45Jfu7D+T4Qan+NhQk8Ck2P8=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down Expand Up @@ -214,7 +210,6 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand All @@ -230,8 +225,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
28 changes: 28 additions & 0 deletions internal/pkg/db/dto/song.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package dto

import (
"database/sql"

"github.com/zeusWPI/scc/internal/pkg/db/sqlc"
)

// Song is the DTO for a song
type Song struct {
ID int64 `json:"id"`
Title string `json:"title"`
Album string `json:"album"`
SpotifyID string `json:"spotify_id" validate:"required"`
DurationMS int64 `json:"duration_ms"`
LyricsType string `json:"lyrics_type"` // Either 'synced' or 'plain'
Lyrics string `json:"lyrics"`
Artists []SongArtist `json:"artists"`
}

Expand All @@ -31,20 +36,43 @@ type SongGenre struct {

// SongDTO converts a sqlc.Song to a Song
func SongDTO(song sqlc.Song) *Song {
var lyricsType string
if song.LyricsType.Valid {
lyricsType = song.Lyrics.String
}
var lyrics string
if song.Lyrics.Valid {
lyrics = song.Lyrics.String
}

return &Song{
ID: song.ID,
Title: song.Title,
Album: song.Album,
SpotifyID: song.SpotifyID,
DurationMS: song.DurationMs,
LyricsType: lyricsType,
Lyrics: lyrics,
}
}

// CreateSongParams converts a Song DTO to a sqlc CreateSongParams object
func (s *Song) CreateSongParams() *sqlc.CreateSongParams {
lyricsType := sql.NullString{String: s.LyricsType, Valid: false}
if s.LyricsType != "" {
lyricsType.Valid = true
}
lyrics := sql.NullString{String: s.Lyrics, Valid: false}
if s.Lyrics != "" {
lyrics.Valid = true
}
return &sqlc.CreateSongParams{
Title: s.Title,
Album: s.Album,
SpotifyID: s.SpotifyID,
DurationMs: s.DurationMS,
LyricsType: lyricsType,
Lyrics: lyrics,
}
}

Expand Down
4 changes: 4 additions & 0 deletions internal/pkg/db/sqlc/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 25e8579

Please sign in to comment.