{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import wavinfo\n",
    "import pprint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "pp = pprint.PrettyPrinter(indent=4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "path = '../tests/test_files/protools/PT A101_4.A1.wav'\n",
    "\n",
    "info = wavinfo.WavInfoReader(path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[   ChunkDescriptor(ident=b'bext', start=20, length=858),\n",
      "    ChunkDescriptor(ident=b'iXML', start=886, length=5226),\n",
      "    ChunkDescriptor(ident=b'fmt ', start=6120, length=16),\n",
      "    ChunkDescriptor(ident=b'data', start=6144, length=864840),\n",
      "    ChunkDescriptor(ident=b'umid', start=870992, length=24),\n",
      "    ChunkDescriptor(ident=b'minf', start=871024, length=16),\n",
      "    ChunkDescriptor(ident=b'regn', start=871048, length=92)]\n"
     ]
    }
   ],
   "source": [
    "import wavinfo.wave_parser\n",
    "\n",
    "with open(path,'rb') as f:\n",
    "    chunk_tree = wavinfo.wave_parser.parse_chunk(f)\n",
    "\n",
    "pp.pprint(chunk_tree.children)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00*\\xfd\\xf5\\x0c$\\xe4s\\x80\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'\n",
      "000000000000002afdf50c24e47380000000000000000000\n",
      "24\n"
     ]
    }
   ],
   "source": [
    "with open(path,'rb') as f:\n",
    "    f.seek( chunk_tree.children[4].start )\n",
    "    umid_bin = f.read(chunk_tree.children[4].length)\n",
    "    f.seek( chunk_tree.children[6].start )\n",
    "    regn_bin = f.read(chunk_tree.children[6].length)\n",
    "    \n",
    "print(umid_bin)\n",
    "print(umid_bin.hex())\n",
    "print(len(umid_bin))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<wavinfo.wave_bext_reader.WavBextReader object at 0x10d5f8ac8>\n"
     ]
    }
   ],
   "source": [
    "print(info.bext)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "b'\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00*\\xfd\\xf5\\x0c$\\xe4s\\x80\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x0c3\\x02\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00T\\xd5\\xa2\\x82\\x00\\x00\\x00\\x00\\x10PT A101_4.A1.wavGK\\xaa\\xaf\\x7f\\x00\\x00@ }\\x06\\x00`\\x00\\x00'\n",
      "01000000000000000000002afdf50c24e473800000000000000000000c330200000000000000000000000000000000000000000054d5a2820000000010505420413130315f342e41312e776176474baaaf7f000040207d0600600000\n",
      "92\n"
     ]
    }
   ],
   "source": [
    "\n",
    "print(regn_bin)\n",
    "print(regn_bin.hex())\n",
    "print(len(regn_bin))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{   'artist': 'Frank Bry',\n",
      "    'comment': 'BULLET Impact Plastic LCD TV Screen Shatter Debris 2x',\n",
      "    'copyright': '2018 Creative Sound Design, LLC (The Recordist Christmas '\n",
      "                 '2018) www.therecordist.com',\n",
      "    'created_date': '2018-11-15',\n",
      "    'engineer': None,\n",
      "    'genre': 'Bullets',\n",
      "    'keywords': None,\n",
      "    'product': 'The Recordist Christmas 2018',\n",
      "    'software': 'Soundminer',\n",
      "    'source': None,\n",
      "    'tape': None,\n",
      "    'title': None}\n",
      "{   'coding_history': '',\n",
      "    'description': 'BULLET Impact Plastic LCD TV Screen Shatter Debris 2x',\n",
      "    'loudness_range': None,\n",
      "    'loudness_value': None,\n",
      "    'max_momentary_loudness': None,\n",
      "    'max_shortterm_loudness': None,\n",
      "    'max_true_peak': None,\n",
      "    'originator': 'TheRecordist',\n",
      "    'originator_date': '2018-12-20',\n",
      "    'originator_ref': 'aaiAKt3fCGTk',\n",
      "    'originator_time': '12:15:37',\n",
      "    'time_reference': 57882,\n",
      "    'version': 0}\n"
     ]
    }
   ],
   "source": [
    "path = '../tests/test_files/BULLET Impact Plastic LCD TV Screen Shatter Debris 2x.wav'\n",
    "\n",
    "info = wavinfo.WavInfoReader(path)\n",
    "\n",
    "with open(path,'rb') as f:\n",
    "    chunk_tree = wavinfo.wave_parser.parse_chunk(f)\n",
    "    \n",
    "pp.pprint(info.info.to_dict())\n",
    "pp.pprint(info.bext.to_dict())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
