This Python script fetches detailed metadata for all videos in a YouTube channel, including video titles, thumbnails, view counts, like counts, and other stats. The metadata is saved into a metadata.json
file for further use.
- Fetch video titles, descriptions, view count, like count, and more.
- Fetch high-quality thumbnails for each video.
- Fetch video duration and other useful metadata.
- Save all data into a structured
metadata.json
file. - Handle large channels with pagination for video listings.
Before running the script, you will need the following:
- Python 3.x installed on your machine.
- YouTube Data API v3 key — Get an API key here.
- Python packages:
requests
to make HTTP requests to the YouTube API.
git clone https://github.com/your-repo-name/YouTube-Video-Metadata.git
pip install requests
- Open the
fetch_metadata.py
script. - Replace the following placeholders:
YOUR_API_KEY
: Replace this with your YouTube Data API v3 key.CHANNEL_ID
: Replace this with the YouTube channel's unique ID. (You can find the channel ID in the URL, e.g.,https://www.youtube.com/channel/CHANNEL_ID
).
-
Run the script: After configuring the script with your API key and channel ID, run it in your terminal:
python fetch_metadata.py
-
What happens next:
- The script will fetch the Uploads playlist of the given channel.
- It will retrieve all video IDs in that playlist.
- The script will then fetch detailed metadata for each video, including:
- Video title
- Video description
- Published date
- View count
- Like count
- Dislike count
- Comment count
- Video duration
- Video thumbnail URL
- All data will be saved in the
metadata.json
file.
The script saves the fetched metadata in a metadata.json
file, structured like this:
[
{
"videoId": "abcd1234",
"title": "Sample Video Title",
"description": "This is the description of the video.",
"publishedAt": "2023-05-01T12:34:56Z",
"viewCount": 1500,
"likeCount": 500,
"dislikeCount": 10,
"commentCount": 150,
"duration": "PT15M30S",
"thumbnail": "https://example.com/thumbnail.jpg"
},
...
]
If the channel has more than 50 videos, the script automatically handles pagination. It will continue fetching videos until all are retrieved.
Feel free to fork this project and submit pull requests. If you have any feature requests or bug fixes, please open an issue or create a pull request.
This project is licensed under the MIT License – see the LICENSE file for details.
- The script uses the YouTube Data API v3 to interact with YouTube and fetch video details.
- Thanks to the requests library for simplifying HTTP requests in Python.