This repository has been archived by the owner on Jun 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
91 lines (68 loc) · 2.29 KB
/
main.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
'''
Usage: Run the script and optionally add commandline arguments to it. Default
configuration (no arguments) downloads the stable version packs.
--download_mode ["stable" or "beta"]
--rp_url <the url to download resourcepack>
--bp_url <the url to download behaviorpack>
rp_url and bp_url overwrites the download mode.
Examples:
Downloading beta packs and extracting data from them:
python main.py --download_mode beta
Downloading packs from custom urls
python main --bp_url example.com --rp_url example1.com
The scripts uses temporary path ".tmp". The path is not cleared after the
execution. The path is removed and added again at the start of the script.
'''
import sys
from zipfile import ZipFile
import os
import shutil
from downloader import download_file
from harvester import harvest
from sound_harvester import strip_sounds
argv = sys.argv
# Reading the commandline arguments
try:
DOWNLOAD_MODE = argv[argv.index('--download_mode')+1]
except:
DOWNLOAD_MODE = 'stable'
if DOWNLOAD_MODE == 'stable':
RP_URL = 'https://aka.ms/resourcepacktemplate'
BP_URL = 'https://aka.ms/behaviorpacktemplate'
elif DOWNLOAD_MODE == 'beta':
RP_URL = 'https://aka.ms/MinecraftBetaResources'
BP_URL = 'https://aka.ms/MinecraftBetaBehaviors'
else:
raise Exception(f'Unknown download mode {DOWNLOAD_MODE}.')
try:
RP_URL = argv[argv.index('--rp_url')+1]
except:
pass
try:
RP_URL = argv[argv.index('--rp_url')+1]
except:
pass
SKIP_DOWNLOAD = '--skip_download' in argv
def main():
if not SKIP_DOWNLOAD:
if os.path.exists('.tmp'):
shutil.rmtree('.tmp')
os.makedirs('.tmp', exist_ok=True)
print("Downloading files...")
download_file(RP_URL, '.tmp/rp.zip')
download_file(BP_URL, '.tmp/bp.zip')
if os.path.exists('.tmp/rp'):
shutil.rmtree('.tmp/rp')
print('Extracting resource pack')
with ZipFile('.tmp/rp.zip') as zipf:
zipf.extractall('.tmp/rp')
if os.path.exists('.tmp/bp'):
shutil.rmtree('.tmp/bp')
print('Extracting behavior pack')
with ZipFile('.tmp/bp.zip') as zipf:
zipf.extractall('.tmp/bp')
stable = DOWNLOAD_MODE == 'stable'
harvest('.tmp/bp', stable)
strip_sounds('.tmp/rp/sounds/sound_definitions.json')
if __name__ == "__main__":
main()