A Node.js utility that processes your official Google Takeout history and uses the YouTube Data API v3 to calculate your total lifetime watchtime.
You must obtain your watch history directly from Google:
- Go to Google Takeout.
- Click Deselect all, then scroll down and check YouTube and YouTube Music.
- Click All YouTube data included, deselect everything, and check only "history".
- Click Multiple formats and ensure the History format is set to JSON.
- Complete the export request and wait for an email from Google.
- Once downloaded, extract the ZIP and find
watch-history.json.
To fetch video durations, you need a Google Cloud API Key:
- Go to the Google Cloud Console.
- Create a new project and enable the YouTube Data API v3.
- Go to Credentials -> Create Credentials -> API Key and copy it.
- Setup: Place your
watch-history.jsonfile in the same directory as the script. - Run the Script: Open your terminal and run:
node script.js watch-history.json YOUR_API_KEY_HERE
(Optional: Add a 3rd argument for max allowed video duration in seconds. Default is 21600 - 6 hours). this option will prevent counting 365 days long livestream videos in your history that you have watched 30 second on accident.
Once the process completes, the script will display:
- The date range of your history.
- The total number of videos processed.
- Your Total Watchtime (Days, Hours, Minutes, Seconds).
- WatchHistoryWithDuration.json: Your final results with durations included.
- progress.json: A local cache. If the script stops, it will resume from where it left off using this file, saving your API quota.
- Resume Support: Automatically skips already-processed videos if the script is restarted.
- Safe Fetching: Includes exponential backoff to handle network errors.
- Efficient Querying: Batches requests into groups of 50 to minimize API hits.