-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchunkv3 manifest downloader.py
65 lines (53 loc) · 2.13 KB
/
chunkv3 manifest downloader.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
"""
Loop through a master.manifest json file, download each chunk's manifest, save to /manifests/file_name.manifest
e.g. https://battlebreakers-live-cdn.ol.epicgames.com/WorldExplorersLive/CL_3514827/Android_ATC/WorldExplorers_pakchunk1000CL_3514827.manifest
"""
import asyncio
import aiohttp
import orjson
import os
import time
async def download_manifest(session: aiohttp.client.ClientSession, url: str, file_name: str) -> None:
"""
Download a manifest file
:param session: The aiohttp session
:param url: The url to download from
:param file_name: The file name to save to
:return: None
"""
async with session.get(url) as response:
if response.status == 200:
with open(f"manifests/{file_name}", "wb") as file:
file.write(await response.read())
file.close()
print(f"Downloaded {file_name}")
else:
print(f"Failed to download {file_name} with status code {response.status}")
async def main() -> None:
"""
The main function
:return: None
"""
# Create the manifests directory if it doesn't exist
if not os.path.exists("manifests"):
os.makedirs("manifests")
# Create the aiohttp session
async with aiohttp.ClientSession() as session:
# Read the master.manifest file
with open("master.manifest", "r", encoding='utf-8') as file:
master_manifest: dict = orjson.loads(file.read())
# Loop through each chunk
for chunk in master_manifest["files"]:
# Download the chunk's manifest
url: str = f"https://battlebreakers-live-cdn.ol.epicgames.com/WorldExplorersLive/{master_manifest['BuildUrl']}/{chunk['filename']}"
await download_manifest(session, url, chunk["filename"])
# Close the aiohttp session
await session.close()
if __name__ == "__main__":
# Start the timer
start_time: float = time.time()
# Run the main function
loop: asyncio.AbstractEventLoop = asyncio.get_event_loop()
loop.run_until_complete(main())
# Print the time it took to run
print("--- %s seconds ---" % (time.time() - start_time))