This tool analyzes the sentiment of comments on a YouTube video using the YouTube Data API and NLTK's VADER sentiment analyzer.
-
Clone this repository:
git clone https://github.com/yourusername/youtube-sentiment-analysis.git cd youtube-sentiment-analysis
-
Install the required dependencies:
pip install -r requirements.txt
-
Set up a YouTube Data API key:
- Go to the Google Developers Console
- Create a new project or select an existing one
- Enable the YouTube Data API v3
- Create credentials (API key)
- Set the API key as an environment variable:
export YOUTUBE_API_KEY='your-api-key-here'
Run the script with a YouTube video ID as an argument:
python main.py VIDEO_ID
Replace VIDEO_ID
with the ID of the YouTube video you want to analyze. The video ID is the value of the 'v' parameter in the video's URL. For example, if the video URL is https://www.youtube.com/watch?v=dQw4w9WgXcQ
, the video ID would be dQw4w9WgXcQ
.
The tool will print the sentiment analysis results, including:
- The total number of comments analyzed
- The percentage of positive, neutral, and negative comments
- The tool is limited by the YouTube API's quota and rate limits.
- Sentiment analysis is performed using a pre-trained model and may not always accurately capture the intended sentiment, especially for complex or nuanced comments.
- The tool currently analyzes only the top-level comments and does not include replies.
This project is open source and available under the MIT License.