-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
enumerateForge.py
executable file
·130 lines (103 loc) · 4.01 KB
/
enumerateForge.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/python3
from __future__ import print_function
import sys
import os
import re
from metautil import *
from forgeutil import *
from jsonobject import *
from distutils.version import LooseVersion
from enum import Enum
import requests
from cachecontrol import CacheControl
from cachecontrol.caches import FileCache
#with open('multimc/index.json', 'r', encoding='utf-8') as index:
#packages = MultiMCPackageIndex(json.load(index))
#for entry in packages.packages:
#print (entry)
class DownloadType(Enum):
NORMAL = 1
FORGE_XZ = 2
class DownloadEntry:
def __init__(self, url : str, kind : DownloadType, name : GradleSpecifier):
self.name = name
self.url = url
self.kind = kind
def __lt__(self, other):
return self.name < other.name
def __eq__(self, other):
return self.name == other.name
def __ne__(self, other):
return not self.__eq__(other)
def __hash__(self):
return self.name.__hash__()
def toString(self):
return "%s %s" % (self.name.toString(), self.url)
def __repr__(self):
return "DownloadEntry('" + self.toString() + "')"
class MojangLibrary (JsonObject):
extract = ObjectProperty(MojangLibraryExtractRules, exclude_if_none=True, default=None)
name = GradleSpecifierProperty(required = True)
downloads = ObjectProperty(MojangLibraryDownloads, exclude_if_none=True, default=None)
natives = DictProperty(StringProperty, exclude_if_none=True, default=None)
rules = ListProperty(MojangRule, exclude_if_none=True, default=None)
class MultiMCLibrary (MojangLibrary):
url = StringProperty(exclude_if_none=True, default=None)
mmcHint = StringProperty(name="MMC-hint", exclude_if_none=True, default=None)
def GetLibraryDownload (library : MultiMCLibrary):
if library.natives:
raise Exception('Natives are not handled yet')
name = library.name
if library.mmcHint == 'forge-pack-xz':
kind = DownloadType.FORGE_XZ
name.extension = 'jar.pack.xz'
else:
kind = DownloadType.NORMAL
if library.downloads:
url = library.downloads.artifact.url
if url.endswith('.zip'):
name.extension = 'zip'
if library.downloads:
url = library.downloads.artifact.url
else:
if library.url:
url = library.url + name.getPath()
else:
url = 'https://libraries.minecraft.net/' + name.getPath()
return DownloadEntry(url, kind, name)
with open('multimc/net.minecraftforge/index.json', 'r', encoding='utf-8') as forgeIndex:
forgeVersions = MultiMCVersionIndex(json.load(forgeIndex))
urlSet = set()
for entry in forgeVersions.versions:
versionString = entry.version
versionPath = "multimc/net.minecraftforge/%s.json" % versionString
with open(versionPath, 'r') as infile:
forgeVersion = MultiMCVersionFile(json.load(infile))
if forgeVersion.libraries:
for entry in forgeVersion.libraries:
urlSet.add(GetLibraryDownload(entry))
if forgeVersion.jarMods:
for entry in forgeVersion.jarMods:
urlSet.add(GetLibraryDownload(entry))
if forgeVersion.mavenFiles:
for entry in forgeVersion.mavenFiles:
urlSet.add(GetLibraryDownload(entry))
forever_cache = FileCache('forge_cache', forever=True)
sess = CacheControl(requests.Session(), forever_cache)
for entry in urlSet:
libraryName = entry.name
folderPath = "forgemaven/%s" % libraryName.getBase()
filePath = "forgemaven/%s" % libraryName.getPath()
if not os.path.isfile(filePath):
os.makedirs(folderPath, exist_ok=True)
rfile = sess.get(entry.url, stream=True)
try:
rfile.raise_for_status()
except requests.exceptions.HTTPError as exc:
print('Missing: %s %s' % (entry.name, entry.url))
continue
print('Downloading %s' % entry.name)
print('To %s' % filePath)
with open(filePath, 'wb') as f:
for chunk in rfile.iter_content(chunk_size=4096):
f.write(chunk)