Skip to content

Instantly share code, notes, and snippets.

@lambdan
Last active January 4, 2025 13:38
Show Gist options
  • Save lambdan/401f9124ea49eede146cf7e8dc6f28d4 to your computer and use it in GitHub Desktop.
Save lambdan/401f9124ea49eede146cf7e8dc6f28d4 to your computer and use it in GitHub Desktop.
Myrient: Calculate size of folder
# usage:
# python3 myrient_size.py URL
# OR
# python3 myrient_size.py URLS.txt
# (where URLS.txt contains 1 URL per line)
from bs4 import BeautifulSoup
import sys, requests
import urllib.parse
def size_to_bytes(size_str):
size, unit = size_str.split(" ")
size = float(size)
if unit == "GiB":
return size * (2**30)
elif unit == "MiB":
return size * (2**20)
elif unit == "KiB":
return size * (2**10)
elif unit == "B":
return size;
else:
raise ValueError(f"Unknown size unit: {unit}")
def urlDecode(s):
return urllib.parse.unquote(s)
def fromURL(url):
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
elements = soup.find_all("td", class_="size")
totalB = 0
for e in elements:
if e.text == "-":
continue
totalB += size_to_bytes(e.text)
totalGiB = totalB / (2**30)
folder_name = urlDecode(url.split("/")[-2])
print(f"{folder_name}: {totalGiB:.2f} GiB")
return totalB
def fromURLS(fp):
lines = []
with open(fp, 'r') as f:
lines = f.readlines()
totalB = 0
for l in lines:
l = l.strip()
if l == "":
continue
if l.startswith("#"):
continue
if l.startswith("//"):
continue
totalB += fromURL(l)
totalTiB = totalB / (2**40)
print(f"Total: {totalTiB:.3f} TiB")
return totalB
if sys.argv[1].startswith("http"):
fromURL(sys.argv[1])
else:
fromURLS(sys.argv[1])
@lambdan
Copy link
Author

lambdan commented Jan 4, 2025

Example using single URL:

$ python3 myrient_size.py "https://myrient.erista.me/files/No-Intro/Sega%20-%20Mega%20Drive%20-%20Genesis/"
Sega - Mega Drive - Genesis: 2.14 GiB

Example using list of URLs:

$ cat urls.txt
https://myrient.erista.me/files/No-Intro/Nintendo%20-%20Nintendo%20Entertainment%20System%20%28Headered%29/
https://myrient.erista.me/files/No-Intro/Nintendo%20-%20Super%20Nintendo%20Entertainment%20System/
https://myrient.erista.me/files/No-Intro/Nintendo%20-%20Nintendo%2064%20%28BigEndian%29/
https://myrient.erista.me/files/No-Intro/Nintendo%20-%20Game%20Boy/
https://myrient.erista.me/files/No-Intro/Nintendo%20-%20Game%20Boy%20Color/
https://myrient.erista.me/files/No-Intro/Nintendo%20-%20Game%20Boy%20Advance/
https://myrient.erista.me/files/Redump/Nintendo%20-%20GameCube%20-%20NKit%20RVZ%20%5Bzstd-19-128k%5D/
https://myrient.erista.me/files/Redump/Nintendo%20-%20Wii%20-%20NKit%20RVZ%20%5Bzstd-19-128k%5D/
https://myrient.erista.me/files/Redump/Nintendo%20-%20Wii%20U%20-%20WUX/
https://myrient.erista.me/files/Redump/Sony%20-%20PlayStation/
https://myrient.erista.me/files/Redump/Sony%20-%20PlayStation%202/
https://myrient.erista.me/files/Redump/Sony%20-%20PlayStation%203/
https://myrient.erista.me/files/Redump/Microsoft%20-%20Xbox/
https://myrient.erista.me/files/Redump/Microsoft%20-%20Xbox%20360/
https://myrient.erista.me/files/No-Intro/Sega%20-%20Mega%20Drive%20-%20Genesis/
https://myrient.erista.me/files/Redump/Sega%20-%20Mega%20CD%20%26%20Sega%20CD/
https://myrient.erista.me/files/Redump/Sega%20-%20Saturn/
https://myrient.erista.me/files/Redump/Sega%20-%20Dreamcast/

$ python3 myrient_size.py urls.txt
Nintendo - Nintendo Entertainment System (Headered): 1.11 GiB
Nintendo - Super Nintendo Entertainment System: 3.49 GiB
Nintendo - Nintendo 64 (BigEndian): 14.02 GiB
Nintendo - Game Boy: 0.23 GiB
Nintendo - Game Boy Color: 0.94 GiB
Nintendo - Game Boy Advance: 13.32 GiB
Nintendo - GameCube - NKit RVZ [zstd-19-128k]: 1499.75 GiB
Nintendo - Wii - NKit RVZ [zstd-19-128k]: 6001.84 GiB
Nintendo - Wii U - WUX: 3743.25 GiB
Sony - PlayStation: 3017.84 GiB
Sony - PlayStation 2: 16332.55 GiB
Sony - PlayStation 3: 33415.12 GiB
Microsoft - Xbox: 15271.47 GiB
Microsoft - Xbox 360: 21220.16 GiB
Sega - Mega Drive - Genesis: 2.14 GiB
Sega - Mega CD & Sega CD: 176.11 GiB
Sega - Saturn: 783.54 GiB
Sega - Dreamcast: 758.70 GiB
Total: 99.859 TiB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment