aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2023-04-27 10:46:00 +0000
committerterminaldweller <devi@terminaldweller.com>2023-04-27 10:46:00 +0000
commitaee6fbba38c0712bff8e4b348a49328d292b725c (patch)
treecf26a9bf73f6f3cd4437ee14fa79ce2c35bf22b0
parentupdated the readme (diff)
downloadmagni-aee6fbba38c0712bff8e4b348a49328d292b725c.tar.gz
magni-aee6fbba38c0712bff8e4b348a49328d292b725c.zip
updated the readme
-rw-r--r--README.md43
-rwxr-xr-xmagni.py17
2 files changed, 45 insertions, 15 deletions
diff --git a/README.md b/README.md
index 3d7ca34..9f8a723 100644
--- a/README.md
+++ b/README.md
@@ -2,9 +2,46 @@
magni takes a url and upscales all the images inside and returns a simple html page with the images embedded.</br>
```sh
-HTTPS_PROXY=socks5h://127.0.0.1:9094 ./magni.py --url https://chapmanganato.com/manga-dt980702/chapter-184
+usage: magni.py [-h] [--url URL] [--method METHOD] [--port PORT]
+
+options:
+ -h, --help show this help message and exit
+ --url URL, -u URL the url to the page containing the images
+ --method METHOD, -m METHOD
+ the method to use. either fsrcnn or espcn
+ --port PORT, -p PORT the port to serve the images over
+```
+
+## Install and Run
+
+### Install
+```sh
+poetry install
+```
+
+### Run
+```sh
+poetry shell && HTTPS_PROXY=socks5h://127.0.0.1:9094 ./magni.py --url https://chapmanganato.com/manga-dt980702/chapter-184
+```
+you can obviously use `poetry run` as well:
+```sh
+HTTPS_PROXY=socks5h://127.0.0.1:9094 poetry run ./magni.py --url https://chapmanganato.com/manga-dt980702/chapter-184
```
-## Notes
-* `magni` can use a socks5 proxy as is displayed in the above example.</br>
+## Env Vars
+magni recognizes three environment variables:</br>
+
+### HTTPS_PROXY
+You must specify a socks5 proxy here since magni uses `pysocks` to make the connections.</br>
+If the env var is not defined magni will not use any proxy.</br>
+
+### MAGNI_MODEL_PATH
+Path to the directory where magni will store the model.</br>
+If the env var is not defined, magni will use `./models` as a default value.</br>
+
+### MAGNI_IMAGE_PATH
+Path to the directory where magni will store the upscaled images.</br>
+If the env var is not defined or empty magni will use `./images` as a default value.</br>
+
+## TODO
* currently the models we are using are not as effective. I should either fine ones that are specifically trained on greyscale images or just train some myself.</br>
diff --git a/magni.py b/magni.py
index 3c9d12e..146a758 100755
--- a/magni.py
+++ b/magni.py
@@ -1,6 +1,5 @@
#!/usr/bin/env python
"""Magni."""
-# HTTPS_PROXY=socks5h://127.0.0.1:9094 ./magni.py --url https://chapmanganato.com/manga-dt980702/chapter-184
import argparse
import asyncio
@@ -8,6 +7,7 @@ import concurrent.futures
import http.server
import os
import random
+import secrets
import socketserver
import sys
import typing
@@ -130,7 +130,7 @@ def get_user_agent() -> str:
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
]
- return user_agents[random.randint(0, len(user_agents) - 1)]
+ return user_agents[secrets.randbelow(len(user_agents))]
def get_proxies() -> typing.Dict:
@@ -192,9 +192,7 @@ def multi_get_tag(
# flake8: noqa: E501
-async def model_downloader() -> typing.Optional[
- typing.List[typing.Tuple[str, str]]
-]:
+async def model_downloader() -> typing.Optional[typing.List[typing.Tuple[str, str]]]:
"""Download the models."""
down_list = [
"https://github.com/fannymonori/TF-ESPCN/raw/master/export/ESPCN_x3.pb",
@@ -208,9 +206,7 @@ async def model_downloader() -> typing.Optional[
url_list: typing.List[str] = []
for model in down_list:
if (
- os.path.exists(
- get_model_path() + "/" + model[model.rfind("/") + 1 :]
- )
+ os.path.exists(get_model_path() + "/" + model[model.rfind("/") + 1 :])
is False
):
url_list.append(model)
@@ -223,10 +219,7 @@ async def model_downloader() -> typing.Optional[
] = multi_get_tag(url_tag_list)
model_path: str = os.getcwd()
- if (
- "MAGNI_MODEL_PATH" in os.environ
- and os.environ["MAGNI_MODEL_PATH"] != ""
- ):
+ if "MAGNI_MODEL_PATH" in os.environ and os.environ["MAGNI_MODEL_PATH"] != "":
model_path = os.environ["MAGNI_MODEL_PATH"]
if response_list is None: