This commit is contained in:
Jamie Hardt
2022-11-23 22:31:42 -08:00
parent 8fcc9787f6
commit b2323a126f
7 changed files with 49 additions and 32 deletions

View File

@@ -47,8 +47,8 @@ class WavADMReader:
Information about a track in the WAV file.
:param index: index of audio track (indexed from zero)
:returns: a dictionary with content_name, object_name, pack_format_name, pack_type,
channel_format_name
:returns: a dictionary with *content_name*, *object_name*, *pack_format_name*, *pack_type*,
*channel_format_name*
"""
channel_info = next((x for x in self.channel_uids if x.track_index == index + 1), None)
@@ -86,4 +86,7 @@ class WavADMReader:
return ret_dict
def to_dict(self):
"""
Get ADM metadata as a dictionary.
"""
return dict(channel_entries=list(map(lambda z: z._asdict(), self.channel_uids)))

View File

@@ -38,7 +38,7 @@ class WavIXMLFormat:
def track_list(self):
"""
A description of each track.
:return: An Iterator
:returns: An Iterator
"""
for track in self.parsed.find("./TRACK_LIST").iter():
if track.tag == 'TRACK':

View File

@@ -3,6 +3,8 @@ import struct
import os
from collections import namedtuple
from typing import Optional
import pathlib
from .riff_parser import parse_chunk, ChunkDescriptor, ListChunkDescriptor
@@ -22,6 +24,8 @@ WavAudioFormat = namedtuple('WavAudioFormat',
class WavInfoReader:
"""
Parse a WAV audio file for metadata.
"""
def __init__(self, path, info_encoding='latin_1', bext_encoding='ascii'):
@@ -55,10 +59,24 @@ class WavInfoReader:
absolute_path = os.path.abspath(path)
#: `file://` url for the file.
self.url = pathlib.Path(absolute_path).as_uri()
self.url: pathlib.Path = pathlib.Path(absolute_path).as_uri()
# for __repr__()
self.path = absolute_path
self.fmt :Optional[WavAudioFormat] = None
":class:`wavinfo.wave_reader.WavAudioFormat`"
self.bext :Optional[WavBextReader] = None
":class:`wavinfo.wave_bext_reader.WavBextReader` with Broadcast-WAV metadata"
self.ixml :Optional[WavIXMLFormat] = None
":class:`wavinfo.wave_ixml_reader.WavIXMLFormat` with iXML metadata"
self.adm :Optional[WavADMReader]= None
":class:`wavinfo.wave_axml_reader.WavADMReader` with ADM metadata"
self.info :Optional[WavInfoChunkReader]= None
":class:`wavinfo.wave_info_reader.WavInfoChunkReader` with RIFF INFO metadata"
with open(path, 'rb') as f:
self.get_wav_info(f)
@@ -69,19 +87,10 @@ class WavInfoReader:
self.main_list = chunks.children
wavfile.seek(0)
#: :class:`wavinfo.wave_reader.WavAudioFormat`
self.fmt = self._get_format(wavfile)
#: :class:`wavinfo.wave_bext_reader.WavBextReader` with Broadcast-WAV metadata
self.bext = self._get_bext(wavfile, encoding=self.bext_encoding)
#: :class:`wavinfo.wave_ixml_reader.WavIXMLFormat` with iXML metadata
self.ixml = self._get_ixml(wavfile)
#: :class:`wavinfo.wave_axml_reader.WavAxmlReader` with ADM metadata
self.adm = self._get_adm(wavfile)
#: :class:`wavinfo.wave_info_reader.WavInfoChunkReader` with RIFF INFO metadata
self.info = self._get_info(wavfile, encoding=self.info_encoding)
self.data = self._describe_data()
@@ -149,9 +158,9 @@ class WavInfoReader:
"""
Walk all of the available metadata fields.
:yields: a string, the :scope: of the metadatum, the string :name: of the
metadata field, and the value.
:yields: tuples of the *scope*, *key*, and *value* of
each metadatum. The *scope* value will be one of
"fmt", "data", "ixml", "bext", "info" or "adm".
"""