Skip to content

Commit

Permalink
hotfix to 0.9.7
Browse files Browse the repository at this point in the history
  • Loading branch information
RaSan147 committed Nov 20, 2024
1 parent 35f8bce commit e4ec6b4
Show file tree
Hide file tree
Showing 27 changed files with 275 additions and 164 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Version 0.9.7
## HOTFIX:
* Fixed requests requirement in the list
* **Server** In init and main, removed the import of the submodules
* **Server** Added folder size limit for zip (default 6GB)

# Version 0.9.6
## Client-side Changes:
* Fixed Logout button in account (No more Sword Art Online)
Expand All @@ -13,7 +19,7 @@
* **Server:** Improved security (naming files and renaming)
* **Server:** Added QR support (needs implementation)
* **Server:** Updated and improved database package (pyroDB) with improved speed and application
* **Server:** Added 7z support (if installed in device)
* **Server:** Added 7z support (if installed in device) (searches for common locations)
* **Server:** Added QR code for easy access to the server (from terminal -q)

## Fixes:
Expand Down Expand Up @@ -198,7 +204,7 @@
* `TODO`: To change log level, use `--log-level` or `-l` flag
* To change log level programmatically, use `pyroboxCore.logger.setLevel(logging.DEBUG|INFO|WARN|ERROR)`
* REMOVED `pyrobox.clone` module (stil available in `dev_src` folder)
* The Entire server is now using `@SimpleHTTPRequestHandler.on_req` decorator importing from pyroboxCore to handle requests
* The Entire server is now using `@SimpleHTTPRequestHandler.on_req` decorator importing from pyroboxCore to handle requests
### check v0.6.1 for more info
* added send_file function to pyroboxCore
* improved POST request handling
Expand Down
41 changes: 27 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
* 🔜 More comming soon
* All of these without the need of any internet connection (having connection will provide better experience)


## Server side requirement

* Python 3.7 or higher. Older support available.[^1]
Expand Down Expand Up @@ -81,27 +82,27 @@ https://github.com/RaSan147/pyrobox/assets/34002411/eb2ac313-f95a-4334-a265-c3fe
1. Simply running the code on will create a server on `CURRENT WORKING DIRECTORY` on `Port: 6969`
1. On browser (on device under same router/wifi network), go to `deviceIP:port_number` to see the output like this: `http://192.168.0.101:6969/`
* you must allow python in firewall to access network, check [FAQ](#faq) for more help
1. To change the server running directory,
* i) either edit the code (see `config` class at top)
* ii) or add `-d` or `--directory` command line argument when launching the program
1. To change the server running directory,
* (i) either edit the code (see `config` class at top)
* (ii) or add `-d` or `--directory` command line argument when launching the program
* `pyrobox -d .` to launch the server in current directory (where the file is)
* `pyrobox -d "D:\Server\Public folder\"` (Use Double-Quotation while directory has space)
* `pyrobox -d "D:/Server/Public folder"` (Forward or backward slash really doesn't matter, unless your terminal thinks otherwise)
1. To change port number
* i) just edit the code for permanent change (see `config` class at top)
* ii) or add the port number at the end of the command line arg
* (i) just edit the code for permanent change (see `config` class at top)
* (ii) or add the port number at the end of the command line arg
* `pyrobox 45678` # will run on port 45678
* `pyrobox -d . 45678` # will run on port 45678 in current directory

1. To specify alternate bind address
* Add bind add `-bind {address}` # ie: `-bind 127.0.0.2` or `-bind 127.0.0.99`

1. To change upload password
* i) or add `-k` or `--password` command line argument when launching the program
* (i) or add `-k` or `--password` command line argument when launching the program
* `pyrobox -k "my new password"` to launch the server with new password
* `pyrobox -k ""` to launch the server without password
* `pyrobox` to launch the server with default password (SECret)
* ii) just edit the code for permanent change (see `config` class at top)
* (ii) just edit the code for permanent change (see `config` class at top)

1. Optional configurations

Expand All @@ -117,12 +118,13 @@ usage: `pyrobox [--password PASSWORD] [--no-upload] [--no-zip] [--no-update] [--

| Flags/Arg `value` | Description |
| --------------------- | ------------|
|--password `PASSWORD`, -k `PASSWORD` | Upload Password (GUESTS users and Nameless server users must use it to upload files)(default: SECret)|
|--password `PASSWORD`, -k `PASSWORD` | Upload Password (GUESTS users and Nameless server users must use it to upload files)(default: `SECret`)|
|--directory `DIRECTORY`, -d `DIRECTORY` | Specify alternative directory [default: current directory]
|--bind `ADDRESS`, -b `ADDRESS` | Specify alternate bind address [default: all interfaces]|
|--bind `ADDRESS`, -b `ADDRESS` | Specify alternate bind address [default: all interfaces (`0.0.0.0`)]|
|--version, -v | show program's version number and exit|
|-h, --help | show this help message and exit|
|--no-extra-log | Disable file path and [= + - #] based logs (default: False)|
|--zip-limit, -zl `ZIP_LIMIT` | Set the limit of zip file size in bytes/KB/MB/GB/TB (default: `6GB`)|

## Customization Options

Expand Down Expand Up @@ -155,12 +157,23 @@ usage: `pyrobox [--password PASSWORD] [--no-upload] [--no-zip] [--no-update] [--
1. `pyrobox -n "My Server3" -aid "admin" -ak "admin123" -ng -ns` # Only admin can access the server. No guest allowed, no signup allowed. Admin can add user from admin page


## Clone Directory

1. Make a python file with the following code
``` python
from pyrobox import clone
clone.main()
```
1. Run the file. Follow the instructions.
1. For advanced use, check the source code of `clone.py` in the `pyrobox` module.


## TODO

* https://github.com/RaSan147/pyrobox/issues/33 Show thumbnails, for png and jpg (how to do with just standard library?), For others, just show extension.
* https://github.com/RaSan147/pyrobox/issues/34 Copy stream URL for videos to play with any video player
* https://github.com/RaSan147/pyrobox/issues/36 Add side bar to do something 🤔
* check output ip and port accuracy on multiple os
* check output ip and port accuracy on multiple os
* https://github.com/RaSan147/pyrobox/issues/37 Backup code if Reload causes unhandled issue and can't be accessed
* Add more flags to disable specific features

Expand All @@ -177,7 +190,7 @@ usage: `pyrobox [--password PASSWORD] [--no-upload] [--no-zip] [--no-update] [--
<summary>Using WSL, "PIP not found"</summary>

> Run this to install `pip3` and add `pip` to path
``` bash
sudo apt -y purge python3-pip
sudo python3 -m pip uninstall pip
Expand Down Expand Up @@ -206,19 +219,19 @@ usage: `pyrobox [--password PASSWORD] [--no-upload] [--no-zip] [--no-update] [--
<details>
<summary>Deleted (Move to Recycle), But WHERE ARE THEY?? [on LINUX & WSL]</summary>

> Actually the feature is working fine, unfortunately NO-GUI mode linux and WSL don't recycle bin, so you can't find it!
> And to make things worse, **you need to manually clear the recyle bin** from `~/.local/share/Trash`
> **SO I'D RECOMMAND USING DELETE PARMANENTLY**
</details>
<details>
<summary>Running on WINDOWS, but can't access with other device [FIREWALL]</summary>

> You probably have **FireWall ON** and not configured.
> For your safety, I'd recommend you to allow Python on private network and run the server when your network is Private.
> IN SHORT: ALLOW PYTHON ON FIREWALL, RUN THE SERVER
> *note: allowed on private but using public network on firewall will cause similar issue, you gotta make both same or allow python both on public and private*
</details>
Expand Down
2 changes: 1 addition & 1 deletion SECURITY PLAN.MD
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
------

## stream-url:
Users can create stream-url . This will **allow nonblocking access to the file** and file only. So, anyone with force flag need to use stream-url to download file with IDM or stream .mkv file on VLC .
Users can create stream-url . This will **allow nonblocking access to the file** and file only. So, anyone with force flag need to use stream-url to download file with IDM or stream .mkv file on VLC .

**Format:** `/stream?id=(5alphanumerical)` [60M links]

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.6
0.9.7
15 changes: 10 additions & 5 deletions dev_src/_arg_parser.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# add additional arguments to the parser

config = None
# the config must be imported from pyroboxCore
# from pyroboxCore import config
if __name__ == "__main__":
from pyroboxCore import config


def main(config):
def main(config=config):
config.parser.add_argument('--password', '-k',
default=config.PASSWORD,
type=str,
help='[Value] Upload Password (default: %(default)s)')



config.parser.add_argument('--qr', '-q',
Expand Down Expand Up @@ -90,4 +92,7 @@ def main(config):
default=False,
help="[Flag] Only allowed to see file list, nothing else (default: %(default)s)")


config.parser.add_argument('--zip-limit', '-zl',
default="6GB",
type=str,
help='[Value] Max size of zip file allowed to download (default: %(default)s) [can be bytes without suffix or suffixes like 1KB, 1MB, 1GB, 1TB]')
37 changes: 33 additions & 4 deletions dev_src/_fs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import time
import traceback
import urllib.parse
from tools import os_scan_walk, xpath
from tools import os_scan_walk_gen, xpath

from _exceptions import LimitExceed

Expand Down Expand Up @@ -77,7 +77,7 @@ def walk_dir(*path, yield_dir=False):
yield_dir (bool): if True yields directories too (default: False)
"""

for f in os_scan_walk(*path, allow_dir=yield_dir):
for f in os_scan_walk_gen(*path, allow_dir=yield_dir):
yield f


Expand Down Expand Up @@ -281,6 +281,35 @@ def humanbytes(B: int):

return ret

def reverse_humanbytes(human_str:str):
"""
Converts human readable size to bytes
"""
human_str = human_str.strip().lower()

if human_str.endswith('bytes'):
return int(human_str[:-5].strip())
if human_str.endswith('byte'):
return int(human_str[:-4].strip())

if human_str.endswith('b'):
human_str = human_str[:-1].strip()

if human_str.endswith('k'):
return int(float(human_str[:-1].strip()) * 1024)

if human_str.endswith('m'):
return int(float(human_str[:-1].strip()) * 1024**2)

if human_str.endswith('g'):
return int(float(human_str[:-1].strip()) * 1024**3)

if human_str.endswith('t'):
return int(float(human_str[:-1].strip()) * 1024**4)

return int(human_str)


def get_dir_m_time(path):
"""
Get the last modified time of a directory and all its subdirectories.
Expand Down Expand Up @@ -492,7 +521,7 @@ def _start(self, server:"ServerHost"):
self.err(f"Failed to upload {os_fn}")

break

else:
self.waited += 1
self.sleep()
Expand All @@ -503,7 +532,7 @@ def _start(self, server:"ServerHost"):
def kill(self):
self.active = False
self.done = True

for f in tuple(self.serial_io.queue):
name = f[0].name
if not f[0].closed:
Expand Down
14 changes: 7 additions & 7 deletions dev_src/_sub_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ def extract_subtitles_from_file(input_file, output_format="vtt", output_dir=None
"""
output_paths = []
sub_names = []

if not os.path.isfile(input_file):
raise FileNotFoundError(f"The file '{input_file}' does not exist.")

if not FFMPEG:
# we don't want to raise an exception here, just return an empty list
return []

try:
# Run ffmpeg to analyze the file
process = subprocess.run(
Expand All @@ -36,7 +36,7 @@ def extract_subtitles_from_file(input_file, output_format="vtt", output_dir=None
text=True
)
output = process.stderr # ffmpeg logs info in stderr

# Extract stream information (Subtitle streams)
# Example: Stream #0:1(eng): Subtitle: dvd_subtitle
stream_pattern = re.compile(
Expand All @@ -52,7 +52,7 @@ def extract_subtitles_from_file(input_file, output_format="vtt", output_dir=None
sub_name = f"{sub_name}_{n}"
else:
sub_name = f"subtitle_{n}"

sub_names.append(sub_name)
n += 1

Expand All @@ -77,16 +77,16 @@ def extract_subtitles_from_file(input_file, output_format="vtt", output_dir=None
os.makedirs(output_dir, exist_ok=True) # Create the output directory if it doesn't exist

output_filename = f"{os.path.splitext(input_file)[0]}_{sub_name}.{output_format}"

# Generate output path
output_paths.append((sub_name, output_filename))

# Use ffmpeg to extract the audio stream
subprocess.run(
[FFMPEG, "-i", input_file, "-map", stream_index, '-y', output_filename],
check=True
)

return output_paths

except subprocess.CalledProcessError as e:
Expand Down
4 changes: 2 additions & 2 deletions dev_src/_zipfly_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@



from _fs_utils import get_dir_m_time, _get_tree_path_n_size
from _fs_utils import get_dir_m_time, _get_tree_path_n_size, humanbytes
from _exceptions import LimitExceed


Expand Down Expand Up @@ -535,7 +535,7 @@ def err(msg):
try:
fs = _get_tree_path_n_size(path, must_read=True, path_type="both", limit=self.size_limit, add_dirs=True)
except LimitExceed as e:
return err("DIRECTORY SIZE LIMIT EXCEED")
return err(f"DIRECTORY SIZE LIMIT EXCEED [CURRENT LIMIT: {humanbytes(self.size_limit)}]")
source_size = sum(i[1] for i in fs)
fm = [i[0] for i in fs]
source_m_time = get_dir_m_time(path)
Expand Down
18 changes: 12 additions & 6 deletions dev_src/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def check_exist(url, path, check_method):

if local_last_modify == original_modify and check_method == "date":
return True

if local_last_modify >= original_modify and check_method == "date+":
return True

Expand Down Expand Up @@ -126,7 +126,7 @@ def dl(url, path, overwrite, check_method):
CANCEL = True
os.remove(local_filename)
return False

except Exception:
traceback.print_exc()
print("ALERT: [dl] Server is probably down")
Expand Down Expand Up @@ -159,7 +159,7 @@ def clone(self, url, path = "./", overwrite = False, check_exist = "date", delet
"""
if url[-1] != "/":
url += "/"

Q = Queue()
def get_json(url):

Expand All @@ -178,7 +178,7 @@ def run_Q(url, path = "./", overwrite = False, check_exist = "date", delete_extr

if path[-1] != "/":
path += "/"

os.makedirs(path, exist_ok=True) # make sure the directory exists even if it's empty

json = get_json(url)
Expand Down Expand Up @@ -236,7 +236,7 @@ def run_Q(url, path = "./", overwrite = False, check_exist = "date", delete_extr



if __name__ == "__main__":
def main():
url = input("URL: ")
path = input("Save to: ")

Expand All @@ -248,7 +248,11 @@ def run_Q(url, path = "./", overwrite = False, check_exist = "date", delete_extr
check_exist = "date+"
o = None
while not o:
o = input("Check exist? (date/date+/size) [Default: date+]: ")
o = input("""Check exist? [Default: date+]
date: download if remote file is update time same as local file
date+: download if remote file is newer or same as local file (ignored if local file is newer)
size: download if remote file size is different from local file
>>> """)
if o in ["date", "date+", "size"]:
check_exist = o
else:
Expand All @@ -271,3 +275,5 @@ def run_Q(url, path = "./", overwrite = False, check_exist = "date", delete_extr
for future in as_completed(cloner.futures):
bool(future.result())

if __name__ == "__main__":
main()
Loading

0 comments on commit e4ec6b4

Please sign in to comment.