Update cmd_wdir.py

This commit is contained in:
m5rcel { Marcel }
2025-09-09 17:22:34 +02:00
committed by GitHub
parent 036ebf99ea
commit 0c6c414cdf

View File

@@ -1,7 +1,8 @@
import requests
from bs4 import BeautifulSoup
from urllib.parse import urljoin, urlparse
from urllib.parse import urljoin
from colorama import Fore, Style
import re
class WdirCommand:
def __init__(self, url):
@@ -12,7 +13,7 @@ class WdirCommand:
print(Fore.RED + "Usage: wdir <url>" + Style.RESET_ALL)
return
# Ensure URL has scheme
# Ensure scheme
if not self.url.startswith("http://") and not self.url.startswith("https://"):
self.url = "http://" + self.url
@@ -37,22 +38,34 @@ class WdirCommand:
if href.startswith("?") or href.startswith("#") or href == "../":
continue
full_url = urljoin(self.url, href)
filename = href.split("/")[-1]
full_url = urljoin(self.url, href)
# Determine file type
# Guess type
if "." in filename:
ext = filename.split(".")[-1].lower()
ftype = f".{ext} file"
else:
ftype = "Directory"
files.append((filename, ftype, full_url))
# Try to extract file size and modified date from raw HTML
row_text = link.parent.get_text(" ", strip=True)
size_match = re.search(r"(\d+(?:\.\d+)?\s*(?:KB|MB|GB|B))", row_text, re.I)
date_match = re.search(r"(\d{4}-\d{2}-\d{2} \d{2}:\d{2})", row_text)
size = size_match.group(1) if size_match else "?"
modified = date_match.group(1) if date_match else "?"
files.append((filename, ftype, size, modified, full_url))
if not files:
print(Fore.YELLOW + "No files or directories found (maybe directory listing is disabled)." + Style.RESET_ALL)
return
print(Fore.GREEN + "\nFiles found:" + Style.RESET_ALL)
for fname, ftype, furl in files:
print(f" {Fore.CYAN}{fname:<30}{Style.RESET_ALL} {Fore.WHITE}{ftype}{Style.RESET_ALL}")
print(Fore.MAGENTA + f"{'Name':<30}{'Type':<15}{'Size':<12}{'Modified':<20}" + Style.RESET_ALL)
print(Fore.MAGENTA + "-" * 77 + Style.RESET_ALL)
for fname, ftype, size, modified, furl in files:
print(f"{Fore.CYAN}{fname:<30}{Style.RESET_ALL} "
f"{Fore.WHITE}{ftype:<15}{size:<12}{modified:<20}{Style.RESET_ALL}")