mirror of
https://git.maid.zone/stuff/soundcloak.git
synced 2025-12-10 13:49:39 +05:00
greeting message and some improvements
This commit is contained in:
@@ -44,3 +44,40 @@ func Log(what ...any) {
|
|||||||
fmt.Println(what...)
|
fmt.Println(what...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ImageClient *fasthttp.HostClient
|
||||||
|
var HlsClient *fasthttp.HostClient
|
||||||
|
var HlsAacClient *fasthttp.HostClient
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if cfg.Restream || cfg.ProxyImages {
|
||||||
|
ImageClient = &fasthttp.HostClient{
|
||||||
|
Addr: cfg.ImageCDN + ":443",
|
||||||
|
IsTLS: true,
|
||||||
|
DialDualStack: true,
|
||||||
|
Dial: (&fasthttp.TCPDialer{DNSCacheDuration: cfg.DNSCacheTTL}).Dial,
|
||||||
|
MaxIdleConnDuration: 1<<63 - 1,
|
||||||
|
StreamResponseBody: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.Restream || cfg.ProxyStreams {
|
||||||
|
HlsClient = &fasthttp.HostClient{
|
||||||
|
Addr: cfg.HLSCDN + ":443",
|
||||||
|
IsTLS: true,
|
||||||
|
DialDualStack: true,
|
||||||
|
Dial: (&fasthttp.TCPDialer{DNSCacheDuration: cfg.DNSCacheTTL}).Dial,
|
||||||
|
MaxIdleConnDuration: 1<<63 - 1,
|
||||||
|
StreamResponseBody: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
HlsAacClient = &fasthttp.HostClient{
|
||||||
|
Addr: cfg.HLSAACCDN + ":443",
|
||||||
|
IsTLS: true,
|
||||||
|
DialDualStack: true,
|
||||||
|
Dial: (&fasthttp.TCPDialer{DNSCacheDuration: cfg.DNSCacheTTL}).Dial,
|
||||||
|
MaxIdleConnDuration: 1<<63 - 1,
|
||||||
|
StreamResponseBody: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,18 +10,9 @@ import (
|
|||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var httpc *fasthttp.HostClient
|
|
||||||
var al_httpc *fasthttp.HostClient
|
var al_httpc *fasthttp.HostClient
|
||||||
|
|
||||||
func Load(r *fiber.App) {
|
func Load(r *fiber.App) {
|
||||||
httpc = &fasthttp.HostClient{
|
|
||||||
Addr: cfg.ImageCDN + ":443",
|
|
||||||
IsTLS: true,
|
|
||||||
DialDualStack: true,
|
|
||||||
Dial: (&fasthttp.TCPDialer{DNSCacheDuration: cfg.DNSCacheTTL}).Dial,
|
|
||||||
MaxIdleConnDuration: 1<<63 - 1,
|
|
||||||
StreamResponseBody: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
al_httpc = &fasthttp.HostClient{
|
al_httpc = &fasthttp.HostClient{
|
||||||
Addr: "al.sndcdn.com:443",
|
Addr: "al.sndcdn.com:443",
|
||||||
@@ -53,7 +44,7 @@ func Load(r *fiber.App) {
|
|||||||
var cl *fasthttp.HostClient
|
var cl *fasthttp.HostClient
|
||||||
if parsed.Host()[0] == 'i' {
|
if parsed.Host()[0] == 'i' {
|
||||||
parsed.SetHost(cfg.ImageCDN)
|
parsed.SetHost(cfg.ImageCDN)
|
||||||
cl = httpc
|
cl = misc.ImageClient
|
||||||
} else if string(parsed.Host()[:2]) == "al" {
|
} else if string(parsed.Host()[:2]) == "al" {
|
||||||
cl = al_httpc
|
cl = al_httpc
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,28 +11,7 @@ import (
|
|||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var httpc *fasthttp.HostClient
|
|
||||||
var httpc_aac *fasthttp.HostClient
|
|
||||||
|
|
||||||
func Load(r *fiber.App) {
|
func Load(r *fiber.App) {
|
||||||
httpc = &fasthttp.HostClient{
|
|
||||||
Addr: cfg.HLSCDN + ":443",
|
|
||||||
IsTLS: true,
|
|
||||||
DialDualStack: true,
|
|
||||||
Dial: (&fasthttp.TCPDialer{DNSCacheDuration: cfg.DNSCacheTTL}).Dial,
|
|
||||||
MaxIdleConnDuration: 1<<63 - 1,
|
|
||||||
StreamResponseBody: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
httpc_aac = &fasthttp.HostClient{
|
|
||||||
Addr: cfg.HLSAACCDN + ":443",
|
|
||||||
IsTLS: true,
|
|
||||||
DialDualStack: true,
|
|
||||||
Dial: (&fasthttp.TCPDialer{DNSCacheDuration: cfg.DNSCacheTTL}).Dial,
|
|
||||||
MaxIdleConnDuration: 1<<63 - 1,
|
|
||||||
StreamResponseBody: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
r.Get("/_/proxy/streams", func(c fiber.Ctx) error {
|
r.Get("/_/proxy/streams", func(c fiber.Ctx) error {
|
||||||
ur := c.Query("url")
|
ur := c.Query("url")
|
||||||
if ur == "" {
|
if ur == "" {
|
||||||
@@ -61,7 +40,7 @@ func Load(r *fiber.App) {
|
|||||||
resp := fasthttp.AcquireResponse()
|
resp := fasthttp.AcquireResponse()
|
||||||
//defer fasthttp.ReleaseResponse(resp)
|
//defer fasthttp.ReleaseResponse(resp)
|
||||||
|
|
||||||
err = sc.DoWithRetry(httpc, req, resp)
|
err = sc.DoWithRetry(misc.HlsClient, req, resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -99,7 +78,7 @@ func Load(r *fiber.App) {
|
|||||||
|
|
||||||
resp := fasthttp.AcquireResponse()
|
resp := fasthttp.AcquireResponse()
|
||||||
|
|
||||||
err = sc.DoWithRetry(httpc_aac, req, resp)
|
err = sc.DoWithRetry(misc.HlsAacClient, req, resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -138,7 +117,7 @@ func Load(r *fiber.App) {
|
|||||||
resp := fasthttp.AcquireResponse()
|
resp := fasthttp.AcquireResponse()
|
||||||
defer fasthttp.ReleaseResponse(resp)
|
defer fasthttp.ReleaseResponse(resp)
|
||||||
|
|
||||||
err = sc.DoWithRetry(httpc, req, resp)
|
err = sc.DoWithRetry(misc.HlsClient, req, resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -189,7 +168,7 @@ func Load(r *fiber.App) {
|
|||||||
resp := fasthttp.AcquireResponse()
|
resp := fasthttp.AcquireResponse()
|
||||||
defer fasthttp.ReleaseResponse(resp)
|
defer fasthttp.ReleaseResponse(resp)
|
||||||
|
|
||||||
err = sc.DoWithRetry(httpc_aac, req, resp)
|
err = sc.DoWithRetry(misc.HlsAacClient, req, resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,10 +17,6 @@ import (
|
|||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var httpc *fasthttp.HostClient
|
|
||||||
var httpc_aac *fasthttp.HostClient
|
|
||||||
var httpc_image *fasthttp.HostClient
|
|
||||||
|
|
||||||
const defaultPartsCapacity = 24
|
const defaultPartsCapacity = 24
|
||||||
|
|
||||||
type reader struct {
|
type reader struct {
|
||||||
@@ -58,9 +54,9 @@ func (r *reader) Setup(url string, aac bool) error {
|
|||||||
r.req.Header.Set("Accept-Encoding", "gzip, deflate, br, zstd")
|
r.req.Header.Set("Accept-Encoding", "gzip, deflate, br, zstd")
|
||||||
|
|
||||||
if aac {
|
if aac {
|
||||||
r.client = httpc_aac
|
r.client = misc.HlsAacClient
|
||||||
} else {
|
} else {
|
||||||
r.client = httpc
|
r.client = misc.HlsClient
|
||||||
}
|
}
|
||||||
|
|
||||||
err := sc.DoWithRetry(r.client, r.req, r.resp)
|
err := sc.DoWithRetry(r.client, r.req, r.resp)
|
||||||
@@ -195,31 +191,6 @@ func (c *collector) Write(data []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Load(r *fiber.App) {
|
func Load(r *fiber.App) {
|
||||||
httpc = &fasthttp.HostClient{
|
|
||||||
Addr: cfg.HLSCDN + ":443",
|
|
||||||
IsTLS: true,
|
|
||||||
DialDualStack: true,
|
|
||||||
Dial: (&fasthttp.TCPDialer{DNSCacheDuration: cfg.DNSCacheTTL}).Dial,
|
|
||||||
MaxIdleConnDuration: 1<<63 - 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
httpc_aac = &fasthttp.HostClient{
|
|
||||||
Addr: cfg.HLSAACCDN + ":443",
|
|
||||||
IsTLS: true,
|
|
||||||
DialDualStack: true,
|
|
||||||
Dial: (&fasthttp.TCPDialer{DNSCacheDuration: cfg.DNSCacheTTL}).Dial,
|
|
||||||
MaxIdleConnDuration: 1<<63 - 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
httpc_image = &fasthttp.HostClient{
|
|
||||||
Addr: cfg.ImageCDN + ":443",
|
|
||||||
IsTLS: true,
|
|
||||||
DialDualStack: true,
|
|
||||||
Dial: (&fasthttp.TCPDialer{DNSCacheDuration: cfg.DNSCacheTTL}).Dial,
|
|
||||||
MaxIdleConnDuration: 1<<63 - 1,
|
|
||||||
StreamResponseBody: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
r.Get("/_/restream/:author/:track", func(c fiber.Ctx) error {
|
r.Get("/_/restream/:author/:track", func(c fiber.Ctx) error {
|
||||||
p, err := preferences.Get(c)
|
p, err := preferences.Get(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -303,7 +274,7 @@ func Load(r *fiber.App) {
|
|||||||
resp := fasthttp.AcquireResponse()
|
resp := fasthttp.AcquireResponse()
|
||||||
defer fasthttp.ReleaseResponse(resp)
|
defer fasthttp.ReleaseResponse(resp)
|
||||||
|
|
||||||
err = sc.DoWithRetry(httpc, req, resp)
|
err = sc.DoWithRetry(misc.HlsClient, req, resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -327,7 +298,7 @@ func Load(r *fiber.App) {
|
|||||||
for _, part := range parts {
|
for _, part := range parts {
|
||||||
req.SetRequestURIBytes(part)
|
req.SetRequestURIBytes(part)
|
||||||
|
|
||||||
err = sc.DoWithRetry(httpc, req, resp)
|
err = sc.DoWithRetry(misc.HlsClient, req, resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -356,7 +327,7 @@ func Load(r *fiber.App) {
|
|||||||
req.SetRequestURI(t.Artwork)
|
req.SetRequestURI(t.Artwork)
|
||||||
req.Header.Del("Accept-Encoding")
|
req.Header.Del("Accept-Encoding")
|
||||||
|
|
||||||
err := sc.DoWithRetry(httpc_image, req, resp)
|
err := sc.DoWithRetry(misc.ImageClient, req, resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -382,7 +353,7 @@ func Load(r *fiber.App) {
|
|||||||
resp := fasthttp.AcquireResponse()
|
resp := fasthttp.AcquireResponse()
|
||||||
defer fasthttp.ReleaseResponse(resp)
|
defer fasthttp.ReleaseResponse(resp)
|
||||||
|
|
||||||
err = sc.DoWithRetry(httpc_aac, req, resp)
|
err = sc.DoWithRetry(misc.HlsAacClient, req, resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -413,7 +384,7 @@ func Load(r *fiber.App) {
|
|||||||
for _, part := range parts {
|
for _, part := range parts {
|
||||||
req.SetRequestURIBytes(part)
|
req.SetRequestURIBytes(part)
|
||||||
|
|
||||||
err = sc.DoWithRetry(httpc_aac, req, resp)
|
err = sc.DoWithRetry(misc.HlsAacClient, req, resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -442,7 +413,7 @@ func Load(r *fiber.App) {
|
|||||||
req.SetRequestURI(t.Artwork)
|
req.SetRequestURI(t.Artwork)
|
||||||
req.Header.Del("Accept-Encoding")
|
req.Header.Del("Accept-Encoding")
|
||||||
|
|
||||||
err := sc.DoWithRetry(httpc_image, req, resp)
|
err := sc.DoWithRetry(misc.ImageClient, req, resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,15 +34,6 @@ var httpc = &fasthttp.HostClient{
|
|||||||
MaxIdleConnDuration: 1<<63 - 1,
|
MaxIdleConnDuration: 1<<63 - 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
var httpc_image = &fasthttp.HostClient{
|
|
||||||
Addr: cfg.ImageCDN + ":443",
|
|
||||||
IsTLS: true,
|
|
||||||
DialDualStack: true,
|
|
||||||
Dial: (&fasthttp.TCPDialer{DNSCacheDuration: cfg.DNSCacheTTL}).Dial,
|
|
||||||
MaxIdleConnDuration: 1<<63 - 1,
|
|
||||||
StreamResponseBody: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
var genericClient = &fasthttp.Client{
|
var genericClient = &fasthttp.Client{
|
||||||
Dial: (&fasthttp.TCPDialer{DNSCacheDuration: cfg.DNSCacheTTL}).Dial,
|
Dial: (&fasthttp.TCPDialer{DNSCacheDuration: cfg.DNSCacheTTL}).Dial,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -452,7 +452,7 @@ func (t Track) DownloadImage() ([]byte, string, error) {
|
|||||||
resp := fasthttp.AcquireResponse()
|
resp := fasthttp.AcquireResponse()
|
||||||
defer fasthttp.ReleaseResponse(resp)
|
defer fasthttp.ReleaseResponse(resp)
|
||||||
|
|
||||||
err := DoWithRetry(httpc_image, req, resp)
|
err := DoWithRetry(misc.ImageClient, req, resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
|
|||||||
50
main.go
50
main.go
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
@@ -26,6 +27,13 @@ import (
|
|||||||
"git.maid.zone/stuff/soundcloak/templates"
|
"git.maid.zone/stuff/soundcloak/templates"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func boolean(b bool) string {
|
||||||
|
if b {
|
||||||
|
return "Enabled"
|
||||||
|
}
|
||||||
|
return "Disabled"
|
||||||
|
}
|
||||||
|
|
||||||
type osfs struct{}
|
type osfs struct{}
|
||||||
|
|
||||||
func (osfs) Open(name string) (fs.File, error) {
|
func (osfs) Open(name string) (fs.File, error) {
|
||||||
@@ -934,8 +942,48 @@ func main() {
|
|||||||
return templates.Base(track.Title+" by "+track.Author.Username, templates.TrackInAlbums(track, p), templates.TrackHeader(prefs, track, false)).Render(c.RequestCtx(), c)
|
return templates.Base(track.Title+" by "+track.Author.Username, templates.TrackInAlbums(track, p), templates.TrackHeader(prefs, track, false)).Render(c.RequestCtx(), c)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// cute
|
||||||
|
const art = `
|
||||||
|
⠀⠀⠀⠀⢀⡴⣆⠀⠀⠀⠀⠀⣠⡀⠀⠀⠀⠀⠀⠀⣼⣿⡗⠀⠀⠀⠀
|
||||||
|
⠀⠀⠀⣠⠟⠀⠘⠷⠶⠶⠶⠾⠉⢳⡄⠀⠀⠀⠀⠀⣧⣿⠀⠀⠀⠀⠀
|
||||||
|
⠀⠀⣰⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⣤⣤⣤⣤⣤⣿⢿⣄⠀⠀⠀⠀
|
||||||
|
___ ___ ⠀⠀⡇⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣧⠀⠀⠀⠀⠀⠀⠙⣷⡴⠶⣦
|
||||||
|
/ __|/ __| ⠀⠀⢱⡀⠀⠉⠉⠀⠀⠀⠀⠛⠃⠀⢠⡟⠂⠀⠀⢀⣀⣠⣤⠿⠞⠛⠋
|
||||||
|
\__ \ (__ ⣠⠾⠋⠙⣶⣤⣤⣤⣤⣤⣀⣠⣤⣾⣿⠴⠶⠚⠋⠉⠁⠀⠀⠀⠀⠀⠀
|
||||||
|
|___/\___| ⠛⠒⠛⠉⠉⠀⠀⠀⣴⠟⣣⡴⠛⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||||
|
~~~~~~~~~~~~~~~~~~~~⠛⠛~~~~~~~~~~~~~~~~~~~~~~~~`
|
||||||
|
fmt.Println(art)
|
||||||
|
|
||||||
|
keys := [...]string{"Built from", "ProxyStreams", "ProxyImages", "Restream", "GetWebProfiles", "Listening on"}
|
||||||
|
// maps in go are unordered..
|
||||||
|
table := map[string]string{
|
||||||
|
"Built from": fmt.Sprintf("%s (%s)", cfg.Commit, cfg.CommitURL),
|
||||||
|
"ProxyStreams": boolean(cfg.ProxyStreams),
|
||||||
|
"ProxyImages": boolean(cfg.ProxyStreams),
|
||||||
|
"Restream": boolean(cfg.Restream),
|
||||||
|
"GetWebProfiles": boolean(cfg.GetWebProfiles),
|
||||||
|
"Listening on": cfg.Addr,
|
||||||
|
}
|
||||||
|
if cfg.Addr[0] == ':' {
|
||||||
|
table["Listening on"] = "127.0.0.1" + cfg.Addr
|
||||||
|
}
|
||||||
|
longest := ""
|
||||||
|
for key := range table {
|
||||||
|
if len(key) > len(longest) {
|
||||||
|
longest = key
|
||||||
|
}
|
||||||
|
}
|
||||||
|
longest += " :: "
|
||||||
|
|
||||||
|
for _, key := range keys {
|
||||||
|
fmt.Print(key)
|
||||||
|
fmt.Print(strings.Repeat(" ", len(longest)-len(key)-len(" :: ")) + " :: ")
|
||||||
|
fmt.Println(table[key])
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
|
||||||
if cfg.CodegenConfig {
|
if cfg.CodegenConfig {
|
||||||
log.Println("Warning: you have CodegenConfig enabled, but the config was loaded dynamically.")
|
log.Println("Warning: you have CodegenConfig enabled, but the config was loaded dynamically.")
|
||||||
}
|
}
|
||||||
log.Fatal(app.Listen(cfg.Addr, fiber.ListenConfig{EnablePrefork: cfg.Prefork}))
|
log.Fatal(app.Listen(cfg.Addr, fiber.ListenConfig{EnablePrefork: cfg.Prefork, DisableStartupMessage: true}))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user