mirror of
https://git.maid.zone/stuff/soundcloak.git
synced 2025-12-10 13:49:39 +05:00
/discover - featured playlists, some more fixes
This commit is contained in:
@@ -137,7 +137,7 @@ footer {
|
|||||||
margin-top: 5rem;
|
margin-top: 5rem;
|
||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template: auto / auto auto;
|
grid-template: auto / auto auto auto;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
</form>
|
</form>
|
||||||
<footer>
|
<footer>
|
||||||
<a class="btn" href="/_/featured">Featured Tracks</a>
|
<a class="btn" href="/_/featured">Featured Tracks</a>
|
||||||
|
<a class="btn" href="/discover">Discover Playlists</a>
|
||||||
<a class="btn" href="/_/preferences">Preferences</a>
|
<a class="btn" href="/_/preferences">Preferences</a>
|
||||||
|
|
||||||
<a class="btn" href="https://github.com/maid-zone/soundcloak">Source code</a>
|
<a class="btn" href="https://github.com/maid-zone/soundcloak">Source code</a>
|
||||||
|
|||||||
59
lib/sc/featured.go
Normal file
59
lib/sc/featured.go
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package sc
|
||||||
|
|
||||||
|
import "github.com/maid-zone/soundcloak/lib/cfg"
|
||||||
|
|
||||||
|
// Functions/structions related to featured/suggested content
|
||||||
|
|
||||||
|
type Selection struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
Kind string `json:"kind"` // should always be "selection"!
|
||||||
|
Items Paginated[*Playlist] `json:"items"` // ?? why
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetFeaturedTracks(prefs cfg.Preferences, args string) (*Paginated[*Track], error) {
|
||||||
|
cid, err := GetClientID()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
p := Paginated[*Track]{Next: "https://" + api + "/featured_tracks/top/all-music" + args + "&client_id=" + cid}
|
||||||
|
// DO NOT UNFOLD
|
||||||
|
// dangerous
|
||||||
|
// seems to go in an infinite loop
|
||||||
|
err = p.Proceed(false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, t := range p.Collection {
|
||||||
|
t.Fix(prefs, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &p, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetSelections(prefs cfg.Preferences) (*Paginated[*Selection], error) {
|
||||||
|
cid, err := GetClientID()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// There is no pagination
|
||||||
|
p := Paginated[*Selection]{Next: "https://" + api + "/mixed-selections?limit=20&client_id=" + cid}
|
||||||
|
err = p.Proceed(false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, t := range p.Collection {
|
||||||
|
t.Fix(prefs)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &p, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Selection) Fix(prefs cfg.Preferences) {
|
||||||
|
for _, p := range s.Items.Collection {
|
||||||
|
p.Fix(prefs, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -397,25 +397,3 @@ func GetTrackByID(prefs cfg.Preferences, id string) (Track, error) {
|
|||||||
|
|
||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetFeaturedTracks(prefs cfg.Preferences, args string) (*Paginated[*Track], error) {
|
|
||||||
cid, err := GetClientID()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
p := Paginated[*Track]{Next: "https://" + api + "/featured_tracks/top/all-music" + args + "&client_id=" + cid}
|
|
||||||
// DO NOT UNFOLD
|
|
||||||
// dangerous
|
|
||||||
// seems to go in an infinite loop
|
|
||||||
err = p.Proceed(false)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, t := range p.Collection {
|
|
||||||
t.Fix(prefs, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &p, nil
|
|
||||||
}
|
|
||||||
|
|||||||
16
main.go
16
main.go
@@ -176,6 +176,22 @@ func main() {
|
|||||||
return templates.Base("Featured Tracks", templates.FeaturedTracks(tracks), nil).Render(context.Background(), c)
|
return templates.Base("Featured Tracks", templates.FeaturedTracks(tracks), nil).Render(context.Background(), c)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.Get("/discover", func(c *fiber.Ctx) error {
|
||||||
|
prefs, err := preferences.Get(c)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
selections, err := sc.GetSelections(prefs) // There is no pagination
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error getting selections: %s\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Set("Content-Type", "text/html")
|
||||||
|
return templates.Base("Discover", templates.Discover(selections), nil).Render(context.Background(), c)
|
||||||
|
})
|
||||||
|
|
||||||
if cfg.ProxyImages {
|
if cfg.ProxyImages {
|
||||||
proxyimages.Load(app)
|
proxyimages.Load(app)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
package templates
|
package templates
|
||||||
|
|
||||||
// I made a separate templates file for this, since I'm planning on adding another "featured" feature later (soundcloud.com/discover)
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/maid-zone/soundcloak/lib/sc"
|
"github.com/maid-zone/soundcloak/lib/sc"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
templ FeaturedTracks(p *sc.Paginated[*sc.Track]) {
|
templ FeaturedTracks(p *sc.Paginated[*sc.Track]) {
|
||||||
<h1>Featured Tracks</h1>
|
<h1>Featured Tracks</h1>
|
||||||
<br/>
|
|
||||||
if len(p.Collection) == 0 {
|
if len(p.Collection) == 0 {
|
||||||
<p>no more tracks</p>
|
<p>no more tracks</p>
|
||||||
} else {
|
} else {
|
||||||
@@ -22,3 +20,27 @@ templ FeaturedTracks(p *sc.Paginated[*sc.Track]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
templ Discover(p *sc.Paginated[*sc.Selection]) {
|
||||||
|
<h1>Discover Playlists</h1> // also tracks apparently? haven't seen any
|
||||||
|
<span>Got { strconv.FormatInt(int64(len(p.Collection)), 10) } playlists</span>
|
||||||
|
if len(p.Collection) != 0 {
|
||||||
|
for _, selection := range p.Collection {
|
||||||
|
// skip so we don't just include the title and zero playlists with it
|
||||||
|
if len(selection.Items.Collection) == 0 {
|
||||||
|
{{ continue }} // raw go code my beloved
|
||||||
|
}
|
||||||
|
|
||||||
|
<h2>{selection.Title}</h2>
|
||||||
|
for _, pl := range selection.Items.Collection {
|
||||||
|
// We don't need the username
|
||||||
|
@PlaylistItem(pl, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// I don't think they have pagination for this endpoint, just leaving this here, in case they actually do
|
||||||
|
// if p.Next != "" {
|
||||||
|
// <a class="btn" href={ templ.URL("/discover?pagination=" + url.QueryEscape(strings.Split(p.Next, "/discover")[1])) } rel="noreferrer">more playlists</a>
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ templ Playlist(p sc.Playlist) {
|
|||||||
}
|
}
|
||||||
<h1>{ p.Title }</h1>
|
<h1>{ p.Title }</h1>
|
||||||
@UserItem(&p.Author)
|
@UserItem(&p.Author)
|
||||||
<div class="btns">
|
<div style="display: flex;">
|
||||||
<a class="btn" href={ templ.URL("https://soundcloud.com/" + p.Author.Permalink + "/sets/" + p.Permalink) }>view on soundcloud</a>
|
<a class="btn" href={ templ.URL("https://soundcloud.com/" + p.Author.Permalink + "/sets/" + p.Permalink) }>view on soundcloud</a>
|
||||||
</div>
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
|
|||||||
Reference in New Issue
Block a user