Skip to content

Commit 94ab079

Browse files
committed
Added package info
1 parent 3a8b129 commit 94ab079

File tree

6 files changed

+113
-39
lines changed

6 files changed

+113
-39
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ MANIFEST
3030
# Usually these files are written by a python script from a template
3131
# before PyInstaller builds the exe, so as to inject date/other infos into it.
3232
*.manifest
33-
*.spec
3433

3534
# Installer logs
3635
pip-log.txt

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
# factorio-mod-downloader
22

3-
Factorio mod downloader, used [re146.dev]{https://re146.dev/factorio/mods} to recursively download a mod and its all required depndedncies. Its really helpful if you want to download a modpack as a modpack contains various different recommended mods, that if you want to download separately will take you a lot of clicks and headache.
3+
Factorio mod downloader, used [re146.dev](https://re146.dev/factorio/mods) to recursively download a mod and its all required depndedncies. Its really helpful if you want to download a modpack as a modpack contains various different recommended mods, that if you want to download separately will take you a lot of clicks and headache.
44

55
If you love the game please buy it and support the developers. I am a big fan of the game.
66

77
### How to run
88
This code is built using python so make sure you have python installed. You can use official Python website to download any version > 3.10
99

10-
1. Open main.py, and replace the mod_url line number 13 with the factorio 2 official mod url of the mod you want to download. for e.g. you want to download Krastorio 2, the mod_url will be exactly like this `mod_url = 'https://mods.factorio.com/mod/Krastorio2'`, dont forget to add inverted commas.
11-
2. Run this command in cmd or terminal. `pip install -r requirements.txt` or `pip3 install -r requirements.txt` (Windows uses pip, while mac/linux uses pip3). It will install all dependencies, required to run this code.
12-
2. Finally run the script using `python main.py` or `python3 main.py` (Windows uses python while mac/linux uses python3)
13-
3. All the mods and its dependencies will be downloaded and saved in a new mods folder
10+
1. Run the app, select the directory and add mod url from factorio portal i.e. URL for Krastorio 2 is: `https://mods.factorio.com/mod/Krastorio2`.
11+
2. Click on generate. The application will seem like its not responding. Don't panic, check the folder which you selected for downoading, the files are downloading, Once done, it will show a completed dialogue.
1412

1513
### Note
1614
I have not included optional dependencies, as its a stupid idea, since a lots of mods, even they don't need something have optional dependencies mentioned. So it will probbaly take forever to finish downloading. It can be implemented although. Not a big task.
1715

18-
Feel free to reach out to me if you need soem help.
16+
Also, download speed is based on re146, Its not super fast but its fine.
17+
18+
Feel free to reach out to me if you need soem help.
19+
20+
21+
### ToDo:
22+
Improve the spec file. I am not good with packaging. 🥹

factorio_mod_downloader.spec

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
import sys
3+
import os
4+
from PyInstaller.utils.hooks import copy_metadata
5+
6+
block_cipher = None
7+
8+
def get_files_in_directory(directory):
9+
for root, dirs, files in os.walk(directory):
10+
for file in files:
11+
yield os.path.join(root, file), os.path.relpath(root, directory)
12+
13+
datas = []
14+
datas.extend(get_files_in_directory('gui'))
15+
datas.extend(get_files_in_directory('mod_downloader'))
16+
17+
18+
a = Analysis(
19+
['gui\\gui.py'],
20+
pathex=[],
21+
binaries=[],
22+
datas=datas,
23+
hiddenimports=['tkinter',
24+
'selenium'
25+
'selenium.webdriver.common.by',
26+
'selenium.webdriver.common.keys',
27+
'selenium.webdriver.chrome.service',
28+
'selenium.webdriver.remote.remote_connection',
29+
'chromedriver_autoinstaller',
30+
'bs4',
31+
'bs4.element',
32+
'bs4.builder',
33+
'requests'
34+
],
35+
hookspath=[],
36+
hooksconfig={},
37+
runtime_hooks=[],
38+
excludes=[],
39+
noarchive=False,
40+
optimize=0,
41+
)
42+
43+
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
44+
45+
exe = EXE(
46+
pyz,
47+
a.scripts,
48+
a.binaries,
49+
a.datas,
50+
[],
51+
name='factorio_mod_downloader',
52+
debug=False,
53+
bootloader_ignore_signals=False,
54+
strip=False,
55+
upx=True,
56+
upx_exclude=[],
57+
runtime_tmpdir=None,
58+
console=False,
59+
disable_windowed_traceback=False,
60+
argv_emulation=False,
61+
target_arch=None,
62+
codesign_identity=None,
63+
entitlements_file=None,
64+
)
65+
66+
coll = COLLECT(
67+
exe,
68+
a.binaries,
69+
a.zipfiles,
70+
a.datas,
71+
strip=False,
72+
upx=True,
73+
upx_exclude=[],
74+
runtime_tmpdir=None,
75+
excludes=[],
76+
cipher=block_cipher,
77+
noarchive=False,
78+
name='factorio_mod_downloader'
79+
)

gui/gui.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
import sys
77
import re
88

9-
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
9+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
1010
try:
11-
from mod_downloader.mod_downloader import ModDownloader
11+
from mod_downloader import ModDownloader
1212
except ModuleNotFoundError:
1313
raise RuntimeError("Couldn't add ModDownloader to the PATH.")
1414

15-
1615
OUTPUT_PATH = Path(__file__).parent
1716
ASSETS_PATH = Path(__file__).resolve().parent / "assets"
1817

@@ -80,9 +79,7 @@ def btn_clicked():
8079
mod_downloader.start_download()
8180

8281
tk.messagebox.showinfo(
83-
"Success!", f"Project successfully generated at {output}.")
84-
85-
82+
"Success!", f"Mods successfully downloaded at {output}.")
8683

8784

8885
# Required in order to add data files to Windows executable

mod_downloader/mod_downloader.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
from pathlib import Path
21
from selenium import webdriver
3-
from selenium.webdriver.common.by import By
4-
from selenium.webdriver.chrome.service import Service
52
from selenium.webdriver.chrome.options import Options
63
import chromedriver_autoinstaller
74
from bs4 import BeautifulSoup
8-
import requests
9-
import random
105
import time
116
import os
12-
from mod_downloader import utils
13-
7+
import requests
8+
import random
149

1510
class ModDownloader:
1611
def __init__(self, mod_url: str, output_path: str):
@@ -37,6 +32,22 @@ def init_driver(self):
3732
def close_driver(self, driver):
3833
driver.quit()
3934

35+
def download_file(self, url, file_path):
36+
response = requests.get(url, stream=True)
37+
response.raise_for_status() # Check if the request was successful
38+
39+
with open(file_path, 'wb') as file:
40+
for chunk in response.iter_content(chunk_size=8192):
41+
file.write(chunk)
42+
43+
print(f"Downloaded: {file_path}")
44+
45+
46+
def generate_anticache(self):
47+
random_number = random.randint(1_000_000_000_000_000, 9_999_999_999_999_999) # 16-digit number
48+
return f"0.{random_number}"
49+
50+
4051
def get_required_dependencies(self, soup):
4152
dependencies = []
4253
required_deps = soup.find('dd', {'id': 'mod-info-required-dependencies'})
@@ -78,6 +89,7 @@ def get_mod_name(self, soup):
7889
return mod_name.strip()
7990

8091
def download_mod_with_dependencies(self, mod_url, download_path):
92+
8193
driver = self.init_driver()
8294
driver.get(mod_url)
8395
time.sleep(2)
@@ -88,14 +100,14 @@ def download_mod_with_dependencies(self, mod_url, download_path):
88100
mod_name = self.get_mod_name(soup)
89101
latest_version = self.get_latest_version(soup)
90102

91-
download_url = f"https://mods-storage.re146.dev/{mod_name}/{latest_version}.zip?anticache={utils.generate_anticache()}"
103+
download_url = f"https://mods-storage.re146.dev/{mod_name}/{latest_version}.zip?anticache={self.generate_anticache()}"
92104
file_name = f"{mod_name}_{latest_version}.zip"
93105
file_path = os.path.join(download_path, file_name)
94106

95107
# Download the mod file
96108
os.makedirs(download_path, exist_ok=True)
97109
print(f"Downloading {file_name} from {download_url}")
98-
utils.download_file(download_url, file_path)
110+
self.download_file(download_url, file_path)
99111

100112
# Get required dependencies and recursively download them
101113
dependencies = self.get_required_dependencies(soup)

mod_downloader/utils.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)