From b27c02fc894510b714c129e898fd0e6792d017b4 Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Sun, 10 Dec 2023 15:31:55 +0100 Subject: [PATCH 01/41] fix(listenbrainz): set track length submission and include submission client details (#424) * Fixed ListenBrainz track duration submission * Include submission client info in ListenBrainz payload * Extended ListenBrainz test --- listenbrainz/listenbrainz.go | 8 +++++--- listenbrainz/listenbrainz_test.go | 9 ++++++++- listenbrainz/model.go | 9 +++++---- listenbrainz/testdata/submit_listens_request.json | 5 ++++- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/listenbrainz/listenbrainz.go b/listenbrainz/listenbrainz.go index df44213..d28e354 100644 --- a/listenbrainz/listenbrainz.go +++ b/listenbrainz/listenbrainz.go @@ -10,6 +10,7 @@ import ( "net/http/httputil" "time" + "go.senan.xyz/gonic" "go.senan.xyz/gonic/db" "go.senan.xyz/gonic/scrobble" ) @@ -44,9 +45,10 @@ func (c *Client) Scrobble(user db.User, track scrobble.Track, stamp time.Time, s payload := &Payload{ TrackMetadata: &TrackMetadata{ AdditionalInfo: &AdditionalInfo{ - TrackNumber: int(track.TrackNumber), - RecordingMBID: track.MusicBrainzID, - TrackLength: int(track.Duration.Seconds()), + TrackNumber: int(track.TrackNumber), + RecordingMBID: track.MusicBrainzID, + Duration: int(track.Duration.Seconds()), + SubmissionClient: gonic.Name, }, ArtistName: track.Artist, TrackName: track.Track, diff --git a/listenbrainz/listenbrainz_test.go b/listenbrainz/listenbrainz_test.go index 13326a7..bab5caf 100644 --- a/listenbrainz/listenbrainz_test.go +++ b/listenbrainz/listenbrainz_test.go @@ -37,7 +37,14 @@ func TestScrobble(t *testing.T) { err := client.Scrobble( db.User{ListenBrainzURL: "https://listenbrainz.org", ListenBrainzToken: "token1"}, - scrobble.Track{Track: "title", Artist: "artist", Album: "album", TrackNumber: 1}, + scrobble.Track{ + Track: "title", + Artist: "artist", + Album: "album", + TrackNumber: 1, + Duration: 242 * time.Second, + MusicBrainzID: "00000000-0000-0000-0000-000000000000", + }, time.Unix(1683804525, 0), true, ) diff --git a/listenbrainz/model.go b/listenbrainz/model.go index dd7446b..89ee918 100644 --- a/listenbrainz/model.go +++ b/listenbrainz/model.go @@ -9,10 +9,11 @@ type ( } AdditionalInfo struct { - TrackNumber int `json:"tracknumber,omitempty"` - TrackMBID string `json:"track_mbid,omitempty"` - RecordingMBID string `json:"recording_mbid,omitempty"` - TrackLength int `json:"track_length,omitempty"` + TrackNumber int `json:"tracknumber,omitempty"` + TrackMBID string `json:"track_mbid,omitempty"` + RecordingMBID string `json:"recording_mbid,omitempty"` + Duration int `json:"duration,omitempty"` + SubmissionClient string `json:"submission_client,omitempty"` } TrackMetadata struct { diff --git a/listenbrainz/testdata/submit_listens_request.json b/listenbrainz/testdata/submit_listens_request.json index c863327..d67703e 100644 --- a/listenbrainz/testdata/submit_listens_request.json +++ b/listenbrainz/testdata/submit_listens_request.json @@ -5,7 +5,10 @@ "listened_at": 1683804525, "track_metadata": { "additional_info": { - "tracknumber": 1 + "tracknumber": 1, + "duration": 242, + "recording_mbid": "00000000-0000-0000-0000-000000000000", + "submission_client": "gonic" }, "artist_name": "artist", "track_name": "title", From aa82b944b794ac07b41a34aeb2b4cc365a2666ef Mon Sep 17 00:00:00 2001 From: sentriz Date: Sun, 10 Dec 2023 17:55:25 +0000 Subject: [PATCH 02/41] feat(lastfm): strip copyright text from albumInfo/artistInfo responses Release-As: 0.16.3 --- lastfm/client.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lastfm/client.go b/lastfm/client.go index 4e406e1..d29df73 100644 --- a/lastfm/client.go +++ b/lastfm/client.go @@ -8,8 +8,10 @@ import ( "fmt" "net/http" "net/url" + "regexp" "sort" "strconv" + "strings" "time" "github.com/andybalholm/cascadia" @@ -57,6 +59,10 @@ func (c *Client) ArtistGetInfo(artistName string) (Artist, error) { if err != nil { return Artist{}, fmt.Errorf("make request: %w", err) } + + resp.Artist.Bio.Summary = cleanLicenceText(resp.Artist.Bio.Summary) + resp.Artist.Bio.Content = cleanLicenceText(resp.Artist.Bio.Content) + return resp.Artist, nil } @@ -77,6 +83,9 @@ func (c *Client) AlbumGetInfo(artistName, albumName string) (Album, error) { return Album{}, fmt.Errorf("make request: %w", err) } + resp.Album.Wiki.Summary = cleanLicenceText(resp.Album.Wiki.Summary) + resp.Album.Wiki.Content = cleanLicenceText(resp.Album.Wiki.Content) + return resp.Album, nil } @@ -324,3 +333,15 @@ func GetParamSignature(params url.Values, secret string) string { hash := md5.Sum([]byte(toHash)) return hex.EncodeToString(hash[:]) } + +var doublePuncExpr = regexp.MustCompile(`\.\s+\.\s+`) +var licenceExpr = regexp.MustCompile(`(?i)user-contributed text.*`) + +func cleanLicenceText(text string) string { + text = licenceExpr.ReplaceAllString(text, "") + text = doublePuncExpr.ReplaceAllString(text, ". ") + text = strings.ReplaceAll(text, " .", ".") + text = strings.Join(strings.Fields(text), " ") + text = strings.TrimSpace(text) + return text +} From 433829dc4f43f3be83a99cb54099be4f781dcf7d Mon Sep 17 00:00:00 2001 From: sentriz Date: Sun, 10 Dec 2023 18:26:31 +0000 Subject: [PATCH 03/41] fix(docker): fix sqlite3 musl build https://github.com/mattn/go-sqlite3/issues/1164 https://github.com/mattn/go-sqlite3/pull/1177 --- go.mod | 2 ++ go.sum | 12 ++---------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index c11d79e..9da6163 100644 --- a/go.mod +++ b/go.mod @@ -68,3 +68,5 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) + +replace github.com/mattn/go-sqlite3 => github.com/leso-kn/go-sqlite3 v0.0.0-20231208152205-55b17a824af9 diff --git a/go.sum b/go.sum index 2e9bd18..a00ceed 100644 --- a/go.sum +++ b/go.sum @@ -6,10 +6,8 @@ github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3Q github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= 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.8.1 h1:uQxhNlArOIdbrH1tr0UXwdVFgDcZDrZVdcpygAcwmWM= github.com/PuerkitoBio/goquery v1.8.1/go.mod h1:Q8ICL1kNUJ2sXGoAhPGUdYDJvgQgHzJsnnd3H7Ho5jQ= -github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA= github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss= github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU= @@ -85,6 +83,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/leso-kn/go-sqlite3 v0.0.0-20231208152205-55b17a824af9 h1:DyuLxMSAOClfLyiBUBt1CoqHIQdsrA1Ia4BMsxyP2FU= +github.com/leso-kn/go-sqlite3 v0.0.0-20231208152205-55b17a824af9/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU= @@ -94,10 +94,6 @@ github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -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.18 h1:JL0eqdCOq6DJVNPSvArO/bIV9/P7fbGrV00LZHc+5aI= -github.com/mattn/go-sqlite3 v1.14.18/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= @@ -157,12 +153,9 @@ golang.org/x/image v0.14.0 h1:tNgSxAFe3jC4uYqvZdTr84SZoM1KfwdC9SKIFrLjFn4= golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= @@ -178,7 +171,6 @@ golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= 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= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= From e31e37e366b755d1401a035b3f1db4502ceac57d Mon Sep 17 00:00:00 2001 From: sentriz Date: Sun, 10 Dec 2023 18:33:03 +0000 Subject: [PATCH 04/41] remove gomoddirectives lint --- .golangci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 682dfc8..51bccad 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -32,7 +32,6 @@ linters: - gofmt - goheader - goimports - - gomoddirectives - gomodguard - goprintffuncname - gosec From a8333b8afac072dc4b6736fa231148f250f3cb9f Mon Sep 17 00:00:00 2001 From: sentriz Date: Sun, 10 Dec 2023 18:44:59 +0000 Subject: [PATCH 05/41] consolidate external text trimming --- lastfm/client.go | 20 ------------------- server/ctrlsubsonic/handlers_by_tags.go | 4 ++-- server/ctrlsubsonic/spec/construct_podcast.go | 13 ++---------- server/ctrlsubsonic/spec/spec.go | 17 ++++++++++++++++ 4 files changed, 21 insertions(+), 33 deletions(-) diff --git a/lastfm/client.go b/lastfm/client.go index d29df73..cc38eaa 100644 --- a/lastfm/client.go +++ b/lastfm/client.go @@ -8,10 +8,8 @@ import ( "fmt" "net/http" "net/url" - "regexp" "sort" "strconv" - "strings" "time" "github.com/andybalholm/cascadia" @@ -60,9 +58,6 @@ func (c *Client) ArtistGetInfo(artistName string) (Artist, error) { return Artist{}, fmt.Errorf("make request: %w", err) } - resp.Artist.Bio.Summary = cleanLicenceText(resp.Artist.Bio.Summary) - resp.Artist.Bio.Content = cleanLicenceText(resp.Artist.Bio.Content) - return resp.Artist, nil } @@ -83,9 +78,6 @@ func (c *Client) AlbumGetInfo(artistName, albumName string) (Album, error) { return Album{}, fmt.Errorf("make request: %w", err) } - resp.Album.Wiki.Summary = cleanLicenceText(resp.Album.Wiki.Summary) - resp.Album.Wiki.Content = cleanLicenceText(resp.Album.Wiki.Content) - return resp.Album, nil } @@ -333,15 +325,3 @@ func GetParamSignature(params url.Values, secret string) string { hash := md5.Sum([]byte(toHash)) return hex.EncodeToString(hash[:]) } - -var doublePuncExpr = regexp.MustCompile(`\.\s+\.\s+`) -var licenceExpr = regexp.MustCompile(`(?i)user-contributed text.*`) - -func cleanLicenceText(text string) string { - text = licenceExpr.ReplaceAllString(text, "") - text = doublePuncExpr.ReplaceAllString(text, ". ") - text = strings.ReplaceAll(text, " .", ".") - text = strings.Join(strings.Fields(text), " ") - text = strings.TrimSpace(text) - return text -} diff --git a/server/ctrlsubsonic/handlers_by_tags.go b/server/ctrlsubsonic/handlers_by_tags.go index 1f45247..a4d8274 100644 --- a/server/ctrlsubsonic/handlers_by_tags.go +++ b/server/ctrlsubsonic/handlers_by_tags.go @@ -333,7 +333,7 @@ func (c *Controller) ServeGetArtistInfoTwo(r *http.Request) *spec.Response { return sub } - sub.ArtistInfoTwo.Biography = info.Biography + sub.ArtistInfoTwo.Biography = spec.CleanExternalText(info.Biography) sub.ArtistInfoTwo.MusicBrainzID = info.MusicBrainzID sub.ArtistInfoTwo.LastFMURL = info.LastFMURL @@ -409,7 +409,7 @@ func (c *Controller) ServeGetAlbumInfoTwo(r *http.Request) *spec.Response { return sub } - sub.AlbumInfo.Notes = info.Notes + sub.AlbumInfo.Notes = spec.CleanExternalText(info.Notes) sub.AlbumInfo.MusicBrainzID = info.MusicBrainzID sub.AlbumInfo.LastFMURL = info.LastFMURL diff --git a/server/ctrlsubsonic/spec/construct_podcast.go b/server/ctrlsubsonic/spec/construct_podcast.go index 70e51ce..bff2555 100644 --- a/server/ctrlsubsonic/spec/construct_podcast.go +++ b/server/ctrlsubsonic/spec/construct_podcast.go @@ -2,19 +2,14 @@ package spec import ( "go.senan.xyz/gonic/db" - "jaytaylor.com/html2text" ) func NewPodcastChannel(p *db.Podcast) *PodcastChannel { - desc, err := html2text.FromString(p.Description, html2text.Options{TextOnly: true}) - if err != nil { - desc = "" - } ret := &PodcastChannel{ ID: p.SID(), OriginalImageURL: p.ImageURL, Title: p.Title, - Description: desc, + Description: CleanExternalText(p.Description), URL: p.URL, CoverArt: p.SID(), Status: "skipped", @@ -30,17 +25,13 @@ func NewPodcastEpisode(pe *db.PodcastEpisode) *PodcastEpisode { if pe == nil { return nil } - desc, err := html2text.FromString(pe.Description, html2text.Options{TextOnly: true}) - if err != nil { - desc = "" - } r := &PodcastEpisode{ ID: pe.SID(), StreamID: pe.SID(), ContentType: pe.MIME(), ChannelID: pe.PodcastSID(), Title: pe.Title, - Description: desc, + Description: CleanExternalText(pe.Description), Status: string(pe.Status), CoverArt: pe.PodcastSID(), PublishDate: *pe.PublishDate, diff --git a/server/ctrlsubsonic/spec/spec.go b/server/ctrlsubsonic/spec/spec.go index 4a33caa..5a0df70 100644 --- a/server/ctrlsubsonic/spec/spec.go +++ b/server/ctrlsubsonic/spec/spec.go @@ -2,11 +2,13 @@ package spec import ( "fmt" + "regexp" "strings" "time" "go.senan.xyz/gonic" "go.senan.xyz/gonic/server/ctrlsubsonic/specid" + "jaytaylor.com/html2text" ) // https://web.archive.org/web/20220707025402/https://www.subsonic.org/pages/api.jsp @@ -472,3 +474,18 @@ func formatRating(rating float64) string { func formatExt(ext string) string { return strings.TrimPrefix(ext, ".") } + +var doublePuncExpr = regexp.MustCompile(`\.\s+\.\s+`) +var licenceExpr = regexp.MustCompile(`(?i)\buser-contributed text.*`) +var readMoreExpr = regexp.MustCompile(`(?i)\bread more on.*`) + +func CleanExternalText(text string) string { + text, _ = html2text.FromString(text, html2text.Options{TextOnly: true}) + text = licenceExpr.ReplaceAllString(text, "") + text = readMoreExpr.ReplaceAllString(text, "") + text = doublePuncExpr.ReplaceAllString(text, ". ") + text = strings.ReplaceAll(text, " .", ".") + text = strings.Join(strings.Fields(text), " ") + text = strings.TrimSpace(text) + return text +} From d640a9fc065bd3908968abacbd5ac080331c3e25 Mon Sep 17 00:00:00 2001 From: sentriz Date: Mon, 11 Dec 2023 00:08:05 +0000 Subject: [PATCH 06/41] fix(db): add double index for right side of unique compound indexes fixes #426 --- db/migrations.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/db/migrations.go b/db/migrations.go index 401d4ae..80304cf 100644 --- a/db/migrations.go +++ b/db/migrations.go @@ -71,6 +71,7 @@ func (db *DB) Migrate(ctx MigrationContext) error { construct(ctx, "202311062259", migrateArtistAppearances), construct(ctx, "202311072309", migrateAlbumInfo), construct(ctx, "202311082304", migrateTemporaryDisplayAlbumArtist), + construct(ctx, "202312110003", migrateAddExtraIndexes), } return gormigrate. @@ -802,3 +803,13 @@ func migrateTemporaryDisplayAlbumArtist(tx *gorm.DB, _ MigrationContext) error { WHERE tag_album_artist='' `).Error } + +func migrateAddExtraIndexes(tx *gorm.DB, _ MigrationContext) error { + return tx.Exec(` + CREATE INDEX idx_track_genres_genre_id ON "track_genres" (genre_id); + CREATE INDEX idx_album_genres_genre_id ON "album_genres" (genre_id); + CREATE INDEX idx_album_artists_artist_id ON "album_artists" (artist_id); + CREATE INDEX idx_track_artists_artist_id ON "track_artists" (artist_id); + CREATE INDEX idx_artist_appearances_album_id ON "artist_appearances" (album_id); + `).Error +} From cba7ad318ffc699f17dd67b433cb5ace90c2e25d Mon Sep 17 00:00:00 2001 From: Senan Kelly Date: Mon, 11 Dec 2023 00:36:10 +0000 Subject: [PATCH 07/41] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index fd2160f..d68b449 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@

+

From 4e9f0f881ae63cc084f3e9d1c7469ef75a7928bf Mon Sep 17 00:00:00 2001 From: Senan Kelly Date: Mon, 11 Dec 2023 00:36:53 +0000 Subject: [PATCH 08/41] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d68b449..d359e48 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@

free-software subsonic server API implementation, supporting its many clients

- +

From a89259564108357d04580b1c2f0a42aba5ec1570 Mon Sep 17 00:00:00 2001 From: sentriz Date: Wed, 13 Dec 2023 01:20:16 +0000 Subject: [PATCH 09/41] adminui: use created_at for recent folders --- server/ctrladmin/adminui/pages/home.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/ctrladmin/adminui/pages/home.tmpl b/server/ctrladmin/adminui/pages/home.tmpl index d330d50..134f607 100644 --- a/server/ctrladmin/adminui/pages/home.tmpl +++ b/server/ctrladmin/adminui/pages/home.tmpl @@ -58,8 +58,8 @@ {{ end }} {{ range $folder := .RecentFolders }}
{{ $folder.RightPath }}
- {{ if not $folder.ModifiedAt.IsZero }} -
{{ $folder.ModifiedAt | dateHuman }}
+ {{ if not $folder.CreatedAt.IsZero }} +
{{ $folder.CreatedAt | dateHuman }}
{{ else }} {{ end }} From 9e12394acc6037c085fd10ff3b841d381a933bf2 Mon Sep 17 00:00:00 2001 From: sentriz Date: Wed, 13 Dec 2023 01:32:01 +0000 Subject: [PATCH 10/41] refactor(scanner): rename scan context to scan state --- mockfs/mockfs.go | 8 +-- scanner/scanner.go | 98 ++++++++++++++++++------------------ scanner/scanner_fuzz_test.go | 14 +++--- scanner/scanner_test.go | 16 +++--- 4 files changed, 68 insertions(+), 68 deletions(-) diff --git a/mockfs/mockfs.go b/mockfs/mockfs.go index 23eabc5..450c136 100644 --- a/mockfs/mockfs.go +++ b/mockfs/mockfs.go @@ -83,17 +83,17 @@ func (m *MockFS) DB() *db.DB { return m.db } func (m *MockFS) TmpDir() string { return m.dir } func (m *MockFS) TagReader() tagcommon.Reader { return m.tagReader } -func (m *MockFS) ScanAndClean() *scanner.Context { +func (m *MockFS) ScanAndClean() *scanner.State { m.t.Helper() - ctx, err := m.scanner.ScanAndClean(scanner.ScanOptions{}) + st, err := m.scanner.ScanAndClean(scanner.ScanOptions{}) if err != nil { m.t.Fatalf("error scan and cleaning: %v", err) } - return ctx + return st } -func (m *MockFS) ScanAndCleanErr() (*scanner.Context, error) { +func (m *MockFS) ScanAndCleanErr() (*scanner.State, error) { m.t.Helper() return m.scanner.ScanAndClean(scanner.ScanOptions{}) diff --git a/scanner/scanner.go b/scanner/scanner.go index 863379a..8e4aa98 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -61,14 +61,14 @@ type ScanOptions struct { IsFull bool } -func (s *Scanner) ScanAndClean(opts ScanOptions) (*Context, error) { +func (s *Scanner) ScanAndClean(opts ScanOptions) (*State, error) { if !s.StartScanning() { return nil, ErrAlreadyScanning } defer s.StopScanning() start := time.Now() - c := &Context{ + st := &State{ seenTracks: map[int]struct{}{}, seenAlbums: map[int]struct{}{}, isFull: opts.IsFull, @@ -77,28 +77,28 @@ func (s *Scanner) ScanAndClean(opts ScanOptions) (*Context, error) { log.Println("starting scan") defer func() { log.Printf("finished scan in %s, +%d/%d tracks (%d err)\n", - durSince(start), c.SeenTracksNew(), c.SeenTracks(), len(c.errs)) + durSince(start), st.SeenTracksNew(), st.SeenTracks(), len(st.errs)) }() for _, dir := range s.musicDirs { err := filepath.WalkDir(dir, func(absPath string, d fs.DirEntry, err error) error { - return s.scanCallback(c, absPath, d, err) + return s.scanCallback(st, absPath, d, err) }) if err != nil { return nil, fmt.Errorf("walk: %w", err) } } - if err := s.cleanTracks(c); err != nil { + if err := s.cleanTracks(st); err != nil { return nil, fmt.Errorf("clean tracks: %w", err) } - if err := s.cleanAlbums(c); err != nil { + if err := s.cleanAlbums(st); err != nil { return nil, fmt.Errorf("clean albums: %w", err) } - if err := s.cleanArtists(c); err != nil { + if err := s.cleanArtists(st); err != nil { return nil, fmt.Errorf("clean artists: %w", err) } - if err := s.cleanGenres(c); err != nil { + if err := s.cleanGenres(st); err != nil { return nil, fmt.Errorf("clean genres: %w", err) } @@ -106,7 +106,7 @@ func (s *Scanner) ScanAndClean(opts ScanOptions) (*Context, error) { return nil, fmt.Errorf("set scan time: %w", err) } - return c, errors.Join(c.errs...) + return st, errors.Join(st.errs...) } func (s *Scanner) ExecuteWatch(done <-chan struct{}) error { @@ -138,7 +138,7 @@ func (s *Scanner) ExecuteWatch(done <-chan struct{}) error { break } for absPath := range batchSeen { - c := &Context{ + st := &State{ seenTracks: map[int]struct{}{}, seenAlbums: map[int]struct{}{}, } @@ -150,7 +150,7 @@ func (s *Scanner) ExecuteWatch(done <-chan struct{}) error { continue } err = filepath.WalkDir(absPath, func(absPath string, d fs.DirEntry, err error) error { - return s.scanCallback(c, absPath, d, err) + return s.scanCallback(st, absPath, d, err) }) if err != nil { log.Printf("error walking: %v", err) @@ -207,9 +207,9 @@ func watchCallback(watcher *fsnotify.Watcher, absPath string, d fs.DirEntry, err return nil } -func (s *Scanner) scanCallback(c *Context, absPath string, d fs.DirEntry, err error) error { +func (s *Scanner) scanCallback(st *State, absPath string, d fs.DirEntry, err error) error { if err != nil { - c.errs = append(c.errs, err) + st.errs = append(st.errs, err) return nil } @@ -219,7 +219,7 @@ func (s *Scanner) scanCallback(c *Context, absPath string, d fs.DirEntry, err er eval, _ := filepath.EvalSymlinks(absPath) return filepath.WalkDir(eval, func(subAbs string, d fs.DirEntry, err error) error { subAbs = strings.Replace(subAbs, eval, absPath, 1) - return s.scanCallback(c, subAbs, d, err) + return s.scanCallback(st, subAbs, d, err) }) default: return nil @@ -233,15 +233,15 @@ func (s *Scanner) scanCallback(c *Context, absPath string, d fs.DirEntry, err er log.Printf("processing folder %q", absPath) return s.db.Transaction(func(tx *db.DB) error { - if err := s.scanDir(tx, c, absPath); err != nil { - c.errs = append(c.errs, fmt.Errorf("%q: %w", absPath, err)) + if err := s.scanDir(tx, st, absPath); err != nil { + st.errs = append(st.errs, fmt.Errorf("%q: %w", absPath, err)) return nil } return nil }) } -func (s *Scanner) scanDir(tx *db.DB, c *Context, absPath string) error { +func (s *Scanner) scanDir(tx *db.DB, st *State, absPath string) error { musicDir, relPath := musicDirRelative(s.musicDirs, absPath) if musicDir == absPath { return nil @@ -280,7 +280,7 @@ func (s *Scanner) scanDir(tx *db.DB, c *Context, absPath string) error { return fmt.Errorf("first or create parent: %w", err) } - c.seenAlbums[parent.ID] = struct{}{} + st.seenAlbums[parent.ID] = struct{}{} dir, basename := filepath.Split(relPath) var album db.Album @@ -288,12 +288,12 @@ func (s *Scanner) scanDir(tx *db.DB, c *Context, absPath string) error { return fmt.Errorf("populate album basics: %w", err) } - c.seenAlbums[album.ID] = struct{}{} + st.seenAlbums[album.ID] = struct{}{} sort.Strings(tracks) for i, basename := range tracks { absPath := filepath.Join(musicDir, relPath, basename) - if err := s.populateTrackAndArtists(tx, c, i, &album, basename, absPath); err != nil { + if err := s.populateTrackAndArtists(tx, st, i, &album, basename, absPath); err != nil { return fmt.Errorf("populate track %q: %w", basename, err) } } @@ -301,7 +301,7 @@ func (s *Scanner) scanDir(tx *db.DB, c *Context, absPath string) error { return nil } -func (s *Scanner) populateTrackAndArtists(tx *db.DB, c *Context, i int, album *db.Album, basename string, absPath string) error { +func (s *Scanner) populateTrackAndArtists(tx *db.DB, st *State, i int, album *db.Album, basename string, absPath string) error { stat, err := os.Stat(absPath) if err != nil { return fmt.Errorf("stating %q: %w", basename, err) @@ -312,8 +312,8 @@ func (s *Scanner) populateTrackAndArtists(tx *db.DB, c *Context, i int, album *d return fmt.Errorf("query track: %w", err) } - if !c.isFull && track.ID != 0 && stat.ModTime().Before(track.UpdatedAt) { - c.seenTracks[track.ID] = struct{}{} + if !st.isFull && track.ID != 0 && stat.ModTime().Before(track.UpdatedAt) { + st.seenTracks[track.ID] = struct{}{} return nil } @@ -384,8 +384,8 @@ func (s *Scanner) populateTrackAndArtists(tx *db.DB, c *Context, i int, album *d return fmt.Errorf("populate track artists: %w", err) } - c.seenTracks[track.ID] = struct{}{} - c.seenTracksNew++ + st.seenTracks[track.ID] = struct{}{} + st.seenTracksNew++ return nil } @@ -540,9 +540,9 @@ func populateArtistAppearances(tx *db.DB, album *db.Album, artistIDs []int) erro return nil } -func (s *Scanner) cleanTracks(c *Context) error { +func (s *Scanner) cleanTracks(st *State) error { start := time.Now() - defer func() { log.Printf("finished clean tracks in %s, %d removed", durSince(start), c.TracksMissing()) }() + defer func() { log.Printf("finished clean tracks in %s, %d removed", durSince(start), st.TracksMissing()) }() var all []int err := s.db. @@ -553,18 +553,18 @@ func (s *Scanner) cleanTracks(c *Context) error { return fmt.Errorf("plucking ids: %w", err) } for _, a := range all { - if _, ok := c.seenTracks[a]; !ok { - c.tracksMissing = append(c.tracksMissing, int64(a)) + if _, ok := st.seenTracks[a]; !ok { + st.tracksMissing = append(st.tracksMissing, int64(a)) } } - return s.db.TransactionChunked(c.tracksMissing, func(tx *db.DB, chunk []int64) error { + return s.db.TransactionChunked(st.tracksMissing, func(tx *db.DB, chunk []int64) error { return tx.Where(chunk).Delete(&db.Track{}).Error }) } -func (s *Scanner) cleanAlbums(c *Context) error { +func (s *Scanner) cleanAlbums(st *State) error { start := time.Now() - defer func() { log.Printf("finished clean albums in %s, %d removed", durSince(start), c.AlbumsMissing()) }() + defer func() { log.Printf("finished clean albums in %s, %d removed", durSince(start), st.AlbumsMissing()) }() var all []int err := s.db. @@ -575,18 +575,18 @@ func (s *Scanner) cleanAlbums(c *Context) error { return fmt.Errorf("plucking ids: %w", err) } for _, a := range all { - if _, ok := c.seenAlbums[a]; !ok { - c.albumsMissing = append(c.albumsMissing, int64(a)) + if _, ok := st.seenAlbums[a]; !ok { + st.albumsMissing = append(st.albumsMissing, int64(a)) } } - return s.db.TransactionChunked(c.albumsMissing, func(tx *db.DB, chunk []int64) error { + return s.db.TransactionChunked(st.albumsMissing, func(tx *db.DB, chunk []int64) error { return tx.Where(chunk).Delete(&db.Album{}).Error }) } -func (s *Scanner) cleanArtists(c *Context) error { +func (s *Scanner) cleanArtists(st *State) error { start := time.Now() - defer func() { log.Printf("finished clean artists in %s, %d removed", durSince(start), c.ArtistsMissing()) }() + defer func() { log.Printf("finished clean artists in %s, %d removed", durSince(start), st.ArtistsMissing()) }() // gorm doesn't seem to support subqueries without parens for UNION q := s.db.Exec(` @@ -602,13 +602,13 @@ func (s *Scanner) cleanArtists(c *Context) error { if err := q.Error; err != nil { return err } - c.artistsMissing = int(q.RowsAffected) + st.artistsMissing = int(q.RowsAffected) return nil } -func (s *Scanner) cleanGenres(c *Context) error { //nolint:unparam +func (s *Scanner) cleanGenres(st *State) error { //nolint:unparam start := time.Now() - defer func() { log.Printf("finished clean genres in %s, %d removed", durSince(start), c.GenresMissing()) }() + defer func() { log.Printf("finished clean genres in %s, %d removed", durSince(start), st.GenresMissing()) }() subTrack := s.db. Select("genres.id"). @@ -625,7 +625,7 @@ func (s *Scanner) cleanGenres(c *Context) error { //nolint:unparam q := s.db. Where("genres.id IN ? AND genres.id IN ?", subTrack, subAlbum). Delete(&db.Genre{}) - c.genresMissing = int(q.RowsAffected) + st.genresMissing = int(q.RowsAffected) return nil } @@ -663,7 +663,7 @@ func durSince(t time.Time) time.Duration { return time.Since(t).Truncate(10 * time.Microsecond) } -type Context struct { +type State struct { errs []error isFull bool @@ -677,14 +677,14 @@ type Context struct { genresMissing int } -func (c *Context) SeenTracks() int { return len(c.seenTracks) } -func (c *Context) SeenAlbums() int { return len(c.seenAlbums) } -func (c *Context) SeenTracksNew() int { return c.seenTracksNew } +func (s *State) SeenTracks() int { return len(s.seenTracks) } +func (s *State) SeenAlbums() int { return len(s.seenAlbums) } +func (s *State) SeenTracksNew() int { return s.seenTracksNew } -func (c *Context) TracksMissing() int { return len(c.tracksMissing) } -func (c *Context) AlbumsMissing() int { return len(c.albumsMissing) } -func (c *Context) ArtistsMissing() int { return c.artistsMissing } -func (c *Context) GenresMissing() int { return c.genresMissing } +func (s *State) TracksMissing() int { return len(s.tracksMissing) } +func (s *State) AlbumsMissing() int { return len(s.albumsMissing) } +func (s *State) ArtistsMissing() int { return s.artistsMissing } +func (s *State) GenresMissing() int { return s.genresMissing } type MultiValueMode uint8 diff --git a/scanner/scanner_fuzz_test.go b/scanner/scanner_fuzz_test.go index daf8e02..b4fc28b 100644 --- a/scanner/scanner_fuzz_test.go +++ b/scanner/scanner_fuzz_test.go @@ -16,13 +16,13 @@ import ( func FuzzScanner(f *testing.F) { checkDelta := func(assert *assert.Assertions, m *mockfs.MockFS, expSeen, expNew int) { - ctx := m.ScanAndClean() - assert.Equal(ctx.SeenTracks(), expSeen) - assert.Equal(ctx.SeenTracksNew(), expNew) - assert.Equal(ctx.TracksMissing(), 0) - assert.Equal(ctx.AlbumsMissing(), 0) - assert.Equal(ctx.ArtistsMissing(), 0) - assert.Equal(ctx.GenresMissing(), 0) + st := m.ScanAndClean() + assert.Equal(st.SeenTracks(), expSeen) + assert.Equal(st.SeenTracksNew(), expNew) + assert.Equal(st.TracksMissing(), 0) + assert.Equal(st.AlbumsMissing(), 0) + assert.Equal(st.ArtistsMissing(), 0) + assert.Equal(st.GenresMissing(), 0) } f.Fuzz(func(t *testing.T, data []byte, seed int64) { diff --git a/scanner/scanner_test.go b/scanner/scanner_test.go index dfec6e5..0541184 100644 --- a/scanner/scanner_test.go +++ b/scanner/scanner_test.go @@ -524,22 +524,22 @@ func TestTagErrors(t *testing.T) { tags.Error = scanner.ErrReadingTags }) - ctx, err := m.ScanAndCleanErr() + st, err := m.ScanAndCleanErr() errs, ok := err.(interface{ Unwrap() []error }) assert.True(t, ok) assert.ErrorAs(t, err, &errs) - assert.Equal(t, 2, len(errs.Unwrap())) // we have 2 dir errors - assert.Equal(t, m.NumTracks()-(3*2), ctx.SeenTracks()) // we saw all tracks bar 2 album contents - assert.Equal(t, m.NumTracks()-(3*2), ctx.SeenTracksNew()) // we have all tracks bar 2 album contents + assert.Equal(t, 2, len(errs.Unwrap())) // we have 2 dir errors + assert.Equal(t, m.NumTracks()-(3*2), st.SeenTracks()) // we saw all tracks bar 2 album contents + assert.Equal(t, m.NumTracks()-(3*2), st.SeenTracksNew()) // we have all tracks bar 2 album contents - ctx, err = m.ScanAndCleanErr() + st, err = m.ScanAndCleanErr() errs, ok = err.(interface{ Unwrap() []error }) assert.True(t, ok) - assert.Equal(t, 2, len(errs.Unwrap())) // we have 2 dir errors - assert.Equal(t, m.NumTracks()-(3*2), ctx.SeenTracks()) // we saw all tracks bar 2 album contents - assert.Equal(t, 0, ctx.SeenTracksNew()) // we have no new tracks + assert.Equal(t, 2, len(errs.Unwrap())) // we have 2 dir errors + assert.Equal(t, m.NumTracks()-(3*2), st.SeenTracks()) // we saw all tracks bar 2 album contents + assert.Equal(t, 0, st.SeenTracksNew()) // we have no new tracks } // https://github.com/sentriz/gonic/issues/185#issuecomment-1050092128 From 7efe29f29f619941324b36c6cb298d353930a2f2 Mon Sep 17 00:00:00 2001 From: sentriz Date: Wed, 13 Dec 2023 02:16:05 +0000 Subject: [PATCH 11/41] refactor(scanner): extract symlink walking --- scanner/scanner.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/scanner/scanner.go b/scanner/scanner.go index 8e4aa98..d9331ce 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -142,7 +142,7 @@ func (s *Scanner) ExecuteWatch(done <-chan struct{}) error { seenTracks: map[int]struct{}{}, seenAlbums: map[int]struct{}{}, } - err = filepath.WalkDir(absPath, func(absPath string, d fs.DirEntry, err error) error { + err := filepath.WalkDir(absPath, func(absPath string, d fs.DirEntry, err error) error { return watchCallback(watcher, absPath, d, err) }) if err != nil { @@ -175,7 +175,7 @@ func (s *Scanner) ExecuteWatch(done <-chan struct{}) error { } batchT.Reset(batchInterval) - case err = <-watcher.Errors: + case err := <-watcher.Errors: log.Printf("error from watcher: %v\n", err) case <-done: @@ -192,9 +192,7 @@ func watchCallback(watcher *fsnotify.Watcher, absPath string, d fs.DirEntry, err switch d.Type() { case os.ModeDir: case os.ModeSymlink: - eval, _ := filepath.EvalSymlinks(absPath) - return filepath.WalkDir(eval, func(subAbs string, d fs.DirEntry, err error) error { - subAbs = strings.Replace(subAbs, eval, absPath, 1) + return symWalk(absPath, func(subAbs string, d fs.DirEntry, err error) error { return watchCallback(watcher, subAbs, d, err) }) default: @@ -216,9 +214,7 @@ func (s *Scanner) scanCallback(st *State, absPath string, d fs.DirEntry, err err switch d.Type() { case os.ModeDir: case os.ModeSymlink: - eval, _ := filepath.EvalSymlinks(absPath) - return filepath.WalkDir(eval, func(subAbs string, d fs.DirEntry, err error) error { - subAbs = strings.Replace(subAbs, eval, absPath, 1) + return symWalk(absPath, func(subAbs string, d fs.DirEntry, err error) error { return s.scanCallback(st, subAbs, d, err) }) default: @@ -732,3 +728,11 @@ func musicDirRelative(musicDirs []string, absPath string) (musicDir, relPath str } return } + +func symWalk(absPath string, fn fs.WalkDirFunc) error { + eval, _ := filepath.EvalSymlinks(absPath) + return filepath.WalkDir(eval, func(subAbs string, d fs.DirEntry, err error) error { + subAbs = strings.Replace(subAbs, eval, absPath, 1) + return fn(subAbs, d, err) + }) +} From 95ba32b401ece26aec435cbe1137941e73bf48ce Mon Sep 17 00:00:00 2001 From: sentriz Date: Fri, 15 Dec 2023 14:22:50 +0000 Subject: [PATCH 12/41] reverse musl build fix --- go.mod | 8 +++----- go.sum | 20 ++++++++++++++------ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 9da6163..73063c8 100644 --- a/go.mod +++ b/go.mod @@ -11,12 +11,12 @@ require ( github.com/fatih/structs v1.1.0 github.com/fsnotify/fsnotify v1.7.0 github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 - github.com/google/uuid v1.4.0 + github.com/google/uuid v1.5.0 github.com/gorilla/securecookie v1.1.2 github.com/gorilla/sessions v1.2.2 github.com/jinzhu/gorm v1.9.17-0.20211120011537-5c235b72a414 github.com/josephburnett/jd v1.7.1 - github.com/mattn/go-sqlite3 v1.14.18 + github.com/mattn/go-sqlite3 v1.14.19 github.com/mitchellh/mapstructure v1.5.0 github.com/mmcdole/gofeed v1.2.1 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 @@ -26,7 +26,7 @@ require ( github.com/sentriz/audiotags v0.0.0-20230419125925-8886243b2137 github.com/sentriz/gormstore v0.0.0-20220105134332-64e31f7f6981 github.com/stretchr/testify v1.8.4 - golang.org/x/exp v0.0.0-20231127185646-65229373498e + golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611 golang.org/x/net v0.19.0 golang.org/x/sync v0.5.0 gopkg.in/gormigrate.v1 v1.6.0 @@ -68,5 +68,3 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) - -replace github.com/mattn/go-sqlite3 => github.com/leso-kn/go-sqlite3 v0.0.0-20231208152205-55b17a824af9 diff --git a/go.sum b/go.sum index a00ceed..219b763 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,10 @@ github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3Q github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= 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.8.1 h1:uQxhNlArOIdbrH1tr0UXwdVFgDcZDrZVdcpygAcwmWM= github.com/PuerkitoBio/goquery v1.8.1/go.mod h1:Q8ICL1kNUJ2sXGoAhPGUdYDJvgQgHzJsnnd3H7Ho5jQ= +github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA= github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss= github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU= @@ -46,8 +48,8 @@ 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.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= -github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= +github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/context v1.1.2 h1:WRkNAv2uoa03QNIc1A6u4O7DAGMUVoopZhkiXWA2V1o= github.com/gorilla/context v1.1.2/go.mod h1:KDPwT9i/MeWHiLl90fuTgrt4/wPcv75vFAZLaOOcbxM= @@ -83,8 +85,6 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/leso-kn/go-sqlite3 v0.0.0-20231208152205-55b17a824af9 h1:DyuLxMSAOClfLyiBUBt1CoqHIQdsrA1Ia4BMsxyP2FU= -github.com/leso-kn/go-sqlite3 v0.0.0-20231208152205-55b17a824af9/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU= @@ -94,6 +94,10 @@ github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +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.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI= +github.com/mattn/go-sqlite3 v1.14.19/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= @@ -146,16 +150,19 @@ golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= -golang.org/x/exp v0.0.0-20231127185646-65229373498e h1:Gvh4YaCaXNs6dKTlfgismwWZKyjVZXwOPfIyUaqU3No= -golang.org/x/exp v0.0.0-20231127185646-65229373498e/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= +golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611 h1:qCEDpW1G+vcj3Y7Fy52pEM1AWm3abj8WimGYejI3SC4= +golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.14.0 h1:tNgSxAFe3jC4uYqvZdTr84SZoM1KfwdC9SKIFrLjFn4= golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= @@ -171,6 +178,7 @@ golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= 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= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= From 326144f5c0c9a7bfd48bde24eed2116610e9352d Mon Sep 17 00:00:00 2001 From: sentriz Date: Sun, 17 Dec 2023 18:45:22 +0000 Subject: [PATCH 13/41] podcast var style --- podcast/podcast.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/podcast/podcast.go b/podcast/podcast.go index 00851e2..6822846 100644 --- a/podcast/podcast.go +++ b/podcast/podcast.go @@ -156,7 +156,7 @@ func (p *Podcasts) AddNewEpisodes(podcast *db.Podcast, items []*gofeed.Item) err Where("podcast_id=?", podcast.ID). Order("publish_date DESC"). First(&podcastEpisode).Error - itemFound := true + var itemFound = true if errors.Is(err, gorm.ErrRecordNotFound) { itemFound = false } else if err != nil { From 2f109f1982dea78dbdfe786cafa3c6718138b66e Mon Sep 17 00:00:00 2001 From: sentriz Date: Sun, 17 Dec 2023 18:47:13 +0000 Subject: [PATCH 14/41] fix(podcast): collect all episode errors when adding new podcast fixes #430 --- podcast/podcast.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/podcast/podcast.go b/podcast/podcast.go index 6822846..fa404d7 100644 --- a/podcast/podcast.go +++ b/podcast/podcast.go @@ -163,12 +163,14 @@ func (p *Podcasts) AddNewEpisodes(podcast *db.Podcast, items []*gofeed.Item) err return err } if !itemFound { + var episodeErrs []error for _, item := range items { if _, err := p.AddEpisode(podcast.ID, item); err != nil { - return err + episodeErrs = append(episodeErrs, err) + continue } } - return nil + return errors.Join(episodeErrs...) } for _, item := range getEntriesAfterDate(items, *podcastEpisode.PublishDate) { episode, err := p.AddEpisode(podcast.ID, item) From f34cd2e213f9be93ae3db4ad32e7e927fd15c618 Mon Sep 17 00:00:00 2001 From: Senan Kelly Date: Thu, 21 Dec 2023 03:20:22 +0000 Subject: [PATCH 15/41] fix(podcast): slightly more robust downloading and concurrency (#433) --- cmd/gonic/gonic.go | 11 + db/db.go | 2 +- podcast/podcast.go | 407 ++++++++++------------ server/ctrlsubsonic/handlers_by_folder.go | 3 +- 4 files changed, 202 insertions(+), 221 deletions(-) diff --git a/cmd/gonic/gonic.go b/cmd/gonic/gonic.go index ee601b2..98b046c 100644 --- a/cmd/gonic/gonic.go +++ b/cmd/gonic/gonic.go @@ -388,6 +388,17 @@ func main() { return nil }) + errgrp.Go(func() error { + defer logJob("podcast download")() + + ctxTick(ctx, 5*time.Second, func() { + if err := podcast.DownloadTick(); err != nil { + log.Printf("failed to download podcast: %s", err) + } + }) + return nil + }) + errgrp.Go(func() error { if *confPodcastPurgeAgeDays == 0 { return nil diff --git a/db/db.go b/db/db.go index a0d57ac..9f0ff60 100644 --- a/db/db.go +++ b/db/db.go @@ -527,7 +527,7 @@ func (pe *PodcastEpisode) MIME() string { } func (pe *PodcastEpisode) AbsPath() string { - if pe.Podcast == nil { + if pe.Podcast == nil || pe.Podcast.RootDir == "" { return "" } return filepath.Join(pe.Podcast.RootDir, pe.Filename) diff --git a/podcast/podcast.go b/podcast/podcast.go index fa404d7..17fc73b 100644 --- a/podcast/podcast.go +++ b/podcast/podcast.go @@ -26,8 +26,7 @@ import ( var ErrNoAudioInFeedItem = errors.New("no audio in feed item") const ( - downloadAllWaitInterval = 3 * time.Second - fetchUserAgent = `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11` + fetchUserAgent = `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11` ) type Podcasts struct { @@ -45,44 +44,24 @@ func New(db *db.DB, base string, tagReader tagcommon.Reader) *Podcasts { } func (p *Podcasts) GetPodcastOrAll(id int, includeEpisodes bool) ([]*db.Podcast, error) { - var err error - podcasts := []*db.Podcast{} + var podcasts []*db.Podcast + q := p.db.DB if id != 0 { - err = p.db.Where("id=?", id).Find(&podcasts).Error - } else { - err = p.db.Find(&podcasts).Error + q = q.Where("id=?", id) } - if err != nil { - return nil, fmt.Errorf("finding podcasts: %w", err) + if includeEpisodes { + q = q.Preload("Episodes", func(db *gorm.DB) *gorm.DB { + return db.Order("podcast_episodes.publish_date DESC") + }) } - if !includeEpisodes { - return podcasts, nil - } - for _, c := range podcasts { - episodes, err := p.GetPodcastEpisodes(c.ID) - if err != nil { - return nil, fmt.Errorf("finding podcast episodes: %w", err) - } - c.Episodes = episodes + if err := q.Find(&podcasts).Error; err != nil { + return nil, fmt.Errorf("find podcasts: %w", err) } return podcasts, nil } -func (p *Podcasts) GetPodcastEpisodes(podcastID int) ([]*db.PodcastEpisode, error) { - episodes := []*db.PodcastEpisode{} - err := p.db. - Where("podcast_id=?", podcastID). - Order("publish_date DESC"). - Find(&episodes). - Error - if err != nil { - return nil, fmt.Errorf("find episodes by podcast id: %w", err) - } - return episodes, nil -} - func (p *Podcasts) GetNewestPodcastEpisodes(count int) ([]*db.PodcastEpisode, error) { - episodes := []*db.PodcastEpisode{} + var episodes []*db.PodcastEpisode err := p.db. Order("publish_date DESC"). Limit(count). @@ -112,14 +91,12 @@ func (p *Podcasts) AddNewPodcast(rssURL string, feed *gofeed.Feed) (*db.Podcast, if err := p.db.Save(&podcast).Error; err != nil { return &podcast, err } - if err := p.AddNewEpisodes(&podcast, feed.Items); err != nil { - return nil, err + if err := p.RefreshPodcast(&podcast, feed.Items); err != nil { + log.Printf("error addign new episodes : %v", err) + } + if err := p.downloadPodcastCover(&podcast); err != nil { + log.Printf("error downloading podcast cover: %v", err) } - go func() { - if err := p.downloadPodcastCover(&podcast); err != nil { - log.Printf("error downloading podcast cover: %v", err) - } - }() return &podcast, nil } @@ -150,69 +127,42 @@ func getEntriesAfterDate(feed []*gofeed.Item, after time.Time) []*gofeed.Item { return items } -func (p *Podcasts) AddNewEpisodes(podcast *db.Podcast, items []*gofeed.Item) error { - podcastEpisode := db.PodcastEpisode{} +func (p *Podcasts) RefreshPodcast(podcast *db.Podcast, items []*gofeed.Item) error { + var lastPodcastEpisode db.PodcastEpisode err := p.db. Where("podcast_id=?", podcast.ID). Order("publish_date DESC"). - First(&podcastEpisode).Error - var itemFound = true - if errors.Is(err, gorm.ErrRecordNotFound) { - itemFound = false - } else if err != nil { + First(&lastPodcastEpisode). + Error + if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { return err } - if !itemFound { - var episodeErrs []error - for _, item := range items { - if _, err := p.AddEpisode(podcast.ID, item); err != nil { - episodeErrs = append(episodeErrs, err) - continue - } - } - return errors.Join(episodeErrs...) + + if lastPodcastEpisode.ID != 0 { + items = getEntriesAfterDate(items, *lastPodcastEpisode.PublishDate) } - for _, item := range getEntriesAfterDate(items, *podcastEpisode.PublishDate) { - episode, err := p.AddEpisode(podcast.ID, item) - if errors.Is(err, ErrNoAudioInFeedItem) { - log.Printf("failed to find audio in feed (%s, %s) item, skipping", podcast.Title, item.Title) + + var episodeErrs []error + for _, item := range items { + podcastEpisode, err := p.addEpisode(podcast.ID, item) + if err != nil { + episodeErrs = append(episodeErrs, err) continue } - if err != nil { - return err - } - if podcast.AutoDownload == db.PodcastAutoDownloadLatest && - (episode.Status != db.PodcastEpisodeStatusCompleted && episode.Status != db.PodcastEpisodeStatusDownloading) { - if err := p.DownloadEpisode(episode.ID); err != nil { - return err + + if lastPodcastEpisode.ID != 0 && podcast.AutoDownload == db.PodcastAutoDownloadLatest { + podcastEpisode.Status = db.PodcastEpisodeStatusDownloading + if err := p.db.Save(&podcastEpisode).Error; err != nil { + return fmt.Errorf("save podcast episode: %w", err) } } } - return nil + + return errors.Join(episodeErrs...) } -func getSecondsFromString(time string) int { - duration, err := strconv.Atoi(time) - if err == nil { - return duration - } - splitTime := strings.Split(time, ":") - if len(splitTime) == 3 { - hours, _ := strconv.Atoi(splitTime[0]) - minutes, _ := strconv.Atoi(splitTime[1]) - seconds, _ := strconv.Atoi(splitTime[2]) - return (3600 * hours) + (60 * minutes) + seconds - } - if len(splitTime) == 2 { - minutes, _ := strconv.Atoi(splitTime[0]) - seconds, _ := strconv.Atoi(splitTime[1]) - return (60 * minutes) + seconds - } - return 0 -} - -func (p *Podcasts) AddEpisode(podcastID int, item *gofeed.Item) (*db.PodcastEpisode, error) { - duration := 0 +func (p *Podcasts) addEpisode(podcastID int, item *gofeed.Item) (*db.PodcastEpisode, error) { + var duration int // if it has the media extension use it for _, content := range item.Extensions["media"]["content"] { durationExt := content.Attrs["duration"] @@ -249,9 +199,7 @@ func (p *Podcasts) isAudio(rawItemURL string) (bool, error) { return p.tagReader.CanRead(itemURL.Path), nil } -func itemToEpisode(podcastID, size, duration int, audio string, - item *gofeed.Item, -) *db.PodcastEpisode { +func itemToEpisode(podcastID, size, duration int, audio string, item *gofeed.Item) *db.PodcastEpisode { return &db.PodcastEpisode{ PodcastID: podcastID, Description: item.Description, @@ -290,17 +238,11 @@ func (p *Podcasts) findMediaAudio(podcastID, duration int, item *gofeed.Item) (* } func (p *Podcasts) RefreshPodcasts() error { - podcasts := []*db.Podcast{} + var podcasts []*db.Podcast if err := p.db.Find(&podcasts).Error; err != nil { return fmt.Errorf("find podcasts: %w", err) } - if err := p.refreshPodcasts(podcasts); err != nil { - return fmt.Errorf("refresh podcasts: %w", err) - } - return nil -} -func (p *Podcasts) refreshPodcasts(podcasts []*db.Podcast) error { var errs []error for _, podcast := range podcasts { fp := gofeed.NewParser() @@ -309,7 +251,7 @@ func (p *Podcasts) refreshPodcasts(podcasts []*db.Podcast) error { errs = append(errs, fmt.Errorf("refreshing podcast with url %q: %w", podcast.URL, err)) continue } - if err = p.AddNewEpisodes(podcast, feed.Items); err != nil { + if err = p.RefreshPodcast(podcast, feed.Items); err != nil { errs = append(errs, fmt.Errorf("adding episodes: %w", err)) continue } @@ -318,97 +260,57 @@ func (p *Podcasts) refreshPodcasts(podcasts []*db.Podcast) error { } func (p *Podcasts) DownloadPodcastAll(podcastID int) error { - podcastEpisodes := []db.PodcastEpisode{} err := p.db. + Model(db.PodcastEpisode{}). + Where("status=?", db.PodcastEpisodeStatusSkipped). Where("podcast_id=?", podcastID). - Find(&podcastEpisodes). + Update("status", db.PodcastEpisodeStatusDownloading). Error if err != nil { - return fmt.Errorf("get episodes by podcast id: %w", err) + return fmt.Errorf("update podcast episodes: %w", err) } - go func() { - for _, episode := range podcastEpisodes { - if episode.Status == db.PodcastEpisodeStatusDownloading || episode.Status == db.PodcastEpisodeStatusCompleted { - log.Println("skipping episode is in progress or already downloaded") - continue - } - if err := p.DownloadEpisode(episode.ID); err != nil { - log.Printf("error downloading episode: %v", err) - continue - } - log.Printf("finished downloading episode: %q", episode.Title) - time.Sleep(downloadAllWaitInterval) - } - }() return nil } func (p *Podcasts) DownloadEpisode(episodeID int) error { - podcastEpisode := db.PodcastEpisode{} - podcast := db.Podcast{} err := p.db. - Preload("Podcast"). + Model(db.PodcastEpisode{}). Where("id=?", episodeID). - First(&podcastEpisode). + Update("status", db.PodcastEpisodeStatusDownloading). Error if err != nil { - return fmt.Errorf("get podcast episode by id: %w", err) + return fmt.Errorf("update podcast episodes: %w", err) } - err = p.db. - Where("id=?", podcastEpisode.PodcastID). - First(&podcast). - Error - if err != nil { - return fmt.Errorf("get podcast by id: %w", err) + return nil +} + +func getContentDispositionFilename(header http.Header) (string, bool) { + contentHeader := header.Get("content-disposition") + _, params, _ := mime.ParseMediaType(contentHeader) + filename, ok := params["filename"] + return filename, ok +} + +func getPodcastEpisodeFilename(podcast *db.Podcast, podcastEpisode *db.PodcastEpisode, header http.Header) (string, error) { + if podcastEpisode.Filename != "" { + return podcastEpisode.Filename, nil } - if podcastEpisode.Status == db.PodcastEpisodeStatusDownloading || podcastEpisode.Status == db.PodcastEpisodeStatusCompleted { - log.Printf("already downloading podcast episode with id %d", episodeID) - return nil - } - podcastEpisode.Status = db.PodcastEpisodeStatusDownloading - p.db.Save(&podcastEpisode) - client := &http.Client{} - req, err := http.NewRequest("GET", podcastEpisode.AudioURL, nil) - if err != nil { - return fmt.Errorf("create http request: %w", err) - } - req.Header.Add("User-Agent", fetchUserAgent) - // nolint: bodyclose - resp, err := client.Do(req) - if err != nil { - return fmt.Errorf("fetch podcast audio: %w", err) - } - filename, ok := getContentDispositionFilename(resp.Header.Get("content-disposition")) + + filename, ok := getContentDispositionFilename(header) if !ok { audioURL, err := url.Parse(podcastEpisode.AudioURL) if err != nil { - return fmt.Errorf("parse podcast audio url: %w", err) + return "", fmt.Errorf("parse podcast audio url: %w", err) } filename = path.Base(audioURL.Path) } path, err := fileutil.Unique(podcast.RootDir, fileutil.Safe(filename)) if err != nil { - return fmt.Errorf("find unique path: %w", err) + return "", fmt.Errorf("find unique path: %w", err) } _, filename = filepath.Split(path) - audioFile, err := os.Create(filepath.Join(podcast.RootDir, filename)) - if err != nil { - return fmt.Errorf("create audio file: %w", err) - } - podcastEpisode.Filename = filename - p.db.Save(&podcastEpisode) - go func() { - if err := p.doPodcastDownload(&podcastEpisode, audioFile, resp.Body); err != nil { - log.Printf("error downloading podcast: %v", err) - } - }() - return nil -} -func getContentDispositionFilename(header string) (string, bool) { - _, params, _ := mime.ParseMediaType(header) - filename, ok := params["filename"] - return filename, ok + return filename, nil } func (p *Podcasts) downloadPodcastCover(podcast *db.Podcast) error { @@ -429,15 +331,16 @@ func (p *Podcasts) downloadPodcastCover(podcast *db.Podcast) error { } defer resp.Body.Close() - ext := path.Ext(imageURL.Path) + var ext = path.Ext(imageURL.Path) if ext == "" { - contentHeader := resp.Header.Get("content-disposition") - filename, _ := getContentDispositionFilename(contentHeader) + filename, _ := getContentDispositionFilename(resp.Header) ext = filepath.Ext(filename) } - cover := "cover" + ext - coverFile, err := os.Create(filepath.Join(podcast.RootDir, cover)) + if err := os.MkdirAll(podcast.RootDir, os.ModePerm); err != nil { + return fmt.Errorf("make podcast root dir: %w", err) + } + coverFile, err := os.Create(filepath.Join(podcast.RootDir, "cover"+ext)) if err != nil { return fmt.Errorf("creating podcast cover: %w", err) } @@ -453,39 +356,9 @@ func (p *Podcasts) downloadPodcastCover(podcast *db.Podcast) error { return nil } -func (p *Podcasts) doPodcastDownload(podcastEpisode *db.PodcastEpisode, file *os.File, src io.Reader) error { - if _, err := io.Copy(file, src); err != nil { - return fmt.Errorf("writing podcast episode: %w", err) - } - defer file.Close() - - podcastTags, err := p.tagReader.Read(podcastEpisode.AbsPath()) - if err != nil { - log.Printf("error parsing podcast audio: %e", err) - podcastEpisode.Status = db.PodcastEpisodeStatusError - p.db.Save(podcastEpisode) - return nil - } - - stat, _ := file.Stat() - podcastEpisode.Bitrate = podcastTags.Bitrate() - podcastEpisode.Status = db.PodcastEpisodeStatusCompleted - podcastEpisode.Length = podcastTags.Length() - podcastEpisode.Size = int(stat.Size()) - - if err := p.db.Save(podcastEpisode).Error; err != nil { - return fmt.Errorf("save podcast episode: %w", err) - } - return nil -} - func (p *Podcasts) DeletePodcast(podcastID int) error { - podcast := db.Podcast{} - err := p.db. - Where("id=?", podcastID). - First(&podcast). - Error - if err != nil { + var podcast db.Podcast + if err := p.db.Where("id=?", podcastID).First(&podcast).Error; err != nil { return err } if podcast.RootDir == "" { @@ -495,38 +368,36 @@ func (p *Podcasts) DeletePodcast(podcastID int) error { if err := os.RemoveAll(podcast.RootDir); err != nil { return fmt.Errorf("delete podcast directory: %w", err) } - err = p.db. - Where("id=?", podcastID). - Delete(db.Podcast{}). - Error - if err != nil { + + if err := p.db.Where("id=?", podcastID).Delete(db.Podcast{}).Error; err != nil { return fmt.Errorf("delete podcast row: %w", err) } return nil } func (p *Podcasts) DeletePodcastEpisode(podcastEpisodeID int) error { - episode := db.PodcastEpisode{} - err := p.db.Preload("Podcast").First(&episode, podcastEpisodeID).Error - if err != nil { + var podcastEpisode db.PodcastEpisode + if err := p.db.Preload("Podcast").First(&podcastEpisode, podcastEpisodeID).Error; err != nil { return err } - episode.Status = db.PodcastEpisodeStatusDeleted - p.db.Save(&episode) - if err := os.Remove(episode.AbsPath()); err != nil { - return err + podcastEpisode.Status = db.PodcastEpisodeStatusDeleted + if err := p.db.Save(&podcastEpisode).Error; err != nil { + return fmt.Errorf("save podcast episode: %w", err) } - return err + if err := os.Remove(podcastEpisode.AbsPath()); err != nil { + return fmt.Errorf("remove episode: %w", err) + } + return nil } func (p *Podcasts) PurgeOldPodcasts(maxAge time.Duration) error { expDate := time.Now().Add(-maxAge) var episodes []*db.PodcastEpisode err := p.db. - Where("status = ?", db.PodcastEpisodeStatusCompleted). - Where("created_at < ?", expDate). - Where("updated_at < ?", expDate). - Where("modified_at < ?", expDate). + Where("status=?", db.PodcastEpisodeStatusCompleted). + Where("created_at Date: Thu, 21 Dec 2023 17:11:08 -0800 Subject: [PATCH 16/41] fix(specid): match music dirs with trailing slash (#439) * Fix bug with checking path prefixes * slash instead * double quote * lint * lint again * ensure trailing slash when substring matching --------- Co-authored-by: sentriz --- server/ctrlsubsonic/specidpaths/specidpaths.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/ctrlsubsonic/specidpaths/specidpaths.go b/server/ctrlsubsonic/specidpaths/specidpaths.go index c054ee1..f39bd3d 100644 --- a/server/ctrlsubsonic/specidpaths/specidpaths.go +++ b/server/ctrlsubsonic/specidpaths/specidpaths.go @@ -54,8 +54,9 @@ func Lookup(dbc *db.DB, musicPaths []string, podcastsPath string, path string) ( var musicPath string for _, mp := range musicPaths { - if strings.HasPrefix(path, mp) { + if strings.HasPrefix(path, filepath.Clean(mp)+string(filepath.Separator) /* ensure trailing */) { musicPath = mp + break } } if musicPath == "" { From 2f40ceea04cbb5260a8636707eda2c52feab5f8a Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Thu, 21 Dec 2023 17:13:10 -0800 Subject: [PATCH 17/41] readme: fix links to multi-valued-tags (#440) * Fix links to multi-valued-tags * soon -> link --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d359e48..cdc1b66 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ - [last.fm](https://www.last.fm/) scrobbling - [listenbrainz](https://listenbrainz.org/) scrobbling (thank you [spezifisch](https://github.com/spezifisch), [lxea](https://github.com/lxea)) - artist similarities and biographies from the last.fm api -- support for multi valued tags like albumartists and genres ([see more](#multi-valued-tags)) +- support for multi valued tags like albumartists and genres ([see more](#multi-valued-tags-v016)) - a web interface for configuration (set up last.fm, manage users, start scans, etc.) - 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) @@ -68,9 +68,9 @@ password can then be changed from the web interface | `GONIC_JUKEBOX_MPV_EXTRA_ARGS` | `-jukebox-mpv-extra-args` | **optional** extra command line arguments to pass to the jukebox mpv daemon | | `GONIC_PODCAST_PURGE_AGE` | `-podcast-purge-age` | **optional** age (in days) to purge podcast episodes if not accessed | | `GONIC_EXCLUDE_PATTERN` | `-exclude-pattern` | **optional** files matching this regex pattern will not be imported | -| `GONIC_MULTI_VALUE_GENRE` | `-multi-value-genre` | **optional** setting for multi-valued genre tags when scanning ([see more](#multi-valued-tags)) | -| `GONIC_MULTI_VALUE_ARTIST` | `-multi-value-artist` | **optional** setting for multi-valued artist tags when scanning ([see more](#multi-valued-tags)) | -| `GONIC_MULTI_VALUE_ALBUM_ARTIST` | `-multi-value-album-artist` | **optional** setting for multi-valued album artist tags when scanning ([see more](#multi-valued-tags)) | +| `GONIC_MULTI_VALUE_GENRE` | `-multi-value-genre` | **optional** setting for multi-valued genre tags when scanning ([see more](#multi-valued-tags-v016)) | +| `GONIC_MULTI_VALUE_ARTIST` | `-multi-value-artist` | **optional** setting for multi-valued artist tags when scanning ([see more](#multi-valued-tags-v016)) | +| `GONIC_MULTI_VALUE_ALBUM_ARTIST` | `-multi-value-album-artist` | **optional** setting for multi-valued album artist tags when scanning ([see more](#multi-valued-tags-v016)) | | `GONIC_EXPVAR` | `-expvar` | **optional** enable the /debug/vars endpoint (exposes useful debugging attributes as well as database stats) | ## multi valued tags (v0.16+) @@ -83,7 +83,7 @@ the available modes are: | value | desc | | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `multi` | gonic will explictly look for multi value fields in your audio metadata. software like musicbrainz picard or beets can set set these ([soon](https://github.com/beetbox/beets/pull/4743)) | +| `multi` | gonic will explictly look for multi value fields in your audio metadata. software like musicbrainz picard or beets can set set these ([link](https://github.com/beetbox/beets/pull/4743)) | | `delim ` | gonic will look at your normal audio metadata fields like "genre" or "album_artist", but split them on a delimiter. for example you could set `-multi-value-genre "delim ;"` to split the single genre field on ";" | | `none` (default) | gonic will not attempt to do any multi value processing | From 6b5195c58380b6dadad97e99528b3e20d0025af8 Mon Sep 17 00:00:00 2001 From: sentriz Date: Fri, 22 Dec 2023 01:38:26 +0000 Subject: [PATCH 18/41] refactor(playlist): use sanity check code for every method fixes #436 --- playlist/playlist.go | 146 +++++++++++++++++++++++++------------------ 1 file changed, 85 insertions(+), 61 deletions(-) diff --git a/playlist/playlist.go b/playlist/playlist.go index 6f9f60e..b229619 100644 --- a/playlist/playlist.go +++ b/playlist/playlist.go @@ -26,40 +26,6 @@ const ( extM3U8 = ".m3u8" ) -type Store struct { - basePath string - mu sync.Mutex -} - -func NewStore(basePath string) (*Store, error) { - if basePath == "" { - return nil, ErrInvalidBasePath - } - - // sanity check layout, just in case someone tries to use an existing folder - entries, err := os.ReadDir(basePath) - if err != nil { - return nil, fmt.Errorf("sanity checking: reading dir: %w", err) - } - var found string - for _, entry := range entries { - if !entry.IsDir() { - continue - } - if _, err := userIDFromPath(entry.Name()); err != nil { - found = entry.Name() - break - } - } - if found != "" { - return nil, fmt.Errorf("sanity checking: %w: item %q in playlists directory is not a user id. see wiki for details on layout of the playlists dir", ErrNoUserPrefix, found) - } - - return &Store{ - basePath: basePath, - }, nil -} - type Playlist struct { UpdatedAt time.Time UserID int @@ -69,18 +35,33 @@ type Playlist struct { IsPublic bool } -func NewPath(userID int, playlistName string) string { - playlistName = fileutil.Safe(playlistName) - if playlistName == "" { - playlistName = "pl" +type Store struct { + basePath string + mu sync.Mutex +} + +func NewStore(basePath string) (*Store, error) { + if basePath == "" { + return nil, ErrInvalidBasePath } - playlistName = fmt.Sprintf("%s-%d%s", playlistName, time.Now().UnixMilli(), extM3U) - return filepath.Join(fmt.Sprint(userID), playlistName) + if err := sanityCheck(basePath); err != nil { + return nil, err + } + + return &Store{ + basePath: basePath, + }, nil } // List finds playlist items in s.basePath. // the expected format is //**/.m3u func (s *Store) List() ([]string, error) { + defer lock(&s.mu)() + + if err := sanityCheck(s.basePath); err != nil { + return nil, err + } + var relPaths []string return relPaths, filepath.WalkDir(s.basePath, func(path string, d fs.DirEntry, err error) error { if err != nil { @@ -100,30 +81,13 @@ func (s *Store) List() ([]string, error) { }) } -const ( - attrPrefix = "#GONIC-" - attrName = "NAME" - attrCommment = "COMMENT" - attrIsPublic = "IS-PUBLIC" -) - -func encodeAttr(name, value string) string { - return fmt.Sprintf("%s%s:%s", attrPrefix, name, strconv.Quote(value)) -} - -func decodeAttr(line string) (name, value string) { - if !strings.HasPrefix(line, attrPrefix) { - return "", "" - } - prefixAndName, rawValue, _ := strings.Cut(line, ":") - name = strings.TrimPrefix(prefixAndName, attrPrefix) - value, _ = strconv.Unquote(rawValue) - return name, value -} - func (s *Store) Read(relPath string) (*Playlist, error) { defer lock(&s.mu)() + if err := sanityCheck(s.basePath); err != nil { + return nil, err + } + absPath := filepath.Join(s.basePath, relPath) stat, err := os.Stat(absPath) if err != nil { @@ -171,6 +135,10 @@ func (s *Store) Read(relPath string) (*Playlist, error) { func (s *Store) Write(relPath string, playlist *Playlist) error { defer lock(&s.mu)() + if err := sanityCheck(s.basePath); err != nil { + return err + } + absPath := filepath.Join(s.basePath, relPath) if err := os.MkdirAll(filepath.Dir(absPath), 0o777); err != nil { return fmt.Errorf("make m3u base dir: %w", err) @@ -217,6 +185,10 @@ func (s *Store) Write(relPath string, playlist *Playlist) error { } func (s *Store) Delete(relPath string) error { + if err := sanityCheck(s.basePath); err != nil { + return err + } + return os.Remove(filepath.Join(s.basePath, relPath)) } @@ -237,3 +209,55 @@ func lock(mu *sync.Mutex) func() { mu.Lock() return mu.Unlock } + +func sanityCheck(basePath string) error { + // sanity check layout, just in case someone tries to use an existing folder + entries, err := os.ReadDir(basePath) + if err != nil { + return fmt.Errorf("sanity checking: reading dir: %w", err) + } + var found string + for _, entry := range entries { + if !entry.IsDir() { + continue + } + if _, err := userIDFromPath(entry.Name()); err != nil { + found = entry.Name() + break + } + } + if found != "" { + return fmt.Errorf("sanity checking: %w: item %q in playlists directory is not a user id. see wiki for details on layout of the playlists dir", ErrNoUserPrefix, found) + } + return nil +} + +const ( + attrPrefix = "#GONIC-" + attrName = "NAME" + attrCommment = "COMMENT" + attrIsPublic = "IS-PUBLIC" +) + +func encodeAttr(name, value string) string { + return fmt.Sprintf("%s%s:%s", attrPrefix, name, strconv.Quote(value)) +} + +func decodeAttr(line string) (name, value string) { + if !strings.HasPrefix(line, attrPrefix) { + return "", "" + } + prefixAndName, rawValue, _ := strings.Cut(line, ":") + name = strings.TrimPrefix(prefixAndName, attrPrefix) + value, _ = strconv.Unquote(rawValue) + return name, value +} + +func NewPath(userID int, playlistName string) string { + playlistName = fileutil.Safe(playlistName) + if playlistName == "" { + playlistName = "pl" + } + playlistName = fmt.Sprintf("%s-%d%s", playlistName, time.Now().UnixMilli(), extM3U) + return filepath.Join(fmt.Sprint(userID), playlistName) +} From f5b6b4d7906292f28f02aa7604cd45a8fcab720f Mon Sep 17 00:00:00 2001 From: sentriz Date: Fri, 22 Dec 2023 12:59:48 +0000 Subject: [PATCH 19/41] fix substring checking in scanner musicDirRelative related https://github.com/sentriz/gonic/issues/437 --- scanner/scanner.go | 2 +- scanner/scanner_test.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/scanner/scanner.go b/scanner/scanner.go index d9331ce..1a32859 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -721,7 +721,7 @@ func parseMulti(parser tagcommon.Info, setting MultiValueSetting, getMulti func( func musicDirRelative(musicDirs []string, absPath string) (musicDir, relPath string) { for _, musicDir := range musicDirs { - if strings.HasPrefix(absPath, musicDir) { + if absPath == musicDir || strings.HasPrefix(absPath, filepath.Clean(musicDir)+string(filepath.Separator)) { // ensure trailing slash for substring check relPath, _ = filepath.Rel(musicDir, absPath) return musicDir, relPath } diff --git a/scanner/scanner_test.go b/scanner/scanner_test.go index 0541184..c2b281b 100644 --- a/scanner/scanner_test.go +++ b/scanner/scanner_test.go @@ -787,3 +787,26 @@ func TestRootNoClobberOnError(t *testing.T) { require.Equal(t, ".", roots[0].RightPath) require.Equal(t, 0, roots[0].ParentID) } + +// https://github.com/sentriz/gonic/issues/437 +func TestPrefixOverlap(t *testing.T) { + t.Parallel() + + m := mockfs.NewWithDirs(t, []string{ + "/music/tagged", + "/music/taggedmanual", + }) + + m.AddItemsPrefix("/music/tagged") + m.AddItemsPrefix("/music/taggedmanual") + + m.ScanAndClean() + + var taggedManual int + require.NoError(t, m.DB().Model(db.Album{}).Where("root_dir LIKE ?", `%/taggedmanual`).Count(&taggedManual).Error) + require.Greater(t, taggedManual, 1) + + var tagged int + require.NoError(t, m.DB().Model(db.Album{}).Where("root_dir LIKE ?", `%/tagged`).Count(&tagged).Error) + require.Greater(t, tagged, 1) +} From 552aa3afb138a125f15ab161a1a06cbe6c68a762 Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Fri, 29 Dec 2023 20:20:14 +0100 Subject: [PATCH 20/41] feat(listenbrainz): submit release MBID (#443) --- listenbrainz/listenbrainz.go | 1 + listenbrainz/listenbrainz_test.go | 13 +++++++------ listenbrainz/model.go | 1 + listenbrainz/testdata/submit_listens_request.json | 1 + scrobble/scrobble.go | 15 ++++++++------- server/ctrlsubsonic/handlers_common.go | 3 +++ 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/listenbrainz/listenbrainz.go b/listenbrainz/listenbrainz.go index d28e354..61db7e5 100644 --- a/listenbrainz/listenbrainz.go +++ b/listenbrainz/listenbrainz.go @@ -47,6 +47,7 @@ func (c *Client) Scrobble(user db.User, track scrobble.Track, stamp time.Time, s AdditionalInfo: &AdditionalInfo{ TrackNumber: int(track.TrackNumber), RecordingMBID: track.MusicBrainzID, + ReleaseMBID: track.MusicBrainzReleaseID, Duration: int(track.Duration.Seconds()), SubmissionClient: gonic.Name, }, diff --git a/listenbrainz/listenbrainz_test.go b/listenbrainz/listenbrainz_test.go index bab5caf..f53fcb5 100644 --- a/listenbrainz/listenbrainz_test.go +++ b/listenbrainz/listenbrainz_test.go @@ -38,12 +38,13 @@ func TestScrobble(t *testing.T) { err := client.Scrobble( db.User{ListenBrainzURL: "https://listenbrainz.org", ListenBrainzToken: "token1"}, scrobble.Track{ - Track: "title", - Artist: "artist", - Album: "album", - TrackNumber: 1, - Duration: 242 * time.Second, - MusicBrainzID: "00000000-0000-0000-0000-000000000000", + Track: "title", + Artist: "artist", + Album: "album", + TrackNumber: 1, + Duration: 242 * time.Second, + MusicBrainzID: "00000000-0000-0000-0000-000000000000", + MusicBrainzReleaseID: "00000000-0000-0000-0000-000000000001", }, time.Unix(1683804525, 0), true, diff --git a/listenbrainz/model.go b/listenbrainz/model.go index 89ee918..0727404 100644 --- a/listenbrainz/model.go +++ b/listenbrainz/model.go @@ -12,6 +12,7 @@ type ( TrackNumber int `json:"tracknumber,omitempty"` TrackMBID string `json:"track_mbid,omitempty"` RecordingMBID string `json:"recording_mbid,omitempty"` + ReleaseMBID string `json:"release_mbid,omitempty"` Duration int `json:"duration,omitempty"` SubmissionClient string `json:"submission_client,omitempty"` } diff --git a/listenbrainz/testdata/submit_listens_request.json b/listenbrainz/testdata/submit_listens_request.json index d67703e..c69c2d0 100644 --- a/listenbrainz/testdata/submit_listens_request.json +++ b/listenbrainz/testdata/submit_listens_request.json @@ -8,6 +8,7 @@ "tracknumber": 1, "duration": 242, "recording_mbid": "00000000-0000-0000-0000-000000000000", + "release_mbid": "00000000-0000-0000-0000-000000000001", "submission_client": "gonic" }, "artist_name": "artist", diff --git a/scrobble/scrobble.go b/scrobble/scrobble.go index 8b8c9f6..6c53763 100644 --- a/scrobble/scrobble.go +++ b/scrobble/scrobble.go @@ -7,13 +7,14 @@ import ( ) type Track struct { - Track string - Artist string - Album string - AlbumArtist string - TrackNumber uint - Duration time.Duration - MusicBrainzID string + Track string + Artist string + Album string + AlbumArtist string + TrackNumber uint + Duration time.Duration + MusicBrainzID string + MusicBrainzReleaseID string } type Scrobbler interface { diff --git a/server/ctrlsubsonic/handlers_common.go b/server/ctrlsubsonic/handlers_common.go index 69c091d..ca9adb6 100644 --- a/server/ctrlsubsonic/handlers_common.go +++ b/server/ctrlsubsonic/handlers_common.go @@ -78,6 +78,9 @@ func (c *Controller) ServeScrobble(r *http.Request) *spec.Response { if _, err := uuid.Parse(track.TagBrainzID); err == nil { scrobbleTrack.MusicBrainzID = track.TagBrainzID } + if _, err := uuid.Parse(track.Album.TagBrainzID); err == nil { + scrobbleTrack.MusicBrainzReleaseID = track.Album.TagBrainzID + } if err := scrobbleStatsUpdateTrack(c.dbc, &track, user.ID, optStamp); err != nil { return spec.NewError(0, "error updating stats: %v", err) From b5de0b3b8468c68c21c47416c1a8743345566a8a Mon Sep 17 00:00:00 2001 From: sentriz Date: Fri, 22 Dec 2023 19:48:14 +0000 Subject: [PATCH 21/41] centralise special path prefix check --- fileutil/fileutil.go | 5 +++++ scanner/scanner.go | 3 ++- server/ctrlsubsonic/specidpaths/specidpaths.go | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/fileutil/fileutil.go b/fileutil/fileutil.go index 8ad23ff..28105be 100644 --- a/fileutil/fileutil.go +++ b/fileutil/fileutil.go @@ -54,3 +54,8 @@ func First(path ...string) (string, error) { } return "", err } + +// HasPrefix checks a path has a prefix, making sure to respect path boundaries. So that /aa & /a does not match, but /a/a & /a does. +func HasPrefix(p, prefix string) bool { + return p == prefix || strings.HasPrefix(p, filepath.Clean(prefix)+string(filepath.Separator)) +} diff --git a/scanner/scanner.go b/scanner/scanner.go index 1a32859..7296a5e 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -20,6 +20,7 @@ import ( "github.com/rainycape/unidecode" "go.senan.xyz/gonic/db" + "go.senan.xyz/gonic/fileutil" "go.senan.xyz/gonic/tags/tagcommon" ) @@ -721,7 +722,7 @@ func parseMulti(parser tagcommon.Info, setting MultiValueSetting, getMulti func( func musicDirRelative(musicDirs []string, absPath string) (musicDir, relPath string) { for _, musicDir := range musicDirs { - if absPath == musicDir || strings.HasPrefix(absPath, filepath.Clean(musicDir)+string(filepath.Separator)) { // ensure trailing slash for substring check + if fileutil.HasPrefix(absPath, musicDir) { relPath, _ = filepath.Rel(musicDir, absPath) return musicDir, relPath } diff --git a/server/ctrlsubsonic/specidpaths/specidpaths.go b/server/ctrlsubsonic/specidpaths/specidpaths.go index f39bd3d..4ff8ab9 100644 --- a/server/ctrlsubsonic/specidpaths/specidpaths.go +++ b/server/ctrlsubsonic/specidpaths/specidpaths.go @@ -6,6 +6,7 @@ import ( "strings" "go.senan.xyz/gonic/db" + "go.senan.xyz/gonic/fileutil" "go.senan.xyz/gonic/server/ctrlsubsonic/specid" ) @@ -54,7 +55,7 @@ func Lookup(dbc *db.DB, musicPaths []string, podcastsPath string, path string) ( var musicPath string for _, mp := range musicPaths { - if strings.HasPrefix(path, filepath.Clean(mp)+string(filepath.Separator) /* ensure trailing */) { + if fileutil.HasPrefix(path, mp) { musicPath = mp break } From 422c684f44369a0c85cb1a825e3d480ee157ca0b Mon Sep 17 00:00:00 2001 From: sentriz Date: Fri, 29 Dec 2023 19:25:45 +0000 Subject: [PATCH 22/41] feat(subsonic): prefer tagged musicbrainz ID over lastfm in getAlbumInfo closes #444 --- server/ctrlsubsonic/handlers_by_tags.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/ctrlsubsonic/handlers_by_tags.go b/server/ctrlsubsonic/handlers_by_tags.go index a4d8274..bb0af77 100644 --- a/server/ctrlsubsonic/handlers_by_tags.go +++ b/server/ctrlsubsonic/handlers_by_tags.go @@ -11,6 +11,7 @@ import ( "strings" "time" + "github.com/google/uuid" "github.com/jinzhu/gorm" "go.senan.xyz/gonic/db" @@ -413,6 +414,10 @@ func (c *Controller) ServeGetAlbumInfoTwo(r *http.Request) *spec.Response { sub.AlbumInfo.MusicBrainzID = info.MusicBrainzID sub.AlbumInfo.LastFMURL = info.LastFMURL + if _, err := uuid.Parse(album.TagBrainzID); err == nil { + sub.AlbumInfo.MusicBrainzID = album.TagBrainzID // prefer db musicbrainz ID over lastfm's + } + return sub } From 5bcd339501b24aad8ebe1cbee5d74b39c1ec80a0 Mon Sep 17 00:00:00 2001 From: sentriz Date: Fri, 29 Dec 2023 22:06:12 +0000 Subject: [PATCH 23/41] add more logging to transcode rules related #445 --- server/ctrlsubsonic/handlers_raw.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/server/ctrlsubsonic/handlers_raw.go b/server/ctrlsubsonic/handlers_raw.go index 4389e19..c77584c 100644 --- a/server/ctrlsubsonic/handlers_raw.go +++ b/server/ctrlsubsonic/handlers_raw.go @@ -188,16 +188,24 @@ func (c *Controller) ServeStream(w http.ResponseWriter, r *http.Request) *spec.R format, _ := params.Get("format") timeOffset, _ := params.GetInt("timeOffset") - if format == "raw" || maxBitRate >= audioFile.AudioBitrate() { + if format == "raw" { http.ServeFile(w, r, file.AbsPath()) return nil } - pref, err := streamGetTransodePreference(c.dbc, user.ID, params.GetOr("c", "")) + client, _ := params.Get("c") + pref, err := streamGetTransodePreference(c.dbc, user.ID, client) if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { return spec.NewError(0, "couldn't find transcode preference: %v", err) } if pref == nil { + log.Printf("serving raw file, no transcode preferences found for client %q", client) + http.ServeFile(w, r, file.AbsPath()) + return nil + } + + if maxBitRate >= audioFile.AudioBitrate() { + log.Printf("serving raw file, requested max bitrate %dk is greater or equal to %dk", maxBitRate, audioFile.AudioBitrate()) http.ServeFile(w, r, file.AbsPath()) return nil } @@ -213,7 +221,7 @@ func (c *Controller) ServeStream(w http.ResponseWriter, r *http.Request) *spec.R profile = transcode.WithSeek(profile, time.Second*time.Duration(timeOffset)) } - log.Printf("trancoding to %q with max bitrate %dk", profile.MIME(), profile.BitRate()) + log.Printf("trancoding to %q with at bitrate %dk", profile.MIME(), profile.BitRate()) w.Header().Set("Content-Type", profile.MIME()) if err := c.transcoder.Transcode(r.Context(), profile, file.AbsPath(), w); err != nil && !errors.Is(err, transcode.ErrFFmpegKilled) { From 59d2bd9e82630ab90317304ce3c7050722d2dd5e Mon Sep 17 00:00:00 2001 From: sentriz Date: Tue, 2 Jan 2024 23:04:02 +0000 Subject: [PATCH 24/41] update raw log style --- server/ctrlsubsonic/handlers_raw.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/ctrlsubsonic/handlers_raw.go b/server/ctrlsubsonic/handlers_raw.go index c77584c..e82131f 100644 --- a/server/ctrlsubsonic/handlers_raw.go +++ b/server/ctrlsubsonic/handlers_raw.go @@ -199,13 +199,13 @@ func (c *Controller) ServeStream(w http.ResponseWriter, r *http.Request) *spec.R return spec.NewError(0, "couldn't find transcode preference: %v", err) } if pref == nil { - log.Printf("serving raw file, no transcode preferences found for client %q", client) + log.Printf("serving raw file, no user transcode preferences found for client %q", client) http.ServeFile(w, r, file.AbsPath()) return nil } if maxBitRate >= audioFile.AudioBitrate() { - log.Printf("serving raw file, requested max bitrate %dk is greater or equal to %dk", maxBitRate, audioFile.AudioBitrate()) + log.Printf("serving raw file, requested max bitrate %d is greater or equal to %d", maxBitRate, audioFile.AudioBitrate()) http.ServeFile(w, r, file.AbsPath()) return nil } @@ -221,7 +221,7 @@ func (c *Controller) ServeStream(w http.ResponseWriter, r *http.Request) *spec.R profile = transcode.WithSeek(profile, time.Second*time.Duration(timeOffset)) } - log.Printf("trancoding to %q with at bitrate %dk", profile.MIME(), profile.BitRate()) + log.Printf("trancoding to %q with at bitrate %d", profile.MIME(), profile.BitRate()) w.Header().Set("Content-Type", profile.MIME()) if err := c.transcoder.Transcode(r.Context(), profile, file.AbsPath(), w); err != nil && !errors.Is(err, transcode.ErrFFmpegKilled) { From eb79cecc44628d3e24b2196e1d680f2b1ba15f97 Mon Sep 17 00:00:00 2001 From: sentriz Date: Tue, 2 Jan 2024 23:06:32 +0000 Subject: [PATCH 25/41] fix(scanner): gracefully handle multi value tag delim splits with adjacent delimiters closes #448 Co-authored-by: Chris Hayes --- scanner/scanner.go | 18 +++++++++++------- scanner/scanner_test.go | 16 ++++++++++++++++ server/ctrlsubsonic/handlers_common.go | 6 +++++- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/scanner/scanner.go b/scanner/scanner.go index 7296a5e..aefa4c1 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -9,6 +9,7 @@ import ( "os" "path/filepath" "regexp" + "slices" "sort" "strconv" "strings" @@ -319,7 +320,7 @@ func (s *Scanner) populateTrackAndArtists(tx *db.DB, st *State, i int, album *db return fmt.Errorf("%w: %w", err, ErrReadingTags) } - genreNames := parseMulti(trags, s.multiValueSettings[Genre], tagcommon.MustGenres, tagcommon.MustGenre) + genreNames := ParseMulti(s.multiValueSettings[Genre], tagcommon.MustGenres(trags), tagcommon.MustGenre(trags)) genreIDs, err := populateGenres(tx, genreNames) if err != nil { return fmt.Errorf("populate genres: %w", err) @@ -331,7 +332,7 @@ func (s *Scanner) populateTrackAndArtists(tx *db.DB, st *State, i int, album *db return fmt.Errorf("delete artist appearances: %w", err) } - albumArtistNames := parseMulti(trags, s.multiValueSettings[AlbumArtist], tagcommon.MustAlbumArtists, tagcommon.MustAlbumArtist) + albumArtistNames := ParseMulti(s.multiValueSettings[AlbumArtist], tagcommon.MustAlbumArtists(trags), tagcommon.MustAlbumArtist(trags)) var albumArtistIDs []int for _, albumArtistName := range albumArtistNames { albumArtist, err := populateArtist(tx, albumArtistName) @@ -364,7 +365,7 @@ func (s *Scanner) populateTrackAndArtists(tx *db.DB, st *State, i int, album *db return fmt.Errorf("populate track genres: %w", err) } - trackArtistNames := parseMulti(trags, s.multiValueSettings[Artist], tagcommon.MustArtists, tagcommon.MustArtist) + trackArtistNames := ParseMulti(s.multiValueSettings[Artist], tagcommon.MustArtists(trags), tagcommon.MustArtist(trags)) var trackArtistIDs []int for _, trackArtistName := range trackArtistNames { trackArtist, err := populateArtist(tx, trackArtistName) @@ -704,19 +705,22 @@ type MultiValueSetting struct { Delim string } -func parseMulti(parser tagcommon.Info, setting MultiValueSetting, getMulti func(tagcommon.Info) []string, get func(tagcommon.Info) string) []string { +func ParseMulti(setting MultiValueSetting, values []string, value string) []string { var parts []string switch setting.Mode { case Multi: - parts = getMulti(parser) + parts = values case Delim: - parts = strings.Split(get(parser), setting.Delim) + parts = strings.Split(value, setting.Delim) default: - parts = []string{get(parser)} + parts = []string{value} } for i := range parts { parts[i] = strings.TrimSpace(parts[i]) } + parts = slices.DeleteFunc(parts, func(s string) bool { + return s == "" + }) return parts } diff --git a/scanner/scanner_test.go b/scanner/scanner_test.go index c2b281b..77f4b1c 100644 --- a/scanner/scanner_test.go +++ b/scanner/scanner_test.go @@ -810,3 +810,19 @@ func TestPrefixOverlap(t *testing.T) { require.NoError(t, m.DB().Model(db.Album{}).Where("root_dir LIKE ?", `%/tagged`).Count(&tagged).Error) require.Greater(t, tagged, 1) } + +// https://github.com/sentriz/gonic/pull/448 +func TestParseMultiDoubleDelim(t *testing.T) { + t.Parallel() + + setting := scanner.MultiValueSetting{ + Mode: scanner.Delim, + Delim: `/`, + } + + values := scanner.ParseMulti(setting, nil, `DON'T//BE//⚜⚜⚜`) + require.Len(t, values, 3) + require.Equal(t, `DON'T`, values[0]) + require.Equal(t, `BE`, values[1]) + require.Equal(t, `⚜⚜⚜`, values[2]) +} diff --git a/server/ctrlsubsonic/handlers_common.go b/server/ctrlsubsonic/handlers_common.go index ca9adb6..ac1ef70 100644 --- a/server/ctrlsubsonic/handlers_common.go +++ b/server/ctrlsubsonic/handlers_common.go @@ -518,7 +518,11 @@ func getMusicFolder(musicPaths []MusicPath, p params.Params) string { } func lowerUDecOrHash(in string) string { - lower := unicode.ToLower(rune(in[0])) + inRunes := []rune(in) + if len(inRunes) == 0 { + return "" + } + lower := unicode.ToLower(inRunes[0]) if !unicode.IsLetter(lower) { return "#" } From 1b0315f416ace3e4099d5d1bd7d09c623ab03777 Mon Sep 17 00:00:00 2001 From: sentriz Date: Wed, 3 Jan 2024 09:01:01 +0000 Subject: [PATCH 26/41] update multi valued tags readme --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index cdc1b66..f6ae7f0 100644 --- a/README.md +++ b/README.md @@ -68,24 +68,24 @@ password can then be changed from the web interface | `GONIC_JUKEBOX_MPV_EXTRA_ARGS` | `-jukebox-mpv-extra-args` | **optional** extra command line arguments to pass to the jukebox mpv daemon | | `GONIC_PODCAST_PURGE_AGE` | `-podcast-purge-age` | **optional** age (in days) to purge podcast episodes if not accessed | | `GONIC_EXCLUDE_PATTERN` | `-exclude-pattern` | **optional** files matching this regex pattern will not be imported | -| `GONIC_MULTI_VALUE_GENRE` | `-multi-value-genre` | **optional** setting for multi-valued genre tags when scanning ([see more](#multi-valued-tags-v016)) | -| `GONIC_MULTI_VALUE_ARTIST` | `-multi-value-artist` | **optional** setting for multi-valued artist tags when scanning ([see more](#multi-valued-tags-v016)) | -| `GONIC_MULTI_VALUE_ALBUM_ARTIST` | `-multi-value-album-artist` | **optional** setting for multi-valued album artist tags when scanning ([see more](#multi-valued-tags-v016)) | +| `GONIC_MULTI_VALUE_GENRE` | `-multi-value-genre` | **optional** setting for multi-valued genre tags when scanning ([see more](#multi-valued-tags-v016)) | +| `GONIC_MULTI_VALUE_ARTIST` | `-multi-value-artist` | **optional** setting for multi-valued artist tags when scanning ([see more](#multi-valued-tags-v016)) | +| `GONIC_MULTI_VALUE_ALBUM_ARTIST` | `-multi-value-album-artist` | **optional** setting for multi-valued album artist tags when scanning ([see more](#multi-valued-tags-v016)) | | `GONIC_EXPVAR` | `-expvar` | **optional** enable the /debug/vars endpoint (exposes useful debugging attributes as well as database stats) | ## multi valued tags (v0.16+) -gonic can support potentially multi valued tags like `genres` and `albumartists`. in both cases gonic will individual entries in its database for each. +gonic can support potentially multi valued tags like `genres`, `artists`, and `albumartists`. in both cases gonic will individual entries in its database for each. this means being able to click find album "X" under both "techno" and "house" for example. or finding the album "My Life in the Bush of Ghosts" under either "David Byrne" or "Brian Eno". it also means not cluttering up your artists list with "A & X", "A and Y", "A ft. Z", etc. you will only have A, X, Y, and Z. the available modes are: -| value | desc | -| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `multi` | gonic will explictly look for multi value fields in your audio metadata. software like musicbrainz picard or beets can set set these ([link](https://github.com/beetbox/beets/pull/4743)) | -| `delim ` | gonic will look at your normal audio metadata fields like "genre" or "album_artist", but split them on a delimiter. for example you could set `-multi-value-genre "delim ;"` to split the single genre field on ";" | -| `none` (default) | gonic will not attempt to do any multi value processing | +| value | desc | +| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `multi` | gonic will explictly look for multi value fields in your audio metadata such as "genres" or "album_artists". software like [musicbrainz picard](https://picard.musicbrainz.org/), [beets](https://beets.io/) (v1.6.1+ / master), or [betanin](https://github.com/sentriz/betanin/) can set set these | +| `delim ` | gonic will look at your normal audio metadata fields like "genre" or "album_artist", but split them on a delimiter. for example you could set `-multi-value-genre "delim ;"` to split the single genre field on ";". note this mode is not recommended unless you use an uncommon delimiter such as ";" or "\|". using a delimiter like "&" will likely lead to many [false positives](https://musicbrainz.org/artist/ccd4879c-5e88-4385-b131-bf65296bf245) | +| `none` (default) | gonic will not attempt to do any multi value processing | ## screenshots From a6bb935623a76c709a32b49ce514052ce64af6ea Mon Sep 17 00:00:00 2001 From: sentriz Date: Fri, 5 Jan 2024 22:11:23 +0000 Subject: [PATCH 27/41] delete extra sprintf --- cmd/gonic/gonic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/gonic/gonic.go b/cmd/gonic/gonic.go index 98b046c..f39d59a 100644 --- a/cmd/gonic/gonic.go +++ b/cmd/gonic/gonic.go @@ -526,7 +526,7 @@ func (mvs multiValueSetting) String() string { case scanner.Delim: return fmt.Sprintf("delim(%s)", mvs.Delim) case scanner.Multi: - return fmt.Sprint("multi", mvs.Delim) + return "multi" default: return "none" } From e978716363fdbe54180a176c5e091cfd1806dd78 Mon Sep 17 00:00:00 2001 From: sentriz Date: Tue, 9 Jan 2024 16:20:23 +0000 Subject: [PATCH 28/41] allow `v` in mpv version string --- jukebox/jukebox.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jukebox/jukebox.go b/jukebox/jukebox.go index 1f03e14..b8254bf 100644 --- a/jukebox/jukebox.go +++ b/jukebox/jukebox.go @@ -410,7 +410,7 @@ func lockr(mu *sync.RWMutex) func() { return mu.RUnlock } -var mpvVersionExpr = regexp.MustCompile(`mpv\s(\d+)\.(\d+)\.(\d+)`) +var mpvVersionExpr = regexp.MustCompile(`mpv\sv?(\d+)\.(\d+)\.(\d+)`) func parseMPVVersion(version string) (major, minor, patch int) { m := mpvVersionExpr.FindStringSubmatch(version) From 42dbfa7a85a25fcb80f2936ac7949d50ed1bfbf8 Mon Sep 17 00:00:00 2001 From: sentriz Date: Sun, 14 Jan 2024 12:18:31 +0000 Subject: [PATCH 29/41] fix(subsonic): return error code 70 for not found errors in more places fixes #454 --- server/ctrlsubsonic/handlers_by_tags.go | 6 +++--- server/ctrlsubsonic/handlers_common.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/ctrlsubsonic/handlers_by_tags.go b/server/ctrlsubsonic/handlers_by_tags.go index bb0af77..5a2fa8f 100644 --- a/server/ctrlsubsonic/handlers_by_tags.go +++ b/server/ctrlsubsonic/handlers_by_tags.go @@ -120,7 +120,7 @@ func (c *Controller) ServeGetAlbum(r *http.Request) *spec.Response { First(album, id.Value). Error if errors.Is(err, gorm.ErrRecordNotFound) { - return spec.NewError(10, "couldn't find an album with that id") + return spec.NewError(70, "couldn't find an album with that id") } sub := spec.NewResponse() sub.Album = spec.NewAlbumByTags(album, album.Artists) @@ -649,7 +649,7 @@ func (c *Controller) ServeGetSimilarSongs(r *http.Request) *spec.Response { First(&track). Error if errors.Is(err, gorm.ErrRecordNotFound) { - return spec.NewError(10, "couldn't find a track with that id") + return spec.NewError(70, "couldn't find a track with that id") } similarTracks, err := c.lastFMClient.TrackGetSimilarTracks(track.TagTrackArtist, track.TagTitle) @@ -715,7 +715,7 @@ func (c *Controller) ServeGetSimilarSongsTwo(r *http.Request) *spec.Response { First(&artist). Error if errors.Is(err, gorm.ErrRecordNotFound) { - return spec.NewError(0, "artist with id %q not found", id) + return spec.NewError(70, "artist with id %q not found", id) } similarArtists, err := c.lastFMClient.ArtistGetSimilar(artist.Name) diff --git a/server/ctrlsubsonic/handlers_common.go b/server/ctrlsubsonic/handlers_common.go index ac1ef70..1ee6484 100644 --- a/server/ctrlsubsonic/handlers_common.go +++ b/server/ctrlsubsonic/handlers_common.go @@ -278,7 +278,7 @@ func (c *Controller) ServeGetSong(r *http.Request) *spec.Response { First(&track). Error if errors.Is(err, gorm.ErrRecordNotFound) { - return spec.NewError(10, "couldn't find a track with that id") + return spec.NewError(70, "couldn't find a track with that id") } transcodeMeta := streamGetTranscodeMeta(c.dbc, user.ID, params.GetOr("c", "")) From 6c6c3493f6523e09792ad5dc810adfda46438d8c Mon Sep 17 00:00:00 2001 From: sentriz Date: Mon, 15 Jan 2024 19:26:27 +0000 Subject: [PATCH 30/41] chore: bump deps --- go.mod | 12 ++++++------ go.sum | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 73063c8..4b6d3e9 100644 --- a/go.mod +++ b/go.mod @@ -26,9 +26,9 @@ require ( github.com/sentriz/audiotags v0.0.0-20230419125925-8886243b2137 github.com/sentriz/gormstore v0.0.0-20220105134332-64e31f7f6981 github.com/stretchr/testify v1.8.4 - golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611 - golang.org/x/net v0.19.0 - golang.org/x/sync v0.5.0 + golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 + golang.org/x/net v0.20.0 + golang.org/x/sync v0.6.0 gopkg.in/gormigrate.v1 v1.6.0 jaytaylor.com/html2text v0.0.0-20230321000545-74c2419ad056 ) @@ -60,9 +60,9 @@ require ( github.com/rivo/uniseg v0.4.4 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect - golang.org/x/crypto v0.16.0 // indirect - golang.org/x/image v0.14.0 // indirect - golang.org/x/sys v0.15.0 // indirect + golang.org/x/crypto v0.18.0 // indirect + golang.org/x/image v0.15.0 // indirect + golang.org/x/sys v0.16.0 // indirect golang.org/x/text v0.14.0 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 219b763..58d5252 100644 --- a/go.sum +++ b/go.sum @@ -148,13 +148,13 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= -golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= -golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611 h1:qCEDpW1G+vcj3Y7Fy52pEM1AWm3abj8WimGYejI3SC4= -golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= +golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= +golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= +golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 h1:hNQpMuAJe5CtcUqCXaWga3FHu+kQvCqcsoVaQgSV60o= +golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08= golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/image v0.14.0 h1:tNgSxAFe3jC4uYqvZdTr84SZoM1KfwdC9SKIFrLjFn4= -golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= +golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8= +golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -169,13 +169,13 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= -golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= -golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= +golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= +golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= 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= -golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= -golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= 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= @@ -186,8 +186,8 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= +golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 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= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= From 8b4fc04d3e7a22ba5beb3d682ea13b541c99d2bb Mon Sep 17 00:00:00 2001 From: sentriz Date: Mon, 15 Jan 2024 19:29:01 +0000 Subject: [PATCH 31/41] feat(subsonic): return `changed` field in playlist response closes #455 --- server/ctrlsubsonic/handlers_playlist.go | 1 + server/ctrlsubsonic/spec/spec.go | 1 + 2 files changed, 2 insertions(+) diff --git a/server/ctrlsubsonic/handlers_playlist.go b/server/ctrlsubsonic/handlers_playlist.go index de03430..ae43cb2 100644 --- a/server/ctrlsubsonic/handlers_playlist.go +++ b/server/ctrlsubsonic/handlers_playlist.go @@ -197,6 +197,7 @@ func playlistRender(c *Controller, params params.Params, playlistID string, play Name: playlist.Name, Comment: playlist.Comment, Created: playlist.UpdatedAt, + Changed: playlist.UpdatedAt, SongCount: len(playlist.Items), Public: playlist.IsPublic, Owner: user.Name, diff --git a/server/ctrlsubsonic/spec/spec.go b/server/ctrlsubsonic/spec/spec.go index 5a0df70..c2a0de0 100644 --- a/server/ctrlsubsonic/spec/spec.go +++ b/server/ctrlsubsonic/spec/spec.go @@ -310,6 +310,7 @@ type Playlist struct { Owner string `xml:"owner,attr" json:"owner"` SongCount int `xml:"songCount,attr" json:"songCount"` Created time.Time `xml:"created,attr" json:"created"` + Changed time.Time `xml:"changed,attr" json:"changed"` Duration int `xml:"duration,attr" json:"duration,omitempty"` Public bool `xml:"public,attr" json:"public,omitempty"` List []*TrackChild `xml:"entry,omitempty" json:"entry,omitempty"` From 7f60d984af15fe95f4817bded94222277bf5228e Mon Sep 17 00:00:00 2001 From: sentriz Date: Wed, 17 Jan 2024 13:12:10 +0000 Subject: [PATCH 32/41] reuse podcast http client --- podcast/podcast.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/podcast/podcast.go b/podcast/podcast.go index 17fc73b..af9c1aa 100644 --- a/podcast/podcast.go +++ b/podcast/podcast.go @@ -30,16 +30,18 @@ const ( ) type Podcasts struct { - db *db.DB - baseDir string - tagReader tagcommon.Reader + httpClient *http.Client + db *db.DB + baseDir string + tagReader tagcommon.Reader } func New(db *db.DB, base string, tagReader tagcommon.Reader) *Podcasts { return &Podcasts{ - db: db, - baseDir: base, - tagReader: tagReader, + db: db, + baseDir: base, + tagReader: tagReader, + httpClient: &http.Client{}, } } @@ -324,8 +326,7 @@ func (p *Podcasts) downloadPodcastCover(podcast *db.Podcast) error { } req.Header.Add("User-Agent", fetchUserAgent) - client := &http.Client{} - resp, err := client.Do(req) + resp, err := p.httpClient.Do(req) if err != nil { return fmt.Errorf("fetch image url: %w", err) } @@ -461,14 +462,13 @@ func (p *Podcasts) DownloadTick() error { } func (p *Podcasts) doPodcastDownload(podcast *db.Podcast, podcastEpisode *db.PodcastEpisode) (err error) { - client := &http.Client{} req, err := http.NewRequest(http.MethodGet, podcastEpisode.AudioURL, nil) if err != nil { return fmt.Errorf("create http request: %w", err) } req.Header.Add("User-Agent", fetchUserAgent) - resp, err := client.Do(req) + resp, err := p.httpClient.Do(req) if err != nil { return fmt.Errorf("fetch podcast audio: %w", err) } From 6f49ab744e64c4f06acf053385a57a7c4cd4601a Mon Sep 17 00:00:00 2001 From: sentriz Date: Wed, 17 Jan 2024 13:25:27 +0000 Subject: [PATCH 33/41] add podcast episode download logging --- podcast/podcast.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/podcast/podcast.go b/podcast/podcast.go index af9c1aa..45a2257 100644 --- a/podcast/podcast.go +++ b/podcast/podcast.go @@ -94,7 +94,7 @@ func (p *Podcasts) AddNewPodcast(rssURL string, feed *gofeed.Feed) (*db.Podcast, return &podcast, err } if err := p.RefreshPodcast(&podcast, feed.Items); err != nil { - log.Printf("error addign new episodes : %v", err) + log.Printf("error adding new episodes : %v", err) } if err := p.downloadPodcastCover(&podcast); err != nil { log.Printf("error downloading podcast cover: %v", err) @@ -458,6 +458,8 @@ func (p *Podcasts) DownloadTick() error { if err := p.doPodcastDownload(podcastEpisode.Podcast, &podcastEpisode); err != nil { return fmt.Errorf("do download: %w", err) } + + log.Printf("downloaded podcast episode %q - %q", podcastEpisode.Podcast.Title, podcastEpisode.Title) return nil } From 87943ea863f5e882ff4acfe329d6dde674ac630b Mon Sep 17 00:00:00 2001 From: Senan Kelly Date: Wed, 17 Jan 2024 19:13:34 +0000 Subject: [PATCH 34/41] fix(subsonic): always return playlist duration fixes #457 --- server/ctrlsubsonic/spec/spec.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/ctrlsubsonic/spec/spec.go b/server/ctrlsubsonic/spec/spec.go index c2a0de0..d48d92e 100644 --- a/server/ctrlsubsonic/spec/spec.go +++ b/server/ctrlsubsonic/spec/spec.go @@ -311,7 +311,7 @@ type Playlist struct { SongCount int `xml:"songCount,attr" json:"songCount"` Created time.Time `xml:"created,attr" json:"created"` Changed time.Time `xml:"changed,attr" json:"changed"` - Duration int `xml:"duration,attr" json:"duration,omitempty"` + Duration int `xml:"duration,attr" json:"duration"` Public bool `xml:"public,attr" json:"public,omitempty"` List []*TrackChild `xml:"entry,omitempty" json:"entry,omitempty"` } From ec55f3b22a8c689cbd2305965b3c538f5c2bf25f Mon Sep 17 00:00:00 2001 From: sentriz Date: Thu, 18 Jan 2024 21:10:19 +0000 Subject: [PATCH 35/41] feat(subsonic): return `playCount` in album responses closes #458 --- db/db.go | 1 + server/ctrlsubsonic/handlers_by_tags.go | 9 +- server/ctrlsubsonic/spec/construct_by_tags.go | 3 + server/ctrlsubsonic/spec/spec.go | 1 + .../testdata/test_get_album_list_alpha_artist | 27 ++- .../testdata/test_get_album_list_alpha_name | 27 ++- .../testdata/test_get_album_list_newest | 27 ++- .../testdata/test_get_album_list_random | 223 +++++++++--------- .../test_get_album_list_two_alpha_artist | 9 + .../test_get_album_list_two_alpha_name | 9 + .../testdata/test_get_album_list_two_newest | 9 + .../testdata/test_get_album_list_two_random | 177 +++++++------- .../testdata/test_get_album_with_cover | 1 + .../testdata/test_get_album_without_cover | 3 +- .../testdata/test_get_artist_id_one | 3 + .../testdata/test_get_artist_id_three | 3 + .../testdata/test_get_artist_id_two | 3 + .../testdata/test_search_three_q_alb | 9 + 18 files changed, 323 insertions(+), 221 deletions(-) diff --git a/db/db.go b/db/db.go index 9f0ff60..0b60c08 100644 --- a/db/db.go +++ b/db/db.go @@ -339,6 +339,7 @@ type Album struct { AlbumStar *AlbumStar AlbumRating *AlbumRating AverageRating float64 `sql:"default: null"` + Play *Play } func (a *Album) SID() *specid.ID { diff --git a/server/ctrlsubsonic/handlers_by_tags.go b/server/ctrlsubsonic/handlers_by_tags.go index 5a2fa8f..3f5da91 100644 --- a/server/ctrlsubsonic/handlers_by_tags.go +++ b/server/ctrlsubsonic/handlers_by_tags.go @@ -117,6 +117,8 @@ func (c *Controller) ServeGetAlbum(r *http.Request) *spec.Response { }). Preload("AlbumStar", "user_id=?", user.ID). Preload("AlbumRating", "user_id=?", user.ID). + Preload("AlbumRating", "user_id=?", user.ID). + Preload("Play", "user_id=?", user.ID). First(album, id.Value). Error if errors.Is(err, gorm.ErrRecordNotFound) { @@ -199,6 +201,7 @@ func (c *Controller) ServeGetAlbumListTwo(r *http.Request) *spec.Response { Preload("Artists"). Preload("AlbumStar", "user_id=?", user.ID). Preload("AlbumRating", "user_id=?", user.ID). + Preload("Play", "user_id=?", user.ID). Find(&albums) sub := spec.NewResponse() sub.AlbumsTwo = &spec.Albums{ @@ -256,7 +259,8 @@ func (c *Controller) ServeSearchThree(r *http.Request) *spec.Response { Preload("Artists"). Preload("Genres"). Preload("AlbumStar", "user_id=?", user.ID). - Preload("AlbumRating", "user_id=?", user.ID) + Preload("AlbumRating", "user_id=?", user.ID). + Preload("Play", "user_id=?", user.ID) for _, s := range queries { q = q.Where(`tag_title LIKE ? OR tag_title_u_dec LIKE ?`, s, s) } @@ -517,7 +521,8 @@ func (c *Controller) ServeGetStarredTwo(r *http.Request) *spec.Response { Order("album_stars.star_date DESC"). Preload("Artists"). Preload("AlbumStar", "user_id=?", user.ID). - Preload("AlbumRating", "user_id=?", user.ID) + Preload("AlbumRating", "user_id=?", user.ID). + Preload("Play", "user_id=?", user.ID) if m := getMusicFolder(c.musicPaths, params); m != "" { q = q.Where("albums.root_dir=?", m) } diff --git a/server/ctrlsubsonic/spec/construct_by_tags.go b/server/ctrlsubsonic/spec/construct_by_tags.go index 07d64c7..a3d8457 100644 --- a/server/ctrlsubsonic/spec/construct_by_tags.go +++ b/server/ctrlsubsonic/spec/construct_by_tags.go @@ -51,6 +51,9 @@ func NewAlbumByTags(a *db.Album, artists []*db.Artist) *Album { for _, g := range a.Genres { ret.Genres = append(ret.Genres, &GenreRef{Name: g.Name}) } + if a.Play != nil { + ret.PlayCount = a.Play.Count + } return ret } diff --git a/server/ctrlsubsonic/spec/spec.go b/server/ctrlsubsonic/spec/spec.go index d48d92e..757234d 100644 --- a/server/ctrlsubsonic/spec/spec.go +++ b/server/ctrlsubsonic/spec/spec.go @@ -144,6 +144,7 @@ type Album struct { Name string `xml:"name,attr" json:"name"` TrackCount int `xml:"songCount,attr" json:"songCount"` Duration int `xml:"duration,attr" json:"duration"` + PlayCount int `xml:"playCount,attr" json:"playCount"` Genre string `xml:"genre,attr,omitempty" json:"genre,omitempty"` Genres []*GenreRef `xml:"genres,omitempty" json:"genres,omitempty"` Year int `xml:"year,attr,omitempty" json:"year,omitempty"` diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_alpha_artist b/server/ctrlsubsonic/testdata/test_get_album_list_alpha_artist index 81f84c6..7654a86 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_alpha_artist +++ b/server/ctrlsubsonic/testdata/test_get_album_list_alpha_artist @@ -20,7 +20,8 @@ "coverArt": "al-3", "name": "album-0", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-4", @@ -35,7 +36,8 @@ "coverArt": "al-4", "name": "album-1", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-5", @@ -50,7 +52,8 @@ "coverArt": "al-5", "name": "album-2", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-7", @@ -65,7 +68,8 @@ "coverArt": "al-7", "name": "album-0", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-8", @@ -80,7 +84,8 @@ "coverArt": "al-8", "name": "album-1", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-9", @@ -95,7 +100,8 @@ "coverArt": "al-9", "name": "album-2", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-11", @@ -110,7 +116,8 @@ "coverArt": "al-11", "name": "album-0", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-12", @@ -125,7 +132,8 @@ "coverArt": "al-12", "name": "album-1", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-13", @@ -140,7 +148,8 @@ "coverArt": "al-13", "name": "album-2", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 } ] } diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_alpha_name b/server/ctrlsubsonic/testdata/test_get_album_list_alpha_name index 0151da9..438dfaf 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_alpha_name +++ b/server/ctrlsubsonic/testdata/test_get_album_list_alpha_name @@ -20,7 +20,8 @@ "coverArt": "al-3", "name": "album-0", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-7", @@ -35,7 +36,8 @@ "coverArt": "al-7", "name": "album-0", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-11", @@ -50,7 +52,8 @@ "coverArt": "al-11", "name": "album-0", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-4", @@ -65,7 +68,8 @@ "coverArt": "al-4", "name": "album-1", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-8", @@ -80,7 +84,8 @@ "coverArt": "al-8", "name": "album-1", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-12", @@ -95,7 +100,8 @@ "coverArt": "al-12", "name": "album-1", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-5", @@ -110,7 +116,8 @@ "coverArt": "al-5", "name": "album-2", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-9", @@ -125,7 +132,8 @@ "coverArt": "al-9", "name": "album-2", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-13", @@ -140,7 +148,8 @@ "coverArt": "al-13", "name": "album-2", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 } ] } diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_newest b/server/ctrlsubsonic/testdata/test_get_album_list_newest index 81f84c6..7654a86 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_newest +++ b/server/ctrlsubsonic/testdata/test_get_album_list_newest @@ -20,7 +20,8 @@ "coverArt": "al-3", "name": "album-0", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-4", @@ -35,7 +36,8 @@ "coverArt": "al-4", "name": "album-1", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-5", @@ -50,7 +52,8 @@ "coverArt": "al-5", "name": "album-2", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-7", @@ -65,7 +68,8 @@ "coverArt": "al-7", "name": "album-0", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-8", @@ -80,7 +84,8 @@ "coverArt": "al-8", "name": "album-1", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-9", @@ -95,7 +100,8 @@ "coverArt": "al-9", "name": "album-2", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-11", @@ -110,7 +116,8 @@ "coverArt": "al-11", "name": "album-0", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-12", @@ -125,7 +132,8 @@ "coverArt": "al-12", "name": "album-1", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-13", @@ -140,7 +148,8 @@ "coverArt": "al-13", "name": "album-2", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 } ] } diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_random b/server/ctrlsubsonic/testdata/test_get_album_list_random index 64fd041..604aaa1 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_random +++ b/server/ctrlsubsonic/testdata/test_get_album_list_random @@ -7,51 +7,6 @@ "openSubsonic": true, "albumList": { "album": [ - { - "id": "al-12", - "created": "2019-11-30T00:00:00Z", - "artist": "artist-2", - "artists": null, - "displayArtist": "", - "title": "album-1", - "album": "album-1", - "parent": "al-10", - "isDir": true, - "coverArt": "al-12", - "name": "album-1", - "songCount": 3, - "duration": 300 - }, - { - "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 - }, - { - "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 - }, { "id": "al-9", "created": "2019-11-30T00:00:00Z", @@ -65,67 +20,8 @@ "coverArt": "al-9", "name": "album-2", "songCount": 3, - "duration": 300 - }, - { - "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 - }, - { - "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 - }, - { - "id": "al-13", - "created": "2019-11-30T00:00:00Z", - "artist": "artist-2", - "artists": null, - "displayArtist": "", - "title": "album-2", - "album": "album-2", - "parent": "al-10", - "isDir": true, - "coverArt": "al-13", - "name": "album-2", - "songCount": 3, - "duration": 300 - }, - { - "id": "al-11", - "created": "2019-11-30T00:00:00Z", - "artist": "artist-2", - "artists": null, - "displayArtist": "", - "title": "album-0", - "album": "album-0", - "parent": "al-10", - "isDir": true, - "coverArt": "al-11", - "name": "album-0", - "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 }, { "id": "al-7", @@ -140,7 +36,120 @@ "coverArt": "al-7", "name": "album-0", "songCount": 3, - "duration": 300 + "duration": 300, + "playCount": 0 + }, + { + "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 + }, + { + "id": "al-12", + "created": "2019-11-30T00:00:00Z", + "artist": "artist-2", + "artists": null, + "displayArtist": "", + "title": "album-1", + "album": "album-1", + "parent": "al-10", + "isDir": true, + "coverArt": "al-12", + "name": "album-1", + "songCount": 3, + "duration": 300, + "playCount": 0 + }, + { + "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 + }, + { + "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 + }, + { + "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 + }, + { + "id": "al-13", + "created": "2019-11-30T00:00:00Z", + "artist": "artist-2", + "artists": null, + "displayArtist": "", + "title": "album-2", + "album": "album-2", + "parent": "al-10", + "isDir": true, + "coverArt": "al-13", + "name": "album-2", + "songCount": 3, + "duration": 300, + "playCount": 0 + }, + { + "id": "al-11", + "created": "2019-11-30T00:00:00Z", + "artist": "artist-2", + "artists": null, + "displayArtist": "", + "title": "album-0", + "album": "album-0", + "parent": "al-10", + "isDir": true, + "coverArt": "al-11", + "name": "album-0", + "songCount": 3, + "duration": 300, + "playCount": 0 } ] } diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_artist b/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_artist index 35104eb..e9d52e7 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_artist +++ b/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_artist @@ -20,6 +20,7 @@ "name": "album-0", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -35,6 +36,7 @@ "name": "album-1", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -50,6 +52,7 @@ "name": "album-2", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -65,6 +68,7 @@ "name": "album-0", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -80,6 +84,7 @@ "name": "album-1", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -95,6 +100,7 @@ "name": "album-2", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -110,6 +116,7 @@ "name": "album-0", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -125,6 +132,7 @@ "name": "album-1", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -140,6 +148,7 @@ "name": "album-2", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 } ] diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_name b/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_name index 6a4aec2..253ae22 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_name +++ b/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_name @@ -20,6 +20,7 @@ "name": "album-0", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -35,6 +36,7 @@ "name": "album-0", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -50,6 +52,7 @@ "name": "album-0", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -65,6 +68,7 @@ "name": "album-1", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -80,6 +84,7 @@ "name": "album-1", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -95,6 +100,7 @@ "name": "album-1", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -110,6 +116,7 @@ "name": "album-2", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -125,6 +132,7 @@ "name": "album-2", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -140,6 +148,7 @@ "name": "album-2", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 } ] diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_two_newest b/server/ctrlsubsonic/testdata/test_get_album_list_two_newest index 35104eb..e9d52e7 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_two_newest +++ b/server/ctrlsubsonic/testdata/test_get_album_list_two_newest @@ -20,6 +20,7 @@ "name": "album-0", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -35,6 +36,7 @@ "name": "album-1", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -50,6 +52,7 @@ "name": "album-2", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -65,6 +68,7 @@ "name": "album-0", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -80,6 +84,7 @@ "name": "album-1", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -95,6 +100,7 @@ "name": "album-2", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -110,6 +116,7 @@ "name": "album-0", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -125,6 +132,7 @@ "name": "album-1", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { @@ -140,6 +148,7 @@ "name": "album-2", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 } ] diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_two_random b/server/ctrlsubsonic/testdata/test_get_album_list_two_random index 0267d2c..99edf56 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_two_random +++ b/server/ctrlsubsonic/testdata/test_get_album_list_two_random @@ -7,51 +7,6 @@ "openSubsonic": true, "albumList2": { "album": [ - { - "id": "al-7", - "created": "2019-11-30T00:00:00Z", - "artistId": "ar-2", - "artist": "artist-1", - "artists": [{ "id": "ar-2", "name": "artist-1" }], - "displayArtist": "artist-1", - "title": "album-0", - "album": "album-0", - "coverArt": "al-7", - "name": "album-0", - "songCount": 3, - "duration": 300, - "year": 2021 - }, - { - "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, - "year": 2021 - }, - { - "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, - "year": 2021 - }, { "id": "al-3", "created": "2019-11-30T00:00:00Z", @@ -65,36 +20,7 @@ "name": "album-0", "songCount": 3, "duration": 300, - "year": 2021 - }, - { - "id": "al-8", - "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", - "songCount": 3, - "duration": 300, - "year": 2021 - }, - { - "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, "year": 2021 }, { @@ -110,21 +36,23 @@ "name": "album-2", "songCount": 3, "duration": 300, + "playCount": 0, "year": 2021 }, { - "id": "al-13", + "id": "al-8", "created": "2019-11-30T00:00:00Z", - "artistId": "ar-3", - "artist": "artist-2", - "artists": [{ "id": "ar-3", "name": "artist-2" }], - "displayArtist": "artist-2", - "title": "album-2", - "album": "album-2", - "coverArt": "al-13", - "name": "album-2", + "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, "year": 2021 }, { @@ -140,6 +68,87 @@ "name": "album-0", "songCount": 3, "duration": 300, + "playCount": 0, + "year": 2021 + }, + { + "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, + "year": 2021 + }, + { + "id": "al-7", + "created": "2019-11-30T00:00:00Z", + "artistId": "ar-2", + "artist": "artist-1", + "artists": [{ "id": "ar-2", "name": "artist-1" }], + "displayArtist": "artist-1", + "title": "album-0", + "album": "album-0", + "coverArt": "al-7", + "name": "album-0", + "songCount": 3, + "duration": 300, + "playCount": 0, + "year": 2021 + }, + { + "id": "al-13", + "created": "2019-11-30T00:00:00Z", + "artistId": "ar-3", + "artist": "artist-2", + "artists": [{ "id": "ar-3", "name": "artist-2" }], + "displayArtist": "artist-2", + "title": "album-2", + "album": "album-2", + "coverArt": "al-13", + "name": "album-2", + "songCount": 3, + "duration": 300, + "playCount": 0, + "year": 2021 + }, + { + "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, + "year": 2021 + }, + { + "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, "year": 2021 } ] diff --git a/server/ctrlsubsonic/testdata/test_get_album_with_cover b/server/ctrlsubsonic/testdata/test_get_album_with_cover index f0185a3..40ee4ae 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_with_cover +++ b/server/ctrlsubsonic/testdata/test_get_album_with_cover @@ -18,6 +18,7 @@ "name": "album-0", "songCount": 3, "duration": 300, + "playCount": 0, "genre": "Unknown Genre", "genres": [{ "name": "Unknown Genre" }], "year": 2021, diff --git a/server/ctrlsubsonic/testdata/test_get_album_without_cover b/server/ctrlsubsonic/testdata/test_get_album_without_cover index 069d3d6..0fd0572 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_without_cover +++ b/server/ctrlsubsonic/testdata/test_get_album_without_cover @@ -15,7 +15,8 @@ "album": "", "name": "", "songCount": 0, - "duration": 0 + "duration": 0, + "playCount": 0 } } } diff --git a/server/ctrlsubsonic/testdata/test_get_artist_id_one b/server/ctrlsubsonic/testdata/test_get_artist_id_one index 5c1fe45..0b02ff1 100644 --- a/server/ctrlsubsonic/testdata/test_get_artist_id_one +++ b/server/ctrlsubsonic/testdata/test_get_artist_id_one @@ -23,6 +23,7 @@ "name": "album-0", "songCount": 3, "duration": 300, + "playCount": 0, "genre": "Unknown Genre", "genres": [{ "name": "Unknown Genre" }], "year": 2021 @@ -40,6 +41,7 @@ "name": "album-1", "songCount": 3, "duration": 300, + "playCount": 0, "genre": "Unknown Genre", "genres": [{ "name": "Unknown Genre" }], "year": 2021 @@ -57,6 +59,7 @@ "name": "album-2", "songCount": 3, "duration": 300, + "playCount": 0, "genre": "Unknown Genre", "genres": [{ "name": "Unknown Genre" }], "year": 2021 diff --git a/server/ctrlsubsonic/testdata/test_get_artist_id_three b/server/ctrlsubsonic/testdata/test_get_artist_id_three index c5542f3..389ed9c 100644 --- a/server/ctrlsubsonic/testdata/test_get_artist_id_three +++ b/server/ctrlsubsonic/testdata/test_get_artist_id_three @@ -23,6 +23,7 @@ "name": "album-0", "songCount": 3, "duration": 300, + "playCount": 0, "genre": "Unknown Genre", "genres": [{ "name": "Unknown Genre" }], "year": 2021 @@ -40,6 +41,7 @@ "name": "album-1", "songCount": 3, "duration": 300, + "playCount": 0, "genre": "Unknown Genre", "genres": [{ "name": "Unknown Genre" }], "year": 2021 @@ -57,6 +59,7 @@ "name": "album-2", "songCount": 3, "duration": 300, + "playCount": 0, "genre": "Unknown Genre", "genres": [{ "name": "Unknown Genre" }], "year": 2021 diff --git a/server/ctrlsubsonic/testdata/test_get_artist_id_two b/server/ctrlsubsonic/testdata/test_get_artist_id_two index e8fb633..b85d4d4 100644 --- a/server/ctrlsubsonic/testdata/test_get_artist_id_two +++ b/server/ctrlsubsonic/testdata/test_get_artist_id_two @@ -23,6 +23,7 @@ "name": "album-0", "songCount": 3, "duration": 300, + "playCount": 0, "genre": "Unknown Genre", "genres": [{ "name": "Unknown Genre" }], "year": 2021 @@ -40,6 +41,7 @@ "name": "album-1", "songCount": 3, "duration": 300, + "playCount": 0, "genre": "Unknown Genre", "genres": [{ "name": "Unknown Genre" }], "year": 2021 @@ -57,6 +59,7 @@ "name": "album-2", "songCount": 3, "duration": 300, + "playCount": 0, "genre": "Unknown Genre", "genres": [{ "name": "Unknown Genre" }], "year": 2021 diff --git a/server/ctrlsubsonic/testdata/test_search_three_q_alb b/server/ctrlsubsonic/testdata/test_search_three_q_alb index 7ffb5dd..2d346c8 100644 --- a/server/ctrlsubsonic/testdata/test_search_three_q_alb +++ b/server/ctrlsubsonic/testdata/test_search_three_q_alb @@ -20,6 +20,7 @@ "name": "album-0", "songCount": 0, "duration": 0, + "playCount": 0, "genre": "Unknown Genre", "genres": [{ "name": "Unknown Genre" }], "year": 2021 @@ -37,6 +38,7 @@ "name": "album-1", "songCount": 0, "duration": 0, + "playCount": 0, "genre": "Unknown Genre", "genres": [{ "name": "Unknown Genre" }], "year": 2021 @@ -54,6 +56,7 @@ "name": "album-2", "songCount": 0, "duration": 0, + "playCount": 0, "genre": "Unknown Genre", "genres": [{ "name": "Unknown Genre" }], "year": 2021 @@ -71,6 +74,7 @@ "name": "album-0", "songCount": 0, "duration": 0, + "playCount": 0, "genre": "Unknown Genre", "genres": [{ "name": "Unknown Genre" }], "year": 2021 @@ -88,6 +92,7 @@ "name": "album-1", "songCount": 0, "duration": 0, + "playCount": 0, "genre": "Unknown Genre", "genres": [{ "name": "Unknown Genre" }], "year": 2021 @@ -105,6 +110,7 @@ "name": "album-2", "songCount": 0, "duration": 0, + "playCount": 0, "genre": "Unknown Genre", "genres": [{ "name": "Unknown Genre" }], "year": 2021 @@ -122,6 +128,7 @@ "name": "album-0", "songCount": 0, "duration": 0, + "playCount": 0, "genre": "Unknown Genre", "genres": [{ "name": "Unknown Genre" }], "year": 2021 @@ -139,6 +146,7 @@ "name": "album-1", "songCount": 0, "duration": 0, + "playCount": 0, "genre": "Unknown Genre", "genres": [{ "name": "Unknown Genre" }], "year": 2021 @@ -156,6 +164,7 @@ "name": "album-2", "songCount": 0, "duration": 0, + "playCount": 0, "genre": "Unknown Genre", "genres": [{ "name": "Unknown Genre" }], "year": 2021 From 29c5397dae82017e24347afe65e9bbf9be10a494 Mon Sep 17 00:00:00 2001 From: sentriz Date: Fri, 2 Feb 2024 19:42:24 +0000 Subject: [PATCH 36/41] feat: bump audiotags fork to support taglib v2 --- go.mod | 2 +- go.sum | 4 ++-- tags/taglib/taglib.go | 10 ++++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 4b6d3e9..2820481 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/peterbourgon/ff v1.7.1 github.com/philippta/go-template v0.0.0-20220911145045-4556aca435e4 github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be - github.com/sentriz/audiotags v0.0.0-20230419125925-8886243b2137 + github.com/sentriz/audiotags v0.0.0-20240202193907-618ae39d7743 github.com/sentriz/gormstore v0.0.0-20220105134332-64e31f7f6981 github.com/stretchr/testify v1.8.4 golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 diff --git a/go.sum b/go.sum index 58d5252..b2e21f0 100644 --- a/go.sum +++ b/go.sum @@ -132,8 +132,8 @@ github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= -github.com/sentriz/audiotags v0.0.0-20230419125925-8886243b2137 h1:K0PSMi/p9ISHpfRFJB03d7VX+jjEsDARsTlAcN1zpac= -github.com/sentriz/audiotags v0.0.0-20230419125925-8886243b2137/go.mod h1:nUVlCJ7n2jQoJ5rttpHozZ8pHJIhD9VehL6GP21FoDU= +github.com/sentriz/audiotags v0.0.0-20240202193907-618ae39d7743 h1:aecPwcrY8mYmZmd9XgQcG8aILRuhRxeQMSunnr6DQ3U= +github.com/sentriz/audiotags v0.0.0-20240202193907-618ae39d7743/go.mod h1:Zoo4UP5t2ySbPwScJfoydAlLLBonoqntv4ovA1T91Z8= 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/ssor/bom v0.0.0-20170718123548-6386211fdfcf h1:pvbZ0lM0XWPBqUKqFU8cmavspvIl9nulOYwdy6IFRRo= diff --git a/tags/taglib/taglib.go b/tags/taglib/taglib.go index ff66016..3008c37 100644 --- a/tags/taglib/taglib.go +++ b/tags/taglib/taglib.go @@ -1,6 +1,7 @@ package taglib import ( + "fmt" "path/filepath" "strconv" "strings" @@ -20,8 +21,13 @@ func (TagLib) CanRead(absPath string) bool { } func (TagLib) Read(absPath string) (tagcommon.Info, error) { - raw, props, err := audiotags.Read(absPath) - return &info{raw, props}, err + f, err := audiotags.Open(absPath) + if err != nil { + return nil, fmt.Errorf("open: %w", err) + } + props := f.ReadAudioProperties() + raw := f.ReadTags() + return &info{raw, props}, nil } type info struct { From 314e9632d72dd7cd68044f9d69295123fff78f80 Mon Sep 17 00:00:00 2001 From: sentriz Date: Fri, 2 Feb 2024 19:57:03 +0000 Subject: [PATCH 37/41] fix(playlist): return new playlist id for createPlaylist fixes #464 --- server/ctrlsubsonic/ctrl.go | 2 +- server/ctrlsubsonic/handlers_playlist.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/server/ctrlsubsonic/ctrl.go b/server/ctrlsubsonic/ctrl.go index 189842f..12d0bab 100644 --- a/server/ctrlsubsonic/ctrl.go +++ b/server/ctrlsubsonic/ctrl.go @@ -111,7 +111,7 @@ func New(dbc *db.DB, scannr *scanner.Scanner, musicPaths []MusicPath, podcastsPa c.Handle("/getUser", chain(resp(c.ServeGetUser))) c.Handle("/getPlaylists", chain(resp(c.ServeGetPlaylists))) c.Handle("/getPlaylist", chain(resp(c.ServeGetPlaylist))) - c.Handle("/createPlaylist", chain(resp(c.ServeCreatePlaylist))) + c.Handle("/createPlaylist", chain(resp(c.ServeCreateOrUpdatePlaylist))) c.Handle("/updatePlaylist", chain(resp(c.ServeUpdatePlaylist))) c.Handle("/deletePlaylist", chain(resp(c.ServeDeletePlaylist))) c.Handle("/savePlayQueue", chain(resp(c.ServeSavePlayQueue))) diff --git a/server/ctrlsubsonic/handlers_playlist.go b/server/ctrlsubsonic/handlers_playlist.go index ae43cb2..ca0c6e5 100644 --- a/server/ctrlsubsonic/handlers_playlist.go +++ b/server/ctrlsubsonic/handlers_playlist.go @@ -67,7 +67,7 @@ func (c *Controller) ServeGetPlaylist(r *http.Request) *spec.Response { return sub } -func (c *Controller) ServeCreatePlaylist(r *http.Request) *spec.Response { +func (c *Controller) ServeCreateOrUpdatePlaylist(r *http.Request) *spec.Response { user := r.Context().Value(CtxUser).(*db.User) params := r.Context().Value(CtxParams).(params.Params) @@ -79,9 +79,8 @@ func (c *Controller) ServeCreatePlaylist(r *http.Request) *spec.Response { playlist = *pl } - // update meta info if playlist.UserID != 0 && playlist.UserID != user.ID { - return spec.NewResponse() + return spec.NewError(50, "you aren't allowed update that user's playlist") } playlist.UserID = user.ID @@ -103,7 +102,9 @@ func (c *Controller) ServeCreatePlaylist(r *http.Request) *spec.Response { if playlistPath == "" { playlistPath = playlistp.NewPath(user.ID, fmt.Sprint(time.Now().UnixMilli())) + playlistID = playlistIDEncode(playlistPath) } + if err := c.playlistStore.Write(playlistPath, &playlist); err != nil { return spec.NewError(0, "save playlist: %v", err) } From 4581a0d28ec1725427d883bb3c178c304c5b1731 Mon Sep 17 00:00:00 2001 From: sentriz Date: Sun, 11 Feb 2024 21:11:37 +0000 Subject: [PATCH 38/41] chore: bump deps --- go.mod | 14 +++++++------- go.sum | 28 ++++++++++++++-------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index 2820481..87c36ec 100644 --- a/go.mod +++ b/go.mod @@ -11,12 +11,12 @@ require ( github.com/fatih/structs v1.1.0 github.com/fsnotify/fsnotify v1.7.0 github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 - github.com/google/uuid v1.5.0 + github.com/google/uuid v1.6.0 github.com/gorilla/securecookie v1.1.2 github.com/gorilla/sessions v1.2.2 github.com/jinzhu/gorm v1.9.17-0.20211120011537-5c235b72a414 github.com/josephburnett/jd v1.7.1 - github.com/mattn/go-sqlite3 v1.14.19 + github.com/mattn/go-sqlite3 v1.14.22 github.com/mitchellh/mapstructure v1.5.0 github.com/mmcdole/gofeed v1.2.1 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 @@ -26,8 +26,8 @@ require ( github.com/sentriz/audiotags v0.0.0-20240202193907-618ae39d7743 github.com/sentriz/gormstore v0.0.0-20220105134332-64e31f7f6981 github.com/stretchr/testify v1.8.4 - golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 - golang.org/x/net v0.20.0 + golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 + golang.org/x/net v0.21.0 golang.org/x/sync v0.6.0 gopkg.in/gormigrate.v1 v1.6.0 jaytaylor.com/html2text v0.0.0-20230321000545-74c2419ad056 @@ -57,12 +57,12 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/rivo/uniseg v0.4.4 // indirect + github.com/rivo/uniseg v0.4.7 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect - golang.org/x/crypto v0.18.0 // indirect + golang.org/x/crypto v0.19.0 // indirect golang.org/x/image v0.15.0 // indirect - golang.org/x/sys v0.16.0 // indirect + golang.org/x/sys v0.17.0 // indirect golang.org/x/text v0.14.0 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index b2e21f0..83a28a0 100644 --- a/go.sum +++ b/go.sum @@ -48,8 +48,8 @@ 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.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= -github.com/google/uuid v1.5.0/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= github.com/gorilla/context v1.1.2 h1:WRkNAv2uoa03QNIc1A6u4O7DAGMUVoopZhkiXWA2V1o= github.com/gorilla/context v1.1.2/go.mod h1:KDPwT9i/MeWHiLl90fuTgrt4/wPcv75vFAZLaOOcbxM= @@ -96,8 +96,8 @@ github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZ github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= 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.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI= -github.com/mattn/go-sqlite3 v1.14.19/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= +github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= +github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= @@ -128,8 +128,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be h1:ta7tUOvsPHVHGom5hKW5VXNc2xZIkfCKP8iaqOyYtUQ= github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be/go.mod h1:MIDFMn7db1kT65GmV94GzpX9Qdi7N/pQlwb+AN8wh+Q= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= -github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= +github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/sentriz/audiotags v0.0.0-20240202193907-618ae39d7743 h1:aecPwcrY8mYmZmd9XgQcG8aILRuhRxeQMSunnr6DQ3U= @@ -148,10 +148,10 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= -golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 h1:hNQpMuAJe5CtcUqCXaWga3FHu+kQvCqcsoVaQgSV60o= -golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08= +golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= +golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= +golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 h1:/RIbNt/Zr7rVhIkQhooTxCxFcdWLGIKnZA4IXNFSrvo= +golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08= golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8= golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= @@ -169,8 +169,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= -golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= -golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= 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= @@ -186,8 +186,8 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 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= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= From 19ebd4540f9e47c521cc70587457a770110495a5 Mon Sep 17 00:00:00 2001 From: sentriz Date: Tue, 13 Feb 2024 21:48:37 +0000 Subject: [PATCH 39/41] fix(scanner): clean up orphaned album genres when dir still exists without tracks fixes #466 --- scanner/scanner.go | 22 ++++++++++++++++++---- scanner/scanner_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/scanner/scanner.go b/scanner/scanner.go index aefa4c1..3da322f 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -610,20 +610,34 @@ func (s *Scanner) cleanGenres(st *State) error { //nolint:unparam subTrack := s.db. Select("genres.id"). - Model(&db.Genre{}). + Model(db.Genre{}). Joins("LEFT JOIN track_genres ON track_genres.genre_id=genres.id"). Where("track_genres.genre_id IS NULL"). SubQuery() subAlbum := s.db. Select("genres.id"). - Model(&db.Genre{}). + Model(db.Genre{}). Joins("LEFT JOIN album_genres ON album_genres.genre_id=genres.id"). Where("album_genres.genre_id IS NULL"). SubQuery() q := s.db. Where("genres.id IN ? AND genres.id IN ?", subTrack, subAlbum). - Delete(&db.Genre{}) - st.genresMissing = int(q.RowsAffected) + Delete(db.Genre{}) + st.genresMissing += int(q.RowsAffected) + + subAlbumGenresNoTracks := s.db. + Select("album_genres.genre_id"). + Model(db.AlbumGenre{}). + Joins("JOIN albums ON albums.id=album_genres.album_id"). + Joins("LEFT JOIN tracks ON tracks.album_id=albums.id"). + Group("album_genres.genre_id"). + Having("count(tracks.id)=0"). + SubQuery() + q = s.db. + Where("genres.id IN ?", subAlbumGenresNoTracks). + Delete(db.Genre{}) + st.genresMissing += int(q.RowsAffected) + return nil } diff --git a/scanner/scanner_test.go b/scanner/scanner_test.go index 77f4b1c..c49b6f8 100644 --- a/scanner/scanner_test.go +++ b/scanner/scanner_test.go @@ -643,6 +643,41 @@ func TestNoOrphanedGenres(t *testing.T) { assert.Equal(t, 0, genreCount) } +// https://github.com/sentriz/gonic/issues/466 +func TestNoOrphanedGenresButOnlyDeleteTracks(t *testing.T) { + t.Parallel() + m := mockfs.New(t) + + m.AddItems() + m.SetTags("artist-0/album-0/track-0.flac", func(tags *mockfs.TagInfo) { tags.RawGenre = "genre-a" }) + m.ScanAndClean() + + trackPaths, err := filepath.Glob(filepath.Join(m.TmpDir(), "*", "*", "*.flac")) + assert.NoError(t, err) + + for _, path := range trackPaths { + assert.NoError(t, os.Remove(path)) + } + + m.ScanAndClean() + + var tracks []*db.Track + assert.NoError(t, m.DB().Find(&tracks).Error) + assert.Len(t, tracks, 0) + + var genres []*db.Genre + assert.NoError(t, m.DB().Find(&genres).Error) + assert.Len(t, genres, 0) + + var trackGenres []*db.TrackGenre + assert.NoError(t, m.DB().Find(&trackGenres).Error) + assert.Len(t, trackGenres, 0) + + var albumGenres []*db.AlbumGenre + assert.NoError(t, m.DB().Find(&albumGenres).Error) + assert.Len(t, albumGenres, 0) +} + func TestMultiArtistSupport(t *testing.T) { t.Parallel() m := mockfs.New(t) From 2949b4c86715d9eebfe5bf116c8df7f0a5875eb3 Mon Sep 17 00:00:00 2001 From: brian-doherty <76168809+brian-doherty@users.noreply.github.com> Date: Tue, 13 Feb 2024 16:30:34 -0600 Subject: [PATCH 40/41] fix(subsonic): fix getAvatar user request comparison (#469) --- server/ctrlsubsonic/handlers_raw.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/ctrlsubsonic/handlers_raw.go b/server/ctrlsubsonic/handlers_raw.go index e82131f..b6bbecc 100644 --- a/server/ctrlsubsonic/handlers_raw.go +++ b/server/ctrlsubsonic/handlers_raw.go @@ -242,7 +242,7 @@ func (c *Controller) ServeGetAvatar(w http.ResponseWriter, r *http.Request) *spe return spec.NewError(10, "please provide an `username` parameter") } reqUser := c.dbc.GetUserByName(username) - if (user != reqUser) && !user.IsAdmin { + if (user.ID != reqUser.ID) && !user.IsAdmin { return spec.NewError(50, "user not admin") } http.ServeContent(w, r, "", time.Now(), bytes.NewReader(reqUser.Avatar)) From 80a9aebd0ea293147b770800991ea2f99db2e8d6 Mon Sep 17 00:00:00 2001 From: sentriz Date: Wed, 14 Feb 2024 17:29:24 +0000 Subject: [PATCH 41/41] update transcode log message --- server/ctrlsubsonic/handlers_raw.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/ctrlsubsonic/handlers_raw.go b/server/ctrlsubsonic/handlers_raw.go index b6bbecc..6d2ec72 100644 --- a/server/ctrlsubsonic/handlers_raw.go +++ b/server/ctrlsubsonic/handlers_raw.go @@ -199,7 +199,7 @@ func (c *Controller) ServeStream(w http.ResponseWriter, r *http.Request) *spec.R return spec.NewError(0, "couldn't find transcode preference: %v", err) } if pref == nil { - log.Printf("serving raw file, no user transcode preferences found for client %q", client) + log.Printf("serving raw file, no user transcode preferences found for user %q and client %q", user.Name, client) http.ServeFile(w, r, file.AbsPath()) return nil }