summaryrefslogtreecommitdiff
path: root/Biz/PodcastItLater
diff options
context:
space:
mode:
Diffstat (limited to 'Biz/PodcastItLater')
-rw-r--r--Biz/PodcastItLater/Core.py47
-rw-r--r--Biz/PodcastItLater/Web.py19
-rw-r--r--Biz/PodcastItLater/Worker.py2
3 files changed, 63 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).
diff --git a/Biz/PodcastItLater/Web.py b/Biz/PodcastItLater/Web.py
index 8586aaf..3493b7b 100644
--- a/Biz/PodcastItLater/Web.py
+++ b/Biz/PodcastItLater/Web.py
@@ -432,6 +432,13 @@ class EpisodeList(Component[AnyChildren, EpisodeListAttrs]):
episode_items.append(
html.div(
html.h4(episode["title"]),
+ # Show author if available
+ html.p(
+ f"by {episode['author']}",
+ style={"margin": "5px 0", "font-style": "italic"},
+ )
+ if episode.get("author")
+ else html.span(),
html.audio(
html.source(
src=episode["audio_url"],
@@ -445,6 +452,18 @@ class EpisodeList(Component[AnyChildren, EpisodeListAttrs]):
f"Duration: {duration_str} | "
f"Created: {episode['created_at']}",
),
+ # Show link to original article if available
+ html.div(
+ html.a(
+ "View original article",
+ href=episode["original_url"],
+ target="_blank",
+ style={"color": "#007cba"},
+ ),
+ style={"margin-top": "10px"},
+ )
+ if episode.get("original_url")
+ else html.span(),
style={
"border": "1px solid #ddd",
"padding": "15px",
diff --git a/Biz/PodcastItLater/Worker.py b/Biz/PodcastItLater/Worker.py
index ce3d432..56a91bc 100644
--- a/Biz/PodcastItLater/Worker.py
+++ b/Biz/PodcastItLater/Worker.py
@@ -280,6 +280,8 @@ class ArticleProcessor:
duration=duration,
content_length=len(content),
user_id=job.get("user_id"),
+ author=job.get("author"), # Pass author from job
+ original_url=url, # Pass the original article URL
db_path=DATABASE_PATH,
)