Updates
This commit is contained in:
parent
e86ab53de5
commit
095bf52a2f
29 changed files with 2494 additions and 758 deletions
|
@ -41,12 +41,13 @@ def update_all_podcasts():
|
|||
|
||||
return stats
|
||||
|
||||
def update_podcast(podcast_id):
|
||||
def update_podcast(podcast_id, progress_callback=None):
|
||||
"""
|
||||
Update a specific podcast.
|
||||
|
||||
Args:
|
||||
podcast_id (int): ID of the podcast to update.
|
||||
progress_callback (callable, optional): Callback function for progress updates.
|
||||
|
||||
Returns:
|
||||
dict: Statistics about the update process.
|
||||
|
@ -63,12 +64,18 @@ def update_podcast(podcast_id):
|
|||
logger.info(f"Updating podcast: {podcast.title} (ID: {podcast.id})")
|
||||
logger.info(f"Feed URL: {podcast.feed_url}")
|
||||
|
||||
if progress_callback:
|
||||
progress_callback(10, f"Fetching episodes for {podcast.title}")
|
||||
|
||||
# Get episodes from feed
|
||||
episodes = get_podcast_episodes(podcast.feed_url)
|
||||
|
||||
# Update podcast last_checked timestamp
|
||||
podcast.last_checked = datetime.utcnow()
|
||||
|
||||
if progress_callback:
|
||||
progress_callback(30, f"Found {len(episodes)} episodes")
|
||||
|
||||
if not episodes:
|
||||
logger.warning(f"No episodes found for podcast: {podcast.title}")
|
||||
stats['feed_status'] = 'no_episodes'
|
||||
|
@ -92,7 +99,11 @@ def update_podcast(podcast_id):
|
|||
logger.error(f"Error refreshing feed URL: {str(e)}")
|
||||
|
||||
# Process each episode
|
||||
for episode_data in episodes:
|
||||
total_episodes = len(episodes)
|
||||
for i, episode_data in enumerate(episodes):
|
||||
if progress_callback and total_episodes > 0:
|
||||
progress = 30 + int((i / total_episodes) * 60) # Scale from 30% to 90%
|
||||
progress_callback(progress, f"Processing episode {i+1}/{total_episodes}")
|
||||
# Skip episodes without required fields
|
||||
if not episode_data.get('guid'):
|
||||
logger.warning(f"Skipping episode without GUID: {episode_data.get('title', 'Unknown')}")
|
||||
|
@ -129,7 +140,9 @@ def update_podcast(podcast_id):
|
|||
# Auto-download if enabled
|
||||
if podcast.auto_download and episode.audio_url:
|
||||
try:
|
||||
download_episode(episode)
|
||||
# Need to commit first to ensure episode has an ID
|
||||
db.session.commit()
|
||||
download_episode(episode.id)
|
||||
stats['episodes_downloaded'] += 1
|
||||
logger.info(f"Auto-downloaded episode: {episode.title}")
|
||||
except Exception as e:
|
||||
|
@ -144,6 +157,9 @@ def update_podcast(podcast_id):
|
|||
db.session.commit()
|
||||
logger.info(f"Podcast update completed: {stats}")
|
||||
|
||||
if progress_callback:
|
||||
progress_callback(100, f"Update complete. Found {stats['new_episodes']} new episodes.")
|
||||
|
||||
return stats
|
||||
|
||||
except Exception as e:
|
||||
|
@ -151,6 +167,10 @@ def update_podcast(podcast_id):
|
|||
logger.error(f"Error updating podcast {podcast.title}: {str(e)}")
|
||||
stats['feed_status'] = 'error'
|
||||
stats['error'] = str(e)
|
||||
|
||||
if progress_callback:
|
||||
progress_callback(100, f"Error: {str(e)}")
|
||||
|
||||
raise
|
||||
|
||||
def schedule_updates():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue