Skip to content
This repository was archived by the owner on May 30, 2022. It is now read-only.

Commit 7629842

Browse files
authored
Merge pull request #9 from nguyenvancaokyfpt/main
improvements Command-Line Args
2 parents 82ac29a + 4b333d5 commit 7629842

File tree

2 files changed

+54
-29
lines changed

2 files changed

+54
-29
lines changed

README.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,36 @@ run from source code (Golang installation required).
1717
git clone https://github.com/SegoCode/swd
1818
cd swd
1919
go get -d ./...
20-
go run swd.go https://steamcommunity.com/sharedfiles/filedetails/?id=1111111111
20+
go run swd.go -url="https://steamcommunity.com/sharedfiles/filedetails/?id=1111111111"
21+
go run swd.go -id=1111111111
2122
```
2223
Or better [donwload a binary](https://github.com/SegoCode/swd/releases).
2324

2425
## Parameters
2526

26-
It's simple, there is only one parameter, the url of the steam workshop article you want to download.
27+
Use -h or --help flags to get help for the program.
2728
```shell
28-
swd https://steamcommunity.com/sharedfiles/filedetails/?id=1111111111
29+
swd -help
2930
```
3031

31-
But... steamworkshopdownloader.io has an optional parameter for download, if you know any you can specify
32+
Use -url for input the url of the steam workshop article you want to download.
3233
```shell
33-
swd https://steamcommunity.com/sharedfiles/filedetails/?id=1111111111 --downloadFormat gmaextract
34+
swd -url="https://steamcommunity.com/sharedfiles/filedetails/?id=1111111111"
35+
```
36+
37+
Use -id for input the id of the steam workshop article you want to download.
38+
```shell
39+
swd -id=1111111111
40+
```
41+
42+
-format (optional) for choosing the format
43+
```shell
44+
swd -id=1111111111 -format=gmaextract
45+
```
46+
47+
-node (optional) for choosing the node server to download ( between 4 and 8 )
48+
```shell
49+
swd -id=1111111111 -node=6
3450
```
3551

3652
## Downloads

swd.go

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strconv"
1010
"strings"
1111
"time"
12+
"flag"
1213

1314
"github.com/briandowns/spinner"
1415
"github.com/fatih/color"
@@ -21,7 +22,10 @@ const INFO = 1
2122
const WARNING = 2
2223
const ERR = 3
2324

25+
// START_NODE and END_NODE get from (steamworkshopdownloader.io)
2426
const DEFAULT_NODE = 8
27+
const START_NODE = 4
28+
const END_NODE = 8
2529

2630
func GetENDPOINT(node int) string {
2731
var ENDPOINT string = "https://node0" + strconv.Itoa(node) + ".steamworkshopdownloader.io/prod//api/"
@@ -99,31 +103,36 @@ func getUUID(api string, publishedFileId string, downloadFormat string) string {
99103

100104
func main() {
101105

102-
// Args validation //
103-
if len(os.Args) <= 1 {
104-
logger("USAGE: swd https://steamcommunity.com/sharedfiles/filedetails/?id=1111111111", ERR)
105-
}
106+
// Get Args //
107+
var fileUrl string
108+
flag.StringVar(&fileUrl, "url", "", "Url of file in steam workshop")
109+
var fileId string
110+
flag.StringVar(&fileId, "id", "", "Published file id of the file in steam workshop")
111+
var downloadFormat string
112+
flag.StringVar(&downloadFormat, "format", "raw", "Download format")
113+
var node int
114+
flag.IntVar(&node, "node", DEFAULT_NODE, "Server node (default: 8)")
115+
flag.Parse()
106116

107-
url, err := url.ParseRequestURI(os.Args[1])
108-
if err != nil {
109-
logger("URL NOT VALID (Example: swd https://steamcommunity.com/sharedfiles/filedetails/?id=1111111111)", ERR)
110-
}
111117

112-
idUrl := url.Query().Get("id")
113-
if idUrl == "" {
114-
logger("URL NOT VALID (Example: swd \"https://steamcommunity.com/sharedfiles/filedetails/?id=1111111111\")", ERR)
118+
// Validation Args //
119+
if fileUrl == "" && fileId == "" {
120+
logger("NEED A FILE URL OR PUBLISHED FILE ID, -help for usage", ERR)
115121
}
116122

117-
var downloadFormat = "raw"
118-
if len(os.Args) >= 3 && (os.Args[2] == "--downloadFormat") {
119-
downloadFormat = os.Args[3]
123+
if fileId == "" {
124+
fileUrl, err := url.ParseRequestURI(fileUrl)
125+
if err != nil {
126+
logger("URL NOT VALID (Example: swd https://steamcommunity.com/sharedfiles/filedetails/?id=1111111111)", ERR)
127+
}
128+
fileId = fileUrl.Query().Get("id")
120129
}
121130

122-
var node = DEFAULT_NODE
123-
if len(os.Args) >= 3 && (os.Args[2] == "--node") {
124-
node, err = strconv.Atoi(os.Args[3])
131+
if node < START_NODE || node > END_NODE {
132+
logger("NODE NOT VALID (Node must be between 4 and 8)", ERR)
125133
}
126-
134+
135+
logger("FileId: " + fileId, INFO)
127136
// End Args validation //
128137

129138
githubTag := &latest.GithubTag{
@@ -144,14 +153,14 @@ func main() {
144153
var initResponse string
145154
var ENDPOINT string
146155

147-
for i := node; i > 0; i-- {
156+
for i := node; i >= START_NODE; i-- { // Node can be 4 to 8
148157
ENDPOINT = GetENDPOINT(i)
149-
initResponse = getUUID(ENDPOINT + "download/request", idUrl, downloadFormat)
150-
logger("REQUESTING DOWNLOAD FROM NODE " + strconv.Itoa(node), INFO)
158+
initResponse = getUUID(ENDPOINT + "download/request", fileId, downloadFormat)
159+
logger("REQUESTING DOWNLOAD FROM NODE " + strconv.Itoa(i), INFO)
151160
if initResponse != "0" {
152161
break
153162
} else {
154-
logger("TRYING TO CONNECT TO NODE " + strconv.Itoa(node), INFO)
163+
logger("TRYING TO CONNECT TO NODE " + strconv.Itoa(i), INFO)
155164
}
156165
}
157166

@@ -182,12 +191,12 @@ func main() {
182191
// File ready, start download //
183192
if readyFile {
184193
dir, _ := os.Getwd()
185-
err := DownloadFile("https://"+storageNode+"/prod//storage/"+storagepath+"?uuid="+uid, dir+string(os.PathSeparator)+idUrl+".zip")
194+
err := DownloadFile("https://"+storageNode+"/prod//storage/"+storagepath+"?uuid="+uid, dir+string(os.PathSeparator)+fileId+".zip")
186195

187196
if err != nil {
188197
panic(err)
189198
} else {
190-
logger("✔️ DOWNLOAD FINISHED IN "+(dir+string(os.PathSeparator)+idUrl+".zip"), INFO)
199+
logger("✔️ DOWNLOAD FINISHED IN "+(dir+string(os.PathSeparator)+fileId+".zip"), INFO)
191200
}
192201

193202
} else {

0 commit comments

Comments
 (0)