mirror of
https://git.maid.zone/stuff/soundcloak.git
synced 2025-12-10 05:39:38 +05:00
small restructuring in preparation for something
This commit is contained in:
101
lib/cfg/init.go
101
lib/cfg/init.go
@@ -2,16 +2,13 @@ package cfg
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/goccy/go-json"
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
// You can now use a soundcloak.json file to configure!
|
||||
@@ -19,64 +16,6 @@ import (
|
||||
// it's not needed to specify every key in your config, it will use the default values for keys you haven't specified
|
||||
// also, when specifying time, specify it in seconds (instead of nanoseconds as time.Duration)
|
||||
|
||||
const (
|
||||
// Downloads the HLS stream on the backend, and restreams it to frontend as a file. Requires no JS, but less stable client-side
|
||||
RestreamPlayer string = "restream"
|
||||
// Downloads the HLS stream on the frontend (proxying can be enabled). Requires JS, more stable client-side
|
||||
HLSPlayer string = "hls"
|
||||
// Disables the song player
|
||||
NonePlayer string = "none"
|
||||
)
|
||||
|
||||
const (
|
||||
// Just plays every song in order, one after another
|
||||
AutoplayNormal string = "normal"
|
||||
// Randomly selects a song to play from the playlist
|
||||
AutoplayRandom string = "random"
|
||||
)
|
||||
|
||||
const (
|
||||
// choose best for quality/size (AudioAAC over AudioOpus over AudioMP3)
|
||||
AudioBest string = "best"
|
||||
|
||||
// 160kbps m4a AAC audio, rarely available (fallback to AudioMP3 if unavailable)
|
||||
AudioAAC string = "aac"
|
||||
|
||||
// 72kbps ogg opus audio, usually available 99% of the time (fallback to AudioMP3 if unavailable)
|
||||
AudioOpus string = "opus"
|
||||
|
||||
// 128kbps mp3 audio, always available, good for compatibility
|
||||
AudioMP3 string = "mpeg"
|
||||
)
|
||||
|
||||
type Preferences struct {
|
||||
Player *string
|
||||
ProxyStreams *bool
|
||||
|
||||
// fully loads the track on page load
|
||||
// this option is here since the stream expires after some time (5 minutes? correct me if im wrong)
|
||||
// if the stream isn't fully loaded before it expires - you'll need to reload the page
|
||||
FullyPreloadTrack *bool
|
||||
|
||||
ProxyImages *bool
|
||||
|
||||
// Highlight @username, https://example.com and email@example.com in text as clickable links
|
||||
ParseDescriptions *bool
|
||||
|
||||
// Automatically play next track in playlists
|
||||
AutoplayNextTrack *bool
|
||||
|
||||
DefaultAutoplayMode *string // "normal" or "random"
|
||||
|
||||
// Check line 38 for constants
|
||||
// Probably best to keep all at "mpeg" by default for compatibility
|
||||
HLSAudio *string // Please don't use "opus" or "best". hls.js doesn't work with ogg/opus
|
||||
RestreamAudio *string // You can actually use anything here
|
||||
DownloadAudio *string // "aac" may not play well with some players
|
||||
|
||||
ShowAudio *bool // display audio (aac, opus, mpeg etc) under track player
|
||||
}
|
||||
|
||||
// // config // //
|
||||
|
||||
// Retrieve links users set in their profile (social media, website, etc)
|
||||
@@ -565,44 +504,4 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
// seems soundcloud has 4 of these (i1, i2, i3, i4)
|
||||
// they point to the same ip from my observations, and they all serve the same files
|
||||
const ImageCDN = "i1.sndcdn.com"
|
||||
const HLSCDN = "cf-hls-media.sndcdn.com"
|
||||
const HLSAACCDN = "playback.media-streaming.soundcloud.cloud"
|
||||
|
||||
var True = true
|
||||
var False = false
|
||||
|
||||
var prpool = sync.Pool{
|
||||
New: func() any {
|
||||
return &ProxyReader{}
|
||||
},
|
||||
}
|
||||
|
||||
func AcquireProxyReader() *ProxyReader {
|
||||
return prpool.Get().(*ProxyReader)
|
||||
}
|
||||
|
||||
type ProxyReader struct {
|
||||
Reader io.Reader
|
||||
Resp *fasthttp.Response
|
||||
}
|
||||
|
||||
func (pr *ProxyReader) Read(p []byte) (int, error) {
|
||||
return pr.Reader.Read(p)
|
||||
}
|
||||
|
||||
func (pr *ProxyReader) Close() error {
|
||||
defer fasthttp.ReleaseResponse(pr.Resp)
|
||||
defer prpool.Put(pr)
|
||||
return pr.Resp.CloseBodyStream()
|
||||
}
|
||||
|
||||
const Debug = false
|
||||
|
||||
func Log(what ...any) {
|
||||
if Debug {
|
||||
fmt.Println(what...)
|
||||
}
|
||||
}
|
||||
|
||||
68
lib/cfg/misc.go
Normal file
68
lib/cfg/misc.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package cfg
|
||||
|
||||
// seems soundcloud has 4 of these (i1, i2, i3, i4)
|
||||
// they point to the same ip from my observations, and they all serve the same files
|
||||
const ImageCDN = "i1.sndcdn.com"
|
||||
const HLSCDN = "cf-hls-media.sndcdn.com"
|
||||
const HLSAACCDN = "playback.media-streaming.soundcloud.cloud"
|
||||
|
||||
var True = true
|
||||
var False = false
|
||||
|
||||
const (
|
||||
// Downloads the HLS stream on the backend, and restreams it to frontend as a file. Requires no JS, but less stable client-side
|
||||
RestreamPlayer string = "restream"
|
||||
// Downloads the HLS stream on the frontend (proxying can be enabled). Requires JS, more stable client-side
|
||||
HLSPlayer string = "hls"
|
||||
// Disables the song player
|
||||
NonePlayer string = "none"
|
||||
)
|
||||
|
||||
const (
|
||||
// Just plays every song in order, one after another
|
||||
AutoplayNormal string = "normal"
|
||||
// Randomly selects a song to play from the playlist
|
||||
AutoplayRandom string = "random"
|
||||
)
|
||||
|
||||
const (
|
||||
// choose best for quality/size (AudioAAC over AudioOpus over AudioMP3)
|
||||
AudioBest string = "best"
|
||||
|
||||
// 160kbps m4a AAC audio, rarely available (fallback to AudioMP3 if unavailable)
|
||||
AudioAAC string = "aac"
|
||||
|
||||
// 72kbps ogg opus audio, usually available 99% of the time (fallback to AudioMP3 if unavailable)
|
||||
AudioOpus string = "opus"
|
||||
|
||||
// 128kbps mp3 audio, always available, good for compatibility
|
||||
AudioMP3 string = "mpeg"
|
||||
)
|
||||
|
||||
type Preferences struct {
|
||||
Player *string
|
||||
ProxyStreams *bool
|
||||
|
||||
// fully loads the track on page load
|
||||
// this option is here since the stream expires after some time (5 minutes? correct me if im wrong)
|
||||
// if the stream isn't fully loaded before it expires - you'll need to reload the page
|
||||
FullyPreloadTrack *bool
|
||||
|
||||
ProxyImages *bool
|
||||
|
||||
// Highlight @username, https://example.com and email@example.com in text as clickable links
|
||||
ParseDescriptions *bool
|
||||
|
||||
// Automatically play next track in playlists
|
||||
AutoplayNextTrack *bool
|
||||
|
||||
DefaultAutoplayMode *string // "normal" or "random"
|
||||
|
||||
// Check line 38 for constants
|
||||
// Probably best to keep all at "mpeg" by default for compatibility
|
||||
HLSAudio *string // Please don't use "opus" or "best". hls.js doesn't work with ogg/opus
|
||||
RestreamAudio *string // You can actually use anything here
|
||||
DownloadAudio *string // "aac" may not play well with some players
|
||||
|
||||
ShowAudio *bool // display audio (aac, opus, mpeg etc) under track player
|
||||
}
|
||||
Reference in New Issue
Block a user