podcastrr/app/web/routes/debug.py
Cody Cook 095bf52a2f Updates
2025-06-15 21:20:30 -07:00

98 lines
3.1 KiB
Python

"""
Debug routes for troubleshooting Podcastrr issues.
"""
from flask import Blueprint, jsonify, render_template, request
from app.models.podcast import Podcast
from app.services.podcast_updater import PodcastUpdater
import logging
debug_bp = Blueprint('debug', __name__, url_prefix='/debug')
@debug_bp.route('/test-feed')
def test_feed():
"""
Test RSS feed parsing for debugging.
"""
feed_url = request.args.get('url')
if not feed_url:
return jsonify({'error': 'No feed URL provided'}), 400
try:
updater = PodcastUpdater()
# Create a temporary podcast object for testing
temp_podcast = type('obj', (object,), {
'id': 0,
'feed_url': feed_url,
'title': 'Test Podcast'
})
# Try to fetch episodes
logging.info(f"Testing feed URL: {feed_url}")
episodes = updater.fetch_episodes(temp_podcast)
return jsonify({
'success': True,
'feed_url': feed_url,
'episodes_found': len(episodes),
'episodes': [
{
'title': ep.get('title', 'No title'),
'description': ep.get('description', 'No description')[:100] + '...' if ep.get(
'description') else 'No description',
'pub_date': str(ep.get('pub_date', 'No date')),
'audio_url': ep.get('audio_url', 'No audio URL')
}
for ep in episodes[:5] # Show first 5 episodes
]
})
except Exception as e:
logging.error(f"Error testing feed {feed_url}: {str(e)}")
return jsonify({
'success': False,
'error': str(e),
'feed_url': feed_url
}), 500
@debug_bp.route('/podcast-info/<int:podcast_id>')
def podcast_info(podcast_id):
"""
Get detailed information about a podcast for debugging.
"""
try:
podcast = Podcast.query.get_or_404(podcast_id)
return jsonify({
'success': True,
'podcast': {
'id': podcast.id,
'title': podcast.title,
'author': podcast.author,
'feed_url': podcast.feed_url,
'image_url': podcast.image_url,
'description': podcast.description[:200] + '...' if podcast.description else None,
'last_updated': str(podcast.last_updated) if podcast.last_updated else None,
'episode_count': len(podcast.episodes) if hasattr(podcast, 'episodes') else 0
}
})
except Exception as e:
logging.error(f"Error getting podcast info for ID {podcast_id}: {str(e)}")
return jsonify({
'success': False,
'error': str(e)
}), 500
@debug_bp.route('/logs')
def view_logs():
"""
View recent application logs.
"""
try:
# This is a simple log viewer - in production you'd want proper log management
return render_template('debug/logs.html')
except Exception as e:
return jsonify({'error': str(e)}), 500