This project is a Python script that calculates the total duration of all videos within a specified YouTube playlist. This is especially useful for assessing the total watch time of course material, tutorial series, or any collection of videos grouped into a YouTube playlist.
- Extracts all video durations from a YouTube playlist.
- Calculates the total length (hours, minutes, and seconds) of all videos combined.
- Utilizes YouTube Data API v3.
- Displays a progress bar during data retrieval and processing.
- Handles API key management (save, update, and use).
- Python 3.x
requests
librarytqdm
library- A valid YouTube Data API key
To install the necessary libraries, use:
pip install requests tqdm
-
API Key: Obtain a YouTube Data API key from the Google Developers Console and save it in a file named
api_key.txt
within the same directory as the script or provide it when prompted. -
Run the Script: Use the script from the command line as follows:
python main.py [-u URL] [-c] [-au]
-u, --url
[URL]: YouTube playlist URL. If not provided, you'll be prompted to input it during execution.-c, --cleanup
: Remove the stored API key file.-au, --api_update
: Update the stored API key file.
python main.py -u "https://www.youtube.com/playlist?list=PLxyz"
- Ensure that you've enabled the YouTube Data API v3 on your Google Developers Console and your API key is active and valid for the YouTube Data API.
- API quotas and limitations apply as per your API key settings in the Google Developers Console.
- The script may take a varying amount of time to retrieve data based on the number of videos in the playlist.
- Invalid URL: Ensure the playlist URL is valid.
- API Quota Exceeded: Ensure you do not exceed your API quota.
- Connection Issues: Ensure your internet connection is stable during execution.
- API Key Issues: Ensure your API key is valid and active.
This project is open-source and available to everyone. Feel free to use, modify, and distribute as per your needs.