DEV Community

Abheet
Abheet

Posted on

🎬 YouTube Comment Analyser

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

  1. You provide a YouTube video URL – through the CLI, web UI, or API.
  2. The backend extracts the video ID and fetches all comments using the YouTube Data API.
  3. Comments are analyzed using a simple rule‑based sentiment classifier (keywords + context).
  4. A detailed report is generated with:
    • Total reviews scanned
    • Breakdown: Positive / Neutral / Negative
    • Approval rating percentage
    • Final verdict with explanation
    • Sample positive & negative comments
  5. 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

Steps

  1. Clone the repository
git clone https://github.com/yourusername/youtube-comment-analyser.git
cd youtube-comment-analyser
Enter fullscreen mode Exit fullscreen mode
  1. Create a virtual environment (recommended)
python -m venv venv
source venv/bin/activate   # On Windows: venv\Scripts\activate
Enter fullscreen mode Exit fullscreen mode
  1. Install dependencies
pip install fastapi uvicorn requests google-api-python-client
Enter fullscreen mode Exit fullscreen mode
  1. Set up environment variables Create a .env file in the root directory:
YOUTUBE_API_KEY=your_youtube_api_key_here
Enter fullscreen mode Exit fullscreen mode
  1. Run the application
uvicorn main:app --reload
Enter fullscreen mode Exit fullscreen mode
  1. Open your browser and navigate to:
  2. Web UI: http://localhost:8000/ui
  3. API: http://localhost:8000/api/{video_id}

🔑 API Key Setup

To use the YouTube Data API, you'll need an API key:

  1. Go to the Google Cloud Console.
  2. Create a new project (or select an existing one).
  3. Enable the YouTube Data API v3.
  4. Create a credential (API Key) and copy it.
  5. Add it to your .env file as YOUTUBE_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?"
Enter fullscreen mode Exit fullscreen mode

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 NGINX and hosted UI on the Cloudflare CDN.
YOU CAN CHANGE YOUR BASE API_URL IN script.js

const API_BASE = 'URL_HERE';
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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?"
  ]
}
Enter fullscreen mode Exit fullscreen mode

📚 What I Learned

This project taught me a lot about building full‑stack applications:

  1. FastAPI Fundamentals

    • Routing (@app.get, @app.post)
    • Path parameters and query parameters
    • Middleware (including CORS middleware)
    • Async/await for non‑blocking operations
  2. YouTube Data API Integration

    • How to authenticate and make requests
    • Fetching comments (including pagination for large videos)
    • Handling rate limits and quotas
  3. CORS (Cross‑Origin Resource Sharing)

    • Why CORS errors happen (same‑origin policy)
    • How to fix them using CORSMiddleware
    • The difference between GET and POST preflight requests
    • Handling null origins for local development (file:// protocol)
  4. Frontend Development

    • Fetch API with error handling
    • Dynamically rendering reports with JavaScript
  5. API Design

    • Creating a RESTful endpoint (/{video_id})
    • Returning consistent JSON responses
    • Versioning through different routes (/cli, /ui, /api)
  6. Problem Solving

    • Debugging CORS errors with browser DevTools (Network tab)
    • Handling API failures gracefully
    • Testing API endpoints with curl and 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)