in pyrit/models/seed_prompt.py [0:0]
def set_encoding_metadata(self):
"""
This method sets the encoding data for the prompt within metadata dictionary. For images, this is just the
file format. For audio and video, this also includes bitrate (kBits/s as int), samplerate (samples/second
as int), bitdepth (as int), filesize (bytes as int), and duration (seconds as int) if the file type is
supported by TinyTag. Example suppported file types include: MP3, MP4, M4A, and WAV.
"""
if self.data_type not in ["audio_path", "video_path", "image_path"]:
return
extension = DataTypeSerializer.get_extension(self.value)
if extension:
extension = extension.lstrip(".")
self.metadata.update({"format": extension})
if self.data_type in ["audio_path", "video_path"]:
if TinyTag.is_supported(self.value):
try:
tag = TinyTag.get(self.value)
self.metadata.update(
{
"bitrate": int(round(tag.bitrate)),
"samplerate": tag.samplerate,
"bitdepth": tag.bitdepth,
"filesize": tag.filesize,
"duration": int(round(tag.duration)),
}
)
except Exception as ex:
logger.error(f"Error getting audio/video data for {self.value}: {ex}")
else:
logger.warning(
f"Getting audio/video data via TinyTag is not supported for {self.value}.\
If needed, update metadata manually."
)