modules.core.database
Audio Library Analyzer
A script that analyzes audio files in a directory and stores metadata in SQLite database.
Functions
|
Analyze audio files in directory and store information in SQLite database. |
|
Create a new SQLite database with tables for music library. |
|
Extract metadata from audio file using mutagen. |
|
Generate a simple hash for the file based on path and size. |
|
Load songs from M3U playlist and add to database. |
|
Main function to handle command line arguments and analyze directory. |
|
Scan directory for audio files and add to database. |
- modules.core.database.create_database(db_path)[source]
Create a new SQLite database with tables for music library.
Creates a comprehensive database schema based on Strawberry Music Player for storing music metadata, file information, and library structure.
- modules.core.database.get_file_hash(filepath)[source]
Generate a simple hash for the file based on path and size.
- modules.core.database.extract_metadata(filepath)[source]
Extract metadata from audio file using mutagen.
- Parameters:
filepath (str) – Path to the audio file.
- Returns:
- Dictionary containing extracted metadata, or None if extraction fails.
Keys include: title, artist, album, albumartist, track, disc, year, originalyear, genre, composer, performer, grouping, comment, lyrics, length, bitrate, samplerate, bitdepth, compilation, art_embedded.
- Return type:
dict or None
- modules.core.database.scan_directory(directory_path, conn)[source]
Scan directory for audio files and add to database.
Recursively scans the specified directory for audio files, extracts metadata, and adds them to the database.
- Parameters:
directory_path (str) – Path to the directory to scan.
conn (sqlite3.Connection) – Database connection object.
- Returns:
(files_added, files_updated, errors) - counts of operation results.
- Return type:
- modules.core.database.load_playlist_to_database(playlist_path, conn)[source]
Load songs from M3U playlist and add to database.
- Parameters:
playlist_path (str) – Path to the M3U playlist file.
conn (sqlite3.Connection) – Database connection object.
- Returns:
True if playlist loaded successfully, False otherwise.
- Return type:
- modules.core.database.analyze_directory(directory_path, db_path)[source]
Analyze audio files in directory and store information in SQLite database.
- modules.core.database.main()[source]
Main function to handle command line arguments and analyze directory.
Parses command-line arguments and initiates database creation, directory scanning, or playlist loading operations.
Examples
- Scan directory and create database:
python database.py /path/to/music
- Scan directory with custom database path:
python database.py /path/to/music –db-path ~/music.db
- Load playlist into database:
python database.py –playlist myplaylist.m3u –db-path ~/music.db
- Scan with test directory:
python database.py ../../testing_files/