summaryrefslogtreecommitdiff
path: root/Biz/PodcastItLater/Core.py
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2025-09-04 10:29:04 -0400
committerBen Sima (aider) <ben@bsima.me>2025-09-04 10:29:04 -0400
commit576a85843dbd1834a8973aed6145ae0b9ddc1b2b (patch)
tree4a5b0c76ea6ca7c12eac61a585113800afe79001 /Biz/PodcastItLater/Core.py
parent34770d0fbf05a85826eb4b635c205dd7281fa660 (diff)
Add Episode Metadata: Author and Original URL
Enhance episode tracking by adding support for author and original article URL. This allows users to see more context about each podcast episode, improving the overall user experience and providing additional information about the source material.
Diffstat (limited to 'Biz/PodcastItLater/Core.py')
-rw-r--r--Biz/PodcastItLater/Core.py47
1 files changed, 42 insertions, 5 deletions
diff --git a/Biz/PodcastItLater/Core.py b/Biz/PodcastItLater/Core.py
index 86676b5..542bb8b 100644
--- a/Biz/PodcastItLater/Core.py
+++ b/Biz/PodcastItLater/Core.py
@@ -122,6 +122,9 @@ class Database: # noqa: PLR0904
# Run migration to add metadata fields
Database.migrate_add_metadata_fields(db_path)
+ # Run migration to add episode metadata fields
+ Database.migrate_add_episode_metadata(db_path)
+
@staticmethod
def add_to_queue( # noqa: PLR0913, PLR0917
url: str,
@@ -218,6 +221,8 @@ class Database: # noqa: PLR0904
duration: int,
content_length: int,
user_id: int | None = None,
+ author: str | None = None,
+ original_url: str | None = None,
db_path: str | None = None,
) -> int:
"""Insert episode record, return episode ID.
@@ -231,9 +236,17 @@ class Database: # noqa: PLR0904
cursor = conn.cursor()
cursor.execute(
"INSERT INTO episodes "
- "(title, audio_url, duration, content_length, user_id) "
- "VALUES (?, ?, ?, ?, ?)",
- (title, audio_url, duration, content_length, user_id),
+ "(title, audio_url, duration, content_length, user_id, author, "
+ "original_url) VALUES (?, ?, ?, ?, ?, ?, ?)",
+ (
+ title,
+ audio_url,
+ duration,
+ content_length,
+ user_id,
+ author,
+ original_url,
+ ),
)
conn.commit()
episode_id = cursor.lastrowid
@@ -316,7 +329,7 @@ class Database: # noqa: PLR0904
cursor.execute(
"""
SELECT id, title, audio_url, duration, created_at,
- content_length
+ content_length, author, original_url
FROM episodes
WHERE user_id = ?
ORDER BY created_at DESC
@@ -326,7 +339,7 @@ class Database: # noqa: PLR0904
else:
cursor.execute("""
SELECT id, title, audio_url, duration, created_at,
- content_length
+ content_length, author, original_url
FROM episodes
ORDER BY created_at DESC
""")
@@ -521,6 +534,30 @@ class Database: # noqa: PLR0904
logger.info("Database migrated to support metadata fields")
@staticmethod
+ def migrate_add_episode_metadata(db_path: str | None = None) -> None:
+ """Add author and original_url fields to episodes table."""
+ if db_path is None:
+ db_path = Database.get_default_db_path()
+ with Database.get_connection(db_path) as conn:
+ cursor = conn.cursor()
+
+ # Check if columns already exist
+ cursor.execute("PRAGMA table_info(episodes)")
+ episodes_info = cursor.fetchall()
+ episodes_columns = [col[1] for col in episodes_info]
+
+ if "author" not in episodes_columns:
+ cursor.execute("ALTER TABLE episodes ADD COLUMN author TEXT")
+
+ if "original_url" not in episodes_columns:
+ cursor.execute(
+ "ALTER TABLE episodes ADD COLUMN original_url TEXT",
+ )
+
+ conn.commit()
+ logger.info("Database migrated to support episode metadata fields")
+
+ @staticmethod
def create_user(email: str, db_path: str | None = None) -> tuple[int, str]:
"""Create a new user and return (user_id, token).