This project provides a Python script to extract data from a YouTube playlist. It uses the YouTube Data API to fetch video details such as title, publication date, views, likes, and dislikes. Dislikes are retrieved through an additional third-party service, which is not officially supported by YouTube.
- Extracts data from all videos in a given YouTube playlist.
- Retrieves and displays the following video details:
- Title
- Thumbnail URL
- Shareable video link
- Publication date
- View count
- Like count
- Dislike count (using a third-party API)
- Saves the extracted data to a CSV file.
To run this script, you need:
- Python 3.6+
- A valid YouTube Data API key (refer to YouTube Data API Documentation to generate a key).
- Clone the repository (or copy the script) to your local machine.
- Install dependencies (if necessary):
- No external dependencies are required as the script only uses Python's built-in libraries:
json
,urllib.request
,datetime
, andcsv
.
- No external dependencies are required as the script only uses Python's built-in libraries:
-
Obtain a YouTube API Key:
- Visit the Google Cloud Console.
- Create a new project and enable the YouTube Data API v3.
- Generate an API key for the project.
-
Run the Script:
- Open a terminal or command prompt.
- Navigate to the directory containing the script.
- Run the script using the command:
python main.py
- Enter your YouTube API key and the playlist ID when prompted.
-
Extract Playlist Video IDs:
- The function
get_playlist_videos
takes a playlist ID and retrieves all video IDs associated with that playlist using the YouTube Data API. - It handles pagination using the
nextPageToken
to ensure all videos in the playlist are fetched.
- The function
-
Fetch Video Details:
- The
get_video_details
function uses the video IDs to get detailed information for each video. - The details include the title, thumbnail URL, shareable link, publication date, view count, and like count.
- The script also retrieves the dislike count using a third-party API called Return YouTube Dislike API, which scrapes data that is no longer available through YouTube's official API.
- The
-
Save Data to CSV:
- The extracted data is saved to a CSV file named
Playlist-{playlist_id}.csv
, where{playlist_id}
is the ID of the playlist. - Each row in the CSV represents a video's details.
- The extracted data is saved to a CSV file named
playlist_id
: The ID of the YouTube playlist to be analyzed.api_key
: Your unique YouTube API key.
After running the script, a CSV file will be generated with the following columns:
title | thumbnail | share | published_date | views | likes | dislikes |
---|---|---|---|---|---|---|
Video Title | URL to video thumbnail | YouTube short link | Date Published | 12345 | 678 | 90 |
- YouTube API Limitations: The script may hit request quotas set by the YouTube Data API, so consider monitoring your API usage.
- Use of Dislike Data: The
Return YouTube Dislike API
is a third-party service that retrieves dislike data for videos.
- The YouTube Data API may not provide all available data due to privacy settings or API restrictions.
- The script is dependent on the availability of the third-party dislike API. If the service is unavailable or banned, dislike data cannot be retrieved.
- Since YouTube removed public dislike counts, the accuracy and legality of retrieving this data through third-party APIs are questionable.
- YouTube Data API Documentation
- Return YouTube Dislike API (for retrieving dislike counts)
This script is intended for educational purposes only. Use it at your own risk. The author is not responsible for any misuse or legal issues that arise from using the script. Always comply with YouTube's terms of service when accessing their data.