ytanalysis
is a Python package designed to analyze YouTube channel statistics using the YouTube Data API. With this package, you can retrieve information about a YouTube channel, including subscriber count, video details, views, likes, comments, and more. It also provides visualization tools to help analyze video views and monthly posting frequency.
- Retrieve detailed YouTube channel statistics (subscribers, views, total videos, etc.)
- Extract video statistics such as views, likes, and comments
- Export video data to a CSV file for further analysis
- Generate visualizations for top-performing videos and monthly posting frequency
To install this package, use pip
:
pip install ytanalysis
You need a YouTube Data API key to use this package. Follow these steps to obtain one:
- Go to the Google Cloud Console.
- Create a new project (or select an existing one) and navigate to APIs & Services > Library.
- Search for "YouTube Data API v3" and enable it for your project.
- Go to APIs & Services > Credentials and create an API key.
- Copy the API key for later use.
To initialize the YTAnalysis
class, replace YOUR_YOUTUBE_API_KEY
with your actual API key and CHANNEL_URL
with the YouTube channel URL you want to analyze:
from ytanalysis import YTAnalysis
api_key = "YOUR_YOUTUBE_API_KEY"
channel_url = "https://www.youtube.com/channel/CHANNEL_ID"
yt = YTAnalysis(channelURL=channel_url, apikey=api_key)
channel_info = yt.getChannelDetail()
print(channel_info)
video_details = yt.getVideoDetail()
print(video_details)
yt.export_csv()
yt.plotViews(values=10, mostViewed=True, save=False)
yt.plotVideoCount(save=False)