"""Flask web application for YouTube RSS feed parsing.""" from flask import Flask, render_template, request, jsonify from feed_parser import YouTubeFeedParser app = Flask(__name__) # Default channel ID for demonstration DEFAULT_CHANNEL_ID = "UCtTWOND3uyl4tVc_FarDmpw" @app.route("/", methods=["GET"]) def index(): """Render the main page.""" return render_template("index.html") @app.route("/api/feed", methods=["GET"]) def get_feed(): """API endpoint to fetch YouTube channel feed. Query parameters: channel_id: YouTube channel ID (optional, uses default if not provided) filter_shorts: Whether to filter out Shorts (default: true) Returns: JSON response with feed data or error message """ channel_id = request.args.get("channel_id", DEFAULT_CHANNEL_ID) filter_shorts = request.args.get("filter_shorts", "true").lower() == "true" parser = YouTubeFeedParser(channel_id) result = parser.fetch_feed(filter_shorts=filter_shorts) if result is None: return jsonify({"error": "Failed to fetch feed"}), 500 return jsonify(result) def main(): """CLI entry point for testing feed parser.""" parser = YouTubeFeedParser(DEFAULT_CHANNEL_ID) result = parser.fetch_feed() if result is None: print("Failed to retrieve RSS feed") return print(f"Feed Title: {result['feed_title']}") print(f"Feed Link: {result['feed_link']}") for entry in result['entries']: print(f"\nEntry Title: {entry['title']}") print(f"Entry Link: {entry['link']}") if __name__ == "__main__": main()