DEV Community

Yuval Greenfield
Yuval Greenfield

Posted on

A Python script to see my most watched YouTube videos

I use YouTube Music and I was wondering which songs I've listened to the most. You can't find that information in the YouTube Music app. But luckily, Google keeps a complete history at Google Takeout. So I can get the list of my most played songs. Here are the steps to do that.

1. Download YouTube Music takeout data

Go to and deselect all takeouts.

Deselect all the takeouts

2. Select YouTube and configure the export

YouTube takeout

3. Deselect all YouTube content options

Deselect all YouTube content options

4. Select just "history" content option

Select just "history" content option

5. Export JSON, not HTML

Export JSON, not HTML

6. Create the export

After this step, you will be emailed a link with a zip file that has your history.

Create the export

7. Unzip the file

If you're on a Mac, that's just double-clicking the zip file.

8. Place the Python code next to watch-history.json

In the new folder that was unzipped, you'll find watch-history.json inside a few folders. In my case the path was Downloads/YouTube and YouTube Music/history/watch-history.json so I developed the script at Downloads/YouTube and YouTube Music/history/

Python code

Paste the following into

import json
from collections import Counter
from pprint import pprint

watched = Counter()
for item in json.load(open('watch-history.json')):
    if "titleUrl" not in item:
        # Watched a video that has been removed
    title = item["title"]
    url = item["titleUrl"]
    key = f"{title} @> {url}"
    watched[key] += 1

Enter fullscreen mode Exit fullscreen mode

Running the code, seeing the result

$ python3
[('Watched Here Comes The Sun (Remastered 2009) @> '
 ('Watched Guess Who Is Back @>',
 ('Watched The Rumbling (TV Size) @> '
 ('Watched ətˈæk 0N tάɪtn @>', 61),
 ('Watched Omokage (produced by Vaundy) @> '
Enter fullscreen mode Exit fullscreen mode

For me, the top result wasn't a song I liked too much, but it was my alarm clock for almost a year. Of these songs, I recommend you check out this one: Omokage by milet, Aimer, Lilas Ikuta, Vaundy

I hope you find this script useful. Cheers.

Top comments (0)