TagQt provides CSV import and export functionality for bulk metadata editing using spreadsheet applications.
Overview
The CSV import/export feature allows you to:
- Export metadata from your audio files to CSV format
- Edit metadata in spreadsheet applications (Excel, LibreOffice Calc, Google Sheets)
- Import the modified metadata back into your audio files
CSV Structure
Column Layout
The CSV file contains the following columns (from csv_io.py:9-10):
| Column | Field | Description |
|---|
filepath | File Path | Full path to the audio file |
filename | File Name | Base name of the file |
title | Title | Song title |
artist | Artist | Artist name |
album | Album | Album title |
album_artist | Album Artist | Album artist (for compilations) |
year | Year | Release year |
genre | Genre | Music genre |
disc_number | Disc Number | Disc number (for multi-disc albums) |
track_number | Track Number | Track number |
bpm | BPM | Beats per minute |
initial_key | Key | Musical key |
comment | Comment | Comment field |
lyrics | Lyrics | Song lyrics |
Field Names
# From csv_io.py:9-10
fieldnames = ['filepath', 'filename', 'title', 'artist', 'album',
'album_artist', 'year', 'genre', 'disc_number',
'track_number', 'bpm', 'initial_key', 'comment', 'lyrics']
Export Process
- Navigate to File → Export to CSV
- Choose a location and filename
- Click Save
- All files in the current library will be exported
Export Implementation
The export process (from csv_io.py:5-37):
def export_metadata_to_csv(files_data, filepath):
fieldnames = ['filepath', 'filename', 'title', 'artist', ...]
with open(filepath, 'w', newline='', encoding='utf-8') as f:
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writeheader()
for path, meta in files_data:
row = {
'filepath': path,
'filename': os.path.basename(path),
'title': meta.title or '',
'artist': meta.artist or '',
# ... more fields
}
writer.writerow(row)
Example Export
filepath,filename,title,artist,album,album_artist,year,genre,disc_number,track_number,bpm,initial_key,comment,lyrics
/music/song1.mp3,song1.mp3,Song Title,Artist Name,Album Name,Album Artist,2024,Rock,1,01,120,Am,Great track,First line...
/music/song2.flac,song2.flac,Another Song,Different Artist,Album 2,,2023,Pop,,02,128,C,,[Verse 1]...
Import Process
- Edit the exported CSV file in your spreadsheet application
- Save the changes
- In TagQt, navigate to File → Import from CSV
- Select the modified CSV file
- Review the import progress in the batch status dialog
Import Implementation
The import process reads the CSV and applies changes to matching files:
# From csv_io.py:40-46
def import_metadata_from_csv(filepath):
with open(filepath, 'r', encoding='utf-8') as f:
reader = csv.DictReader(f)
return list(reader), None
The CsvImportWorker then processes each row and updates the corresponding file’s metadata.
File Matching
Files are matched by the filepath column. The file must exist at the specified path for the import to succeed.
Editing CSV Files
Spreadsheet Applications
You can edit CSV files using:
- Microsoft Excel: Open the CSV file directly
- LibreOffice Calc: Use “Text CSV” import
- Google Sheets: Import the CSV file
- Text Editors: Any text editor (VS Code, Notepad++, etc.)
When opening CSV files in Excel or LibreOffice, make sure to specify UTF-8 encoding to preserve special characters.
Common Editing Tasks
Bulk Editing
- Standardize artist names: Use find/replace to fix variations
- Fix album names: Correct spelling or capitalization
- Add missing genres: Fill in genre information for multiple tracks
- Update years: Correct release years for albums
- Renumber tracks: Use spreadsheet formulas to generate track numbers
# Generate track numbers with padding
=TEXT(ROW()-1, "00")
# Combine artist and title
=B2 & " - " & C2
# Extract year from date
=YEAR(G2)
# Uppercase genre
=UPPER(H2)
Field Handling
Empty Fields
Empty fields in the CSV are represented as empty strings:
- During export: Missing metadata is exported as empty
- During import: Empty fields are set to empty strings (clearing existing data)
Special Characters
The CSV format uses UTF-8 encoding, supporting:
- Unicode characters (émojis, accented characters, etc.)
- Multi-line text in the lyrics field
- Commas and quotes (automatically escaped by the CSV library)
Lyrics Field
The lyrics field can contain:
- Multi-line text (preserved with line breaks)
- LRC timestamps
- Special characters
Excel may have issues with multi-line fields. Use LibreOffice Calc or Google Sheets for better handling of lyrics.
Batch Import Status
During CSV import, TagQt provides:
- Real-time progress: Progress bar showing completion percentage
- Individual file status: Success/error status for each file
- Error reporting: Detailed error messages for failed imports
- Batch summary: Total successes, failures, and skipped files
Import Results
Possible import statuses:
| Status | Description |
|---|
| Success | Metadata imported successfully |
| Error | File not found or import failed |
| Skipped | File skipped (invalid path) |
Best Practices
Export
Export your metadata before making bulk changes. This creates a backup of your current metadata that you can reference or restore if needed.
- Export before editing: Always export first to get the current state
- Use descriptive filenames: Include date in export filename (e.g.,
metadata-2024-03-04.csv)
- Test on a small subset: Export a few files first to understand the format
Import
CSV import overwrites existing metadata. Empty fields in the CSV will clear the corresponding metadata fields in your files.
- Keep filepath column unchanged: Don’t modify the filepath column
- Verify paths: Ensure all file paths in the CSV are valid
- Test on copies: Test import on backup files first
- Check encoding: Save CSV files with UTF-8 encoding
- Preserve quotes: Let your spreadsheet application handle special characters
Workflow
Recommended workflow for bulk editing:
- Export metadata to CSV
- Create a backup copy of the CSV file
- Edit the CSV in your spreadsheet application
- Save the CSV (UTF-8 encoding)
- Create backups of your audio files (optional but recommended)
- Import the modified CSV
- Verify the changes in TagQt
- Save changes to audio files
Error Handling
Export Errors
- No files to export: Load files before exporting
- Permission denied: Check write permissions for the export location
- Disk full: Ensure adequate disk space
Import Errors
- File not found: CSV references files that don’t exist
- Invalid CSV format: CSV file is corrupted or improperly formatted
- Encoding issues: CSV not saved with UTF-8 encoding
- Permission denied: Can’t write to audio files (check permissions)
Technical Details
Source Code Reference
- Source:
tagqt/core/csv_io.py
- Functions:
export_metadata_to_csv(files_data, filepath) - Export to CSV
import_metadata_from_csv(filepath) - Read CSV data
- Worker:
CsvImportWorker (in tagqt/ui/workers.py)
CSV Library
TagQt uses Python’s built-in csv module:
csv.DictWriter for exports (writes rows as dictionaries)
csv.DictReader for imports (reads rows as dictionaries)
- Automatic handling of quotes and escaping
- UTF-8 encoding support
Use Cases
Scenario: Fix metadata for a multi-disc album
- Export metadata to CSV
- In spreadsheet:
- Sort by album
- Update album artist
- Set disc numbers
- Fix track numbering
- Import back to TagQt
Genre Classification
Scenario: Classify a large library by genre
- Export to CSV
- Use spreadsheet pivot tables and filtering
- Assign genres based on artist or album patterns
- Use formulas to batch-assign genres
- Import updated metadata
Scenario: Standardize formatting across library
- Export to CSV
- Use find/replace for common issues:
- Remove extra spaces
- Standardize capitalization
- Fix encoding errors
- Import cleaned data