diff --git a/.gitignore b/.gitignore index 6ef3500..c52dc6d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ package-lock.json fly.toml *.fiber.gz soundcloak.json +compose.yml \ No newline at end of file diff --git a/README.md b/README.md index d8fe2f6..5db899b 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ An easier way is to navigate to `/_/preferences`. If some features are disabled by the instance, they won't show up there. Available features: -- ParseDescriptions: Highlight `@username`, `https://example.com` and `email@example.com` in text as clickable links +- Parse descriptions: Highlight `@username`, `https://example.com` and `email@example.com` in text as clickable links - Proxy images: Retrieve images through the instance, instead of going to soundcloud's servers for them - Player: In what way should the track be streamed. Can be Restream (does not require JS, better compatibility, can be a bit buggy client-side) or HLS (requires JS, more stable, less good compatibility (you'll be ok unless you are using a very outdated browser)) - Player-specific settings: They will only show up if you have selected HLS player currently. @@ -44,6 +44,9 @@ You can contribute on: You can also [reach out to me privately](https://laptopc.at) # Setting it up +
+1. Regular method + ## Prerequisites: 1. [node.js + npm](https://nodejs.org) (any recent enough version should do, it's just used for getting hls.js builds) 2. [golang](https://go.dev) (1.21 or higher was tested, others might work too) @@ -102,9 +105,50 @@ go build main.go ``` This will run soundcloak on localhost, port 4664. (by default) +
+ +
+2. Docker image +The docker image was made by [vlnst](https://github.com/vlnst) + +## Prerequisites: +1. [Docker](https://www.docker.com/) +2. [Git](https://git-scm.com) + +## Setup: +1. Clone this repository: +```sh +git clone https://github.com/maid-zone/soundcloak +``` + +2. Go into the cloned repository: +```sh +cd soundcloak +``` + +3. Make a copy of the example `compose.yaml` file: +```sh +cp compose.example.yaml compose.yaml +``` +Make adjustments as needed. + +4. *Optional.* Edit config: + +You can make a `soundcloak.json` file in the folder if you want. Refer to `soundcloak.json.example` and `lib/cfg/init.go` for configuration values and their meaning. + +5. Run the container + +```sh +docker compose up -d +``` +(if you get `docker: 'compose' is not a docker command.`, use `docker-compose up -d`) + +This will run soundcloak as a daemon (remove the -d part of the command to just run it) on localhost, port 4664. (by default) +
# Maintenance-related stuffs ## Updating +Note: this guide works only if you install from source. If you used docker, you could probably do the 1st step (pulling the code), stop the container (`docker container stop soundcloak`) and start it again. (`docker compose up -d`) 1. Retrieve the latest code: ```sh @@ -124,7 +168,7 @@ rm *.fiber.gz 3. *Optional.* Edit config: -Sometimes, new updates add new config values or change default ones. You can make a `soundcloak.json` file in the folder with the binary if you want, or an environment variable `SOUNDCLOAK_CONFIG` with path to the config. Refer to `lib/cfg/init.go` for configuration values and their meaning. +Sometimes, new updates add new config values or change default ones. You can make a `soundcloak.json` file in the folder with the binary if you want, or an environment variable `SOUNDCLOAK_CONFIG` with path to the config. Refer to `soundcloak.json.example` and `lib/cfg/init.go` for configuration values and their meaning. 4. Regenerate templates (if they changed): diff --git a/compose.yaml b/compose.example.yaml similarity index 100% rename from compose.yaml rename to compose.example.yaml diff --git a/lib/cfg/init.go b/lib/cfg/init.go index 82d30f7..4630267 100644 --- a/lib/cfg/init.go +++ b/lib/cfg/init.go @@ -111,6 +111,26 @@ var TrustedProxies = []string{} // // end of config // // +func defaultPreferences() { + var p string + if Restream { + p = RestreamPlayer + } else { + p = HLSPlayer + } + DefaultPreferences.Player = &p + + DefaultPreferences.ProxyStreams = &ProxyStreams + + var f bool + var t = true + DefaultPreferences.FullyPreloadTrack = &f + + DefaultPreferences.ProxyImages = &ProxyImages + + DefaultPreferences.ParseDescriptions = &t +} + func init() { filename := "soundcloak.json" if env := os.Getenv("SOUNDCLOAK_CONFIG"); env != "" { @@ -120,6 +140,7 @@ func init() { data, err := os.ReadFile(filename) if err != nil { log.Printf("failed to load config from %s: %s\n", filename, err) + defaultPreferences() return } @@ -150,6 +171,7 @@ func init() { err = json.Unmarshal(data, &config) if err != nil { log.Printf("failed to parse config from %s: %s\n", filename, err) + defaultPreferences() return } @@ -261,22 +283,6 @@ func init() { DefaultPreferences.ParseDescriptions = &t } } else { - var p string - if Restream { - p = RestreamPlayer - } else { - p = HLSPlayer - } - DefaultPreferences.Player = &p - - DefaultPreferences.ProxyStreams = &ProxyStreams - - var f bool - var t = true - DefaultPreferences.FullyPreloadTrack = &f - - DefaultPreferences.ProxyImages = &ProxyImages - - DefaultPreferences.ParseDescriptions = &t + defaultPreferences() } } diff --git a/lib/restream/init.go b/lib/restream/init.go index 8756f49..a31cce6 100644 --- a/lib/restream/init.go +++ b/lib/restream/init.go @@ -6,7 +6,6 @@ import ( "github.com/gofiber/fiber/v2" "github.com/maid-zone/soundcloak/lib/cfg" - "github.com/maid-zone/soundcloak/lib/preferences" "github.com/maid-zone/soundcloak/lib/sc" "github.com/valyala/fasthttp" ) @@ -21,6 +20,19 @@ var httpc = &fasthttp.HostClient{ MaxIdleConnDuration: 1<<63 - 1, } +// Needed for restream to work even if prefs.Player != RestreamPlayer +var stubPrefs = cfg.Preferences{} + +func init() { + p := cfg.RestreamPlayer + + stubPrefs.Player = &p + + f := false + + stubPrefs.ProxyStreams = &f +} + type reader struct { parts [][]byte leftover []byte @@ -115,12 +127,7 @@ func (r *reader) Read(buf []byte) (n int, err error) { func Load(r fiber.Router) { r.Get("/_/restream/:author/:track", func(c *fiber.Ctx) error { - prefs, err := preferences.Get(c) - if err != nil { - return err - } - - t, err := sc.GetTrack(prefs, c.Params("author")+"/"+c.Params("track")) + t, err := sc.GetTrack(stubPrefs, c.Params("author")+"/"+c.Params("track")) if err != nil { return err } @@ -130,7 +137,7 @@ func Load(r fiber.Router) { return fiber.ErrExpectationFailed } - u, err := tr.GetStream(prefs, t.Authorization) + u, err := tr.GetStream(stubPrefs, t.Authorization) if err != nil { return err } diff --git a/lib/textparsing/init.go b/lib/textparsing/init.go index f1f7a53..ec636df 100644 --- a/lib/textparsing/init.go +++ b/lib/textparsing/init.go @@ -12,8 +12,8 @@ import ( // var urlre = regexp.MustCompile(`https?:\/\/[-a-zA-Z0-9@%._\+~#=]{2,256}\.[a-z]{1,6}[-a-zA-Z0-9@:%_\+.~#?&\/\/=]*`) // var emailre = regexp.MustCompile(`[-a-zA-Z0-9%._\+~#=]+@[-a-zA-Z0-9%._\+~=&]{2,256}\.[a-z]{1,6}`) -// var usernamere = regexp.MustCompile(`@[a-z0-9\-]+`) -var theregex = regexp.MustCompile(`@[a-z0-9\-]+|(?:https?:\/\/[-a-zA-Z0-9@%._\+~#=]{2,256}\.[a-z]{1,6}[-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)|(?:[-a-zA-Z0-9%._\+~#=]+@[-a-zA-Z0-9%._\+~=&]{2,256}\.[a-z]{1,6})`) +// var usernamere = regexp.MustCompile(`@[a-zA-Z0-9\-]+`) +var theregex = regexp.MustCompile(`@[a-zA-Z0-9\-]+|(?:https?:\/\/[-a-zA-Z0-9@%._\+~#=]{2,256}\.[a-z]{1,6}[-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)|(?:[-a-zA-Z0-9%._\+~#=]+@[-a-zA-Z0-9%._\+~=&]{2,256}\.[a-z]{1,6})`) func replacer(ent string) string { if strings.HasPrefix(ent, "@") { diff --git a/soundcloak.json.example b/soundcloak.json.example new file mode 100644 index 0000000..615639d --- /dev/null +++ b/soundcloak.json.example @@ -0,0 +1,29 @@ +{ + // Some common settings + "ProxyImages": true, // Proxy images (load images through the instance, instead of going to soundcloud's CDN) + + "ProxyStreams": true, // Proxy streams (load track streams through the instance, instead of going to soundcloud's CDN) + + "Restream": true, // Enables Restream Player and endpoint. + // This player works without any JavaScript, but is a bit less stable from personal observations (when listening to a track on repeat specifically) + + // Default preferences (look at the /_/preferences page) + "DefaultPreferences": { + "ProxyImages": false, // This preference will be same as the config value ProxyImages by default, but you can override it + + // The player is basically the method used to load and play the track + // It can be "hls", "restream" or "none" + "Player": "hls", // The player is already hls by default, but if you enable Restream - it's going to be restream, this line overrides it to still be HLS + + // These two preferences only work with HLS player. + // RestreamPlayer already loads the track on the backend, and it also fully preloads it. This behaviour of RestreamPlayer cannot be disabled due to technical reasons. + "ProxyStreams": false, // This preference will be same as the config value ProxyStream by default + "FullyPreloadTrack": true // This fully loads the track instead of buffering a small part of it. False by default. + }, + + // Listening address and port. This is already the default, but doesn't hurt to include it here as well. + "Addr": "127.0.0.1:4664" + + // Note: if you are going to make your own config, you should start from scratch, or remove the comments. Comments aren't allowed in JSON, but they are used here to explain some stuff. + // For all the possible configuration keys, refer to lib/cfg/init.go file. +} \ No newline at end of file