#!/usr/bin/env python3
"""size-table.py: file size at YouTube's recommended SDR upload bit rates (read 2026-10-30,
https://support.google.com/youtube/answer/1722171) and which upload limit (256 GB or 12 hours) is reached first.
Formula: bytes = (video bps + audio bps) * seconds / 8. Size columns use MB = 1,048,576 bytes and GB = 2^30 bytes,
the same convention as the Koldflux video file size calculator. The 256 GB limit is tested both ways (10^9 and 2^30 bytes).
Audio: stereo 384 kbps (YouTube's stereo recommendation)."""
AUDIO = 384_000
ROWS = [  # label, standard-fps Mbps (low, high), high-fps Mbps (low, high)
    ('2160p (4K)', (35, 45), (53, 68)), ('1440p', (16, 16), (24, 24)), ('1080p', (8, 8), (12, 12)),
    ('720p', (5, 5), (7.5, 7.5)), ('480p', (2.5, 2.5), (4, 4)), ('360p', (1, 1), (1.5, 1.5)),
    ('8K (4320p)', (80, 160), (120, 240))]
def size(mbps, secs): return (mbps * 1e6 + AUDIO) * secs / 8
def fmt(b):
    return f'{b/2**20:,.0f} MB' if b < 2**30 else f'{b/2**30:,.2f} GB'
print('label | tier | Mbps | per minute | per 10 minutes | per hour | 12 hours | which limit comes first')
LIM_B = 256 * 10**9
LIM_S = 12 * 3600
for label, std, hi in ROWS:
    for tier, (lo, hh) in (('24-30 fps', std), ('48-60 fps', hi)):
        for m in sorted({lo, hh}):
            b12 = size(m, LIM_S)
            if (b12 > LIM_B) != (b12 > 256 * 2**30):
                first = 'DEPENDS ON GB DEFINITION'
            elif b12 > LIM_B:
                secs = LIM_B * 8 / (m * 1e6 + AUDIO); secs2 = 256 * 2**30 * 8 / (m * 1e6 + AUDIO)
                first = f'256 GB first, after {secs/3600:.2f} h if GB = 10^9 bytes, {secs2/3600:.2f} h if GB = 2^30 bytes'
            else:
                first = f'12 hours first (file {b12/2**30:.1f} GB)'
            print(f'{label} | {tier} | {m:g} | {fmt(size(m,60))} | {fmt(size(m,600))} | {fmt(size(m,3600))} | {fmt(b12)} | {first}')
# GB versus GiB: does the answer change for 1080p 8 Mbps and 4K 45 Mbps?
for m in (8, 45, 160):
    for name, lim in (('256 GB (10^9)', 256 * 10**9), ('256 GiB (2^30)', 256 * 2**30)):
        print(f'{m} Mbps + 384 kbps audio: time to reach {name} = {lim*8/(m*1e6+AUDIO)/3600:.3f} h (12 h cap applies if larger)')
# control: 8 Mbps + 384 kbps for exactly 10 s must be (8,384,000 * 10 / 8) = 10,480,000 bytes
c = size(8, 10); print('CONTROL 8 Mbps + 384 kbps for 10 s =', int(c), 'bytes; expected 10480000;', 'PASS' if int(c) == 10480000 else 'FAIL')
