From 794557f23ab41b7651fe9a85168c469430645593 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 18 Jan 2026 18:15:13 +0000 Subject: [PATCH] feat: Integrate YouTube API for video gallery Adds a new page to display YouTube videos related to environmental protection. Implements a backend endpoint (`/api/youtube_videos`) to fetch videos from the YouTube API using a server-side API key. Creates the corresponding frontend HTML, CSS, and JavaScript (`youtube.html`, `youtube.css`, `youtube.js`) to display the videos. Adds a link to the new page on the homepage. Includes a `.env.example` to document the required `YOUTUBE_API_KEY`. --- eco_project/backend/.env.example | 1 + eco_project/backend/app.py | 32 ++++++++++++++++++++++ eco_project/backend/requirements.txt | 1 + eco_project/backend/static/index.html | 1 + eco_project/backend/static/youtube.css | 23 ++++++++++++++++ eco_project/backend/static/youtube.html | 30 +++++++++++++++++++++ eco_project/backend/static/youtube.js | 36 +++++++++++++++++++++++++ 7 files changed, 124 insertions(+) create mode 100644 eco_project/backend/.env.example create mode 100644 eco_project/backend/static/youtube.css create mode 100644 eco_project/backend/static/youtube.html create mode 100644 eco_project/backend/static/youtube.js diff --git a/eco_project/backend/.env.example b/eco_project/backend/.env.example new file mode 100644 index 0000000..b267e8e --- /dev/null +++ b/eco_project/backend/.env.example @@ -0,0 +1 @@ +YOUTUBE_API_KEY= diff --git a/eco_project/backend/app.py b/eco_project/backend/app.py index 6a93c44..c9f71f5 100644 --- a/eco_project/backend/app.py +++ b/eco_project/backend/app.py @@ -657,6 +657,38 @@ def uploaded_file(filename): def handle_chat_message(message): emit('chat_message', message, broadcast=True) + +from googleapiclient.discovery import build + +@app.route('/api/youtube_videos') +def youtube_videos(): + youtube_api_key = os.environ.get('YOUTUBE_API_KEY') + if not youtube_api_key: + return jsonify({"error": "YouTube API key is not configured."}), 500 + + try: + youtube = build('youtube', 'v3', developerKey=youtube_api_key) + + search_response = youtube.search().list( + q="environmental protection", + part="snippet", + maxResults=10, + type="video" + ).execute() + + videos = [] + for search_result in search_response.get("items", []): + videos.append({ + "title": search_result["snippet"]["title"], + "video_id": search_result["id"]["videoId"] + }) + + return jsonify(videos) + + except Exception as e: + return jsonify({"error": str(e)}), 500 + + if __name__ == '__main__': port = int(os.environ.get("PORT", 8080)) socketio.run(app, host='0.0.0.0', port=port, debug=False, allow_unsafe_werkzeug=True) diff --git a/eco_project/backend/requirements.txt b/eco_project/backend/requirements.txt index eaa9415..de58f0b 100644 --- a/eco_project/backend/requirements.txt +++ b/eco_project/backend/requirements.txt @@ -3,3 +3,4 @@ requests gunicorn google-cloud-logging Flask-SocketIO +google-api-python-client diff --git a/eco_project/backend/static/index.html b/eco_project/backend/static/index.html index 2edadc5..b188942 100644 --- a/eco_project/backend/static/index.html +++ b/eco_project/backend/static/index.html @@ -52,6 +52,7 @@

Community

Share your ideas and connect with others.