The ObjMedia module provides classes for interacting with media file metadata and storing this information in a database. It is designed to work with media files, parse their technical details, and manage corresponding records in a database. The primary class, DocumentMedia, handles individual media files, while DocumentMediaSet manages collections of media.
This module relies on the pymediainfo library to extract media information, so it's essential to have it installed (pip install pymediainfo) along with its underlying dependency, mediainfo (apt-get install mediainfo or equivalent for your OS).
The DocumentMedia class inherits from ObjData.ObjData and is responsible for handling metadata for a single media document. It provides methods to create, read, and update media information in a database table named document_media.
Modify(self)This method is intended to handle modifications to the media document's data. (Currently, it is a placeholder and does not contain any implementation.)
Read(self, Guid)Fetches the record for a media document from the document_media table using its Guid.
Guid: The unique identifier for the media document.Create(self, Guid)Creates a new record in the document_media table for a new media file.
Guid: The unique identifier for the new media document.Update(self)Updates the record of a media document in the database. It constructs and executes an SQL UPDATE statement based on the object's current attributes.
find_cover(self)A method intended to find a cover image for the media file. (The current implementation only checks if a _Largecover attribute is set to 'Y'.)
Parse(self, File)Parses a given media file to extract its metadata. It uses MediaInfo.parse() to get technical details about the tracks in the file (e.g., audio bitrate, codec).
File: The full path to the media file to be parsed.Example: Parsing a media file
import ObjMedia
# Create an instance of DocumentMedia
media_doc = ObjMedia.DocumentMedia()
# Parse a media file to extract its info
media_doc.Parse("/path/to/your/mediafile.mp3")
The DocumentMediaSet class also inherits from ObjData.ObjData and is used to manage a collection of DocumentMedia objects. It can read a list of media documents based on a category and perform batch operations on them.
Read(self, Category="")Reads a list of media Guids from a Selection table based on a given Category. For each Guid, it creates a DocumentMedia object and adds it to an internal list (self.Items).
Category: The category used to filter the media selection.Build(self, Category="")Builds the set of media documents. If a Category is provided, it first calls Read() to populate the set. Then, it iterates through the items and can perform actions on each, such as find_cover().
The module can be run from the command line for simple operations.
PARSE [file_path]: Parses the specified media file and prints its audio track information.Example CLI Usage:
# Parse a specific WAV file
python ObjMedia.py PARSE /var/www/pseudopod/speech/6DhK75c42in6AhVP6UGFJN.wav
cythonize -3 -a -i ObjMedia.py
Compiling /home/axion/projects/axion/factory.core/ObjMedia.py because it changed..[1/1] Cythonizing /home/axion/projects/axion/factory.core/ObjMedia.py
Updated : 2025-09-10