How it works...

To extract information from a sample MP3 or MP4 file, we first import the three libraries needed for this recipe: argparse, json, and mutagen. The json library allows us to load definitions for the QuickTime MP4 metadata format used later in this recipe.

from __future__ import print_functionimport argparseimport jsonimport mutagen

This recipe's command-line handler takes one positional argument, AV_FILE, which represents the path to the MP3 or MP4 file to process. After parsing the user-supplied arguments, we use the mutagen.File() method to open a handle to the file. Depending on the extension of the input file, we send this handle to the appropriate function: handle_id3() or handle_mp4().

if __name__ == '__main__': parser ...

Get Python Digital Forensics Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.