diff --git a/lib/misc/init.go b/lib/misc/init.go
index 6395a6a..ba8f847 100644
--- a/lib/misc/init.go
+++ b/lib/misc/init.go
@@ -29,9 +29,14 @@ func (pr *ProxyReader) Read(p []byte) (int, error) {
}
func (pr *ProxyReader) Close() error {
- defer fasthttp.ReleaseResponse(pr.Resp)
- defer prpool.Put(pr)
- return pr.Resp.CloseBodyStream()
+ pr.Resp.CloseBodyStream()
+ fasthttp.ReleaseResponse(pr.Resp)
+
+ pr.Reader = nil
+ pr.Resp = nil
+
+ prpool.Put(pr)
+ return nil
}
func Log(what ...any) {
diff --git a/lib/proxy_images/init.go b/lib/proxy_images/init.go
index da91430..ea85b47 100644
--- a/lib/proxy_images/init.go
+++ b/lib/proxy_images/init.go
@@ -11,6 +11,7 @@ import (
)
var httpc *fasthttp.HostClient
+var al_httpc *fasthttp.HostClient
func Load(r fiber.Router) {
httpc = &fasthttp.HostClient{
@@ -22,6 +23,15 @@ func Load(r fiber.Router) {
StreamResponseBody: true,
}
+ al_httpc = &fasthttp.HostClient{
+ Addr: "al.sndcdn.com:443",
+ IsTLS: true,
+ DialDualStack: true,
+ Dial: (&fasthttp.TCPDialer{DNSCacheDuration: cfg.DNSCacheTTL}).Dial,
+ MaxIdleConnDuration: 1<<63 - 1,
+ StreamResponseBody: true,
+ }
+
r.Get("/_/proxy/images", func(c *fiber.Ctx) error {
url := c.Query("url")
if url == "" {
@@ -40,7 +50,13 @@ func Load(r fiber.Router) {
return fiber.ErrBadRequest
}
- parsed.SetHost(cfg.ImageCDN)
+ var cl *fasthttp.HostClient
+ if parsed.Host()[0] == 'i' {
+ parsed.SetHost(cfg.ImageCDN)
+ cl = httpc
+ } else if string(parsed.Host()[:2]) == "al" {
+ cl = al_httpc
+ }
req := fasthttp.AcquireRequest()
defer fasthttp.ReleaseRequest(req)
@@ -52,7 +68,7 @@ func Load(r fiber.Router) {
resp := fasthttp.AcquireResponse()
//defer fasthttp.ReleaseResponse(resp) moved to proxyreader!!!
- err = sc.DoWithRetry(httpc, req, resp)
+ err = sc.DoWithRetry(cl, req, resp)
if err != nil {
return err
}
diff --git a/lib/sc/playlist.go b/lib/sc/playlist.go
index 6fbc440..53652bd 100644
--- a/lib/sc/playlist.go
+++ b/lib/sc/playlist.go
@@ -19,7 +19,7 @@ type Playlist struct {
Artwork string `json:"artwork_url"`
CreatedAt string `json:"created_at"`
Description string `json:"description"`
- Kind string `json:"kind"` // should always be "playlist"!
+ Kind string `json:"kind"` // should always be "playlist"! or "system-playlist"
LastModified string `json:"last_modified"`
Likes int64 `json:"likes_count"`
Permalink string `json:"permalink"`
@@ -57,7 +57,7 @@ func GetPlaylist(cid string, permalink string) (Playlist, error) {
return p, err
}
- if p.Kind != "playlist" {
+ if p.Kind != "playlist" && p.Kind != "system-playlist" {
return p, ErrKindNotCorrect
}
@@ -217,5 +217,17 @@ func (p *Playlist) GetMissingTracks(cid string) error {
}
func (p Playlist) Href() string {
+ if p.Kind == "system-playlist" {
+ return "/discover/sets/" + p.Permalink
+ }
+
return "/" + p.Author.Permalink + "/sets/" + p.Permalink
}
+
+func (p Playlist) TracksCount() int64 {
+ if p.TrackCount != 0 {
+ return p.TrackCount
+ }
+
+ return int64(len(p.Tracks))
+}
diff --git a/lib/sc/track.go b/lib/sc/track.go
index b1b60df..43ed9f5 100644
--- a/lib/sc/track.go
+++ b/lib/sc/track.go
@@ -44,6 +44,7 @@ type Track struct {
Authorization string `json:"track_authorization"`
Author User `json:"user"`
Policy TrackPolicy `json:"policy"`
+ Station string `json:"station_permalink"`
}
type TrackPolicy string
diff --git a/lib/sc/user.go b/lib/sc/user.go
index 62a1182..4de8754 100644
--- a/lib/sc/user.go
+++ b/lib/sc/user.go
@@ -35,6 +35,7 @@ type User struct {
ID json.Number `json:"id"`
Username string `json:"username"`
Verified bool `json:"verified"`
+ Station string `json:"station_permalink"`
WebProfiles []Link
}
diff --git a/templates/playlist.templ b/templates/playlist.templ
index 3a64e37..2300997 100644
--- a/templates/playlist.templ
+++ b/templates/playlist.templ
@@ -32,7 +32,7 @@ templ PlaylistItem(playlist *sc.Playlist, showUsername bool) {
if showUsername {
{ playlist.Author.Username }
}
-
{ strconv.FormatInt(playlist.TrackCount, 10) } tracks
+ { strconv.FormatInt(playlist.TracksCount(), 10) } tracks
}
@@ -48,7 +48,7 @@ templ Playlist(prefs cfg.Preferences, p sc.Playlist) {
@Description(prefs, p.Description, nil)
- { strconv.FormatInt(p.TrackCount, 10) } tracks
+ { strconv.FormatInt(p.TracksCount(), 10) } tracks
@@ -69,8 +69,12 @@ templ Playlist(prefs cfg.Preferences, p sc.Playlist) {
}
{ strconv.FormatInt(p.Likes, 10) } likes
-
Created: { p.CreatedAt }
-
Last modified: { p.LastModified }
+ if p.CreatedAt != "" {
+
Created: { p.CreatedAt }
+ }
+ if p.LastModified != "" {
+
Last modified: { p.LastModified }
+ }
}
diff --git a/templates/tags.templ b/templates/tags.templ
index 976565d..37f1829 100644
--- a/templates/tags.templ
+++ b/templates/tags.templ
@@ -9,7 +9,7 @@ import (
templ TagsButtons(current string, tag string) {
- for _, b := range [...]btn{{"recent tracks", "", false},{"popular tracks", "/popular-tracks", false},{"playlists", "/playlists",false}} {
+ for _, b := range [...]btn{{"recent tracks", "", false, false},{"popular tracks", "/popular-tracks", false, false},{"playlists", "/playlists", false, false}} {
if b.text == current {
{ b.text }
} else {
diff --git a/templates/track.templ b/templates/track.templ
index da34f5c..f00e971 100644
--- a/templates/track.templ
+++ b/templates/track.templ
@@ -23,14 +23,18 @@ func toExt(audio string) string {
templ TrackButtons(current string, track sc.Track) {
- for _, b := range [...]btn{{"related tracks", "/recommended", false},{"in albums", "/albums", false},{"in playlists", "/sets", false},{"view on soundcloud", "https://soundcloud.com"+track.Href(), true}} {
+ for _, b := range [...]btn{{"related tracks", "/recommended", false, false},{"in albums", "/albums", false, false},{"in playlists", "/sets", false, false},{"track station", "/discover/sets/"+track.Station, true, false},{"view on soundcloud", "https://soundcloud.com"+track.Href(), true, true}} {
if b.text == current {
{ b.text }
} else {
if b.external {
{ b.text }
} else {
-
{ b.text }
+ if b.override {
+
{ b.text }
+ } else {
+
{ b.text }
+ }
}
}
}
diff --git a/templates/user.templ b/templates/user.templ
index cdc4c0e..d64a056 100644
--- a/templates/user.templ
+++ b/templates/user.templ
@@ -77,20 +77,25 @@ templ UserBase(prefs cfg.Preferences, u sc.User) {
type btn struct {
text string
href string
+ override bool
external bool
}
-templ UserButtons(current string, user string) {
+templ UserButtons(current string, user sc.User) {
// this part is the tedious one now, because formatting breaks if i space the list out with newlines
- for _, b := range [...]btn{{"tracks", "", false},{"popular tracks", "/popular-tracks", false},{"playlists", "/sets",false},{"albums", "/albums", false},{"reposts","/reposts", false},{"related", "/_/related", false},{"view on soundcloud", "https://soundcloud.com/"+user, true}} {
+ for _, b := range [...]btn{{"tracks", "", false, false},{"popular tracks", "/popular-tracks", false, false},{"playlists", "/sets", false, false},{"albums", "/albums", false, false},{"reposts","/reposts", false, false},{"related", "/_/related", false, false},{"user station", "/discover/sets/"+user.Station, true, false},{"view on soundcloud", "https://soundcloud.com/"+user.Permalink, true, true}} {
if b.text == current {
{ b.text }
} else {
if b.external {
{ b.text }
} else {
-
{ b.text }
+ if b.override {
+
{ b.text }
+ } else {
+
{ b.text }
+ }
}
}
}
@@ -101,7 +106,7 @@ templ User(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Track]) {
@UserBase(prefs, u)
// kinda tedious but whatever, might make it more flexible in the future
// ^ outdated, no longer tedious but whatever
- @UserButtons("tracks", u.Permalink)
+ @UserButtons("tracks", u)
if len(p.Collection) != 0 {
@@ -119,7 +124,7 @@ templ User(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Track]) {
templ UserPlaylists(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Playlist]) {
@UserBase(prefs, u)
- @UserButtons("playlists", u.Permalink)
+ @UserButtons("playlists", u)
if len(p.Collection) != 0 {
@@ -137,7 +142,7 @@ templ UserPlaylists(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Playli
templ UserAlbums(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Playlist]) {
@UserBase(prefs, u)
- @UserButtons("albums", u.Permalink)
+ @UserButtons("albums", u)
if len(p.Collection) != 0 {
@@ -155,7 +160,7 @@ templ UserAlbums(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Playlist]
templ UserReposts(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Repost]) {
@UserBase(prefs, u)
- @UserButtons("reposts", u.Permalink)
+ @UserButtons("reposts", u)
if len(p.Collection) != 0 {
@@ -177,7 +182,7 @@ templ UserReposts(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Repost])
templ UserLikes(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Like]) {
@UserBase(prefs, u)
- @UserButtons("", u.Permalink)
+ @UserButtons("", u)
Likes
if len(p.Collection) != 0 {
@@ -199,7 +204,7 @@ templ UserLikes(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Like]) {
templ UserRelated(prefs cfg.Preferences, u sc.User, r []*sc.User) {
@UserBase(prefs, u)
- @UserButtons("related", u.Permalink)
+ @UserButtons("related", u)
if len(r) != 0 {
@@ -214,7 +219,7 @@ templ UserRelated(prefs cfg.Preferences, u sc.User, r []*sc.User) {
templ UserTopTracks(prefs cfg.Preferences, u sc.User, t []*sc.Track) {
@UserBase(prefs, u)
- @UserButtons("popular tracks", u.Permalink)
+ @UserButtons("popular tracks", u)
if len(t) != 0 {
@@ -229,7 +234,7 @@ templ UserTopTracks(prefs cfg.Preferences, u sc.User, t []*sc.Track) {
templ UserFollowers(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.User]) {
@UserBase(prefs, u)
- @UserButtons("", u.Permalink)
+ @UserButtons("", u)
Followers
if len(p.Collection) != 0 {
@@ -247,7 +252,7 @@ templ UserFollowers(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.User])
templ UserFollowing(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.User]) {
@UserBase(prefs, u)
- @UserButtons("", u.Permalink)
+ @UserButtons("", u)
Following
if len(p.Collection) != 0 {