Skip to content

A script that processes a YouTube video URL and generates an Excel sheet with the video comments categorized by sentiment (Positive, Neutral, Negative).

Notifications You must be signed in to change notification settings

michellevit/Comment-Sentiment-Analyzer

Repository files navigation

YouTube Comment Sentiment Analyzer

Python Hugging Face Hub openpyxl TensorFlow YouTube API

This script intakes a YouTube video link, and outputs all of the video's YouTube comments in an excel sheet, sorted by sentiment (i.e. Positive, Neutral, or Negative). The sentiment analysis done by the 'Hugging Face' cardiffnlp roBERTA-base language model, which was trained on ~58 million tweets.

Comment Sentiment Analyzer Demo

Table of Contents

Requirements

  • Libraries
    • Python 3.9
    • googleapiclient 2.14.0
    • openpyxl 3.1.2
    • dotenv 1.0.0
    • transformers 4.35.2
    • tensorflow 2.15.0
    • huggingface-hub 0.19.4
    • langdetect 1.0.9
  • Other:
    • Google account
    • YouTube API key

How To Install

  • Download the repository from GitHub
    • Click the green 'Code' button
    • Click 'Download ZIP'
    • Unzip the file (find the folder in your computer and right-click 'Extract all')
  • Install Python 3.9 to your computer
    • If it does not work, make sure it is added to your system's PATH
    • Note: It must be version 3.9 for Tensorflow to work
  • Install Rust
  • Create a Virtual environment
  • Install required libraries in virtual env
    • Open a terminal
    • Activate the virtual environment"
      • Run C:\Users\Michelle\.virtualenvs\Comment-Sentiment-Analyzer-Virtual-Env\Scripts\Activate.ps1
    • Run:
      • pip install --upgrade google-api-python-client
      • pip install openpyxl
      • pip install python-dotenv
      • pip install transformers
      • pip install tensorflow
      • pip install huggingface-hub
      • pip install langdetect
  • Open the 'env.txt' file in VSCode (or a text/code editor)
    • Fill in all the 'youtube_api_key' line
      • How to Get a YouTube API Key:
        • Log in to Google Developers Console
        • Create a new project
        • On the new project dashboard, click Explore & Enable APIs
        • In the library, navigate to YouTube Data API v3 under YouTube APIs
        • Enable the API
        • Create a credential
        • A screen will appear with the API key
    • Rename the 'env.txt' file to '.env' and save it
  • Update the file paths in 'run_script_1.bat' and 'run_script_2.bat'
    • Note: there are 2 paths per file which need to be updated

How To Run

  • Double click the 'run_script_1.bat' file
    • Open the newly created 'YouTube-Comment-Analyzer-Setup.xlsx' file
    • Enter the YouTube video link in the B1 cell
    • Adjust the B2 cell value to analyze more/less comments
      • Note: comment analysis takes ~3 seconds per comment
    • Save and close the file
  • Double click the 'run_script_2.bat' file
    • Once it is ready, it will be renamed: "YouTube-Comment-Analyzer-Complete.xlsx"
    • Note: replies to comments will not be recorded
    • Note: only english comments will be recorded
    • Note: the most recent comments will be returned first

Troubleshooting

  • The excel files cannot be open while running the script
  • Comment analysis takes ~3 seconds per comment, so you may need to wait

Credits

Michelle Flandin

About

A script that processes a YouTube video URL and generates an Excel sheet with the video comments categorized by sentiment (Positive, Neutral, Negative).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published