A flexible framework for scraping and analyzing YouTube comments
Project description
Sentiframe
A flexible framework for scraping and analyzing YouTube comments. This framework provides an easy-to-use interface for fetching comments and metadata from YouTube videos.
Features
- Easy-to-use API for fetching YouTube comments
- Support for various YouTube URL formats (standard, shorts, embedded)
- Fetch video metadata (title, views, likes, etc.)
- Configurable comment limit
- Built-in error handling
- Extensible base scraper class for adding more platforms
Installation
You can install the package using pip:
pip install sentiframe
For web interface support, install with web extras:
pip install sentiframe[web]
Setup
-
Get a YouTube Data API key:
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the YouTube Data API v3
- Create credentials (API key)
- Copy the API key
-
Set up your API key:
- Create a
.envfile in your project root - Add your API key:
YOUTUBE_API_KEY=your_api_key_here - Or provide it directly when initializing the scraper
- Create a
Usage
Basic Usage
from sentiframe import YouTubeScraper
# Initialize the scraper
scraper = YouTubeScraper() # Will use API key from .env
# Or provide API key directly:
# scraper = YouTubeScraper(api_key="your_api_key_here")
# Analyze a video
video_url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
result = scraper.analyze_video(video_url, max_comments=50)
# Access metadata
print(f"Title: {result['metadata']['title']}")
print(f"Views: {result['metadata']['view_count']}")
# Access comments
for comment in result['comments']:
print(f"Author: {comment['author']}")
print(f"Text: {comment['text']}")
Advanced Usage
# Fetch metadata only
video_id = scraper.extract_id(video_url)
metadata = scraper.fetch_metadata(video_id)
# Fetch comments only
comments = scraper.fetch_comments(video_id, max_results=100)
# Clear stored data
scraper.clear()
Extending the Framework
You can create your own scrapers by inheriting from the BaseScraper class:
from sentiframe import BaseScraper
class MyCustomScraper(BaseScraper):
def extract_id(self, url):
# Implement ID extraction
pass
def fetch_comments(self, content_id, max_results=100):
# Implement comment fetching
pass
def fetch_metadata(self, content_id):
# Implement metadata fetching
pass
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sentiframe-0.1.0.tar.gz.
File metadata
- Download URL: sentiframe-0.1.0.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1502033e9651b607de8be591df2256673b5a1f3285c1dea421383da490108a41
|
|
| MD5 |
dd8d255958e1c10a06344f06f5d7c3fa
|
|
| BLAKE2b-256 |
1436f7bb4f68853e43db99820ca568eb7ec9fb0ee5ae300ac06c8e2903a61f42
|
File details
Details for the file sentiframe-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sentiframe-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4a0c9ff7ad324c158eddb4ad3448de66aabda8ddd863172cb5082e551fd9799
|
|
| MD5 |
e5a96a328e869d16715b6aca4d274dc7
|
|
| BLAKE2b-256 |
6fe8e32954721213fe2dc6a176c511e38a5f117142f30d627d74068f01400109
|