How much total time have you spent on YouTube? Here's one way to find out taking it's data from a Google Takeout YouTube history export. The export doesn't contain the durations of the videos so we have to take an extra step to query for them. My watch_history.html was about 28MB so I decided to do this as a 2-step process, knowing this would take a long time. Step one is to extract the actual video links. While this sounds like the perfect case for a Perl or shell one-liner, I couldn't come with a working one so here's some Python code to do that (extract.py): import re, sys html = sys.stdin.readlines() links = re.findall('<a href="(https://www.youtube.com/watch\?v=.+?)">', str(html)) for l in links: print(l) We can pipe the links directly to (the excellent) youtube-dl tool to grab the durations and save them into a separate file (times.txt): cat watch_history.html | python extract.py | xargs -n 1 youtube-dl \ --get-duration > times.txt That process took all night for me, resulting in a file with 25036 lines. I don't like where this is going... Next, we need to add up all those durations. IMHO, Python isn't the most straight-forward tool for time arithmetic, but here's what I came up with (total.py): import sys, time from datetime import timedelta s = 0 # total seconds d = ('%S', '%M:%S', '%H:%M:%S') # formats for the durations while True: line = sys.stdin.readline().strip() if line == '': break if line == '60:00': line = '01:00:00' i = line.count(':') _ = time.strptime(line, d[i]) # 😎 s += _.tm_sec + _.tm_min*60 + _.tm_hour*60*60 print(str(timedelta(seconds=s))) Finally, let's tally the numbers: cat times.txt | python total.py ... 🥁🥁🥁🥁🥁🥁🥁 ....
318 days, 8:50:18
In other words, I've spent nearly a year of my life staring at YouTube. I might not have watched every video to the end, but the duration query failed on many videos (video either no longer available or requires login) so I'm calling the results "close enough". 318 days. That's a long time. There's a lot of "good" in those 318+ days, but also tons of crap. Crap that I most likely wached only because YouTube recommended it to me and would never have come across if we didn't live in our current video sharing plaform monopoly. I guess the point I'm trying to make, or at least ponder, is if we lived in a normal world with millions of sites posting videos - I would probably still have found the ones I truly needed/cared about without wasting over a percent of my lifetime just "watching stuff". Of course, there's no way for me to back up my claim since all of this completely unprecedented in the history of humanity. Special shoutout to Jupyter Notebook which I was checking out while testing those code snippets. #youtube #media #python Older posts