Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Support optional title and meeting_date fields in upload API

Murtaza Nasirbdbe7077d1b8
diff --git a/src/api/recordings.py b/src/api/recordings.py
index d02135e6..854d8ece 100644
--- a/src/api/recordings.py
+++ b/src/api/recordings.py
@@ -2033,6 +2033,10 @@ def upload_file():
# Get notes from the form
notes = request.form.get('notes')
+ # Get optional user-provided title and meeting_date
+ user_title = request.form.get('title')
+ user_meeting_date = request.form.get('meeting_date')
+
# Get file's lastModified timestamp from client (milliseconds since epoch)
file_last_modified = request.form.get('file_last_modified')
@@ -2146,11 +2150,21 @@ def upload_file():
# Create initial database entry
now = datetime.utcnow()
- # Determine meeting_date: prefer client-provided lastModified, then file metadata, then current time
+ # Determine meeting_date: prefer user-provided, then client lastModified, then file metadata, then current time
meeting_date = None
- # First try client-provided file lastModified (most reliable for uploads)
- if file_last_modified:
+ # First try user-provided meeting_date (ISO 8601 format)
+ if user_meeting_date:
+ try:
+ parsed = datetime.fromisoformat(user_meeting_date.replace('Z', '+00:00'))
+ # Strip timezone to store as naive datetime, consistent with other date sources
+ meeting_date = parsed.replace(tzinfo=None)
+ current_app.logger.info(f"Using user-provided meeting_date: {meeting_date}")
+ except (ValueError, TypeError) as e:
+ current_app.logger.warning(f"Could not parse user meeting_date '{user_meeting_date}': {e}")
+
+ # Then try client-provided file lastModified (most reliable for uploads)
+ if not meeting_date and file_last_modified:
try:
# JavaScript lastModified is in milliseconds since epoch
timestamp_ms = int(file_last_modified)
@@ -2173,7 +2187,7 @@ def upload_file():
recording = Recording(
audio_path=filepath,
original_filename=original_filename,
- title=f"Recording - {original_filename}",
+ title=user_title.strip() if user_title and user_title.strip() else f"Recording - {original_filename}",
file_size=final_file_size,
status='PENDING',
meeting_date=meeting_date,
diff --git a/src/tasks/processing.py b/src/tasks/processing.py
index e3238aed..0b755362 100644
--- a/src/tasks/processing.py
+++ b/src/tasks/processing.py
@@ -215,6 +215,19 @@ def generate_title_task(app_context, recording_id, will_auto_summarize=False):
current_app.logger.error(f"Error: Recording {recording_id} not found for title generation.")
return
+ # Skip title generation if user provided a non-placeholder title
+ placeholder_patterns = [
+ f"Recording - {recording.original_filename}",
+ f"Auto-processed - {recording.original_filename}",
+ ]
+ if recording.title and recording.title not in placeholder_patterns:
+ current_app.logger.info(f"Recording {recording_id} has user-provided title '{recording.title}', skipping AI title generation")
+ if not will_auto_summarize:
+ recording.status = 'COMPLETED'
+ recording.completed_at = datetime.utcnow()
+ db.session.commit()
+ return
+
# Resolve naming template: first tag with template → user default → None
naming_template = None
for tag in recording.tags:
@@ -523,6 +536,12 @@ def generate_summary_only_task(app_context, recording_id, custom_prompt_override
context_parts = []
context_parts.append(f"Current date: {current_date}")
+ # Add recording metadata to context
+ if recording.meeting_date:
+ context_parts.append(f"Recording date: {recording.meeting_date.strftime('%B %d, %Y')}")
+ if recording.title:
+ context_parts.append(f"Recording title: {recording.title}")
+
# Add folder information if recording is in a folder
if recording.folder:
context_parts.append(f"Folder: {recording.folder.name}")
diff --git a/tests/test_upload_title_and_date.py b/tests/test_upload_title_and_date.py
new file mode 100644
index 00000000..681a5e16
--- /dev/null
+++ b/tests/test_upload_title_and_date.py
@@ -0,0 +1,194 @@
+#!/usr/bin/env python3
+"""
+Tests for upload API title and meeting_date support, title generation skip logic,
+and summary context enrichment.
+"""
+
+import sys
+import os
+from datetime import datetime
+from unittest.mock import MagicMock, patch
+
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+
+def test_placeholder_pattern_detection():
+ """Placeholder titles should be detected, user titles should not."""
+ original_filename = "interview.mp3"
+ placeholder_patterns = [
+ f"Recording - {original_filename}",
+ f"Auto-processed - {original_filename}",
+ ]
+
+ # Placeholders match
+ assert "Recording - interview.mp3" in placeholder_patterns
+ assert "Auto-processed - interview.mp3" in placeholder_patterns
+
+ # User titles don't match
+ assert "My Custom Title" not in placeholder_patterns
+ assert "Interview with John" not in placeholder_patterns
+ assert "" not in placeholder_patterns
+
+ print(" PASS: placeholder pattern detection")
+
+
+def test_meeting_date_iso_parsing():
+ """ISO 8601 meeting_date strings should parse correctly."""
+ # With Z suffix
+ val = "2024-06-15T10:30:00Z"
+ dt = datetime.fromisoformat(val.replace('Z', '+00:00'))
+ assert dt.year == 2024
+ assert dt.month == 6
+ assert dt.day == 15
+
+ # Without timezone
+ val2 = "2024-06-15T10:30:00"
+ dt2 = datetime.fromisoformat(val2)
+ assert dt2.year == 2024
+
+ # Date only
+ val3 = "2024-06-15"
+ dt3 = datetime.fromisoformat(val3)
+ assert dt3.year == 2024
+ assert dt3.month == 6
+
+ # Invalid string should raise
+ try:
+ datetime.fromisoformat("not-a-date")
+ assert False, "Should have raised ValueError"
+ except ValueError:
+ pass
+
+ print(" PASS: ISO 8601 meeting_date parsing")
+
+
+def test_user_title_applied():
+ """User-provided title should be used instead of placeholder."""
+ original_filename = "test.mp3"
+
+ # With user title
+ user_title = " My Custom Title "
+ result = user_title.strip() if user_title and user_title.strip() else f"Recording - {original_filename}"
+ assert result == "My Custom Title"
+
+ # Empty string falls back to placeholder
+ user_title = " "
+ result = user_title.strip() if user_title and user_title.strip() else f"Recording - {original_filename}"
+ assert result == f"Recording - {original_filename}"
+
+ # None falls back to placeholder
+ user_title = None
+ result = user_title.strip() if user_title and user_title.strip() else f"Recording - {original_filename}"
+ assert result == f"Recording - {original_filename}"
+
+ print(" PASS: user title application logic")
+
+
+def test_meeting_date_priority():
+ """User-provided meeting_date should take priority over file_last_modified."""
+ user_meeting_date = "2023-01-15T12:00:00Z"
+ file_last_modified = "1700000000000" # Nov 2023
+
+ # User date takes priority
+ meeting_date = None
+ if user_meeting_date:
+ try:
+ meeting_date = datetime.fromisoformat(user_meeting_date.replace('Z', '+00:00'))
+ except (ValueError, TypeError):
+ pass
+
+ assert meeting_date is not None
+ assert meeting_date.year == 2023
+ assert meeting_date.month == 1
+ assert meeting_date.day == 15
+
+ # file_last_modified should NOT be reached
+ # (in real code, the `if not meeting_date` guard prevents it)
+ print(" PASS: meeting_date priority over file_last_modified")
+
+
+def test_summary_context_includes_metadata():
+ """Summary context should include recording date and title."""
+ context_parts = []
+ current_date = datetime.now().strftime("%B %d, %Y")
+ context_parts.append(f"Current date: {current_date}")
+
+ # Simulate recording with meeting_date and title
+ meeting_date = datetime(2024, 3, 15)
+ title = "Q1 Planning Meeting"
+
+ if meeting_date:
+ context_parts.append(f"Recording date: {meeting_date.strftime('%B %d, %Y')}")
+ if title:
+ context_parts.append(f"Recording title: {title}")
+
+ context = "\n".join(context_parts)
+ assert "Recording date: March 15, 2024" in context
+ assert "Recording title: Q1 Planning Meeting" in context
+
+ # Without metadata, those lines should be absent
+ context_parts2 = [f"Current date: {current_date}"]
+ meeting_date2 = None
+ title2 = None
+ if meeting_date2:
+ context_parts2.append(f"Recording date: {meeting_date2.strftime('%B %d, %Y')}")
+ if title2:
+ context_parts2.append(f"Recording title: {title2}")
+
+ context2 = "\n".join(context_parts2)
+ assert "Recording date:" not in context2
+ assert "Recording title:" not in context2
+
+ print(" PASS: summary context includes recording metadata")
+
+
+def test_neither_title_nor_date():
+ """Without title or meeting_date, existing behavior is preserved."""
+ original_filename = "audio.mp3"
+ user_title = None
+ user_meeting_date = None
+
+ # Title falls back to placeholder
+ title = user_title.strip() if user_title and user_title.strip() else f"Recording - {original_filename}"
+ assert title == "Recording - audio.mp3"
+
+ # meeting_date falls through to next priority
+ meeting_date = None
+ if user_meeting_date:
+ try:
+ meeting_date = datetime.fromisoformat(user_meeting_date.replace('Z', '+00:00'))
+ except (ValueError, TypeError):
+ pass
+ assert meeting_date is None # Would proceed to file_last_modified in real code
+
+ print(" PASS: existing behavior preserved when no title/date provided")
+
+
+def main():
+ print("Running upload title and meeting_date tests...\n")
+ passed = 0
+ failed = 0
+
+ tests = [
+ test_placeholder_pattern_detection,
+ test_meeting_date_iso_parsing,
+ test_user_title_applied,
+ test_meeting_date_priority,
+ test_summary_context_includes_metadata,
+ test_neither_title_nor_date,
+ ]
+
+ for test in tests:
+ try:
+ test()
+ passed += 1
+ except Exception as e:
+ print(f" FAIL: {test.__name__}: {e}")
+ failed += 1
+
+ print(f"\n{passed} passed, {failed} failed")
+ sys.exit(0 if failed == 0 else 1)
+
+
+if __name__ == "__main__":
+ main()