tywil04 / slavartdl

Simple tool written in Go(lang) to download music using the SlavArt Divolt server
GNU General Public License v3.0
17 stars 1 forks source link

Feature request (session token, channel ids, multiple urls) #8

Closed bacon-cheeseburger closed 1 year ago

bacon-cheeseburger commented 1 year ago

Just a few more suggestions on ways to make things easier/enhanced for users...

  1. Ability for slavartdl to get its own dedicated token. Login credentials could be set on command line and stored in the config file. Would eliminate users needing to poke around in http headers/source.

  2. Store channel ids in the config file rather than hardcode them so they're easy for users to update in case they change, or try to check/update them automatically. Would eliminate the need for a new app version to be compiled if so.

  3. Store AllowedHosts array in the config file for the same reasons as explained in 2.

  4. Ability to supply multiple download urls on the command line, or possibly a list of download urls stored in a text file with a command line argument to refer to that file for url(s). I guess you could use the config file for this too and automatically remove urls that were successfully downloaded. One caveat to using the config file for this is the possibility users accidentally bork their config. Would streamline the process for downloading in bulk.

An additional benefit to moving the hardcoded stuff into a config file and expanding what can be done on the command line is that the app could be used beyond slavart where the same function could apply.

tywil04 commented 1 year ago

I think request 1 is viable and will be beneficial, while its not difficult to get the session token it can be a pain.

I don't know if request 2 is really that beneficial though, this bot is designed to work around Divolt, which hosts the Slavart server where the bot is located. I don't see a situation where the user would need to configure the request/upload channel ids. I do agree there should be some way for me to update them, maybe I should think about making the tool update itself, considering how often I am releasing patches I think self-updating is a good idea.

I have the same thoughts about request 3 as I did request 2.

Right now, the download command does accept multiple URLs, maybe when you last tested it you used an older version? I think allowing the tool to read from lines in a text file could work or maybe instead I could allow for inputs via standard input instead or maybe both to be flexible.

I don't think there is any other bot that works like Slavart does, so I don't think its necessary to move some of the hard coded stuff.

bacon-cheeseburger commented 1 year ago

For 1 luckily you can api login with POST and the token is included in (successful) returned json data. I don't know go but managed to slap together a test that seems to work well.

/test/gocurl$ go build gettoken.go; time ./gettoken token = 29.......

real 0m0.521s user 0m0.011s sys 0m0.010s

The main reasons for 2 and 3 is so users could easily use the app with other channels that use the same request/upload system (if exists - thought there were others but maybe not), to easily add/remove allowed sources when slavart changes, and generally disliking hardcoding that kind of stuff since it's easier to edit a config file than to have to update source code and recompile a new binary version every time something that was hardcoded changes. Ultimately it might not really matter in this case and boil down to design preference, I dunno. Efforts are better spent on things that have an immediate use/impact for sure though, like the case with 1.

tywil04 commented 1 year ago

Can I see the code you put together for 1? It would make things quicker!

bacon-cheeseburger commented 1 year ago
package main

import (
        "fmt"
        "io"
        "log"
        "net/http"
        "strings"
        "encoding/json"
)

var EMAIL = "e@mail.com"
var PASSWORD = "secretpassword"
var SESSION_NAME = "Linux/bash"

type jsonResult struct {
        Result string `json:"result"`
        ID     string `json:"_id"`
        UserID string `json:"user_id"`
        Token  string `json:"token"`
        Name   string `json:"name"`
}

func main() {
        client := &http.Client{}
        var data = strings.NewReader(fmt.Sprintf("{ \"email\":\"%s\",\"password\":\"%s\",\"friendly_name\":\"%s\" }", EMAIL, PASSWORD, SESSION_NAME))
        req, err := http.NewRequest("POST", "https://api.divolt.xyz/auth/session/login", data)
        if err != nil { log.Fatal(err); }

        req.Header.Set("Content-Type", "application/json")
        resp, err := client.Do(req)
        if err != nil { log.Fatal(err); }
        defer resp.Body.Close()

        bodyText, err := io.ReadAll(resp.Body)
        if err != nil { log.Fatal(err); }

        var jsonresult jsonResult
        json.Unmarshal([]byte(bodyText), &jsonresult)
        fmt.Println("token =", jsonresult.Token)
}
tywil04 commented 1 year ago

Users can now add there Divolt accounts into the config using email and password, here is the commit if your interested https://github.com/tywil04/slavartdl/commit/507fe06e3d9da6a5aff21118ac1bfb60cbdb4fb5.

tywil04 commented 1 year ago

2 and 3 I have (sort of) resolved, I don't think adding those options to the config would be beneficial, there are no other servers that this tool will work on (because there are no other servers which contain the slavart bot). If I added those options to the config i'm worried some users who might not understand would bork their config.

I have, however, implemented an update command. Its available from v1.1.6 onwards. So if for whatever reasons the channels change I can release a new version with the new values and users can update easily.