-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCollectionDL.py
55 lines (46 loc) · 1.67 KB
/
CollectionDL.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import json
import os
import sys
import time
import requests
import WorkshopDL
def download(CollectionID, AppID=-1):
"""Downloads the metadata for a collection and then batch downloads the items in it"""
# SteamWebAPI endpoint
GetCollectionDetails = (
"https://api.steampowered.com/ISteamRemoteStorage/GetCollectionDetails/v1/"
)
# Timeout Variable
LoadAttempts = 1000
# Load SteamWebAPI Key
with open("./SteamWebAPI.key") as KeyFile:
Key = KeyFile.read()
# Load Workshop Page Details
for _ in range(LoadAttempts):
try:
GetCollectionDetailsData = {
"key": Key,
"collectioncount": 1,
"publishedfileids[0]": CollectionID,
}
GetCollectionDetailsRaw = requests.post(
url=GetCollectionDetails, data=GetCollectionDetailsData
)
CollectionDetails = json.loads(GetCollectionDetailsRaw.text)["response"][
"collectiondetails"
][0]
except json.JSONDecodeError:
time.sleep(3600)
continue
break
WorkshopDL.download(CollectionID, True)
if AppID != -1:
os.makedirs("./" + str(AppID) + "/CollectionDetails/", exist_ok=True)
with open(
"./" + str(AppID) + "/CollectionDetails/" + str(CollectionID) + ".json", "w"
) as OutputFile:
json.dump(CollectionDetails, OutputFile, sort_keys=True, indent=4)
for Entry in CollectionDetails["children"]:
WorkshopDL.download(Entry["publishedfileid"])
if __name__ == "__main__":
download(sys.argv[1])