Skip to content

ImXanax/ytwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

YouTube Watchtime Calculator

A Node.js utility that processes your official Google Takeout history and uses the YouTube Data API v3 to calculate your total lifetime watchtime.


πŸ›  Prerequisites

1. Request Your YouTube Data

You must obtain your watch history directly from Google:

  1. Go to Google Takeout.
  2. Click Deselect all, then scroll down and check YouTube and YouTube Music.
  3. Click All YouTube data included, deselect everything, and check only "history".
  4. Click Multiple formats and ensure the History format is set to JSON.
  5. Complete the export request and wait for an email from Google.
  6. Once downloaded, extract the ZIP and find watch-history.json.

2. Get a YouTube API Key

To fetch video durations, you need a Google Cloud API Key:

  1. Go to the Google Cloud Console.
  2. Create a new project and enable the YouTube Data API v3.
  3. Go to Credentials -> Create Credentials -> API Key and copy it.

πŸš€ How to Use

  1. Setup: Place your watch-history.json file in the same directory as the script.
  2. 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.


πŸ“Š What to Expect

Output & Stats

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).

Generated Files

  • 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.

πŸ”₯ Key Features

  • 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.

About

A Youtube watch time calculator

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors