Docker and more calendar work

This commit is contained in:
Cody Cook 2025-06-17 16:00:46 -07:00
commit f7a919ebf2
22 changed files with 2036 additions and 79 deletions

View file

@ -13,14 +13,18 @@ from app.services.podcast_downloader import download_episode
# Set up logging
logger = logging.getLogger(__name__)
def update_all_podcasts():
def update_all_podcasts(progress_callback=None):
"""
Update all podcasts in the database.
Args:
progress_callback (callable, optional): Callback function for progress updates.
Returns:
dict: Statistics about the update process.
"""
podcasts = Podcast.query.all()
total_podcasts = len(podcasts)
stats = {
'podcasts_updated': 0,
@ -29,16 +33,32 @@ def update_all_podcasts():
'errors': 0
}
for podcast in podcasts:
if progress_callback:
progress_callback(0, f"Starting update of {total_podcasts} podcasts")
for i, podcast in enumerate(podcasts):
try:
if progress_callback:
progress = int((i / total_podcasts) * 100)
progress_callback(progress, f"Updating podcast {i+1}/{total_podcasts}: {podcast.title}")
result = update_podcast(podcast.id)
stats['podcasts_updated'] += 1
stats['new_episodes'] += result['new_episodes']
stats['episodes_downloaded'] += result['episodes_downloaded']
if progress_callback:
progress_callback(progress, f"Updated podcast {i+1}/{total_podcasts}: {podcast.title} - Found {result['new_episodes']} new episodes")
except Exception as e:
logger.error(f"Error updating podcast {podcast.title}: {str(e)}")
stats['errors'] += 1
if progress_callback:
progress_callback(progress, f"Error updating podcast {i+1}/{total_podcasts}: {podcast.title} - {str(e)}")
if progress_callback:
progress_callback(100, f"Update complete. Updated {stats['podcasts_updated']} podcasts, found {stats['new_episodes']} new episodes.")
return stats
def update_podcast(podcast_id, progress_callback=None):
@ -67,12 +87,40 @@ def update_podcast(podcast_id, progress_callback=None):
if progress_callback:
progress_callback(10, f"Fetching episodes for {podcast.title}")
# Get episodes from feed
episodes = get_podcast_episodes(podcast.feed_url)
# Get episodes and podcast metadata from feed
episodes, podcast_metadata = get_podcast_episodes(podcast.feed_url)
# Update podcast last_checked timestamp
podcast.last_checked = datetime.utcnow()
# Update podcast metadata if available
updated = False
# Update image URL if available
if podcast_metadata.get('image_url'):
if podcast.image_url != podcast_metadata['image_url']:
logger.info(f"Updating podcast image URL from {podcast.image_url} to {podcast_metadata['image_url']}")
podcast.image_url = podcast_metadata['image_url']
updated = True
# Update author if available
if podcast_metadata.get('author'):
if podcast.author != podcast_metadata['author']:
logger.info(f"Updating podcast author from '{podcast.author}' to '{podcast_metadata['author']}'")
podcast.author = podcast_metadata['author']
updated = True
# Update description if available
if podcast_metadata.get('description'):
if podcast.description != podcast_metadata['description']:
logger.info(f"Updating podcast description")
podcast.description = podcast_metadata['description']
updated = True
# Commit changes if any updates were made
if updated:
db.session.commit()
if progress_callback:
progress_callback(30, f"Found {len(episodes)} episodes")
@ -103,8 +151,36 @@ def update_podcast(podcast_id, progress_callback=None):
db.session.commit()
# Try again with the new feed URL
episodes = get_podcast_episodes(podcast.feed_url)
episodes, updated_metadata = get_podcast_episodes(podcast.feed_url)
logger.info(f"Found {len(episodes)} episodes with updated feed URL")
# Update podcast metadata with the new feed
updated_from_new_feed = False
# Update image URL if available
if updated_metadata.get('image_url'):
if podcast.image_url != updated_metadata['image_url']:
logger.info(f"Updating podcast image URL from new feed: {updated_metadata['image_url']}")
podcast.image_url = updated_metadata['image_url']
updated_from_new_feed = True
# Update author if available
if updated_metadata.get('author'):
if podcast.author != updated_metadata['author']:
logger.info(f"Updating podcast author from new feed: '{updated_metadata['author']}'")
podcast.author = updated_metadata['author']
updated_from_new_feed = True
# Update description if available
if updated_metadata.get('description'):
if podcast.description != updated_metadata['description']:
logger.info(f"Updating podcast description from new feed")
podcast.description = updated_metadata['description']
updated_from_new_feed = True
# Commit changes if any updates were made
if updated_from_new_feed:
db.session.commit()
except Exception as e:
logger.error(f"Error refreshing feed URL: {str(e)}")