mirror of
https://git.maid.zone/stuff/soundcloak.git
synced 2025-12-10 13:49:39 +05:00
changed a bunch of shit not going to elaborate
This commit is contained in:
BIN
assets/fixed.ttf
Normal file
BIN
assets/fixed.ttf
Normal file
Binary file not shown.
@@ -2,7 +2,7 @@
|
||||
|
||||
@font-face {
|
||||
font-family: "fixed";
|
||||
src: url("https://assets.maid.zone/fixed.ttf");
|
||||
src: url("/fixed.ttf");
|
||||
}
|
||||
|
||||
:root {
|
||||
@@ -144,3 +144,9 @@ details > summary:hover {
|
||||
padding: 0.5rem;
|
||||
width: fit-content;
|
||||
}
|
||||
|
||||
footer {
|
||||
margin-top: 5rem;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
<link rel="stylesheet" href="global.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="sc">Soundcloak</h1>
|
||||
<h1 id="sc">soundcloak</h1>
|
||||
<form action="/search">
|
||||
<div style="display: flex; gap: .5rem;">
|
||||
<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;">
|
||||
</form>
|
||||
</body>
|
||||
|
||||
<footer>
|
||||
<a class="btn" href="https://github.com/maid-zone/soundcloak">Source code</a>
|
||||
</footer>
|
||||
</html>
|
||||
@@ -189,9 +189,7 @@ func GetUser(permalink string) (User, error) {
|
||||
return u, err
|
||||
}
|
||||
|
||||
u.Avatar = strings.Replace(u.Avatar, "-large.", "-t200x200.", 1)
|
||||
ls := strings.Split(u.URN, ":")
|
||||
u.ID = ls[len(ls)-1]
|
||||
u.Fix()
|
||||
usersCache[permalink] = cached[User]{Value: u, Expires: time.Now().Add(cfg.UserTTL)}
|
||||
|
||||
return u, err
|
||||
@@ -212,7 +210,7 @@ func GetTrack(permalink string) (Track, error) {
|
||||
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)}
|
||||
|
||||
return u, nil
|
||||
@@ -261,6 +259,10 @@ func (u User) GetTracks(args string) (*Paginated[Track], error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, u := range p.Collection {
|
||||
u.Fix()
|
||||
}
|
||||
|
||||
return &p, nil
|
||||
}
|
||||
|
||||
@@ -312,48 +314,60 @@ func (t Track) GetStream() (string, error) {
|
||||
return s.URL, nil
|
||||
}
|
||||
|
||||
func SearchTracks(args string) (*Paginated[Track], error) {
|
||||
func SearchTracks(args string) (*Paginated[*Track], error) {
|
||||
cid, err := GetClientID()
|
||||
if err != nil {
|
||||
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()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, u := range p.Collection {
|
||||
u.Fix()
|
||||
}
|
||||
|
||||
return &p, nil
|
||||
}
|
||||
|
||||
func SearchUsers(args string) (*Paginated[User], error) {
|
||||
func SearchUsers(args string) (*Paginated[*User], error) {
|
||||
cid, err := GetClientID()
|
||||
if err != nil {
|
||||
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()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, u := range p.Collection {
|
||||
u.Fix()
|
||||
}
|
||||
|
||||
return &p, nil
|
||||
}
|
||||
|
||||
func SearchPlaylists(args string) (*Paginated[Playlist], error) {
|
||||
func SearchPlaylists(args string) (*Paginated[*Playlist], error) {
|
||||
cid, err := GetClientID()
|
||||
if err != nil {
|
||||
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()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, u := range p.Collection {
|
||||
u.Fix(false)
|
||||
}
|
||||
|
||||
return &p, nil
|
||||
}
|
||||
|
||||
@@ -372,17 +386,34 @@ func GetPlaylist(permalink string) (Playlist, error) {
|
||||
return u, ErrKindNotCorrect
|
||||
}
|
||||
|
||||
err = u.GetMissingTracks()
|
||||
err = u.Fix(true)
|
||||
if err != nil {
|
||||
return u, err
|
||||
}
|
||||
|
||||
u.Artwork = strings.Replace(u.Artwork, "-large.", "-t200x200.", 1)
|
||||
playlistsCache[permalink] = cached[Playlist]{Value: u, Expires: time.Now().Add(cfg.PlaylistTTL)}
|
||||
|
||||
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) {
|
||||
inString := false
|
||||
cur := []rune{}
|
||||
@@ -469,7 +500,7 @@ func (p Playlist) FormatDescription() string {
|
||||
}
|
||||
|
||||
type MissingTrack struct {
|
||||
ID int64
|
||||
ID string
|
||||
Index int
|
||||
}
|
||||
|
||||
@@ -501,12 +532,15 @@ func GetTracks(ids string) ([]Track, error) {
|
||||
|
||||
var res []Track
|
||||
err = cfg.JSON.Unmarshal(data, &res)
|
||||
for _, t := range res {
|
||||
t.Fix()
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func JoinMissingTracks(missing []MissingTrack) (st string) {
|
||||
for i, track := range missing {
|
||||
st += strconv.FormatInt(track.ID, 10)
|
||||
st += track.ID
|
||||
if i != len(missing)-1 {
|
||||
st += ","
|
||||
}
|
||||
@@ -560,3 +594,15 @@ func (p *Playlist) GetMissingTracks() error {
|
||||
|
||||
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]
|
||||
}
|
||||
|
||||
@@ -13,11 +13,9 @@ type User struct {
|
||||
Permalink string `json:"permalink"`
|
||||
Playlists int64 `json:"playlist_count"`
|
||||
Tracks int64 `json:"track_count"`
|
||||
URN string `json:"urn"`
|
||||
ID string `json:"urn"`
|
||||
Username string `json:"username"`
|
||||
Verified bool `json:"verified"`
|
||||
|
||||
ID string `json:"-"`
|
||||
}
|
||||
|
||||
type Protocol string
|
||||
@@ -60,7 +58,6 @@ type Track struct {
|
||||
Description string `json:"description"`
|
||||
//Duration int `json:"duration"` // there are duration and full_duration fields wtf does that mean
|
||||
Genre string `json:"genre"`
|
||||
ID int64 `json:"id"`
|
||||
Kind string `json:"kind"` // should always be "track"!
|
||||
LastModified string `json:"last_modified"`
|
||||
Likes int64 `json:"likes_count"`
|
||||
@@ -68,6 +65,7 @@ type Track struct {
|
||||
Played int64 `json:"playback_count"`
|
||||
TagList string `json:"tag_list"`
|
||||
Title string `json:"title"`
|
||||
ID string `json:"urn"`
|
||||
Media Media `json:"media"`
|
||||
Authorization string `json:"track_authorization"`
|
||||
Author User `json:"user"`
|
||||
|
||||
@@ -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"/>
|
||||
<link rel="stylesheet" href="/global.css"/>
|
||||
if title != "" {
|
||||
<title>{ title } • Soundcloak</title>
|
||||
<title>{ title } • soundcloak</title>
|
||||
} else {
|
||||
<title>Soundcloak</title>
|
||||
<title>soundcloak</title>
|
||||
}
|
||||
if head != nil {
|
||||
@head
|
||||
}
|
||||
</head>
|
||||
<body>
|
||||
<a href="/" id="sc"><h1>Soundcloak</h1></a>
|
||||
<a href="/" id="sc"><h1>soundcloak</h1></a>
|
||||
@content
|
||||
</body>
|
||||
</html>
|
||||
}
|
||||
|
||||
css ViewTransition(name string) {
|
||||
view-transition-name: { templ.SafeCSSProperty(name) };
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
templ SearchPlaylists(p *sc.Paginated[sc.Playlist]) {
|
||||
templ SearchPlaylists(p *sc.Paginated[*sc.Playlist]) {
|
||||
<span>Found { strconv.FormatInt(p.Total, 10) } playlists</span>
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
@@ -7,18 +7,14 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
templ SearchTracks(p *sc.Paginated[sc.Track]) {
|
||||
templ SearchTracks(p *sc.Paginated[*sc.Track]) {
|
||||
<span>Found { strconv.FormatInt(p.Total, 10) } tracks</span>
|
||||
<br/>
|
||||
<br/>
|
||||
for _, track := range p.Collection {
|
||||
<a class="listing" href={ templ.URL("/" + track.Author.Permalink + "/" + track.Permalink) }>
|
||||
if track.Artwork != "" {
|
||||
@templ.Raw("<img src='")
|
||||
{ track.Artwork }
|
||||
@templ.Raw("' style='view-transition-name:")
|
||||
{ "track-" + strconv.FormatInt(track.ID, 10) }
|
||||
@templ.Raw("'>")
|
||||
<img src={ track.Artwork } class={ViewTransition("t" + track.ID)}>
|
||||
} else {
|
||||
<img src="/placeholder.jpg"/>
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
templ SearchUsers(p *sc.Paginated[sc.User]) {
|
||||
templ SearchUsers(p *sc.Paginated[*sc.User]) {
|
||||
<span>Found { strconv.FormatInt(p.Total, 10) } users</span>
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
@@ -17,11 +17,7 @@ templ TrackEmbed(t sc.Track) {
|
||||
|
||||
templ Track(t sc.Track, stream string) {
|
||||
if t.Artwork != "" {
|
||||
@templ.Raw("<img src='")
|
||||
{ t.Artwork }
|
||||
@templ.Raw("' style='view-transition-name:")
|
||||
{ "track-" + strconv.FormatInt(t.ID, 10) }
|
||||
@templ.Raw("'>")
|
||||
<img src={t.Artwork} class={ViewTransition("t" + t.ID)}>
|
||||
}
|
||||
<h1>{ t.Title }</h1>
|
||||
<audio id="track" data-stream={ stream } controls></audio>
|
||||
|
||||
Reference in New Issue
Block a user