GitHub - nerder/comments-analysis: Download YouTube comments and run AI-powered sentiment analysis & bot detection with detailed reports

2 min read Original article ↗

YouTube Comments Analysis Tool

A comprehensive tool for downloading YouTube comments and performing sentiment analysis and bot detection using AI.

Features

  • Download YouTube Comments: Fetches all comments and replies from any YouTube video
  • Sentiment Analysis: Analyzes emotional tone of comments (positive, negative, neutral, mixed)
  • Bot Detection: Identifies potential bot accounts and spam patterns
  • Detailed Reports: Generates comprehensive JSON reports and human-readable summaries

Setup

  1. Install dependencies:
pip install -r requirements.txt
  1. Get API keys:

YouTube Data API v3

  • Go to Google Cloud Console
  • Create a new project or select existing
  • Enable YouTube Data API v3
  • Create credentials (API Key)

OpenAI API

  1. Configure environment variables:
cp .env.example .env
# Edit .env and add your API keys:
# YOUTUBE_API_KEY='your-youtube-api-key'
# OPENAI_API_KEY='your-openai-api-key'

Usage

1. Download Comments

python youtube_comments_downloader.py 'https://www.youtube.com/watch?v=VIDEO_ID'

Output: output/comments_VIDEO_ID.json

2. Analyze Comments

Full Analysis (Sentiment + Bot Detection)

python analyze_comments.py output/comments_VIDEO_ID.json

Sentiment Analysis Only

python analyze_comments.py output/comments_VIDEO_ID.json --no-bots

Bot Detection Only

python analyze_comments.py output/comments_VIDEO_ID.json --no-sentiment

Custom Output Directory

python analyze_comments.py output/comments_VIDEO_ID.json --output-dir my_analysis

Project Structure

├── analyzers/              # Analysis modules
│   ├── sentiment_analyzer.py
│   └── bot_detector.py
├── prompts/               # AI prompt templates
│   ├── sentiment_single.txt
│   ├── sentiment_batch.txt
│   ├── bot_detection.txt
│   └── ...
├── output/                # Downloaded comments
└── analysis_results/      # Analysis reports

Output Formats

Downloaded Comments (JSON)

[{
    "author": {
        "name": "Author Name",
        "createdAt": "2021-01-01T00:00:00Z"
    },
    "comment": "Comment text",
    "numberOfLikes": 100,
    "replies": [/* nested replies */]
}]

Sentiment Analysis Output

  • Sentiment distribution (positive/negative/neutral/mixed)
  • Confidence scores for each prediction
  • Emotion tags (happy, angry, frustrated, etc.)
  • Detailed per-comment analysis

Bot Detection Output

  • Identified bot accounts with confidence scores
  • Spam pattern frequency analysis
  • Bot indicators (account age, message similarity, etc.)
  • Human-readable summary report

Analysis Features

Sentiment Analysis

  • Analyzes emotional tone using GPT-4
  • Batch processing for efficiency
  • Emotion tagging
  • Confidence scoring

Bot Detection

  • Pattern matching for common spam indicators
  • Account age verification
  • Message similarity analysis
  • AI-powered behavioral analysis
  • Comprehensive bot scoring system

Notes

  • Comments are fetched with all their replies
  • Handles pagination automatically to get all comments
  • Works with various YouTube URL formats (youtube.com, youtu.be, etc.)
  • Prompts are externalized in text files for easy customization
  • All analysis results are saved in timestamped files

Requirements

  • Python 3.8+
  • YouTube Data API v3 key
  • OpenAI API key (for analysis features)