Author SHA1 Message Date
yaemiku 094ab2e458 Merge branch 'master' into ldap_auth 2026-04-26 03:02:46 +02:00
yaemiku 88edd8b546 Merge branch 'master' into ldap_auth 2026-03-11 22:19:10 +01:00
yaemiku 9c258bd316 Merge branch 'master' into ldap_auth 2026-02-19 03:25:57 +01:00
yaemiku bb8a68fe77 Enable a flag to change username attribute in LDAP 2026-02-19 00:22:34 +01:00
yaemiku 1e99bb4a0a README LDAP env vars entries 2026-02-15 05:50:41 +01:00
yaemiku 9e331dd459 Move LDAP store out of the global variable 2026-02-15 05:01:16 +01:00
yaemiku ae99e76fc7 Merge branch 'master' into ldap_auth 2026-02-14 03:58:30 +01:00
yaemiku 4837448092 Merge remote-tracking branch 'origin' into ldap_auth 2026-02-14 03:54:36 +01:00
yaemiku eccc957fd1 Merge branch 'master' into ldap_auth
Nightly Release / Check latest commit (push) Successful in 6s
Nightly Release / Lint and test (push) Has been skipped
Nightly Release / Build and release Docker image (push) Has been skipped
2025-10-12 11:06:18 +02:00
yaemiku 6fba25ca0b ldap login logic, subsonic api hex encrypted password 2025-09-21 08:02:10 +02:00
yaemiku e5c192c83c Merge branch 'master' into ldap_auth 2025-09-21 06:37:41 +02:00
Daniel Hall d9facdcca6 Merge branch 'master' into ldap_auth 2024-09-08 10:59:37 -07:00
Daniel Hall 21b562b5fe style: Made invalid auth chain less chain-y 2024-06-26 15:54:39 -07:00
Daniel Hall 758c4c7279 lint: Fixed ineffassign on Add 2024-06-26 15:49:41 -07:00
Daniel Hall 4c5c015190 go mod tidy 2024-06-26 15:34:15 -07:00
Daniel Hall 7159e1ca09 fix: Fixed conf music path check 2024-06-26 15:33:54 -07:00
betapictoris f812c15fa1 Merge branch 'master' into ldap_auth 2024-06-10 23:00:54 -07:00
betapictoris dc98b6aa50 Merge branch 'sentriz:master' into ldap_auth 2024-04-08 19:00:41 -07:00
Daniel Hall e2415e944c Do session change on failed LDAP check 2024-04-08 18:13:16 -07:00
Daniel Hall 0f7e24b39b Fixed filter params 2024-04-08 13:52:04 -07:00
Daniel Hall f5195f15c4 Fix password check for local users 2024-04-07 12:55:29 -07:00
Daniel Hall fccf01642f Added LDAP password cache 2024-04-07 12:29:45 -07:00
Daniel Hall 5638ef5df7 Added LDAP admin filter 2024-04-07 11:24:26 -07:00
Daniel Hall 6ca68b2c26 Only allow use of subsonic API with one auth method 2024-04-07 10:43:07 -07:00
Daniel Hall b36f26e32a Have LDAP read from config 2024-04-07 10:18:00 -07:00
Daniel Hall 995c566131 Readded gofeed dep 2024-04-07 09:55:46 -07:00
Daniel Hall 6eddc2a1a9 Made withUser return a middleware and take dbc 2024-04-07 09:40:25 -07:00
betapictoris 6d7c605578 Merge branch 'master' into ldap_auth 2024-04-01 10:49:18 -07:00
Daniel Hall 6bf39cc0c4 Removed LDAP config from admin templates 2024-04-01 10:45:55 -07:00
Daniel Hall 8ba05ef14d Reverted home template 2024-04-01 10:42:11 -07:00
Daniel Hall dc3682dc8f Removed LDAP web UI 2024-04-01 10:40:42 -07:00
Daniel Hall 3cf6d0a28b Added LDAP config 2024-04-01 10:33:59 -07:00
Daniel Hall c531666eb6 Bump LDAP deps 2024-04-01 10:13:33 -07:00
Daniel 02fd31452d Merge branch 'sentriz:master' into ldap_auth 2024-02-28 13:57:45 -08:00
Daniel 9a97fa4b22 Merge branch 'master' into ldap_auth 2024-02-23 11:00:55 -08:00
Daniel 8d4c22ad2f Merge branch 'master' into ldap_auth 2024-02-22 07:35:53 -08:00
Daniel Hall 0d85e0ce02 Stopped opening up a second connection when creating a user from LDAP 2024-02-18 09:44:26 -08:00
Daniel Hall 8793a36364 Rewrote if-else to switch for LDAP results 2024-02-17 22:38:19 -08:00
Daniel Hall ac31258f88 Removed unnecessary trailing newline 2024-02-17 22:29:29 -08:00
Daniel Hall 683525aad2 Removed unused password parameter from createUserFromLDAP 2024-02-17 22:27:57 -08:00
Daniel Hall bc62b213a5 Lower-cased and removed punctuation for errors
Fixes linting
2024-02-17 22:27:08 -08:00
Daniel Hall f6ecd6d39b Added dashboard login for LDAP users 2024-02-17 22:23:38 -08:00
Daniel Hall fdceb555bf Removed unused logs 2024-02-17 22:23:12 -08:00
Daniel Hall 6301cb25bc Fix User struct from having not null passwords
This is required for LDAP auth to work, blank passwords don't work anyway.
2024-02-17 22:13:52 -08:00
Daniel Hall 408d325c2c Move LDAP into a seperate file 2024-02-17 22:12:56 -08:00
Daniel e944817f8b Merge with upstream
Merge pull request #1 from BetaPictoris/master
2024-02-15 11:00:04 -08:00
Daniel f8b0fbbfa2 Merge branch 'ldap_auth' into master 2024-02-15 10:59:33 -08:00
Daniel 90b5324179 gofmt handlers 2023-12-08 23:15:51 -08:00
Daniel 05149961b5 Used log to log instead of fmt 2023-12-08 23:15:10 -08:00
Daniel 84e29da258 Merge branch 'master' into ldap_auth 2023-12-08 23:12:25 -08:00
Daniel 7c6e1957fb Simplified code using gofmt 2023-12-08 23:10:26 -08:00
Daniel df42923f7b Made LDAP query log message match others 2023-12-08 23:04:13 -08:00
Daniel 4799fb2441 Update go-ldap/ldap to v3 2023-12-01 12:31:24 -08:00
Daniel 322aa0747a Made WithUser middleware private 2023-11-30 14:23:51 -08:00
Daniel 7558bb3f23 Merge branch 'master' into ldap_auth 2023-11-11 17:12:27 -08:00
Daniel e770eaa07a Fixed old references to use the new style
Readded goldap
Fixed `c.DB` to `c.dbc`
Fixed `WithUser`
2023-11-10 13:58:33 -08:00
Daniel a24b7c07cb Merge branch master into ldap_auth 2023-11-10 13:47:47 -08:00
BetaPictoris c03e10454c Fixed merge conflicts 2023-10-28 17:05:50 -07:00
BetaPictoris a99d63ab12 Fixed nil password causing invalid dereferences 2023-10-27 16:02:47 -07:00
BetaPictoris 667cf731fd Extract out LDAP connection creation 2023-10-27 15:48:41 -07:00
BetaPictoris 38ea72bbc6 Only try to login if there is exactly 1 user, otherwise return an error. 2023-10-27 10:53:43 -07:00
BetaPictoris d6d51ed9f7 Update username error message to match Subsonic API 2023-10-27 10:50:33 -07:00
beta 9e5b8d4ac8 Fixed newLDAPUser being reset 2023-09-09 09:55:29 -07:00
beta 238856ad73 Fixed newLDAPUser def 2023-09-09 09:49:48 -07:00
beta 7de6cf1e9e Fixed use of newLDAPUser 2023-09-09 09:48:54 -07:00
beta e7d6fdab69 Fixed bug where two requests got merged 2023-09-09 09:37:36 -07:00
beta 94027dcf9b Fixed variable defs 2023-09-09 09:28:57 -07:00
beta 46dac6d463 Check errors in ldap do handler 2023-09-09 09:27:12 -07:00
Daniel fc08e0a171 Merge branch 'sentriz:master' into ldap_auth 2023-09-05 02:53:33 +00:00
Daniel c317046fc9 Merge branch 'sentriz:master' into ldap_auth 2023-08-15 15:39:05 -07:00
BetaPictoris a558947da6 Fixed SetSetting err checking 2023-08-06 03:20:29 -07:00
BetaPictoris e5f815c79e Fixed filter labels 2023-08-06 03:14:43 -07:00
BetaPictoris 80f5facbd2 Added c.DB.SetSetting (errcheck) 2023-08-06 03:12:36 -07:00
BetaPictoris 23d23c7c6a Fixed r param revive 2023-08-06 03:04:59 -07:00
BetaPictoris 1fd8c9b2c3 Fix else if (gocritic) 2023-08-06 03:02:13 -07:00
BetaPictoris 9c56bf61ab Fixed for LDAP connection 2023-08-06 03:00:00 -07:00
BetaPictoris 79b28ef653 Fixed ineffassign to 2023-08-06 02:58:40 -07:00
BetaPictoris d8338590fd Added LDAP user creation 2023-08-06 02:54:17 -07:00
BetaPictoris fdb2ec66de Added LDAP auth if there is a user 2023-08-06 01:33:21 -07:00
BetaPictoris 6c8f5fa968 Added go-ldap dep 2023-08-06 00:43:20 -07:00
BetaPictoris 6602495032 Added a way of disabling LDAP auth 2023-08-06 00:40:26 -07:00
BetaPictoris 6b2f853b3c Removed eURL file 2023-08-05 22:12:13 -07:00
BetaPictoris 23e797e62a Addd default value for LDAP config page 2023-08-05 22:11:05 -07:00
BetaPictoris 1fab192195 Added TODO 2023-08-05 18:48:01 -07:00
BetaPictoris 98be763e37 Added saving of LDAP settings 2023-08-05 18:46:47 -07:00
BetaPictoris 830ab090fd Fixed typo 2023-08-05 18:42:27 -07:00
BetaPictoris 13bb999bd5 Made TLS checkbox work.
TODO: Make the styles match the rest of the page and move them out of inline.
2023-08-05 17:06:37 -07:00
BetaPictoris ae9f95aa75 Added LDAP route 2023-08-05 16:43:03 -07:00
BetaPictoris c5b35a6ff1 Added LDAP config template 2023-08-05 16:30:54 -07:00
BetaPictoris cf3f6666e0 Added LDAP link 2023-08-05 15:19:10 -07:00
35 changed files with 737 additions and 745 deletions

No files matched your search

-18
View File
@@ -1,18 +0,0 @@
version: 2
multi-ecosystem-groups:
all:
schedule:
interval: weekly
updates:
- package-ecosystem: docker
directory: /
multi-ecosystem-group: all
patterns: ["*"]
- package-ecosystem: github-actions
directory: /
multi-ecosystem-group: all
patterns: ["*"]
- package-ecosystem: gomod
directory: /
multi-ecosystem-group: all
patterns: ["*"]
+1 -3
View File
@@ -1,4 +1,5 @@
*.db
*.db.*.bak
*db-wal
*db-shm
*.sql
@@ -12,6 +13,3 @@ dist
*.swp
.tags*
*.test
.env
config
genre-tree
+2 -2
View File
@@ -1,5 +1,5 @@
# syntax=docker/dockerfile:1
FROM --platform=$BUILDPLATFORM golang:1.26-alpine3.23 AS builder
FROM --platform=$BUILDPLATFORM golang:1.25-alpine3.22 AS builder
ARG TARGETOS
ARG TARGETARCH
WORKDIR /src
@@ -12,7 +12,7 @@ RUN \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /out/ ./cmd/...
FROM alpine:3.23
FROM alpine:3.22
LABEL org.opencontainers.image.source=https://github.com/sentriz/gonic
RUN apk add -U --no-cache \
ffmpeg \
+10 -2
View File
@@ -24,7 +24,7 @@
- support for the [album-artist](https://mkoby.com/2007/02/18/artist-versus-album-artist/) tag, to not clutter your artist list with compilation album appearances
- written in [go](https://golang.org/), so lightweight and suitable for a raspberry pi, etc. (see ARM images below)
- newer salt and token auth
- tested on [airsonic-refix](https://github.com/tamland/airsonic-refix), [amperfy](https://github.com/BLeeEZ/amperfy), [symfonium](https://symfonium.app), [dsub](https://f-droid.org/en/packages/github.daneren2005.dsub/), [jamstash](https://github.com/sqrlmstr5000/Jamstash), [music-assistant](https://www.music-assistant.io/), [subsonic.el](https://git.sr.ht/~amk/subsonic.el), [sublime music](https://github.com/sublime-music/sublime-music), [soundwaves](https://apps.apple.com/us/app/soundwaves/id736139596), [stmp](https://github.com/wildeyedskies/stmp), [termsonic](https://git.sixfoisneuf.fr/termsonic/), [tempus](https://github.com/eddyizm/tempus/), [strawberry](https://www.strawberrymusicplayer.org/), and [ultrasonic](https://gitlab.com/ultrasonic/ultrasonic)
- tested on [airsonic-refix](https://github.com/tamland/airsonic-refix), [amperfy](https://github.com/BLeeEZ/amperfy), [symfonium](https://symfonium.app), [dsub](https://f-droid.org/en/packages/github.daneren2005.dsub/), [jamstash](https://github.com/sqrlmstr5000/Jamstash), [subsonic.el](https://git.sr.ht/~amk/subsonic.el), [sublime music](https://github.com/sublime-music/sublime-music), [soundwaves](https://apps.apple.com/us/app/soundwaves/id736139596), [stmp](https://github.com/wildeyedskies/stmp), [termsonic](https://git.sixfoisneuf.fr/termsonic/), [tempus](https://github.com/eddyizm/tempus/), [strawberry](https://www.strawberrymusicplayer.org/), and [ultrasonic](https://gitlab.com/ultrasonic/ultrasonic)
## installation
@@ -52,7 +52,6 @@ password can then be changed from the web interface
| env var | command line arg | description |
| ----------------------------------- | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `GONIC_MUSIC_PATH` | `-music-path` | path to your music collection (see also multi-folder support below) |
| `GONIC_DEFAULT_MUSIC_PATH` | `-default-music-path` | default music path for when no folder is selected in client (useful for when client does not support choosing a folder) |
| `GONIC_PODCAST_PATH` | `-podcast-path` | path to a podcasts directory |
| `GONIC_PLAYLISTS_PATH` | `-playlists-path` | path to new or existing directory with m3u files for subsonic playlists. items in the directory should be in the format `<userid>/<name>.m3u`. for example the admin user could have `1/my-playlist.m3u`. gonic create and make changes to these playlists over the subsonic api. |
| `GONIC_CACHE_PATH` | `-cache-path` | path to store audio transcodes, covers, etc |
@@ -76,6 +75,15 @@ password can then be changed from the web interface
| `GONIC_TRANSCODE_CACHE_SIZE` | `-transcode-cache-size` | **optional** size of the transcode cache in MB (0 = no limit) |
| `GONIC_TRANSCODE_EJECT_INTERVAL` | `-transcode-eject-interval` | **optional** interval (in minutes) to eject transcode cache (0 = never) |
| `GONIC_EXPVAR` | `-expvar` | **optional** enable the /debug/vars endpoint (exposes useful debugging attributes as well as database stats) |
| `GONIC_LDAP_FQDN` | `-ldap-fqdn` | **optional** the name of the server to connect to (required for LDAP) |
| `GONIC_LDAP_PORT` | `-ldap-port` | **optional** what port the LDAP server is hosted on (_default_ `389`) |
| `GONIC_LDAP_TLS` | `-ldap-tls` | **optional** whether gonic will connect to the LDAP server using TLS (_default_ `false`) |
| `GONIC_LDAP_BASE_DN` | `-ldap-base-dn` | **optional** the base DN for LDAP objects (required for LDAP, escaping the commas might be necessary if using environmental variable) |
| `GONIC_LDAP_USERNAME_ATTR` | `-ldap-username-attr` | **optional** attribute used by the LDAP server for usernames, gets prepended to BaseDN (_default_ `uid`) |
| `GONIC_LDAP_BIND_USER` | `-ldap-bind-user` | **optional** the bind user to bind to LDAP with (required for LDAP) |
| `GONIC_LDAP_BIND_PASS` | `-ldap-bind-pass` | **optional** the password of the LDAP bind user (required for LDAP) |
| `GONIC_LDAP_FILTER` | `-ldap-filter` | **optional** the filter to select LDAP objects with (escaping the commas might be necessary if using environmental variable) |
| `GONIC_LDAP_ADMIN_FILTER` | `-ldap-admin-filter` | **optional** the filter to select LDAP admin objects with (escaping the commas might be necessary if using environmental variable) (_default_ `(memberof=cn=admin)`) |
## multi valued tags (v0.16+)
+23 -3
View File
@@ -39,6 +39,7 @@ import (
"go.senan.xyz/gonic/infocache/artistinfocache"
"go.senan.xyz/gonic/jukebox"
"go.senan.xyz/gonic/lastfm"
"go.senan.xyz/gonic/ldap"
"go.senan.xyz/gonic/listenbrainz"
"go.senan.xyz/gonic/playlist"
"go.senan.xyz/gonic/podcast"
@@ -62,7 +63,6 @@ func main() {
var confMusicPaths pathAliases
flag.Var(&confMusicPaths, "music-path", "path to music")
defaultMusicPath := flag.String("default-music-path", "", "interval (in minutes) to automatically scan music (optional)")
confPlaylistsPath := flag.String("playlists-path", "", "path to your list of new or existing m3u playlists that gonic can manage")
@@ -84,6 +84,26 @@ func main() {
confExcludePattern := flag.String("exclude-pattern", "", "regex pattern to exclude files from scan (optional)")
var ldapConfig ldap.Config
var ldapStore = make(ldap.LDAPStore)
flag.StringVar(&ldapConfig.BindUser, "ldap-bind-user", "", "the bind user to bind to LDAP with (required for LDAP)")
flag.StringVar(&ldapConfig.BindPass, "ldap-bind-pass", "", "the password of the LDAP bind user (required for LDAP)")
flag.StringVar(&ldapConfig.BaseDN, "ldap-base-dn", "", "the base DN for LDAP objects (required for LDAP)")
flag.StringVar(&ldapConfig.UsernameAttr, "ldap-username-attr", "uid", "attribute used by the LDAP server for usernames, gets prepended to BaseDN (optional)")
flag.StringVar(&ldapConfig.Filter, "ldap-filter", "", "the filter to select LDAP objects with (optional)")
flag.StringVar(&ldapConfig.AdminFilter, "ldap-admin-filter", "(memberof=cn=admin)", "the filter to select LDAP objects with (optional)")
flag.StringVar(&ldapConfig.FQDN, "ldap-fqdn", "", "the name of the server to connect to (required for LDAP)")
flag.UintVar(&ldapConfig.Port, "ldap-port", 389, "what port the LDAP server is hosted on (optional)")
flag.BoolVar(&ldapConfig.TLS, "ldap-tls", false, "whether gonic will connect to the LDAP server using TLS (optional)")
if ldapConfig.FQDN != "" {
if ldapConfig.BindUser == "" || ldapConfig.BindPass == "" || ldapConfig.BaseDN == "" {
log.Fatal("a server was provided for an LDAP connection, but configuration is incomplete")
}
}
var confMultiValueGenre, confMultiValueArtist, confMultiValueAlbumArtist multiValueSetting
flag.Var(&confMultiValueGenre, "multi-value-genre", "setting for multi-valued genre scanning (optional)")
flag.Var(&confMultiValueArtist, "multi-value-artist", "setting for multi-valued track artist scanning (optional)")
@@ -253,11 +273,11 @@ func main() {
return url.String()
}
ctrlAdmin, err := ctrladmin.New(dbc, sessDB, scannr, podcast, lastfmClient, resolveProxyPath)
ctrlAdmin, err := ctrladmin.New(dbc, sessDB, scannr, podcast, lastfmClient, resolveProxyPath, ldapConfig, ldapStore)
if err != nil {
log.Panicf("error creating admin controller: %v\n", err)
}
ctrlSubsonic, err := ctrlsubsonic.New(dbc, scannr, musicPaths, *defaultMusicPath, *confPodcastPath, cacheDirAudio, cacheDirCovers, jukebx, playlistStore, scrobblers, podcast, transcoder, lastfmClient, artistInfoCache, albumInfoCache, tagReader, resolveProxyPath)
ctrlSubsonic, err := ctrlsubsonic.New(dbc, scannr, musicPaths, *confPodcastPath, cacheDirAudio, cacheDirCovers, jukebx, playlistStore, scrobblers, podcast, transcoder, lastfmClient, artistInfoCache, albumInfoCache, tagReader, resolveProxyPath, ldapConfig, ldapStore)
if err != nil {
log.Panicf("error creating subsonic controller: %v\n", err)
}
+11 -45
View File
@@ -54,34 +54,19 @@ func NewMock(opts url.Values) (*DB, error) {
}
func (db *DB) InsertBulkLeftMany(table string, head []string, left int, col []int) error {
rows := make([][]any, len(col))
for i, c := range col {
rows[i] = []any{c}
}
return db.InsertBulkLeftManyRows(table, head, left, rows)
}
func (db *DB) InsertBulkLeftManyRows(table string, head []string, left int, rows [][]any) error {
if len(rows) == 0 {
if len(col) == 0 {
return nil
}
tail := len(head) - 1
placeholder := "(?" + strings.Repeat(", ?", tail) + ")"
placeholders := make([]string, len(rows))
values := make([]any, 0, len(rows)*len(head))
for i, r := range rows {
if len(r) != tail {
return fmt.Errorf("row %d has %d values, expected %d", i, len(r), tail)
}
placeholders[i] = placeholder
values = append(values, left)
values = append(values, r...)
var rows []string
var values []any
for _, c := range col {
rows = append(rows, "(?, ?)")
values = append(values, left, c)
}
q := fmt.Sprintf("INSERT OR IGNORE INTO %q (%s) VALUES %s",
table,
strings.Join(head, ", "),
strings.Join(placeholders, ", "),
strings.Join(rows, ", "),
)
return db.Exec(q, values...).Error
}
@@ -142,15 +127,15 @@ func (db *DB) TransactionChunked(data []int64, cb func(*DB, []int64) error) erro
}
// https://sqlite.org/limits.html
const size = 999
return db.Transaction(func(tx *DB) error {
for i := 0; i < len(data); i += size {
end := min(i+size, len(data))
if err := db.Transaction(func(tx *DB) error {
return cb(tx, data[i:end])
}); err != nil {
if err := cb(tx, data[i:end]); err != nil {
return err
}
}
return nil
})
}
type SettingKey string
@@ -228,7 +213,6 @@ type Track struct {
Album *Album
AlbumID int `gorm:"not null; unique_index:idx_folder_filename" sql:"default: null; type:int REFERENCES albums(id) ON DELETE CASCADE"`
Artists []*Artist `gorm:"many2many:track_artists"`
Contributors []*TrackContributor `gorm:"foreignkey:track_id"`
Genres []*Genre `gorm:"many2many:track_genres"`
Size int `sql:"default: null"`
Length int `sql:"default: null"`
@@ -304,7 +288,7 @@ type User struct {
ID int `gorm:"primary_key"`
CreatedAt time.Time
Name string `gorm:"not null; unique_index" sql:"default: null"`
Password string `gorm:"not null" sql:"default: null"`
Password string `sql:"default: null"`
LastFMSession string `sql:"default: null"`
ListenBrainzURL string `sql:"default: null"`
ListenBrainzToken string `sql:"default: null"`
@@ -420,24 +404,6 @@ type TrackArtist struct {
ArtistID int `gorm:"not null; unique_index:idx_track_id_artist_id" sql:"default: null; type:int REFERENCES artists(id) ON DELETE CASCADE"`
}
type ContributorRole string
const (
ContributorRoleComposer ContributorRole = "composer"
ContributorRoleLyricist ContributorRole = "lyricist"
ContributorRoleRemixer ContributorRole = "remixer"
ContributorRoleConductor ContributorRole = "conductor"
ContributorRoleProducer ContributorRole = "producer"
ContributorRoleArranger ContributorRole = "arranger"
)
type TrackContributor struct {
TrackID int `gorm:"not null; unique_index:idx_track_contributor" sql:"default: null; type:int REFERENCES tracks(id) ON DELETE CASCADE"`
ArtistID int `gorm:"not null; unique_index:idx_track_contributor" sql:"default: null; type:int REFERENCES artists(id) ON DELETE CASCADE"`
Role ContributorRole `gorm:"not null; unique_index:idx_track_contributor" sql:"default: null"`
Artist *Artist
}
type ArtistAppearances struct {
ArtistID int `gorm:"not null; unique_index:idx_artist_id_album_id" sql:"default: null; type:int REFERENCES artists(id) ON DELETE CASCADE"`
AlbumID int `gorm:"not null; unique_index:idx_artist_id_album_id" sql:"default: null; type:int REFERENCES albums(id) ON DELETE CASCADE"`
-5
View File
@@ -84,7 +84,6 @@ func (db *DB) Migrate(ctx MigrationContext) error {
construct(ctx, "202512021147", migrateAlbumAddIndexOnCreatedAt),
construct(ctx, "202601201000", migrateAddAlbumDiscTitles),
construct(ctx, "202602061800", migrateAddTrackYear),
construct(ctx, "202604231200", migrateAddTrackContributors),
}
return gormigrate.
@@ -882,10 +881,6 @@ func migrateAddAlbumDiscTitles(tx *gorm.DB, _ MigrationContext) error {
return tx.AutoMigrate(AlbumDiscTitle{}).Error
}
func migrateAddTrackContributors(tx *gorm.DB, _ MigrationContext) error {
return tx.AutoMigrate(TrackContributor{}).Error
}
func migrateAddTrackYear(tx *gorm.DB, _ MigrationContext) error {
step := tx.AutoMigrate(Track{})
if err := step.Error; err != nil {
+1
View File
@@ -7,6 +7,7 @@ import (
// Cgo-free Wasm database
_ "github.com/ncruces/go-sqlite3/driver"
_ "github.com/ncruces/go-sqlite3/embed"
// Cgo-free Wasm tagger
"go.senan.xyz/gonic/tags/taglib"
+16 -14
View File
@@ -1,6 +1,6 @@
module go.senan.xyz/gonic
go 1.26.0
go 1.25
require (
github.com/Masterminds/sprig v2.22.0+incompatible
@@ -13,17 +13,18 @@ require (
github.com/env25/mpdlrc v0.7.4
github.com/fatih/structs v1.1.0
github.com/fsnotify/fsnotify v1.9.0
github.com/go-ldap/ldap/v3 v3.4.6
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/google/uuid v1.6.0
github.com/gorilla/securecookie v1.1.2
github.com/gorilla/sessions v1.4.0
github.com/jinzhu/gorm v1.9.17-0.20211120011537-5c235b72a414
github.com/josephburnett/jd v1.9.2
github.com/mattn/go-sqlite3 v1.14.42
github.com/mattn/go-sqlite3 v1.14.33
github.com/microcosm-cc/bluemonday v1.0.27
github.com/mitchellh/mapstructure v1.5.0
github.com/mmcdole/gofeed v1.3.0
github.com/ncruces/go-sqlite3 v0.33.3
github.com/ncruces/go-sqlite3 v0.30.4
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/philippta/go-template v0.0.0-20220911145045-4556aca435e4
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be
@@ -31,20 +32,22 @@ require (
github.com/stretchr/testify v1.11.1
go.senan.xyz/flagconf v0.1.11
go.senan.xyz/taglib v0.11.1
go.senan.xyz/wrtag v0.30.1-0.20260423121427-fec4b6e433cb
golang.org/x/net v0.53.0
golang.org/x/sync v0.20.0
go.senan.xyz/wrtag v0.20.0
golang.org/x/net v0.49.0
golang.org/x/sync v0.19.0
gopkg.in/gormigrate.v1 v1.6.0
)
require (
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/PuerkitoBio/goquery v1.12.0 // indirect
github.com/PuerkitoBio/goquery v1.11.0 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-openapi/jsonpointer v0.23.1 // indirect
github.com/go-openapi/swag/jsonname v0.26.0 // indirect
github.com/go-asn1-ber/asn1-ber v1.5.5 // indirect
github.com/go-openapi/jsonpointer v0.22.4 // indirect
github.com/go-openapi/swag/jsonname v0.25.4 // indirect
github.com/gorilla/context v1.1.2 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/huandu/xstrings v1.5.0 // indirect
@@ -59,14 +62,13 @@ require (
github.com/mmcdole/goxpp v1.1.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/ncruces/go-sqlite3-wasm v1.1.1-0.20260409221933-87e4b35a38d0 // indirect
github.com/ncruces/julianday v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/tetratelabs/wazero v1.11.0 // indirect
golang.org/x/crypto v0.50.0 // indirect
golang.org/x/image v0.39.0 // indirect
golang.org/x/sys v0.43.0 // indirect
golang.org/x/text v0.36.0 // indirect
golang.org/x/crypto v0.47.0 // indirect
golang.org/x/image v0.35.0 // indirect
golang.org/x/sys v0.40.0 // indirect
golang.org/x/text v0.33.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
+40 -30
View File
@@ -1,4 +1,6 @@
cloud.google.com/go v0.33.1/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 h1:mFRzDkZVAjdal+s7s0MwaRv9igoPqLRdzOLzw/8Xvq8=
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358/go.mod h1:chxPXzSsl7ZWRAuOIE23GDNzjWuZquvFlgA8xmpunjU=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
@@ -6,8 +8,10 @@ github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF0
github.com/Masterminds/sprig v2.22.0+incompatible h1:z4yfnGrZ7netVz+0EDJ0Wi+5VZCSYp4Z0m2dk6cEM60=
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/PuerkitoBio/goquery v1.12.0 h1:pAcL4g3WRXekcB9AU/y1mbKez2dbY2AajVhtkO8RIBo=
github.com/PuerkitoBio/goquery v1.12.0/go.mod h1:802ej+gV2y7bbIhOIoPY5sT183ZW0YFofScC4q/hIpQ=
github.com/PuerkitoBio/goquery v1.11.0 h1:jZ7pwMQXIITcUXNH83LLk+txlaEy6NVOfTuP43xxfqw=
github.com/PuerkitoBio/goquery v1.11.0/go.mod h1:wQHgxUOU3JGuj3oD/QFfxUdlzW6xPHfqyHre6VMY4DQ=
github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74 h1:Kk6a4nehpJ3UuJRqlA3JxYxBZEqCeOmATOvrbT4p9RA=
github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74/go.mod h1:cEWa1LVoE5KvSD9ONXsZrj0z6KqySlCCNKHlLzbqAt4=
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM=
github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA=
@@ -37,12 +41,16 @@ github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/go-openapi/jsonpointer v0.23.1 h1:1HBACs7XIwR2RcmItfdSFlALhGbe6S92p0ry4d1GWg4=
github.com/go-openapi/jsonpointer v0.23.1/go.mod h1:iWRmZTrGn7XwYhtPt/fvdSFj1OfNBngqRT2UG3BxSqY=
github.com/go-openapi/swag/jsonname v0.26.0 h1:gV1NFX9M8avo0YSpmWogqfQISigCmpaiNci8cGECU5w=
github.com/go-openapi/swag/jsonname v0.26.0/go.mod h1:urBBR8bZNoDYGr653ynhIx+gTeIz0ARZxHkAPktJK2M=
github.com/go-openapi/testify/v2 v2.4.2 h1:tiByHpvE9uHrrKjOszax7ZvKB7QOgizBWGBLuq0ePx4=
github.com/go-openapi/testify/v2 v2.4.2/go.mod h1:SgsVHtfooshd0tublTtJ50FPKhujf47YRqauXXOUxfw=
github.com/go-asn1-ber/asn1-ber v1.5.5 h1:MNHlNMBDgEKD4TcKr36vQN68BA00aDfjIt3/bD50WnA=
github.com/go-asn1-ber/asn1-ber v1.5.5/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
github.com/go-ldap/ldap/v3 v3.4.6 h1:ert95MdbiG7aWo/oPYp9btL3KJlMPKnP58r09rI8T+A=
github.com/go-ldap/ldap/v3 v3.4.6/go.mod h1:IGMQANNtxpsOzj7uUAMjpGBaOVTC4DYyIy8VsTdxmtc=
github.com/go-openapi/jsonpointer v0.22.4 h1:dZtK82WlNpVLDW2jlA1YCiVJFVqkED1MegOUy9kR5T4=
github.com/go-openapi/jsonpointer v0.22.4/go.mod h1:elX9+UgznpFhgBuaMQ7iu4lvvX1nvNsesQ3oxmYTw80=
github.com/go-openapi/swag/jsonname v0.25.4 h1:bZH0+MsS03MbnwBXYhuTttMOqk+5KcQ9869Vye1bNHI=
github.com/go-openapi/swag/jsonname v0.25.4/go.mod h1:GPVEk9CWVhNvWhZgrnvRA6utbAltopbKwDu8mXNUMag=
github.com/go-openapi/testify/v2 v2.0.2 h1:X999g3jeLcoY8qctY/c/Z8iBHTbwLz7R2WXd6Ub6wls=
github.com/go-openapi/testify/v2 v2.0.2/go.mod h1:HCPmvFFnheKK2BuwSA0TbbdxJ3I16pjwMkYkP4Ywn54=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
@@ -57,6 +65,7 @@ github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
@@ -103,8 +112,8 @@ github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus=
github.com/mattn/go-sqlite3 v1.14.42 h1:MigqEP4ZmHw3aIdIT7T+9TLa90Z6smwcthx+Azv4Cgo=
github.com/mattn/go-sqlite3 v1.14.42/go.mod h1:pjEuOr8IwzLJP2MfGeTb0A35jauH+C2kbHKBr7yXKVQ=
github.com/mattn/go-sqlite3 v1.14.33 h1:A5blZ5ulQo2AtayQ9/limgHEkFreKj1Dv226a1K73s0=
github.com/mattn/go-sqlite3 v1.14.33/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk=
github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
@@ -122,10 +131,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/ncruces/go-sqlite3 v0.33.3 h1:6jCR3KuGvJSEwhaQrkHDGeIe2qCQ6nOUDNsPz7ZIotw=
github.com/ncruces/go-sqlite3 v0.33.3/go.mod h1:t2Osfw0wcKzJTgv2EvrkTtVLqlbKTA5Yvwb2ypAlBcY=
github.com/ncruces/go-sqlite3-wasm v1.1.1-0.20260409221933-87e4b35a38d0 h1:ymE9H30x1AyW5VfMNkJC9teuI2W1jjMsQS7kc6zl6Tg=
github.com/ncruces/go-sqlite3-wasm v1.1.1-0.20260409221933-87e4b35a38d0/go.mod h1:/H3+JykPsfSlvKbOxNSx9kKwm3ecqQGzyCs1e9KkNsU=
github.com/ncruces/go-sqlite3 v0.30.4 h1:j9hEoOL7f9ZoXl8uqXVniaq1VNwlWAXihZbTvhqPPjA=
github.com/ncruces/go-sqlite3 v0.30.4/go.mod h1:7WR20VSC5IZusKhUdiR9y1NsUqnZgqIYCmKKoMEYg68=
github.com/ncruces/julianday v1.0.0 h1:fH0OKwa7NWvniGQtxdJRxAgkBMolni2BjDHaWTxqt7M=
github.com/ncruces/julianday v1.0.0/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvza5fFc9G7g=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
@@ -143,8 +150,11 @@ github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4/go.mod h1:C1a7
github.com/sentriz/gormstore v0.0.0-20220105134332-64e31f7f6981 h1:sLILANWN76ja66/K4k/mBqJuCjDZaM67w+Ru6rEB0s0=
github.com/sentriz/gormstore v0.0.0-20220105134332-64e31f7f6981/go.mod h1:Rx8XB1ck+so+41uu9VY1gMKs1CPQ2NTq0pzf+OCCQHo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/tetratelabs/wazero v1.11.0 h1:+gKemEuKCTevU4d7ZTzlsvgd1uaToIDtlQlmNbwqYhA=
@@ -154,8 +164,8 @@ go.senan.xyz/flagconf v0.1.11 h1:ApA9DpoSrfVQlLt8spKJC3fOT7oTEZ2/MmBGMnb9mt4=
go.senan.xyz/flagconf v0.1.11/go.mod h1:NqOFfSwJvNWXOTUabcRZ8mPK9+sJmhStJhqtEt74wNQ=
go.senan.xyz/taglib v0.11.1 h1:S3mO5e3HRRG0Ehw1jLUodYbAJK8TtqdOoNgqkC0D3uU=
go.senan.xyz/taglib v0.11.1/go.mod h1:qyTl978MnGeZ/ny4d/t0ErLXxysA+39X4+SNSCk56Zs=
go.senan.xyz/wrtag v0.30.1-0.20260423121427-fec4b6e433cb h1:hFxxWH6MlgcHZQv2BpkQ1KSp8MSbXMHtN338/HfSzdY=
go.senan.xyz/wrtag v0.30.1-0.20260423121427-fec4b6e433cb/go.mod h1:sWPfwc3FM2O9Ka/l46vDp+/XwLCgywukxgfZipaWrKw=
go.senan.xyz/wrtag v0.20.0 h1:Q57ITuEl3TuRuOIkerCL+y4O3WrCqC1lUrewHtluUjc=
go.senan.xyz/wrtag v0.20.0/go.mod h1:1h39mVCOu6mqeQGYVToCvMhegBRCpOt6FO7g69EvuSM=
golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@@ -165,11 +175,11 @@ golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliY
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/crypto v0.50.0 h1:zO47/JPrL6vsNkINmLoo/PH1gcxpls50DNogFvB5ZGI=
golang.org/x/crypto v0.50.0/go.mod h1:3muZ7vA7PBCE6xgPX7nkzzjiUq87kRItoJQM1Yo8S+Q=
golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8=
golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.39.0 h1:skVYidAEVKgn8lZ602XO75asgXBgLj9G/FE3RbuPFww=
golang.org/x/image v0.39.0/go.mod h1:sIbmppfU+xFLPIG0FoVUTvyBMmgng1/XAMhQ2ft0hpA=
golang.org/x/image v0.35.0 h1:LKjiHdgMtO8z7Fh18nGY6KDcoEtVfsgLDPeLyguqb7I=
golang.org/x/image v0.35.0/go.mod h1:MwPLTVgvxSASsxdLzKrl8BRFuyqMyGhLwmC+TO1Sybk=
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/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
@@ -189,8 +199,8 @@ golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/net v0.53.0 h1:d+qAbo5L0orcWAr0a9JweQpjXF19LMXJE8Ey7hwOdUA=
golang.org/x/net v0.53.0/go.mod h1:JvMuJH7rrdiCfbeHoo3fCQU24Lf5JJwT9W3sJFulfgs=
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -198,8 +208,8 @@ golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -214,8 +224,8 @@ golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI=
golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
@@ -234,16 +244,16 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/text v0.36.0 h1:JfKh3XmcRPqZPKevfXVpI1wXPTqbkE5f7JA92a55Yxg=
golang.org/x/text v0.36.0/go.mod h1:NIdBknypM8iqVmPiuco0Dh6P5Jcdk8lJL0CUebqK164=
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/tools v0.44.0 h1:UP4ajHPIcuMjT1GqzDWRlalUEoY+uzoZKnhOjbIPD2c=
golang.org/x/tools v0.44.0/go.mod h1:KA0AfVErSdxRZIsOVipbv3rQhVXTnlU6UhKxHd1seDI=
golang.org/x/tools v0.40.0 h1:yLkxfA+Qnul4cs9QA3KnlFu0lVmd8JJfoq+E41uSutA=
golang.org/x/tools v0.40.0/go.mod h1:Ik/tzLRlbscWpqqMRjyWYDisX8bG13FrdXp3o4Sr9lc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+1 -2
View File
@@ -80,9 +80,8 @@ func (a *ArtistInfoCache) Lookup(ctx context.Context, artist *db.Artist) (*db.Ar
}
artistInfo.SetSimilarArtists(similar)
if url, _ := a.lastfmClient.StealArtistImage(info.URL); url != "" {
url, _ := a.lastfmClient.StealArtistImage(info.URL)
artistInfo.ImageURL = url
}
topTracksResponse, err := a.lastfmClient.ArtistGetTopTracks(artist.Name)
if err != nil {
+5 -9
View File
@@ -10,7 +10,6 @@ import (
"net/url"
"sort"
"strconv"
"strings"
"time"
"github.com/andybalholm/cascadia"
@@ -204,9 +203,6 @@ func (c *Client) StealArtistImage(artistURL string) (string, error) {
return "", fmt.Errorf("get artist url: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode/100 != 2 {
return "", fmt.Errorf("get artist url: %s", resp.Status)
}
node, err := html.Parse(resp.Body)
if err != nil {
@@ -344,12 +340,12 @@ func GetParamSignature(params url.Values, secret string) string {
paramKeys = append(paramKeys, k)
}
sort.Strings(paramKeys)
var toHash strings.Builder
toHash := ""
for _, k := range paramKeys {
toHash.WriteString(k)
toHash.WriteString(params[k][0])
toHash += k
toHash += params[k][0]
}
toHash.WriteString(secret)
hash := md5.Sum([]byte(toHash.String()))
toHash += secret
hash := md5.Sum([]byte(toHash))
return hex.EncodeToString(hash[:])
}
+225
View File
@@ -0,0 +1,225 @@
package ldap
import (
"errors"
"fmt"
"log"
"time"
"go.senan.xyz/gonic/db"
"github.com/go-ldap/ldap/v3"
)
// LDAPStore maps users to a cached password
type LDAPStore map[string]CachedLDAPpassword
// Add caches a password username set.
func (store LDAPStore) Add(username, password string) {
store[username] = CachedLDAPpassword{
Password: password,
ExpiresAt: time.Now().Add(time.Hour * 8), // Keep the password valid for 8 hours.
}
}
// IsValid checks if a user's password is stored in the cache and checks if a
// given password is valid.
func (store LDAPStore) IsValid(username, password string) bool {
cached, ok := store[username]
if !ok {
return false
}
if cached.Password != password {
return false
}
return cached.IsValid()
}
// CachedLDAPpassword stores an LDAP user's password and a time at which the
// server should no longer accept it.
type CachedLDAPpassword struct {
Password string
ExpiresAt time.Time
}
func (password CachedLDAPpassword) IsValid() bool {
return password.ExpiresAt.After(time.Now())
}
// Cofig stores the user's LDAP server options.
type Config struct {
BindUser string
BindPass string
BaseDN string
UsernameAttr string
Filter string
AdminFilter string
FQDN string
Port uint
TLS bool
}
func (c Config) IsSetup() bool {
// This is basically checking if LDAP is setup, if ldapFQDN isn't set we can
// assume that the user hasn't configured LDAP.
return c.FQDN != ""
}
func CheckLDAPcreds(username string, password string, dbc *db.DB, config Config, store LDAPStore) (bool, error) {
if !config.IsSetup() {
return false, nil
}
if store.IsValid(username, password) {
log.Println("Password authenticated via cache!")
return true, nil
}
log.Println("Checking password against LDAP server ...")
// Now, we can try to connect to the LDAP server.
l, err := createLDAPconnection(config)
if err != nil {
// Return a generic error.
log.Println("Failed to connect to LDAP server:", err)
return false, errors.New("failed to connect to LDAP server")
}
defer l.Close()
// Create the user if it doesn't exist on the database already.
err = createUserFromLDAP(username, dbc, config, l)
if err != nil {
log.Println("Failed to create user from LDAP:", err)
return false, err
}
// After we have a connection, let's try binding
_, err = l.SimpleBind(&ldap.SimpleBindRequest{
Username: fmt.Sprintf("%s=%s,%s", config.UsernameAttr, username, config.BaseDN),
Password: password,
})
if err == nil {
// Authentication was OK
store.Add(username, password)
return true, nil
}
log.Println("Failed to bind to LDAP server:", err)
return false, nil
}
// Creates a user from creds
func createUserFromLDAP(username string, dbc *db.DB, config Config, l *ldap.Conn) error {
user := dbc.GetUserByName(username)
if user != nil {
return nil
}
if !config.IsSetup() {
return nil
}
isAdmin := doesLDAPAdminExist(username, config, l)
log.Println(username, isAdmin)
if !doesLDAPUserExist(username, config, l) {
return errors.New("no such user")
}
newUser := db.User{
Name: username,
Password: "", // no password because we want auth to fail.
IsAdmin: isAdmin,
}
err := dbc.Create(&newUser).Error
if err != nil {
return err
}
log.Println("User created via LDAP:", username)
return nil
}
// doesLDAPAdminExist checks if an admin exists on the server.
func doesLDAPAdminExist(username string, config Config, l *ldap.Conn) bool {
filter := fmt.Sprintf("(&(%s=%s)%s)", config.UsernameAttr, ldap.EscapeFilter(username), config.AdminFilter)
searchReq := ldap.NewSearchRequest(
config.BaseDN,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
filter,
[]string{"dn"},
nil,
)
result, err := l.Search(searchReq)
if err != nil {
log.Println("failed to query LDAP server:", err)
return false
}
if len(result.Entries) == 1 {
return true
}
return false
}
// doesLDAPUserExist checks if a user exists on the server.
func doesLDAPUserExist(username string, config Config, l *ldap.Conn) bool {
filter := fmt.Sprintf("(&(%s=%s)%s)", config.UsernameAttr, ldap.EscapeFilter(username), config.Filter)
searchReq := ldap.NewSearchRequest(
config.BaseDN,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
filter,
[]string{"dn"},
nil,
)
result, err := l.Search(searchReq)
if err != nil {
log.Println("failed to query LDAP server:", err)
return false
}
if len(result.Entries) == 1 {
return true
}
return false
}
// Creates a connection to an LDAP server.
func createLDAPconnection(config Config) (*ldap.Conn, error) {
protocol := "ldap"
if config.TLS {
protocol = "ldaps"
}
// Now, we can try to connect to the LDAP server.
l, err := ldap.DialURL(fmt.Sprintf("%s://%s:%d", protocol, config.FQDN, config.Port))
if err != nil {
// Warn the server and return the error.
log.Println("Failed to connect to LDAP server", err)
return nil, err
}
// After we have a connection, let's try binding
_, err = l.SimpleBind(&ldap.SimpleBindRequest{
Username: fmt.Sprintf("%s=%s,%s", config.UsernameAttr, config.BindUser, config.BaseDN),
Password: config.BindPass,
})
if err != nil {
log.Println("Failed to bind to LDAP:", err)
return nil, errors.New("wrong username or password")
}
return l, nil
}
+5 -63
View File
@@ -372,30 +372,20 @@ func (s *Scanner) scanDir(st *State, absPath string) error {
return nil
}
// read tags outside the transaction to avoid holding db locks during disk i/o
type trackTagData struct {
trackUpdate
trprops tags.Properties
trags tags.Tags
}
tagData := make([]trackTagData, 0, len(trackUpdates))
return s.db.Transaction(func(tx *db.DB) error {
var discTitles = map[int]string{}
for _, t := range trackUpdates {
trprops, trags, err := s.tagReader.Read(t.absPath)
if err != nil {
return fmt.Errorf("read %q: %w: %w", t.basename, err, ErrReadingTags)
}
tagData = append(tagData, trackTagData{trackUpdate: t, trprops: trprops, trags: trags})
}
return s.db.Transaction(func(tx *db.DB) error {
var discTitles = map[int]string{}
for _, t := range tagData {
if err := s.populateTrackAndArtists(tx, st, t.i, &album, t.track, t.timeSpec, t.trprops, t.trags, t.basename, t.absPath); err != nil {
if err := s.populateTrackAndArtists(tx, st, t.i, &album, t.track, t.timeSpec, trprops, trags, t.basename, t.absPath); err != nil {
return fmt.Errorf("populate track %q: %w", t.basename, err)
}
discNum := cmp.Or(tags.ParseInt(normtag.Get(t.trags, normtag.DiscNumber)), 1)
discSubtitle := normtag.Get(t.trags, "DISCSUBTITLE")
discNum := cmp.Or(tags.ParseInt(normtag.Get(trags, normtag.DiscNumber)), 1)
discSubtitle := normtag.Get(trags, "DISCSUBTITLE")
if _, exists := discTitles[discNum]; !exists && discSubtitle != "" {
discTitles[discNum] = discSubtitle
@@ -485,14 +475,6 @@ func (s *Scanner) populateTrackAndArtists(tx *db.DB, st *State, i int, album *db
return fmt.Errorf("populate track artists: %w", err)
}
contributorIDs, err := populateTrackContributors(tx, track, trags)
if err != nil {
return fmt.Errorf("populate track contributors: %w", err)
}
if err := populateArtistAppearances(tx, album, contributorIDs); err != nil {
return fmt.Errorf("populate contributor appearances: %w", err)
}
// possible album level embedded covers come only from the first track
if i == 0 {
if err := populateAlbumEmbeddedCover(tx, s.scanEmbeddedCover, album, track, trprops); err != nil {
@@ -694,46 +676,6 @@ func populateAlbumArtists(tx *db.DB, album *db.Album, albumArtistIDs []int) erro
return nil
}
//nolint:gochecknoglobals
var contributorTagKeys = []struct {
keys []string
role db.ContributorRole
}{
{[]string{normtag.Remixers, normtag.Remixer}, db.ContributorRoleRemixer},
{[]string{normtag.Composers, normtag.Composer}, db.ContributorRoleComposer},
{[]string{normtag.Lyricists, normtag.Lyricist}, db.ContributorRoleLyricist},
{[]string{normtag.Conductors, normtag.Conductor}, db.ContributorRoleConductor},
{[]string{normtag.Producers, normtag.Producer}, db.ContributorRoleProducer},
{[]string{normtag.Arrangers, normtag.Arranger}, db.ContributorRoleArranger},
}
func populateTrackContributors(tx *db.DB, track *db.Track, trags tags.Tags) ([]int, error) {
if err := tx.Where("track_id=?", track.ID).Delete(db.TrackContributor{}).Error; err != nil {
return nil, fmt.Errorf("delete old track contributors: %w", err)
}
var rows [][]any
var artistIDs []int
for _, rk := range contributorTagKeys {
for _, name := range tags.FirstValues(trags, rk.keys...) {
if name == "" {
continue
}
artist, err := populateArtist(tx, name)
if err != nil {
return nil, fmt.Errorf("populate contributor artist: %w", err)
}
rows = append(rows, []any{artist.ID, string(rk.role)})
artistIDs = append(artistIDs, artist.ID)
}
}
if err := tx.InsertBulkLeftManyRows("track_contributors", []string{"track_id", "artist_id", "role"}, track.ID, rows); err != nil {
return nil, fmt.Errorf("insert bulk track contributors: %w", err)
}
return artistIDs, nil
}
func populateTrackArtists(tx *db.DB, track *db.Track, trackArtistIDs []int) error {
if err := tx.Where("track_id=?", track.ID).Delete(db.TrackArtist{}).Error; err != nil {
return fmt.Errorf("delete old track artists: %w", err)
+1 -1
View File
@@ -26,7 +26,7 @@ func FuzzScanner(f *testing.F) {
m := mockfs.New(t)
const toAdd = 1000
for i := range toAdd {
for i := 0; i < toAdd; i++ {
path := fmt.Sprintf("artist-%d/album-%d/track-%d.flac", i/6, i/3, i)
m.AddTrack(path)
m.SetTags(path, func(tags *mockfs.TagInfo) {
-68
View File
@@ -461,74 +461,6 @@ func TestMultiFolderWithSharedArtist(t *testing.T) {
}
}
func TestTrackContributors(t *testing.T) {
t.Parallel()
m := mockfs.New(t)
m.AddTrack("artist-a/album-a/track-1.flac")
m.SetTags("artist-a/album-a/track-1.flac", func(tags *mockfs.TagInfo) {
normtag.Set(tags.Tags, normtag.Artist, "artist-a")
normtag.Set(tags.Tags, normtag.AlbumArtist, "artist-a")
normtag.Set(tags.Tags, normtag.Album, "album-a")
normtag.Set(tags.Tags, normtag.Title, "track-1")
normtag.Set(tags.Tags, normtag.Composers, "comp-a", "comp-b")
normtag.Set(tags.Tags, normtag.Remixer, "rem-a")
normtag.Set(tags.Tags, "LYRICIST", "lyr-a")
normtag.Set(tags.Tags, "PRODUCER", "prod-a")
})
m.ScanAndClean()
var track db.Track
require.NoError(t, m.DB().Preload("Contributors.Artist").Where("tag_title=?", "track-1").First(&track).Error)
type pair struct {
Role db.ContributorRole
Artist string
}
var got []pair
for _, c := range track.Contributors {
got = append(got, pair{Role: c.Role, Artist: c.Artist.Name})
}
assert.ElementsMatch(t, []pair{
{db.ContributorRoleComposer, "comp-a"},
{db.ContributorRoleComposer, "comp-b"},
{db.ContributorRoleRemixer, "rem-a"},
{db.ContributorRoleLyricist, "lyr-a"},
{db.ContributorRoleProducer, "prod-a"},
}, got)
// contributor artists should also show up on the album via artist_appearances
for _, name := range []string{"comp-a", "comp-b", "rem-a", "lyr-a", "prod-a"} {
var count int
require.NoError(t, m.DB().
Model(&db.ArtistAppearances{}).
Joins("JOIN artists ON artists.id=artist_appearances.artist_id").
Where("artists.name=?", name).
Count(&count).Error)
assert.Equal(t, 1, count, "expected %q in artist_appearances", name)
}
// re-scanning with a changed composer list should clear the stale row (comp-b)
// and add the new one (comp-c). other roles stay since their tags didn't change.
m.SetTags("artist-a/album-a/track-1.flac", func(tags *mockfs.TagInfo) {
normtag.Set(tags.Tags, normtag.Composers, "comp-a", "comp-c")
})
m.ScanAndClean()
require.NoError(t, m.DB().Preload("Contributors.Artist").Where("tag_title=?", "track-1").First(&track).Error)
got = got[:0]
for _, c := range track.Contributors {
got = append(got, pair{Role: c.Role, Artist: c.Artist.Name})
}
assert.ElementsMatch(t, []pair{
{db.ContributorRoleComposer, "comp-a"},
{db.ContributorRoleComposer, "comp-c"},
{db.ContributorRoleRemixer, "rem-a"},
{db.ContributorRoleLyricist, "lyr-a"},
{db.ContributorRoleProducer, "prod-a"},
}, got)
}
func TestSymlinkedAlbum(t *testing.T) {
t.Parallel()
m := mockfs.NewWithDirs(t, []string{"scan"})
+6 -1
View File
@@ -27,6 +27,7 @@ import (
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/handlerutil"
"go.senan.xyz/gonic/lastfm"
"go.senan.xyz/gonic/ldap"
"go.senan.xyz/gonic/podcast"
"go.senan.xyz/gonic/scanner"
"go.senan.xyz/gonic/server/ctrladmin/adminui"
@@ -48,11 +49,13 @@ type Controller struct {
podcasts *podcast.Podcasts
lastfmClient *lastfm.Client
resolveProxyPath ProxyPathResolver
ldapConfig ldap.Config
ldapStore ldap.LDAPStore
}
type ProxyPathResolver func(in string) string
func New(dbc *db.DB, sessDB *gormstore.Store, scanner *scanner.Scanner, podcasts *podcast.Podcasts, lastfmClient *lastfm.Client, resolveProxyPath ProxyPathResolver) (*Controller, error) {
func New(dbc *db.DB, sessDB *gormstore.Store, scanner *scanner.Scanner, podcasts *podcast.Podcasts, lastfmClient *lastfm.Client, resolveProxyPath ProxyPathResolver, ldapConfig ldap.Config, ldapStore ldap.LDAPStore) (*Controller, error) {
c := Controller{
ServeMux: http.NewServeMux(),
@@ -62,6 +65,8 @@ func New(dbc *db.DB, sessDB *gormstore.Store, scanner *scanner.Scanner, podcasts
podcasts: podcasts,
lastfmClient: lastfmClient,
resolveProxyPath: resolveProxyPath,
ldapConfig: ldapConfig,
ldapStore: ldapStore,
}
resp := respHandler(adminui.TemplatesFS, resolveProxyPath)
+22 -2
View File
@@ -1,28 +1,48 @@
package ctrladmin
import (
"log"
"net/http"
"github.com/gorilla/sessions"
"go.senan.xyz/gonic/ldap"
)
func (c *Controller) ServeLoginDo(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value(CtxSession).(*sessions.Session)
username := r.FormValue("username")
password := r.FormValue("password")
user := c.dbc.GetUserByName(username)
if username == "" || password == "" {
sessAddFlashW(session, []string{"please provide username and password"})
sessLogSave(session, w, r)
http.Redirect(w, r, r.Referer(), http.StatusSeeOther)
return
}
user := c.dbc.GetUserByName(username)
if user == nil || password != user.Password {
if c.ldapConfig.IsSetup() {
ok, err := ldap.CheckLDAPcreds(username, password, c.dbc, c.ldapConfig, c.ldapStore)
if err != nil {
log.Println("Failed to check LDAP credentials:", err)
sessAddFlashW(session, []string{"failed to check LDAP credentials"})
sessLogSave(session, w, r)
http.Redirect(w, r, r.Referer(), http.StatusSeeOther)
return
} else if !ok {
sessAddFlashW(session, []string{"invalid username / password"})
sessLogSave(session, w, r)
http.Redirect(w, r, r.Referer(), http.StatusSeeOther)
return
}
} else if user == nil || user.Password != password {
sessAddFlashW(session, []string{"invalid username / password"})
sessLogSave(session, w, r)
http.Redirect(w, r, r.Referer(), http.StatusSeeOther)
return
}
user = c.dbc.GetUserByName(username)
// put the user name into the session. future endpoints after this one
// are wrapped with WithUserSession() which will get the name from the
// session and put the row into the request context
+54 -11
View File
@@ -10,6 +10,7 @@ import (
"io"
"log"
"net/http"
"strings"
"time"
"go.senan.xyz/gonic/db"
@@ -18,6 +19,7 @@ import (
"go.senan.xyz/gonic/infocache/artistinfocache"
"go.senan.xyz/gonic/jukebox"
"go.senan.xyz/gonic/lastfm"
"go.senan.xyz/gonic/ldap"
"go.senan.xyz/gonic/playlist"
"go.senan.xyz/gonic/podcast"
"go.senan.xyz/gonic/scanner"
@@ -56,7 +58,6 @@ type Controller struct {
dbc *db.DB
scanner *scanner.Scanner
musicPaths []MusicPath
defaultMusicPath string
podcastsPath string
cacheAudioPath string
cacheCoverPath string
@@ -73,14 +74,13 @@ type Controller struct {
resolveProxyPath ProxyPathResolver
}
func New(dbc *db.DB, scannr *scanner.Scanner, musicPaths []MusicPath, defaultMusicPath string, podcastsPath string, cacheAudioPath string, cacheCoverPath string, jukebox *jukebox.Jukebox, playlistStore *playlist.Store, scrobblers []scrobble.Scrobbler, podcasts *podcast.Podcasts, transcoder transcode.Transcoder, lastFMClient *lastfm.Client, artistInfoCache *artistinfocache.ArtistInfoCache, albumInfoCache *albuminfocache.AlbumInfoCache, tagReader tags.Reader, resolveProxyPath ProxyPathResolver) (*Controller, error) {
func New(dbc *db.DB, scannr *scanner.Scanner, musicPaths []MusicPath, podcastsPath string, cacheAudioPath string, cacheCoverPath string, jukebox *jukebox.Jukebox, playlistStore *playlist.Store, scrobblers []scrobble.Scrobbler, podcasts *podcast.Podcasts, transcoder transcode.Transcoder, lastFMClient *lastfm.Client, artistInfoCache *artistinfocache.ArtistInfoCache, albumInfoCache *albuminfocache.AlbumInfoCache, tagReader tags.Reader, resolveProxyPath ProxyPathResolver, ldapConfig ldap.Config, ldapStore ldap.LDAPStore) (*Controller, error) {
c := Controller{
ServeMux: http.NewServeMux(),
dbc: dbc,
scanner: scannr,
musicPaths: musicPaths,
defaultMusicPath: defaultMusicPath,
podcastsPath: podcastsPath,
cacheAudioPath: cacheAudioPath,
cacheCoverPath: cacheCoverPath,
@@ -100,7 +100,7 @@ func New(dbc *db.DB, scannr *scanner.Scanner, musicPaths []MusicPath, defaultMus
chain := handlerutil.Chain(
withParams,
withRequiredParams,
withUser(dbc),
withUser(dbc, ldapConfig, ldapStore),
)
chainRaw := handlerutil.Chain(
chain,
@@ -231,39 +231,82 @@ func withRequiredParams(next http.Handler) http.Handler {
})
}
func withUser(dbc *db.DB) handlerutil.Middleware {
func withUser(dbc *db.DB, ldapConfig ldap.Config, ldapStore ldap.LDAPStore) handlerutil.Middleware {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
params := r.Context().Value(CtxParams).(params.Params)
// ignoring errors here, a middleware has already ensured they exist
username, _ := params.Get("u")
password, _ := params.Get("p")
passwordHex, _ := params.Get("p")
token, _ := params.Get("t")
salt, _ := params.Get("s")
passwordAuth := token == "" && salt == ""
tokenAuth := password == ""
tokenAuth := passwordHex == ""
if tokenAuth == passwordAuth {
_ = writeResp(w, r, spec.NewError(10,
"please provide `t` and `s`, or just `p`"))
return
}
user := dbc.GetUserByName(username)
if user == nil {
_ = writeResp(w, r, spec.NewError(40,
"invalid username %q", username))
var password string
if passwordAuth && passwordHex != "" {
if strings.HasPrefix(passwordHex, "enc:") {
raw := strings.TrimPrefix(passwordHex, "enc:")
decoded, err := hex.DecodeString(raw)
if err != nil {
log.Println("Failed to decode hex password:", err)
_ = writeResp(w, r, spec.NewError(40, "invalid password encoding"))
return
}
password = string(decoded)
} else {
// if not prefixed with "enc:", treat as plain text
password = passwordHex
}
}
user := dbc.GetUserByName(username)
if ldapConfig.IsSetup() {
// Complete auth using LDAP
log.Println("Authenticating using LDAP ...")
ok, err := ldap.CheckLDAPcreds(username, password, dbc, ldapConfig, ldapStore)
if err != nil {
log.Println("Failed to check LDAP creds:", err)
_ = writeResp(w, r, spec.NewError(40, "invalid password"))
return
}
if !ok {
_ = writeResp(w, r, spec.NewError(40, "invalid password"))
return
}
withUser := context.WithValue(r.Context(), CtxUser, user)
next.ServeHTTP(w, r.WithContext(withUser))
return
}
log.Println("Authenticating using built-in ...")
if user == nil {
_ = writeResp(w, r, spec.NewError(40, "invalid password"))
return
}
var credsOk bool
if tokenAuth {
credsOk = checkCredsToken(user.Password, token, salt)
} else {
credsOk = checkCredsBasic(user.Password, password)
}
if !credsOk {
_ = writeResp(w, r, spec.NewError(40, "invalid password"))
return
}
withUser := context.WithValue(r.Context(), CtxUser, user)
next.ServeHTTP(w, r.WithContext(withUser))
})
-1
View File
@@ -44,7 +44,6 @@ func (c *Controller) ServeGetBookmarks(r *http.Request) *spec.Response {
Preload("Album").
Preload("Album.Artists").
Preload("Artists").
Preload("Contributors.Artist").
Find(&track, "id=?", bookmark.EntryID).
Error
if err != nil {
+8 -8
View File
@@ -25,7 +25,7 @@ func (c *Controller) ServeGetIndexes(r *http.Request) *spec.Response {
Select("id").
Model(&db.Album{}).
Where("parent_id IS NULL")
if m := getMusicFolder(c, params); m != "" {
if m := getMusicFolder(c.musicPaths, params); m != "" {
rootQ = rootQ.
Where("root_dir=?", m)
}
@@ -170,7 +170,7 @@ func (c *Controller) ServeGetAlbumList(r *http.Request) *spec.Response {
return spec.NewError(10, "unknown value %q for parameter 'type'", v)
}
if m := getMusicFolder(c, params); m != "" {
if m := getMusicFolder(c.musicPaths, params); m != "" {
q = q.Where("root_dir=?", m)
}
var folders []*db.Album
@@ -220,7 +220,7 @@ func (c *Controller) ServeSearchTwo(r *http.Request) *spec.Response {
Select("id").
Model(&db.Album{}).
Where("parent_id IS NULL")
if m := getMusicFolder(c, params); m != "" {
if m := getMusicFolder(c.musicPaths, params); m != "" {
rootQ = rootQ.Where("root_dir=?", m)
}
@@ -261,7 +261,7 @@ func (c *Controller) ServeSearchTwo(r *http.Request) *spec.Response {
Preload("AlbumRating", "user_id=?", user.ID).
Offset(params.GetOrInt("albumOffset", 0)).
Limit(params.GetOrInt("albumCount", 20))
if m := getMusicFolder(c, params); m != "" {
if m := getMusicFolder(c.musicPaths, params); m != "" {
q = q.Where("root_dir=?", m)
}
if err := q.Find(&albums).Error; err != nil {
@@ -287,7 +287,7 @@ func (c *Controller) ServeSearchTwo(r *http.Request) *spec.Response {
Preload("TrackRating", "user_id=?", user.ID).
Offset(params.GetOrInt("songOffset", 0)).
Limit(params.GetOrInt("songCount", 20))
if m := getMusicFolder(c, params); m != "" {
if m := getMusicFolder(c.musicPaths, params); m != "" {
q = q.
Joins("JOIN albums ON albums.id=tracks.album_id").
Where("albums.root_dir=?", m)
@@ -324,7 +324,7 @@ func (c *Controller) ServeGetStarred(r *http.Request) *spec.Response {
Select("id").
Model(&db.Album{}).
Where("parent_id IS NULL")
if m := getMusicFolder(c, params); m != "" {
if m := getMusicFolder(c.musicPaths, params); m != "" {
rootQ = rootQ.Where("root_dir=?", m)
}
@@ -350,7 +350,7 @@ func (c *Controller) ServeGetStarred(r *http.Request) *spec.Response {
Where("album_stars.user_id=?", user.ID).
Preload("AlbumStar", "user_id=?", user.ID).
Preload("AlbumRating", "user_id=?", user.ID)
if m := getMusicFolder(c, params); m != "" {
if m := getMusicFolder(c.musicPaths, params); m != "" {
q = q.Where("root_dir=?", m)
}
if err := q.Find(&albums).Error; err != nil {
@@ -369,7 +369,7 @@ func (c *Controller) ServeGetStarred(r *http.Request) *spec.Response {
Preload("Artists").
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID)
if m := getMusicFolder(c, params); m != "" {
if m := getMusicFolder(c.musicPaths, params); m != "" {
q = q.
Joins("JOIN albums ON albums.id=tracks.album_id").
Where("albums.root_dir=?", m)
+15 -24
View File
@@ -33,7 +33,7 @@ func (c *Controller) ServeGetArtists(r *http.Request) *spec.Response {
Preload("Info").
Group("artists.id").
Order("artists.name COLLATE NOCASE")
if m := getMusicFolder(c, params); m != "" {
if m := getMusicFolder(c.musicPaths, params); m != "" {
q = q.
Joins("JOIN albums ON albums.id=album_artists.album_id").
Where("albums.root_dir=?", m)
@@ -113,7 +113,6 @@ func (c *Controller) ServeGetAlbum(r *http.Request) *spec.Response {
return db.
Order("tracks.tag_disc_number, tracks.tag_track_number").
Preload("Artists").
Preload("Contributors.Artist").
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID)
}).
@@ -155,24 +154,24 @@ func (c *Controller) ServeGetAlbumListTwo(r *http.Request) *spec.Response {
q = q.Joins("JOIN artists ON artists.id=album_artists.artist_id")
q = q.Order("artists.name")
case "alphabeticalByName":
q = q.Order("albums.tag_title")
q = q.Order("tag_title")
case "byYear":
y1, y2 := params.GetOrInt("fromYear", 1800),
params.GetOrInt("toYear", 2200)
// support some clients sending wrong order like DSub
q = q.Where("albums.tag_year BETWEEN ? AND ?", min(y1, y2), max(y1, y2))
q = q.Order("albums.tag_year DESC")
q = q.Where("tag_year BETWEEN ? AND ?", min(y1, y2), max(y1, y2))
q = q.Order("tag_year DESC")
case "byGenre":
genre, _ := params.Get("genre")
q = q.Joins("JOIN album_genres ON album_genres.album_id=albums.id")
q = q.Joins("JOIN genres ON genres.id=album_genres.genre_id AND genres.name=?", genre)
q = q.Order("albums.tag_title")
q = q.Order("tag_title")
case "frequent":
user := r.Context().Value(CtxUser).(*db.User)
q = q.Joins("JOIN plays ON albums.id=plays.album_id AND plays.user_id=?", user.ID)
q = q.Order("plays.length DESC")
case "newest":
q = q.Order("albums.created_at DESC")
q = q.Order("created_at DESC")
case "random":
q = q.Order(gorm.Expr("random()"))
case "recent":
@@ -180,14 +179,14 @@ func (c *Controller) ServeGetAlbumListTwo(r *http.Request) *spec.Response {
q = q.Order("plays.time DESC")
case "starred":
q = q.Joins("JOIN album_stars ON albums.id=album_stars.album_id AND album_stars.user_id=?", user.ID)
q = q.Order("albums.tag_title")
q = q.Order("tag_title")
case "highest":
q = q.Joins("JOIN album_ratings ON album_ratings.album_id=albums.id AND album_ratings.user_id=?", user.ID)
q = q.Order("album_ratings.rating DESC")
default:
return spec.NewError(10, "unknown value %q for parameter 'type'", listType)
}
if m := getMusicFolder(c, params); m != "" {
if m := getMusicFolder(c.musicPaths, params); m != "" {
q = q.Where("root_dir=?", m)
}
var albums []*db.Album
@@ -255,7 +254,7 @@ func (c *Controller) ServeSearchThree(r *http.Request) *spec.Response {
Preload("Info").
Offset(params.GetOrInt("artistOffset", 0)).
Limit(params.GetOrInt("artistCount", 20))
if m := getMusicFolder(c, params); m != "" {
if m := getMusicFolder(c.musicPaths, params); m != "" {
q = q.Where("albums.root_dir=?", m)
}
if err := q.Find(&artists).Error; err != nil {
@@ -284,7 +283,7 @@ func (c *Controller) ServeSearchThree(r *http.Request) *spec.Response {
q = q.
Offset(params.GetOrInt("albumOffset", 0)).
Limit(params.GetOrInt("albumCount", 20))
if m := getMusicFolder(c, params); m != "" {
if m := getMusicFolder(c.musicPaths, params); m != "" {
q = q.Where("root_dir=?", m)
}
if err := q.Find(&albums).Error; err != nil {
@@ -301,7 +300,6 @@ func (c *Controller) ServeSearchThree(r *http.Request) *spec.Response {
Preload("Album.Artists").
Preload("Genres").
Preload("Artists").
Preload("Contributors.Artist").
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID)
switch {
@@ -313,7 +311,7 @@ func (c *Controller) ServeSearchThree(r *http.Request) *spec.Response {
}
q = q.Offset(params.GetOrInt("songOffset", 0)).
Limit(params.GetOrInt("songCount", 20))
if m := getMusicFolder(c, params); m != "" {
if m := getMusicFolder(c.musicPaths, params); m != "" {
q = q.
Joins("JOIN albums ON albums.id=tracks.album_id").
Where("albums.root_dir=?", m)
@@ -454,7 +452,6 @@ func (c *Controller) ServeGetGenres(_ *http.Request) *spec.Response {
(SELECT count(1) FROM album_genres WHERE genre_id=genres.id) album_count,
(SELECT count(1) FROM track_genres WHERE genre_id=genres.id) track_count`).
Group("genres.id").
Order("genres.name").
Find(&genres)
sub := spec.NewResponse()
sub.Genres = &spec.Genres{
@@ -481,12 +478,11 @@ func (c *Controller) ServeGetSongsByGenre(r *http.Request) *spec.Response {
Preload("Album").
Preload("Album.Artists").
Preload("Artists").
Preload("Contributors.Artist").
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID).
Offset(params.GetOrInt("offset", 0)).
Limit(params.GetOrInt("count", 10))
if m := getMusicFolder(c, params); m != "" {
if m := getMusicFolder(c.musicPaths, params); m != "" {
q = q.Where("albums.root_dir=?", m)
}
q = q.Group("tracks.id")
@@ -527,7 +523,7 @@ func (c *Controller) ServeGetStarredTwo(r *http.Request) *spec.Response {
Preload("ArtistRating", "user_id=?", user.ID).
Preload("Info").
Group("artists.id")
if m := getMusicFolder(c, params); m != "" {
if m := getMusicFolder(c.musicPaths, params); m != "" {
q = q.Where("albums.root_dir=?", m)
}
if err := q.Find(&artists).Error; err != nil {
@@ -548,7 +544,7 @@ func (c *Controller) ServeGetStarredTwo(r *http.Request) *spec.Response {
Preload("AlbumStar", "user_id=?", user.ID).
Preload("AlbumRating", "user_id=?", user.ID).
Preload("Play", "user_id=?", user.ID)
if m := getMusicFolder(c, params); m != "" {
if m := getMusicFolder(c.musicPaths, params); m != "" {
q = q.Where("albums.root_dir=?", m)
}
if err := q.Find(&albums).Error; err != nil {
@@ -567,10 +563,9 @@ func (c *Controller) ServeGetStarredTwo(r *http.Request) *spec.Response {
Preload("Album").
Preload("Album.Artists").
Preload("Artists").
Preload("Contributors.Artist").
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID)
if m := getMusicFolder(c, params); m != "" {
if m := getMusicFolder(c.musicPaths, params); m != "" {
q = q.
Joins("JOIN albums ON albums.id=tracks.album_id").
Where("albums.root_dir=?", m)
@@ -641,7 +636,6 @@ func (c *Controller) ServeGetTopSongs(r *http.Request) *spec.Response {
Where("artists.id=?", artist.ID).
Preload("Album").
Preload("Artists").
Preload("Contributors.Artist").
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID).
Group("tracks.id").
@@ -751,7 +745,6 @@ func getSimilarSongsFromTrack(c *Controller, id specid.ID, params params.Params,
Select("tracks.*").
Preload("Album").
Preload("Artists").
Preload("Contributors.Artist").
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID).
Where("tracks.tag_title IN (?)", similarTrackNames).
@@ -805,7 +798,6 @@ func getSimilarSongsFromArtist(c *Controller, id specid.ID, params params.Params
err = c.dbc.
Preload("Album").
Preload("Artists").
Preload("Contributors.Artist").
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID).
Joins("JOIN track_artists ON track_artists.track_id=tracks.id").
@@ -874,7 +866,6 @@ func getSimilarSongsFromAlbum(c *Controller, id specid.ID, params params.Params,
Select("tracks.*").
Preload("Album").
Preload("Artists").
Preload("Contributors.Artist").
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID).
Where("tracks.tag_title IN (?)", similarTrackNames).
+4 -7
View File
@@ -293,7 +293,6 @@ func (c *Controller) ServeGetSong(r *http.Request) *spec.Response {
Preload("Album").
Preload("Album.Artists").
Preload("Artists").
Preload("Contributors.Artist").
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID).
First(&track).
@@ -321,7 +320,6 @@ func (c *Controller) ServeGetRandomSongs(r *http.Request) *spec.Response {
Preload("Album").
Preload("Album.Artists").
Preload("Artists").
Preload("Contributors.Artist").
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID).
Joins("JOIN albums ON tracks.album_id=albums.id").
@@ -336,7 +334,7 @@ func (c *Controller) ServeGetRandomSongs(r *http.Request) *spec.Response {
q = q.Joins("JOIN track_genres ON track_genres.track_id=tracks.id")
q = q.Joins("JOIN genres ON genres.id=track_genres.genre_id AND genres.name=?", genre)
}
if m := getMusicFolder(c, params); m != "" {
if m := getMusicFolder(c.musicPaths, params); m != "" {
q = q.Where("albums.root_dir=?", m)
}
if err := q.Find(&tracks).Error; err != nil {
@@ -400,7 +398,7 @@ func (c *Controller) ServeJukebox(r *http.Request) *spec.Response { // nolint:go
switch id.Type {
case specid.Track:
var track db.Track
if err := c.dbc.Where("id=?", id.Value).Preload("Album").Preload("Album.Artists").Preload("Artists").Preload("Contributors.Artist").Find(&track).Error; err != nil {
if err := c.dbc.Where("id=?", id.Value).Preload("Album").Preload("Album.Artists").Preload("Artists").Find(&track).Error; err != nil {
return nil, fmt.Errorf("load track: %w", err)
}
ret = append(ret, spec.NewTrackByTags(&track, track.Album))
@@ -779,11 +777,10 @@ func scrobbleStatsUpdatePodcastEpisode(dbc *db.DB, peID int) error {
return nil
}
func getMusicFolder(c *Controller, p params.Params) string {
musicPaths := c.musicPaths
func getMusicFolder(musicPaths []MusicPath, p params.Params) string {
idx, err := p.GetInt("musicFolderId")
if err != nil {
return c.defaultMusicPath
return ""
}
if idx < 0 || idx >= len(musicPaths) {
return os.DevNull
@@ -20,7 +20,7 @@ func NewAlbumByFolder(f *db.Album) *Album {
TrackCount: f.ChildCount,
Duration: f.Duration,
Created: f.CreatedAt,
AverageRating: f.AverageRating,
AverageRating: formatRating(f.AverageRating),
ReleaseTypes: []string{},
}
if f.AlbumStar != nil {
@@ -44,7 +44,7 @@ func NewTCAlbumByFolder(f *db.Album) *TrackChild {
Title: f.RightPath,
ParentID: f.ParentSID(),
CreatedAt: f.CreatedAt,
AverageRating: f.AverageRating,
AverageRating: formatRating(f.AverageRating),
Year: f.TagYear,
}
if f.AlbumStar != nil {
@@ -84,7 +84,7 @@ func NewTCTrackByFolder(t *db.Track, parent *db.Album) *TrackChild {
Type: "music",
MusicBrainzID: t.TagBrainzID,
CreatedAt: t.CreatedAt,
AverageRating: t.AverageRating,
AverageRating: formatRating(t.AverageRating),
Year: t.TagYear,
}
if trCh.Title == "" {
@@ -170,7 +170,7 @@ func NewArtistByFolder(f *db.Album) *Artist {
ID: f.SID(),
Name: f.RightPath,
AlbumCount: f.ChildCount,
AverageRating: f.AverageRating,
AverageRating: formatRating(f.AverageRating),
}
if f.AlbumStar != nil {
a.Starred = &f.AlbumStar.StarDate
@@ -192,7 +192,7 @@ func NewDirectoryByFolder(f *db.Album, children []*TrackChild) *Directory {
Name: f.RightPath,
Children: children,
ParentID: f.ParentSID(),
AverageRating: f.AverageRating,
AverageRating: formatRating(f.AverageRating),
}
if f.AlbumStar != nil {
d.Starred = &f.AlbumStar.StarDate
+9 -30
View File
@@ -3,9 +3,7 @@ package spec
import (
"cmp"
"path/filepath"
"slices"
"sort"
"strings"
"go.senan.xyz/gonic/db"
)
@@ -24,7 +22,7 @@ func NewAlbumByTags(a *db.Album, artists []*db.Artist) *Album {
Genres: []*GenreRef{},
Year: a.TagYear,
Tracks: []*TrackChild{},
AverageRating: a.AverageRating,
AverageRating: formatRating(a.AverageRating),
IsCompilation: a.TagCompilation,
ReleaseTypes: formatReleaseTypes(a.TagReleaseType),
DiscTitles: []*DiscTitle{},
@@ -99,7 +97,7 @@ func NewTrackByTags(t *db.Track, album *db.Album) *TrackChild {
DiscNumber: t.TagDiscNumber,
Type: "music",
MusicBrainzID: t.TagBrainzID,
AverageRating: t.AverageRating,
AverageRating: formatRating(t.AverageRating),
TranscodeMeta: TranscodeMeta{},
Year: t.TagYear,
}
@@ -120,8 +118,12 @@ func NewTrackByTags(t *db.Track, album *db.Album) *TrackChild {
ret.UserRating = t.TrackRating.Rating
}
slices.SortFunc(t.Artists, func(a, b *db.Artist) int { return cmp.Compare(a.ID, b.ID) })
slices.SortFunc(album.Artists, func(a, b *db.Artist) int { return cmp.Compare(a.ID, b.ID) })
sort.Slice(t.Artists, func(i, j int) bool {
return t.Artists[i].ID < t.Artists[j].ID
})
sort.Slice(album.Artists, func(i, j int) bool {
return album.Artists[i].ID < album.Artists[j].ID
})
switch {
case len(t.Artists) > 0:
@@ -143,29 +145,6 @@ func NewTrackByTags(t *db.Track, album *db.Album) *TrackChild {
for _, a := range album.Artists {
ret.AlbumArtists = append(ret.AlbumArtists, &ArtistRef{ID: a.SID(), Name: a.Name})
}
slices.SortStableFunc(t.Contributors, func(a, b *db.TrackContributor) int {
return cmp.Or(
cmp.Compare(a.Role, b.Role),
cmp.Compare(a.ArtistID, b.ArtistID),
)
})
var composers []string
for _, c := range t.Contributors {
if c.Artist == nil {
continue
}
ret.Contributors = append(ret.Contributors, &Contributor{
Role: string(c.Role),
Artist: &ArtistRef{ID: c.Artist.SID(), Name: c.Artist.Name},
})
if c.Role == db.ContributorRoleComposer {
composers = append(composers, c.Artist.Name)
}
}
ret.DisplayComposer = strings.Join(composers, ", ")
if t.ReplayGainTrackGain != 0 || t.ReplayGainAlbumGain != 0 {
ret.ReplayGain = &ReplayGain{
TrackGain: t.ReplayGainTrackGain,
@@ -183,7 +162,7 @@ func NewArtistByTags(a *db.Artist) *Artist {
Name: a.Name,
AlbumCount: a.AlbumCount,
Albums: []*Album{},
AverageRating: a.AverageRating,
AverageRating: formatRating(a.AverageRating),
}
if a.Info != nil && a.Info.ImageURL != "" {
r.CoverID = a.SID()
+11 -13
View File
@@ -125,12 +125,6 @@ type GenreRef struct {
Name string `xml:"name,attr" json:"name"`
}
// https://opensubsonic.netlify.app/docs/responses/contributor/
type Contributor struct {
Role string `xml:"role,attr" json:"role"`
Artist *ArtistRef `xml:"artist" json:"artist"`
}
type DiscTitle struct {
Disc int `xml:"disc,attr" json:"disc"`
Title string `xml:"title,attr" json:"title"`
@@ -171,7 +165,7 @@ type Album struct {
// star / rating
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
UserRating int `xml:"userRating,attr,omitempty" json:"userRating,omitempty"`
AverageRating float64 `xml:"averageRating,attr,omitempty" json:"averageRating,omitempty"`
AverageRating string `xml:"averageRating,attr,omitempty" json:"averageRating,omitempty"`
}
type RandomTracks struct {
@@ -210,9 +204,6 @@ type TrackChild struct {
AlbumArtists []*ArtistRef `xml:"albumArtists" json:"albumArtists"`
AlbumDisplayArtist string `xml:"displayAlbumArtist,attr" json:"displayAlbumArtist"`
Contributors []*Contributor `xml:"contributors" json:"contributors"`
DisplayComposer string `xml:"displayComposer,attr" json:"displayComposer"`
Bitrate int `xml:"bitRate,attr,omitempty" json:"bitRate,omitempty"`
ContentType string `xml:"contentType,attr,omitempty" json:"contentType,omitempty"`
CoverID *specid.ID `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
@@ -237,7 +228,7 @@ type TrackChild struct {
// star / rating
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
UserRating int `xml:"userRating,attr,omitempty" json:"userRating,omitempty"`
AverageRating float64 `xml:"averageRating,attr,omitempty" json:"averageRating,omitempty"`
AverageRating string `xml:"averageRating,attr,omitempty" json:"averageRating,omitempty"`
ReplayGain *ReplayGain `xml:"replayGain" json:"replayGain"`
@@ -258,7 +249,7 @@ type Artist struct {
// star / rating
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
UserRating int `xml:"userRating,attr,omitempty" json:"userRating,omitempty"`
AverageRating float64 `xml:"averageRating,attr,omitempty" json:"averageRating,omitempty"`
AverageRating string `xml:"averageRating,attr,omitempty" json:"averageRating,omitempty"`
}
type Indexes struct {
@@ -278,7 +269,7 @@ type Directory struct {
Name string `xml:"name,attr,omitempty" json:"name"`
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
UserRating int `xml:"userRating,attr,omitempty" json:"userRating,omitempty"`
AverageRating float64 `xml:"averageRating,attr,omitempty" json:"averageRating,omitempty"`
AverageRating string `xml:"averageRating,attr,omitempty" json:"averageRating,omitempty"`
Children []*TrackChild `xml:"child,omitempty" json:"child,omitempty"`
}
@@ -516,6 +507,13 @@ type OpenSubsonicExtension struct {
type OpenSubsonicExtensions []OpenSubsonicExtension
func formatRating(rating float64) string {
if rating == 0 {
return ""
}
return fmt.Sprintf("%.2f", rating)
}
func formatExt(ext string) string {
return strings.TrimPrefix(ext, ".")
}
+114 -114
View File
@@ -7,44 +7,6 @@
"openSubsonic": true,
"albumList": {
"album": [
{
"id": "al-8",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-1",
"artists": null,
"displayArtist": "",
"title": "album-1",
"album": "album-1",
"parent": "al-6",
"isDir": true,
"coverArt": "al-8",
"name": "album-1",
"songCount": 3,
"duration": 300,
"playCount": 0,
"isCompilation": false,
"releaseTypes": [],
"discTitles": null
},
{
"id": "al-5",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-0",
"artists": null,
"displayArtist": "",
"title": "album-2",
"album": "album-2",
"parent": "al-2",
"isDir": true,
"coverArt": "al-5",
"name": "album-2",
"songCount": 3,
"duration": 300,
"playCount": 0,
"isCompilation": false,
"releaseTypes": [],
"discTitles": null
},
{
"id": "al-11",
"created": "2019-11-30T00:00:00Z",
@@ -64,82 +26,6 @@
"releaseTypes": [],
"discTitles": null
},
{
"id": "al-7",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-1",
"artists": null,
"displayArtist": "",
"title": "album-0",
"album": "album-0",
"parent": "al-6",
"isDir": true,
"coverArt": "al-7",
"name": "album-0",
"songCount": 3,
"duration": 300,
"playCount": 0,
"isCompilation": false,
"releaseTypes": [],
"discTitles": null
},
{
"id": "al-9",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-1",
"artists": null,
"displayArtist": "",
"title": "album-2",
"album": "album-2",
"parent": "al-6",
"isDir": true,
"coverArt": "al-9",
"name": "album-2",
"songCount": 3,
"duration": 300,
"playCount": 0,
"isCompilation": false,
"releaseTypes": [],
"discTitles": null
},
{
"id": "al-3",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-0",
"artists": null,
"displayArtist": "",
"title": "album-0",
"album": "album-0",
"parent": "al-2",
"isDir": true,
"coverArt": "al-3",
"name": "album-0",
"songCount": 3,
"duration": 300,
"playCount": 0,
"isCompilation": false,
"releaseTypes": [],
"discTitles": null
},
{
"id": "al-4",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-0",
"artists": null,
"displayArtist": "",
"title": "album-1",
"album": "album-1",
"parent": "al-2",
"isDir": true,
"coverArt": "al-4",
"name": "album-1",
"songCount": 3,
"duration": 300,
"playCount": 0,
"isCompilation": false,
"releaseTypes": [],
"discTitles": null
},
{
"id": "al-13",
"created": "2019-11-30T00:00:00Z",
@@ -159,6 +45,101 @@
"releaseTypes": [],
"discTitles": null
},
{
"id": "al-7",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-1",
"artists": null,
"displayArtist": "",
"title": "album-0",
"album": "album-0",
"parent": "al-6",
"isDir": true,
"coverArt": "al-7",
"name": "album-0",
"songCount": 3,
"duration": 300,
"playCount": 0,
"isCompilation": false,
"releaseTypes": [],
"discTitles": null
},
{
"id": "al-5",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-0",
"artists": null,
"displayArtist": "",
"title": "album-2",
"album": "album-2",
"parent": "al-2",
"isDir": true,
"coverArt": "al-5",
"name": "album-2",
"songCount": 3,
"duration": 300,
"playCount": 0,
"isCompilation": false,
"releaseTypes": [],
"discTitles": null
},
{
"id": "al-4",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-0",
"artists": null,
"displayArtist": "",
"title": "album-1",
"album": "album-1",
"parent": "al-2",
"isDir": true,
"coverArt": "al-4",
"name": "album-1",
"songCount": 3,
"duration": 300,
"playCount": 0,
"isCompilation": false,
"releaseTypes": [],
"discTitles": null
},
{
"id": "al-8",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-1",
"artists": null,
"displayArtist": "",
"title": "album-1",
"album": "album-1",
"parent": "al-6",
"isDir": true,
"coverArt": "al-8",
"name": "album-1",
"songCount": 3,
"duration": 300,
"playCount": 0,
"isCompilation": false,
"releaseTypes": [],
"discTitles": null
},
{
"id": "al-9",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-1",
"artists": null,
"displayArtist": "",
"title": "album-2",
"album": "album-2",
"parent": "al-6",
"isDir": true,
"coverArt": "al-9",
"name": "album-2",
"songCount": 3,
"duration": 300,
"playCount": 0,
"isCompilation": false,
"releaseTypes": [],
"discTitles": null
},
{
"id": "al-12",
"created": "2019-11-30T00:00:00Z",
@@ -177,6 +158,25 @@
"isCompilation": false,
"releaseTypes": [],
"discTitles": null
},
{
"id": "al-3",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-0",
"artists": null,
"displayArtist": "",
"title": "album-0",
"album": "album-0",
"parent": "al-2",
"isDir": true,
"coverArt": "al-3",
"name": "album-0",
"songCount": 3,
"duration": 300,
"playCount": 0,
"isCompilation": false,
"releaseTypes": [],
"discTitles": null
}
]
}
+83 -83
View File
@@ -8,16 +8,79 @@
"albumList2": {
"album": [
{
"id": "al-8",
"id": "al-12",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-3",
"artist": "artist-2",
"artists": [{ "id": "ar-3", "name": "artist-2" }],
"displayArtist": "artist-2",
"title": "album-1",
"album": "album-1",
"coverArt": "al-12",
"name": "album-1",
"songCount": 3,
"duration": 300,
"playCount": 0,
"genre": "Unknown Genre",
"genres": [{ "name": "Unknown Genre" }],
"year": 2021,
"isCompilation": false,
"releaseTypes": ["Album"],
"discTitles": []
},
{
"id": "al-5",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-1",
"artist": "artist-0",
"artists": [{ "id": "ar-1", "name": "artist-0" }],
"displayArtist": "artist-0",
"title": "album-2",
"album": "album-2",
"coverArt": "al-5",
"name": "album-2",
"songCount": 3,
"duration": 300,
"playCount": 0,
"genre": "Unknown Genre",
"genres": [{ "name": "Unknown Genre" }],
"year": 2021,
"isCompilation": false,
"releaseTypes": ["Album"],
"discTitles": []
},
{
"id": "al-9",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-2",
"artist": "artist-1",
"artists": [{ "id": "ar-2", "name": "artist-1" }],
"displayArtist": "artist-1",
"title": "album-1",
"album": "album-1",
"coverArt": "al-8",
"name": "album-1",
"title": "album-2",
"album": "album-2",
"coverArt": "al-9",
"name": "album-2",
"songCount": 3,
"duration": 300,
"playCount": 0,
"genre": "Unknown Genre",
"genres": [{ "name": "Unknown Genre" }],
"year": 2021,
"isCompilation": false,
"releaseTypes": ["Album"],
"discTitles": []
},
{
"id": "al-3",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-1",
"artist": "artist-0",
"artists": [{ "id": "ar-1", "name": "artist-0" }],
"displayArtist": "artist-0",
"title": "album-0",
"album": "album-0",
"coverArt": "al-3",
"name": "album-0",
"songCount": 3,
"duration": 300,
"playCount": 0,
@@ -71,16 +134,16 @@
"discTitles": []
},
{
"id": "al-3",
"id": "al-8",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-1",
"artist": "artist-0",
"artists": [{ "id": "ar-1", "name": "artist-0" }],
"displayArtist": "artist-0",
"title": "album-0",
"album": "album-0",
"coverArt": "al-3",
"name": "album-0",
"artistId": "ar-2",
"artist": "artist-1",
"artists": [{ "id": "ar-2", "name": "artist-1" }],
"displayArtist": "artist-1",
"title": "album-1",
"album": "album-1",
"coverArt": "al-8",
"name": "album-1",
"songCount": 3,
"duration": 300,
"playCount": 0,
@@ -92,15 +155,15 @@
"discTitles": []
},
{
"id": "al-12",
"id": "al-4",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-3",
"artist": "artist-2",
"artists": [{ "id": "ar-3", "name": "artist-2" }],
"displayArtist": "artist-2",
"artistId": "ar-1",
"artist": "artist-0",
"artists": [{ "id": "ar-1", "name": "artist-0" }],
"displayArtist": "artist-0",
"title": "album-1",
"album": "album-1",
"coverArt": "al-12",
"coverArt": "al-4",
"name": "album-1",
"songCount": 3,
"duration": 300,
@@ -132,69 +195,6 @@
"isCompilation": false,
"releaseTypes": ["Album"],
"discTitles": []
},
{
"id": "al-9",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-2",
"artist": "artist-1",
"artists": [{ "id": "ar-2", "name": "artist-1" }],
"displayArtist": "artist-1",
"title": "album-2",
"album": "album-2",
"coverArt": "al-9",
"name": "album-2",
"songCount": 3,
"duration": 300,
"playCount": 0,
"genre": "Unknown Genre",
"genres": [{ "name": "Unknown Genre" }],
"year": 2021,
"isCompilation": false,
"releaseTypes": ["Album"],
"discTitles": []
},
{
"id": "al-5",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-1",
"artist": "artist-0",
"artists": [{ "id": "ar-1", "name": "artist-0" }],
"displayArtist": "artist-0",
"title": "album-2",
"album": "album-2",
"coverArt": "al-5",
"name": "album-2",
"songCount": 3,
"duration": 300,
"playCount": 0,
"genre": "Unknown Genre",
"genres": [{ "name": "Unknown Genre" }],
"year": 2021,
"isCompilation": false,
"releaseTypes": ["Album"],
"discTitles": []
},
{
"id": "al-4",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-1",
"artist": "artist-0",
"artists": [{ "id": "ar-1", "name": "artist-0" }],
"displayArtist": "artist-0",
"title": "album-1",
"album": "album-1",
"coverArt": "al-4",
"name": "album-1",
"songCount": 3,
"duration": 300,
"playCount": 0,
"genre": "Unknown Genre",
"genres": [{ "name": "Unknown Genre" }],
"year": 2021,
"isCompilation": false,
"releaseTypes": ["Album"],
"discTitles": []
}
]
}
@@ -33,8 +33,6 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -63,8 +61,6 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -93,8 +89,6 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -20,8 +20,6 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -50,8 +48,6 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -80,8 +76,6 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -17,8 +17,6 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-3",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
@@ -36,8 +34,6 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-4",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
@@ -55,8 +51,6 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-5",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
-40
View File
@@ -17,8 +17,6 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -49,8 +47,6 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -81,8 +77,6 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -113,8 +107,6 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-4",
@@ -145,8 +137,6 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-4",
@@ -177,8 +167,6 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-4",
@@ -209,8 +197,6 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-5",
@@ -241,8 +227,6 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-5",
@@ -273,8 +257,6 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-5",
@@ -305,8 +287,6 @@
"displayArtist": "artist-1",
"albumArtists": [{ "id": "ar-2", "name": "artist-1" }],
"displayAlbumArtist": "artist-1",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-7",
@@ -337,8 +317,6 @@
"displayArtist": "artist-1",
"albumArtists": [{ "id": "ar-2", "name": "artist-1" }],
"displayAlbumArtist": "artist-1",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-7",
@@ -369,8 +347,6 @@
"displayArtist": "artist-1",
"albumArtists": [{ "id": "ar-2", "name": "artist-1" }],
"displayAlbumArtist": "artist-1",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-7",
@@ -401,8 +377,6 @@
"displayArtist": "artist-1",
"albumArtists": [{ "id": "ar-2", "name": "artist-1" }],
"displayAlbumArtist": "artist-1",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-8",
@@ -433,8 +407,6 @@
"displayArtist": "artist-1",
"albumArtists": [{ "id": "ar-2", "name": "artist-1" }],
"displayAlbumArtist": "artist-1",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-8",
@@ -465,8 +437,6 @@
"displayArtist": "artist-1",
"albumArtists": [{ "id": "ar-2", "name": "artist-1" }],
"displayAlbumArtist": "artist-1",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-8",
@@ -497,8 +467,6 @@
"displayArtist": "artist-1",
"albumArtists": [{ "id": "ar-2", "name": "artist-1" }],
"displayAlbumArtist": "artist-1",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-9",
@@ -529,8 +497,6 @@
"displayArtist": "artist-1",
"albumArtists": [{ "id": "ar-2", "name": "artist-1" }],
"displayAlbumArtist": "artist-1",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-9",
@@ -561,8 +527,6 @@
"displayArtist": "artist-1",
"albumArtists": [{ "id": "ar-2", "name": "artist-1" }],
"displayAlbumArtist": "artist-1",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-9",
@@ -593,8 +557,6 @@
"displayArtist": "artist-2",
"albumArtists": [{ "id": "ar-3", "name": "artist-2" }],
"displayAlbumArtist": "artist-2",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-11",
@@ -625,8 +587,6 @@
"displayArtist": "artist-2",
"albumArtists": [{ "id": "ar-3", "name": "artist-2" }],
"displayAlbumArtist": "artist-2",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-11",
-18
View File
@@ -14,8 +14,6 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-3",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
@@ -33,8 +31,6 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-4",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
@@ -52,8 +48,6 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-5",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
@@ -71,8 +65,6 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-7",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
@@ -90,8 +82,6 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-8",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
@@ -109,8 +99,6 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-9",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
@@ -128,8 +116,6 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-11",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
@@ -147,8 +133,6 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-12",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
@@ -166,8 +150,6 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-13",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
-40
View File
@@ -17,8 +17,6 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -47,8 +45,6 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -77,8 +73,6 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -107,8 +101,6 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-4",
@@ -137,8 +129,6 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-4",
@@ -167,8 +157,6 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-4",
@@ -197,8 +185,6 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-5",
@@ -227,8 +213,6 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-5",
@@ -257,8 +241,6 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-5",
@@ -287,8 +269,6 @@
"displayArtist": "artist-1",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-7",
@@ -317,8 +297,6 @@
"displayArtist": "artist-1",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-7",
@@ -347,8 +325,6 @@
"displayArtist": "artist-1",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-7",
@@ -377,8 +353,6 @@
"displayArtist": "artist-1",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-8",
@@ -407,8 +381,6 @@
"displayArtist": "artist-1",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-8",
@@ -437,8 +409,6 @@
"displayArtist": "artist-1",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-8",
@@ -467,8 +437,6 @@
"displayArtist": "artist-1",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-9",
@@ -497,8 +465,6 @@
"displayArtist": "artist-1",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-9",
@@ -527,8 +493,6 @@
"displayArtist": "artist-1",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-9",
@@ -557,8 +521,6 @@
"displayArtist": "artist-2",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-11",
@@ -587,8 +549,6 @@
"displayArtist": "artist-2",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-11",
+12 -12
View File
@@ -33,15 +33,6 @@ const (
FallbackGenre = "Unknown Genre"
)
func FirstValues(p Tags, keys ...string) []string {
for _, k := range keys {
if v := normtag.Values(p, k); len(v) > 0 {
return v
}
}
return nil
}
func MustAlbum(p Tags) string {
if r := normtag.Get(p, normtag.Album); r != "" {
return r
@@ -57,7 +48,10 @@ func MustArtist(p Tags) string {
}
func MustArtists(p Tags) []string {
if r := FirstValues(p, normtag.Artists, normtag.Artist); len(r) > 0 {
if r := normtag.Values(p, normtag.Artists); len(r) > 0 {
return r
}
if r := normtag.Values(p, normtag.Artist); len(r) > 0 {
return r
}
return []string{FallbackArtist}
@@ -71,7 +65,10 @@ func MustAlbumArtist(p Tags) string {
}
func MustAlbumArtists(p Tags) []string {
if r := FirstValues(p, normtag.AlbumArtists, normtag.AlbumArtist); len(r) > 0 {
if r := normtag.Values(p, normtag.AlbumArtists); len(r) > 0 {
return r
}
if r := normtag.Values(p, normtag.AlbumArtist); len(r) > 0 {
return r
}
return []string{MustArtist(p)}
@@ -85,7 +82,10 @@ func MustGenre(p Tags) string {
}
func MustGenres(p Tags) []string {
if r := FirstValues(p, normtag.Genres, normtag.Genre); len(r) > 0 {
if r := normtag.Values(p, normtag.Genres); len(r) > 0 {
return r
}
if r := normtag.Values(p, normtag.Genre); len(r) > 0 {
return r
}
return []string{FallbackGenre}