This is my personal mini-project — it takes any YouTube video URL, fetches all its comments, analyzes the sentiment, and gives you a clear verdict on whether the community loves it, hates it, or feels neutral about it.
I built this to learn backend development with FastAPI, integrate with the YouTube Data API, and tackle real-world challenges like CORS while connecting a frontend to a backend.
Visit the Github Repo Link :- https://github.com/abheetsharma09/yt-comment-analyser
✨ Features
- Sentiment Analysis – Classifies comments as Positive, Neutral, or Negative.
- Approval Rating – Calculates the percentage of positive feedback.
- Smart Verdict – Gives a clear verdict: "Must Watch 🌟", "Good 👍", "Mixed 🤔", or "Skip ⚠️".
- Sample Comments – Shows top positive and negative comments for quick insights.
- Three Interfaces – Access the tool via CLI, Web UI, or REST API.
-
Beautiful Dashboard – A glass‑morphism UI with real‑time feedback (for
/ui). -
Video Metadata – Displays video thumbnail and title alongside the report. (for
/ui)
⚙️ How It Works
- You provide a YouTube video URL – through the CLI, web UI, or API.
- The backend extracts the video ID and fetches all comments using the YouTube Data API.
- Comments are analyzed using a simple rule‑based sentiment classifier (keywords + context).
-
A detailed report is generated with:
- Total reviews scanned
- Breakdown: Positive / Neutral / Negative
- Approval rating percentage
- Final verdict with explanation
- Sample positive & negative comments
- The report is returned to the client (terminal, web dashboard, or JSON response).
🚀 Versions
I've provided three versions of this tool to suit different use cases:
| Version | Endpoint | Description |
|---|---|---|
| CLI | /cli |
Run from the terminal – perfect for quick analysis without a browser. |
| Web UI | /ui |
Beautiful interactive dashboard – paste a URL and see the report instantly. |
| API | /api |
REST API endpoint – returns JSON data for integration with other apps. |
NOTE - ALL REQUIRES API KEY EXCEPT MY DEPLOYED VERSION
🧰 Tech Stack
| Layer | Technology |
|---|---|
| Backend | FastAPI (Python) |
| Frontend | HTML, CSS, JavaScript (Vanilla) |
| External API | YouTube Data API v3 |
📦 Installation
Prerequisites
- Python 3.8+
- A YouTube Data API v3 key (see API Key Setup)
Steps
- Clone the repository
git clone https://github.com/yourusername/youtube-comment-analyser.git
cd youtube-comment-analyser
- Create a virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies
pip install fastapi uvicorn requests google-api-python-client
-
Set up environment variables
Create a
.envfile in the root directory:
YOUTUBE_API_KEY=your_youtube_api_key_here
- Run the application
uvicorn main:app --reload
- Open your browser and navigate to:
- Web UI:
http://localhost:8000/ui - API:
http://localhost:8000/api/{video_id}
🔑 API Key Setup
To use the YouTube Data API, you'll need an API key:
- Go to the Google Cloud Console.
- Create a new project (or select an existing one).
- Enable the YouTube Data API v3.
- Create a credential (API Key) and copy it.
- Add it to your
.envfile asYOUTUBE_API_KEY.
⚠️ Note: The YouTube API has usage quotas. Free tier usually allows 10,000 requests per day, which is plenty for personal use.
💻 Usage
CLI Version (/cli)
Run the tool from your terminal for quick, no‑frills analysis.\
HERE YOU HAVE TO PROVIDE YOUR_API_KEY & YT-VIDEO-ID to extract the following output.
The output will look like:
==================================================
🎬 VIDEO AUDIENCE REPORT FOR ID: UZio8TcTMrI
==================================================
📋 Total Reviews Scanned: 230
💬 Breakdown: 132 Pos | 91 Neu | 7 Neg
📈 Approval Rating: 95.0% Positive Feedback
🚨 FINAL VERDICT: MUST WATCH 🌟
📝 Summary: The community overwhelmingly praises this video.
==================================================
✨ KEY PRAISES (Why people like it):
1. "very interesting lecture ,all the stuffs started making me more curious..."
2. "Dada tumi khub valo porao . Thank you so much 😊😊"
3. "most underrated channel ever 🔥"
🚩 CRITICAL POINTS (Viewer complaints):
1. "bro hates BJP ...me too hahaha"
2. "“I have a doubt: Can NLP detect sarcasm? ..."
3. "why the language is not english?"
Web UI Version (/ui)
The interactive dashboard — just paste a YouTube URL and get a beautiful, visual report.
Access it via: http://localhost:8000/ or you can simple open the index.html in browser that also works fine.
- Enter a YouTube URL in the input box.
- Click Analyze (or press Enter).
- See the report instantly with stats, approval bar, verdict, and sample comments.
- Video thumbnail and title are fetched automatically.
💡 Tip: The UI works only with a valid API URL and you have to configure the CORS policies in your backend for testing i am using
NGINXand hosted UI on the Cloudflare CDN.
YOU CAN CHANGE YOUR BASE API_URL INscript.js
const API_BASE = 'URL_HERE';
API Version (/api)
For developers who want to integrate the analysis into their own apps.
Endpoint: GET /{video_id}
Example:
curl "http://localhost:8000/UZio8TcTMrI"
Response (JSON):
{
"video_id": "UZio8TcTMrI",
"total_review": 230,
"vdo_breakdown": {
"positive": 132,
"neutral": 91,
"negetive": 7
},
"percentage": "95.0",
"veridct": "MUST WATCH 🌟",
"quick_summary": "The community overwhelmingly praises this video. High educational value.",
"positive_comment": [
"very interesting lecture ,all the stuffs started making me more curious about learning ML",
"Dada tumi khub valo porao . Thank you so much 😊😊",
"most underrated channel ever 🔥"
],
"negative_comment": [
"bro hates BJP ...me too hahaha",
"“I have a doubt: Can NLP detect sarcasm? ...",
"why the language is not english?"
]
}
📚 What I Learned
This project taught me a lot about building full‑stack applications:
-
FastAPI Fundamentals
- Routing (
@app.get,@app.post) - Path parameters and query parameters
- Middleware (including CORS middleware)
- Async/await for non‑blocking operations
- Routing (
-
YouTube Data API Integration
- How to authenticate and make requests
- Fetching comments (including pagination for large videos)
- Handling rate limits and quotas
-
CORS (Cross‑Origin Resource Sharing)
- Why CORS errors happen (same‑origin policy)
- How to fix them using
CORSMiddleware - The difference between
GETandPOSTpreflight requests - Handling
nullorigins for local development (file://protocol)
-
Frontend Development
- Fetch API with error handling
- Dynamically rendering reports with JavaScript
-
API Design
- Creating a RESTful endpoint (
/{video_id}) - Returning consistent JSON responses
- Versioning through different routes (
/cli,/ui,/api)
- Creating a RESTful endpoint (
-
Problem Solving
- Debugging CORS errors with browser DevTools (Network tab)
- Handling API failures gracefully
- Testing API endpoints with
curland Postman
🔮 Future Improvements
Here's what I'd like to add next:
-
AI‑Powered Sentiment – Use a pre‑trained NLP model (e.g.,
transformers) for more accurate sentiment analysis. - Comment Filtering – Skip spam or irrelevant comments for cleaner analysis.
- Multi‑Language Support – Detect and analyze comments in any language.
- Caching – Cache results for 24 hours to reduce API calls and speed up repeated requests.
- Video Insights – Add data like view count, like/dislike ratio, and channel info.
- Export Reports – Allow users to download reports as PDF or CSV.
- User Authentication – Add login to save analysis history.
Top comments (0)