"""Bit-budget arithmetic, no MP3 parser, encoder or duration detector."""
from fractions import Fraction as F
import json
if __name__=='__main__':
    segments=[(F(2),64000),(F(2),192000)]
    seconds=sum(t for t,b in segments);bits=sum(t*b for t,b in segments)
    audio_bytes=bits/8;average=bits/seconds
    wrong_first_rate=bits/segments[0][1]
    metadata_bytes=12000;wrong_whole_file=(bits+8*metadata_bytes)/segments[0][1]
    assert seconds==4 and bits==512000 and audio_bytes==64000 and average==128000
    assert wrong_first_rate==8 and wrong_whole_file==F(19,2)
    assert bits/average==seconds
    print(json.dumps({'true_constructed_seconds':float(seconds),'audio_bytes':int(audio_bytes),'average_bits_per_second':int(average),'wrong_first_rate_seconds':float(wrong_first_rate),'wrong_whole_file_seconds':float(wrong_whole_file),'actual_mp3_processed':False},indent=2))
