start working on embeds; add prefork to cfg

This commit is contained in:
Laptop
2024-08-25 23:57:47 +03:00
parent 7ca5a3a9e3
commit 9fa85bb47d
7 changed files with 106 additions and 12 deletions

View File

@@ -28,4 +28,8 @@ const DNSCacheTTL = 10 * time.Minute
// run soundcloak on this address (localhost:4664 by default)
const Addr = ":4664"
// run multiple instances of soundcloud locally to be able to handle more requests
// each one will be a separate process, so they will have separate cache
const Prefork = false
var JSON = jsoniter.ConfigFastest

View File

@@ -7,6 +7,7 @@ import (
"net/url"
"os"
"regexp"
"strconv"
"strings"
"time"
@@ -375,3 +376,69 @@ func GetPlaylist(permalink string) (Playlist, error) {
return u, nil
}
func TagListParser(taglist string) (res []string) {
inString := false
cur := []rune{}
for i, c := range taglist {
if c == '"' {
if i == len(taglist)-1 {
res = append(res, string(cur))
return
}
inString = !inString
continue
}
if !inString && c == ' ' {
res = append(res, string(cur))
cur = []rune{}
continue
}
cur = append(cur, c)
}
return
}
func (t Track) FormatDescription() string {
desc := t.Description
if t.Description != "" {
desc += "\n\n"
}
desc += strconv.FormatInt(t.Likes, 10) + " ❤️ | " + strconv.FormatInt(t.Played, 10) + " ▶️"
desc += "\nGenre: " + t.Genre
desc += "\nCreated: " + t.CreatedAt
desc += "\nLast modified: " + t.LastModified
if len(t.TagList) != 0 {
desc += "\nTags: " + strings.Join(TagListParser(t.TagList), ", ")
}
return desc
}
func (u User) FormatDescription() string {
desc := u.Description
if u.Description != "" {
desc += "\n\n"
}
desc += strconv.FormatInt(u.Followers, 10) + " followers | " + strconv.FormatInt(u.Following, 10) + " following"
desc += "\n" + strconv.FormatInt(u.Tracks, 10) + " tracks | " + strconv.FormatInt(u.Playlists, 10) + " playlists"
desc += "\nCreated: " + u.CreatedAt
desc += "\nLast modified: " + u.LastModified
return desc
}
func (u User) FormatUsername() string {
res := u.Username
if u.Verified {
res += " ☑️"
}
return res
}

View File

@@ -57,14 +57,16 @@ type Track struct {
Artwork string `json:"artwork_url"`
Comments int `json:"comment_count"`
CreatedAt string `json:"created_at"`
Description string `json:"description"`
Duration int `json:"duration"` // there are duration and full_duration fields wtf does that mean
Genre string `json:"genre"`
ID int `json:"id"`
Kind string `json:"kind"` // should always be "track"!
LastModified string `json:"last_modified"`
Likes int `json:"likes_count"`
Likes int64 `json:"likes_count"`
Permalink string `json:"permalink"`
Played int `json:"playback_count"`
Played int64 `json:"playback_count"`
TagList string `json:"tag_list"`
Title string `json:"title"`
Media Media `json:"media"`
Authorization string `json:"track_authorization"`