changed a bunch of shit not going to elaborate

This commit is contained in:
Laptop
2024-09-17 17:11:03 +03:00
parent 7b9ccb81bd
commit d3bf719dba
10 changed files with 87 additions and 37 deletions

BIN
assets/fixed.ttf Normal file

Binary file not shown.

View File

@@ -2,7 +2,7 @@
@font-face { @font-face {
font-family: "fixed"; font-family: "fixed";
src: url("https://assets.maid.zone/fixed.ttf"); src: url("/fixed.ttf");
} }
:root { :root {
@@ -144,3 +144,9 @@ details > summary:hover {
padding: 0.5rem; padding: 0.5rem;
width: fit-content; width: fit-content;
} }
footer {
margin-top: 5rem;
display: flex;
justify-content: center;
}

View File

@@ -7,7 +7,7 @@
<link rel="stylesheet" href="global.css"> <link rel="stylesheet" href="global.css">
</head> </head>
<body> <body>
<h1 id="sc">Soundcloak</h1> <h1 id="sc">soundcloak</h1>
<form action="/search"> <form action="/search">
<div style="display: flex; gap: .5rem;"> <div style="display: flex; gap: .5rem;">
<input name="q" type="text" style="padding: .5rem .6rem; flex-grow: 1;"> <input name="q" type="text" style="padding: .5rem .6rem; flex-grow: 1;">
@@ -22,4 +22,8 @@
<input type="submit" value="Search" class="btn" style="width: 100%; margin-top: .5rem;"> <input type="submit" value="Search" class="btn" style="width: 100%; margin-top: .5rem;">
</form> </form>
</body> </body>
<footer>
<a class="btn" href="https://github.com/maid-zone/soundcloak">Source code</a>
</footer>
</html> </html>

View File

@@ -189,9 +189,7 @@ func GetUser(permalink string) (User, error) {
return u, err return u, err
} }
u.Avatar = strings.Replace(u.Avatar, "-large.", "-t200x200.", 1) u.Fix()
ls := strings.Split(u.URN, ":")
u.ID = ls[len(ls)-1]
usersCache[permalink] = cached[User]{Value: u, Expires: time.Now().Add(cfg.UserTTL)} usersCache[permalink] = cached[User]{Value: u, Expires: time.Now().Add(cfg.UserTTL)}
return u, err return u, err
@@ -212,7 +210,7 @@ func GetTrack(permalink string) (Track, error) {
return u, ErrKindNotCorrect return u, ErrKindNotCorrect
} }
u.Artwork = strings.Replace(u.Artwork, "-large.", "-t200x200.", 1) u.Fix()
tracksCache[permalink] = cached[Track]{Value: u, Expires: time.Now().Add(cfg.TrackTTL)} tracksCache[permalink] = cached[Track]{Value: u, Expires: time.Now().Add(cfg.TrackTTL)}
return u, nil return u, nil
@@ -261,6 +259,10 @@ func (u User) GetTracks(args string) (*Paginated[Track], error) {
return nil, err return nil, err
} }
for _, u := range p.Collection {
u.Fix()
}
return &p, nil return &p, nil
} }
@@ -312,48 +314,60 @@ func (t Track) GetStream() (string, error) {
return s.URL, nil return s.URL, nil
} }
func SearchTracks(args string) (*Paginated[Track], error) { func SearchTracks(args string) (*Paginated[*Track], error) {
cid, err := GetClientID() cid, err := GetClientID()
if err != nil { if err != nil {
return nil, err return nil, err
} }
p := Paginated[Track]{Next: "https://api-v2.soundcloud.com/search/tracks" + args + "&client_id=" + cid} p := Paginated[*Track]{Next: "https://api-v2.soundcloud.com/search/tracks" + args + "&client_id=" + cid}
err = p.Proceed() err = p.Proceed()
if err != nil { if err != nil {
return nil, err return nil, err
} }
for _, u := range p.Collection {
u.Fix()
}
return &p, nil return &p, nil
} }
func SearchUsers(args string) (*Paginated[User], error) { func SearchUsers(args string) (*Paginated[*User], error) {
cid, err := GetClientID() cid, err := GetClientID()
if err != nil { if err != nil {
return nil, err return nil, err
} }
p := Paginated[User]{Next: "https://api-v2.soundcloud.com/search/users" + args + "&client_id=" + cid} p := Paginated[*User]{Next: "https://api-v2.soundcloud.com/search/users" + args + "&client_id=" + cid}
err = p.Proceed() err = p.Proceed()
if err != nil { if err != nil {
return nil, err return nil, err
} }
for _, u := range p.Collection {
u.Fix()
}
return &p, nil return &p, nil
} }
func SearchPlaylists(args string) (*Paginated[Playlist], error) { func SearchPlaylists(args string) (*Paginated[*Playlist], error) {
cid, err := GetClientID() cid, err := GetClientID()
if err != nil { if err != nil {
return nil, err return nil, err
} }
p := Paginated[Playlist]{Next: "https://api-v2.soundcloud.com/search/playlists" + args + "&client_id=" + cid} p := Paginated[*Playlist]{Next: "https://api-v2.soundcloud.com/search/playlists" + args + "&client_id=" + cid}
err = p.Proceed() err = p.Proceed()
if err != nil { if err != nil {
return nil, err return nil, err
} }
for _, u := range p.Collection {
u.Fix(false)
}
return &p, nil return &p, nil
} }
@@ -372,17 +386,34 @@ func GetPlaylist(permalink string) (Playlist, error) {
return u, ErrKindNotCorrect return u, ErrKindNotCorrect
} }
err = u.GetMissingTracks() err = u.Fix(true)
if err != nil { if err != nil {
return u, err return u, err
} }
u.Artwork = strings.Replace(u.Artwork, "-large.", "-t200x200.", 1)
playlistsCache[permalink] = cached[Playlist]{Value: u, Expires: time.Now().Add(cfg.PlaylistTTL)} playlistsCache[permalink] = cached[Playlist]{Value: u, Expires: time.Now().Add(cfg.PlaylistTTL)}
return u, nil return u, nil
} }
func (u *Playlist) Fix(cached bool) error {
if cached {
for _, t := range u.Tracks {
if t.Title != "" {
t.Fix()
}
}
err := u.GetMissingTracks()
if err != nil {
return err
}
}
u.Artwork = strings.Replace(u.Artwork, "-large.", "-t200x200.", 1)
return nil
}
func TagListParser(taglist string) (res []string) { func TagListParser(taglist string) (res []string) {
inString := false inString := false
cur := []rune{} cur := []rune{}
@@ -469,7 +500,7 @@ func (p Playlist) FormatDescription() string {
} }
type MissingTrack struct { type MissingTrack struct {
ID int64 ID string
Index int Index int
} }
@@ -501,12 +532,15 @@ func GetTracks(ids string) ([]Track, error) {
var res []Track var res []Track
err = cfg.JSON.Unmarshal(data, &res) err = cfg.JSON.Unmarshal(data, &res)
for _, t := range res {
t.Fix()
}
return res, err return res, err
} }
func JoinMissingTracks(missing []MissingTrack) (st string) { func JoinMissingTracks(missing []MissingTrack) (st string) {
for i, track := range missing { for i, track := range missing {
st += strconv.FormatInt(track.ID, 10) st += track.ID
if i != len(missing)-1 { if i != len(missing)-1 {
st += "," st += ","
} }
@@ -560,3 +594,15 @@ func (p *Playlist) GetMissingTracks() error {
return nil return nil
} }
func (u *Track) Fix() {
u.Artwork = strings.Replace(u.Artwork, "-large.", "-t200x200.", 1)
ls := strings.Split(u.ID, ":")
u.ID = ls[len(ls)-1]
}
func (u *User) Fix() {
u.Avatar = strings.Replace(u.Avatar, "-large.", "-t200x200.", 1)
ls := strings.Split(u.ID, ":")
u.ID = ls[len(ls)-1]
}

View File

@@ -13,11 +13,9 @@ type User struct {
Permalink string `json:"permalink"` Permalink string `json:"permalink"`
Playlists int64 `json:"playlist_count"` Playlists int64 `json:"playlist_count"`
Tracks int64 `json:"track_count"` Tracks int64 `json:"track_count"`
URN string `json:"urn"` ID string `json:"urn"`
Username string `json:"username"` Username string `json:"username"`
Verified bool `json:"verified"` Verified bool `json:"verified"`
ID string `json:"-"`
} }
type Protocol string type Protocol string
@@ -60,7 +58,6 @@ type Track struct {
Description string `json:"description"` Description string `json:"description"`
//Duration int `json:"duration"` // there are duration and full_duration fields wtf does that mean //Duration int `json:"duration"` // there are duration and full_duration fields wtf does that mean
Genre string `json:"genre"` Genre string `json:"genre"`
ID int64 `json:"id"`
Kind string `json:"kind"` // should always be "track"! Kind string `json:"kind"` // should always be "track"!
LastModified string `json:"last_modified"` LastModified string `json:"last_modified"`
Likes int64 `json:"likes_count"` Likes int64 `json:"likes_count"`
@@ -68,6 +65,7 @@ type Track struct {
Played int64 `json:"playback_count"` Played int64 `json:"playback_count"`
TagList string `json:"tag_list"` TagList string `json:"tag_list"`
Title string `json:"title"` Title string `json:"title"`
ID string `json:"urn"`
Media Media `json:"media"` Media Media `json:"media"`
Authorization string `json:"track_authorization"` Authorization string `json:"track_authorization"`
Author User `json:"user"` Author User `json:"user"`

View File

@@ -8,17 +8,21 @@ templ Base(title string, content templ.Component, head templ.Component) {
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="/global.css"/> <link rel="stylesheet" href="/global.css"/>
if title != "" { if title != "" {
<title>{ title } • Soundcloak</title> <title>{ title } • soundcloak</title>
} else { } else {
<title>Soundcloak</title> <title>soundcloak</title>
} }
if head != nil { if head != nil {
@head @head
} }
</head> </head>
<body> <body>
<a href="/" id="sc"><h1>Soundcloak</h1></a> <a href="/" id="sc"><h1>soundcloak</h1></a>
@content @content
</body> </body>
</html> </html>
} }
css ViewTransition(name string) {
view-transition-name: { templ.SafeCSSProperty(name) };
}

View File

@@ -7,7 +7,7 @@ import (
"strings" "strings"
) )
templ SearchPlaylists(p *sc.Paginated[sc.Playlist]) { templ SearchPlaylists(p *sc.Paginated[*sc.Playlist]) {
<span>Found { strconv.FormatInt(p.Total, 10) } playlists</span> <span>Found { strconv.FormatInt(p.Total, 10) } playlists</span>
<br/> <br/>
<br/> <br/>

View File

@@ -7,18 +7,14 @@ import (
"strings" "strings"
) )
templ SearchTracks(p *sc.Paginated[sc.Track]) { templ SearchTracks(p *sc.Paginated[*sc.Track]) {
<span>Found { strconv.FormatInt(p.Total, 10) } tracks</span> <span>Found { strconv.FormatInt(p.Total, 10) } tracks</span>
<br/> <br/>
<br/> <br/>
for _, track := range p.Collection { for _, track := range p.Collection {
<a class="listing" href={ templ.URL("/" + track.Author.Permalink + "/" + track.Permalink) }> <a class="listing" href={ templ.URL("/" + track.Author.Permalink + "/" + track.Permalink) }>
if track.Artwork != "" { if track.Artwork != "" {
@templ.Raw("<img src='") <img src={ track.Artwork } class={ViewTransition("t" + track.ID)}>
{ track.Artwork }
@templ.Raw("' style='view-transition-name:")
{ "track-" + strconv.FormatInt(track.ID, 10) }
@templ.Raw("'>")
} else { } else {
<img src="/placeholder.jpg"/> <img src="/placeholder.jpg"/>
} }

View File

@@ -7,7 +7,7 @@ import (
"strings" "strings"
) )
templ SearchUsers(p *sc.Paginated[sc.User]) { templ SearchUsers(p *sc.Paginated[*sc.User]) {
<span>Found { strconv.FormatInt(p.Total, 10) } users</span> <span>Found { strconv.FormatInt(p.Total, 10) } users</span>
<br/> <br/>
<br/> <br/>

View File

@@ -17,11 +17,7 @@ templ TrackEmbed(t sc.Track) {
templ Track(t sc.Track, stream string) { templ Track(t sc.Track, stream string) {
if t.Artwork != "" { if t.Artwork != "" {
@templ.Raw("<img src='") <img src={t.Artwork} class={ViewTransition("t" + t.ID)}>
{ t.Artwork }
@templ.Raw("' style='view-transition-name:")
{ "track-" + strconv.FormatInt(t.ID, 10) }
@templ.Raw("'>")
} }
<h1>{ t.Title }</h1> <h1>{ t.Title }</h1>
<audio id="track" data-stream={ stream } controls></audio> <audio id="track" data-stream={ stream } controls></audio>