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
2122const WARNING = 2
2223const ERR = 3
2324
25+ // START_NODE and END_NODE get from (steamworkshopdownloader.io)
2426const DEFAULT_NODE = 8
27+ const START_NODE = 4
28+ const END_NODE = 8
2529
2630func GetENDPOINT (node int ) string {
2731var 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
100104func 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
129138githubTag := & latest.GithubTag {
@@ -144,14 +153,14 @@ func main() {
144153var initResponse string
145154var ENDPOINT string
146155
147- for i := node ; i > 0 ; i -- {
156+ for i := node ; i >= START_NODE ; i -- { // Node can be 4 to 8
148157ENDPOINT = 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 )
151160if initResponse != "0" {
152161break
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 //
183192if readyFile {
184193dir , _ := 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
187196if err != nil {
188197panic (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