summaryrefslogtreecommitdiff
path: root/Biz/PodcastItLater/Core.py
diff options
context:
space:
mode:
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).