A Python library for managing video metadata using MySQL database with PyMySQL.
- MySQL-based storage for video metadata with PyMySQL
- JSON serialization for flexible metadata storage
- Simple CRUD operations (Create, Read, Update)
- Type hints and comprehensive documentation
- Connection pooling and retry mechanism
- Sharded database support
- git clone https://github.com/sentient-io/video-metadata.git
- cd video-metadata
- pip install -e .
pip install git+https://github.com/sentient-io/video-metadata.git
- Python 3.6+
- PyMySQL>=1.0.2
- MySQL 5.7+ or compatible (tested with Vitess/Sharded MySQL)
from video_metadata_manager import VideoMetaDataManager
# Initialize the manager with your database credentials
manager = VideoMetaDataManager(
host="your_database_host",
user="your_username",
password="your_password",
db_name="your_database_name",
port=3306 # default MySQL port
)
# Insert video data
video_id = manager.insert_video_data(
"video_001",
{
"title": "My Video",
"duration": 120,
"resolution": "1080p",
"tags": ["tutorial", "python"]
}
)
print(f"Inserted video with ID: {video_id}")
# Update metadata
updated_count = manager.update_video_metadata(
"video_001",
{
"title": "Updated Video Title",
"category": "educational",
"views": 1500
}
)
print(f"Updated {updated_count} record(s)")
# Get metadata for a specific video
video_data = manager.get_video_metadata("video_001")
print(f"Video data: {video_data}")
# Get all videos
all_videos = manager.get_all_videos()
print(f"Total videos: {len(all_videos)}")
Initialize the VideoMetaDataManager with database connection parameters.
Insert a new video record with the given metadata.
- Returns: The ID of the inserted row, or None if insertion failed
Update metadata for an existing video.
- Returns: Number of rows updated (0 if not found, 1 if updated)
Retrieve metadata for a specific video.
- Returns: Dictionary containing video data or None if not found
Retrieve all video records from the database.
- Returns: List of video dictionaries
The library creates a video_metadata table with:
video_id: VARCHAR(255) PRIMARY KEY (unique video identifier)metadata: TEXT (JSON string containing video metadata)created_at: TIMESTAMP (automatically set on record creation)updated_at: TIMESTAMP (automatically updated on record modification)
The library provides detailed error messages for common database operations. All database operations are wrapped in try-catch blocks to prevent crashes.