#!/usr/bin/env python3
"""Derived numbers quoted on the video podcast file size page (Koldflux, 2026-12-01). Pure arithmetic, no files read.
Usage: python3 derive.py"""
GB, GIB = 1e9, 2 ** 30
def gb(kbps, s):
    return kbps * 1000 * s / 8 / GB
print("rule check: 8384 kbps x 0.00045 =", round(8384 * 0.00045, 2), "GB per hour")
for kbps, name in ((8384, "YouTube 1080p30"), (5384, "YouTube 720p30"), (45384, "YouTube 4K30 high"), (25128, "Spotify 1080p")):
    print(f"{name}: hours in 1 TB (1,000 GB decimal) = {1000 / gb(kbps, 3600):.1f}; 75 min = {gb(kbps, 4500):.2f} GB")
for kbps, name in ((25128, "Spotify 1080p"), (35128, "Spotify 4K")):
    print(f"{name}: 4 h = {gb(kbps, 14400):.2f} GB (Spotify accepts up to 60 GB, recommends less than 4 hours)")
for mbps in (20, 50, 100):
    print(f"upload of 3.77 GB (1080p30 hour) at {mbps} Mbps, no overhead: {3.77e9 * 8 / (mbps * 1e6) / 60:.1f} min; "
          f"20.42 GB (4K high hour): {20.42e9 * 8 / (mbps * 1e6) / 60:.1f} min")
for kbps, name in ((45384, "YouTube 4K30 high 45000+384"), (53384, "YouTube 4K60 low 53000+384"), (68384, "YouTube 4K60 high 68000+384"),
                   (44384, "YouTube HDR 4K30 low 44000+384"), (56384, "YouTube HDR 4K30 high 56000+384")):
    print(f"{name}: 256 GB reached after {256 / gb(kbps, 3600):.2f} h; 12 h = {gb(kbps, 43200):.2f} GB "
          f"({'256 GB first' if gb(kbps, 43200) > 256 else '12 hours first'})")
print(f"YouTube 256 GB in 12 h equals {256e9 * 8 / 43200 / 1000:,.0f} kbps in total")
print(f"  = {256e9 * 8 / 43200 / 1000 - 384:,.0f} kbps of video with 384 kbps audio (HDR 4K30 range 44,000-56,000 crosses it)")
print(f"4K vs 1080p at platform bitrates: {gb(35384, 3600) / gb(8384, 3600):.2f}x to {gb(45384, 3600) / gb(8384, 3600):.2f}x")
print(f"1 TB drive in Windows units: {1e12 / GIB:.1f} GB; GiB/GB factor {GB / GIB:.4f}")
print(f"audio 384 vs 128 kbps per hour: {gb(256, 3600):.3f} GB = {gb(256, 3600) / gb(8384, 3600) * 100:.1f}% of a 1080p30 hour")
print("decimal GB vs Windows GB (GiB) for the units table:")
for label, b in (("1 h YouTube 1080p30 8000+384", 8384 * 450000), ("75 min measured export", 4.67e9), ("1 h Spotify 1080p 25000+128", 25128 * 450000),
                 ("Spotify recommended 10 GB", 10e9), ("YouTube limit 256 GB", 256e9), ("1 TB drive", 1e12)):
    print(f"  {label}: {b / 1e9:,.2f} GB = {b / 2**30:,.2f} GiB")
# Page rounding of the measured files: pass measure.txt (output of measure.py) as the first argument.
import sys as _sys
if len(_sys.argv) > 1:
    print("measured GB per hour as rounded on the page (from measure.txt):")
    for line in open(_sys.argv[1], encoding="utf-8"):
        p = [x.strip() for x in line.split("|")]
        if len(p) >= 6 and p[0].endswith(".mp4"):
            print(f"  {p[0]}: {int(p[2]) / float(p[1]) * 3600 / 1e9:.2f} GB/h")
