# Path: chirp/common/mp3_frame.py
# _READ_SIZE = 4 << 10  # 4k
# _DEAD_AIR_DATA = (
#     "\xff\xfa\x80\x48\x80\x3d\x00\x00\x02\x5f\x09\x4f\x79\x26\x31\x20"
#     "\x4b\x81\x29\xcf\x24\xc2\x24\x09\x94\x23\x3f\xe3\x18\x44\x81\x1f"
#     "\x84\x67\x3c\x92\x8c\x90\x8b\xbb\xab\xaa\x77\x6d\x76\x91\xb4\x54"
#     "\x46\x74\x4e\xa8\xa1\x57\x75\x20\xa3\x8b\x98\xb3\x1e\xd1\xea\x78"
#     "\x71\x86\xd2\x6d\x49\x71\x93\x93\x91\x45\xaa\x38\x73\xe2\xab\x26"
#     "\xd8\xe9\xed\xa1\x0b\xb5\xc5\x6f\x36\xb6\x9f\x16\xba\xc4\x8a\x9e"
#     "\x26\x7d\x75\x54\xf5\xa7\x2c\xb6\x1c\x41\x8a\x75\xf6\xb2\x0d\xac"
#     "\x06\x2e\xd3\x55\x53\x30\xec\xb6\x59\x23\x44\x4b\x4f\x9a\x0f\x1a"
#     "\x07\x03\x22\x38\xf1\xa1\xc3\x80\xc8\x25\x81\xe2\xe8\x11\x15\x87"
#     "\x25\xf2\xeb\x4e\x31\xfd\x41\x6a\xa2\xf5\x20\x28\xbb\x07\x10\x0d"
#     "\xac\xdb\xcb\x29\xe9\x1f\xd8\x86\xd6\xfa\x48\xe8\x1a\xa8\x9a\xeb"
#     "\x90\xe1\xe7\x9e\x28\xe3\xe8\x15\x2f\xc0\x8f\xa5\x22\xd1\x79\x95"
#     "\x75\x50\xcf\xbe\xda\xd8\xcd\x70\x00\xd0\x12\xc0\x21\x41\xc4\xa2"
#     "\x40\xf1\x9c\x10\x9c\x12\xd8\x2a\x94\xcc\xa4\x09\x6c\xe9\x7a\x98"
#     "\xe6\x15\x06\x5e\x96\xcf\x2b\xd6\xb6\xbb\x16\x68\xd4\xa5\xa2\xdc"
#     "\x4f\x31\x02\xf4\x91\x50\x49\x4f\x58\xc2\xf3\xa6\x49\x0a\xb0\x3f"
#     "\x1e\x2f\xdd\x7a\xca\x3d\xc3\x03\x54\x1b\x6a\xa9\x0a\x97\x74\x49"
#     "\x24\xb1\xa2\x2b\x8e\x09\x08\x15\x81\xb1\xc4\x02\x82\x44\xa1\x30"
#     "\x10\xc4\x21\xe5\x92\xb9\xfa\x49\xa0\x9a\xec\xf5\xbc\x51\x62\xe3"
#     "\xd3\x60\x55\xac\x78\x77\x27\x4d\xe6\xda\x80\x71\x76\x54\x93\x2f"
#     "\x52\xe0\x0f\xa9\xee\xb1\x54\x86\x0b\x2d\xf6\xd5\x53\x9a\x2d\x9c"
#     "\x72\x90\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
#     "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
# _DEAD_AIR_DURATION_MS = mp3_header._SAMPLES_PER_FRAME / 44.1
# def split(file_obj, expected_hdr=None):
#     def block_generator():
# def split_blocks(block_iter, expected_hdr=None):
# def split_one_block(data, expected_hdr=None):
# def dead_air(approximate_duration_ms):


import cStringIO
import hashlib
import os
from chirp.common import mp3_frame


# TODO(trow): Some of the validity checks in this function might be
# too strict.
def analyze(file_obj, au_file, compute_fingerprint=True, get_payload=True):
    """Populate an AudioFile object with information extracted from a file.

    Args:
      file_obj: A file-like object.
      au_file: An AudioFile object to store the results of the analysis in.
      compute_fingerprint: If False, do not compute a fingerprint.

    Returns:
      The same AudioFile object that was passed in as au_file, which
      should now have several fields set.

    Raises:
      InvalidFileError: if the file appears to be corrupted.
    """
    au_file.frame_count = 0
    au_file.frame_size = 0
    au_file.duration_ms = 0
    sha1_calc = hashlib.sha1()  # unused if compute_fingerprint is False.
    payload = cStringIO.StringIO()  # unused if get_payload is False.

    bit_rate_kbps_sum = 0
    expected_hdr = None
    first_bit_rate_kbps = None
    is_vbr = False


# Path: chirp/common/mp3_frame.py
# _READ_SIZE = 4 << 10  # 4k
# _DEAD_AIR_DATA = (
#     "\xff\xfa\x80\x48\x80\x3d\x00\x00\x02\x5f\x09\x4f\x79\x26\x31\x20"
#     "\x4b\x81\x29\xcf\x24\xc2\x24\x09\x94\x23\x3f\xe3\x18\x44\x81\x1f"
#     "\x84\x67\x3c\x92\x8c\x90\x8b\xbb\xab\xaa\x77\x6d\x76\x91\xb4\x54"
#     "\x46\x74\x4e\xa8\xa1\x57\x75\x20\xa3\x8b\x98\xb3\x1e\xd1\xea\x78"
#     "\x71\x86\xd2\x6d\x49\x71\x93\x93\x91\x45\xaa\x38\x73\xe2\xab\x26"
#     "\xd8\xe9\xed\xa1\x0b\xb5\xc5\x6f\x36\xb6\x9f\x16\xba\xc4\x8a\x9e"
#     "\x26\x7d\x75\x54\xf5\xa7\x2c\xb6\x1c\x41\x8a\x75\xf6\xb2\x0d\xac"
#     "\x06\x2e\xd3\x55\x53\x30\xec\xb6\x59\x23\x44\x4b\x4f\x9a\x0f\x1a"
#     "\x07\x03\x22\x38\xf1\xa1\xc3\x80\xc8\x25\x81\xe2\xe8\x11\x15\x87"
#     "\x25\xf2\xeb\x4e\x31\xfd\x41\x6a\xa2\xf5\x20\x28\xbb\x07\x10\x0d"
#     "\xac\xdb\xcb\x29\xe9\x1f\xd8\x86\xd6\xfa\x48\xe8\x1a\xa8\x9a\xeb"
#     "\x90\xe1\xe7\x9e\x28\xe3\xe8\x15\x2f\xc0\x8f\xa5\x22\xd1\x79\x95"
#     "\x75\x50\xcf\xbe\xda\xd8\xcd\x70\x00\xd0\x12\xc0\x21\x41\xc4\xa2"
#     "\x40\xf1\x9c\x10\x9c\x12\xd8\x2a\x94\xcc\xa4\x09\x6c\xe9\x7a\x98"
#     "\xe6\x15\x06\x5e\x96\xcf\x2b\xd6\xb6\xbb\x16\x68\xd4\xa5\xa2\xdc"
#     "\x4f\x31\x02\xf4\x91\x50\x49\x4f\x58\xc2\xf3\xa6\x49\x0a\xb0\x3f"
#     "\x1e\x2f\xdd\x7a\xca\x3d\xc3\x03\x54\x1b\x6a\xa9\x0a\x97\x74\x49"
#     "\x24\xb1\xa2\x2b\x8e\x09\x08\x15\x81\xb1\xc4\x02\x82\x44\xa1\x30"
#     "\x10\xc4\x21\xe5\x92\xb9\xfa\x49\xa0\x9a\xec\xf5\xbc\x51\x62\xe3"
#     "\xd3\x60\x55\xac\x78\x77\x27\x4d\xe6\xda\x80\x71\x76\x54\x93\x2f"
#     "\x52\xe0\x0f\xa9\xee\xb1\x54\x86\x0b\x2d\xf6\xd5\x53\x9a\x2d\x9c"
#     "\x72\x90\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
#     "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
# _DEAD_AIR_DURATION_MS = mp3_header._SAMPLES_PER_FRAME / 44.1
# def split(file_obj, expected_hdr=None):
#     def block_generator():
# def split_blocks(block_iter, expected_hdr=None):
# def split_one_block(data, expected_hdr=None):
# def dead_air(approximate_duration_ms):


# Path: chirp/library/analyzer.py
import cStringIO
import hashlib
import os
from chirp.common import mp3_frame



# TODO(trow): Some of the validity checks in this function might be
# too strict.
def analyze(file_obj, au_file, compute_fingerprint=True, get_payload=True):
    """Populate an AudioFile object with information extracted from a file.

    Args:
      file_obj: A file-like object.
      au_file: An AudioFile object to store the results of the analysis in.
      compute_fingerprint: If False, do not compute a fingerprint.

    Returns:
      The same AudioFile object that was passed in as au_file, which
      should now have several fields set.

    Raises:
      InvalidFileError: if the file appears to be corrupted.
    """
    au_file.frame_count = 0
    au_file.frame_size = 0
    au_file.duration_ms = 0
    sha1_calc = hashlib.sha1()  # unused if compute_fingerprint is False.
    payload = cStringIO.StringIO()  # unused if get_payload is False.

    bit_rate_kbps_sum = 0
    expected_hdr = None
    first_bit_rate_kbps = None
    is_vbr = False


    for hdr, data_buffer in mp3_frame.split(file_obj):