Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all your watch history from youtube?

So I want to create a program to get my entire watch history and put it into a list format (excel or html list) of all the videos from my watch history with their titles and their links.

I'm a novice though so I might have to pay someone else to do it, but I want to know if this is even possible and how to accomplish it in case I want to try it on my own.

https://google-developers.appspot.com/youtube/2.0/developers_guide_protocol_watch_history?hl=ar-SA

The API for v2.0 lists how to do it, but I'm not sure if that works for 3.0 since 2.0 has been deprecated. Any help please? thanks.

like image 241
DarkVoid Avatar asked Dec 11 '25 15:12

DarkVoid


1 Answers

I don't know about "a program." It sounds like they no longer have an API for it. But you can partially automate it via the javascript console. The following instructions apply since youtube changed to material design and the history page uses infinite scrolling.

  1. Go to https://www.youtube.com/feed/history in Google Chrome and open the javascript console. (Other browsers should work as well but there may be slight differences.)

  2. In the javascript console you can automate scrolling down by entering window.scrollBy(0, 100000). I haven't tried it but you should be able to do this repeatedly with something like window.setInterval(() => window.scrollBy(0, 100000), 5000). That should cause a scroll-down every 5000ms (5 seconds); depending on your computer's speed you can tweak that number. 100000 is the number of pixels to scroll down. (It won't scroll past the end of the page, but hitting the end of the page causes it to load more and expand the page.)

  3. Once the page has scrolled far enough, enter console.clear(); document.querySelectorAll('h3 a').forEach(x => console.log(x.innerText)). Based on the current page markup, this will log all the video titles (and a few other lines). (It will clear the console first.) NOTE: the h3 a part is subject to change. It means "all anchor tags that are inside a level-3 heading tag." Also, this line can be tweaked to get things besides titles.

  4. Right-click in the console and in the context menu click Save as... to export what was just printed to a text file.

like image 57
nafg Avatar answered Dec 15 '25 17:12

nafg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!