youtube playlist changes

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mauritius
Posts: 25
Joined: 06 Nov 2020, 14:00
Contact:

youtube playlist changes

01 Oct 2023, 15:45

Hello,
I want to write a script which runs in the background and monitores changes in a youtube playlist that i'm interested in.
I have some trouble getting a list of videos in that playlist. When I want to download it, i get an accept-cookies page instead of the playlist content.
What's interesting - when i want to download a single video content (like title, description) I have no problem.
I use below code from this tread:

Code: Select all

MsgBox, % YouTubeTitle("https://youtu.be/dQw4w9WgXcQ")
return

YouTubeTitle(url) {
	hObject := ComObjCreate("WinHttp.WinHttpRequest.5.1")
	hObject.Open("GET", url)
	hObject.Send()
	RegExMatch(hObject.ResponseText, "(?<=title>).*?(?= - YouTube</title>)", title)
	return title
}
I'm pretty sure that many of you have much experience with retrieving data from youtube so if you could point me in some direction i'd be thankful.

[Mod action: Moved topic from AHK v2 help to v1 help, based on posted code.]
teadrinker
Posts: 4364
Joined: 29 Mar 2015, 09:41
Contact:

Re: youtube playlist changes

01 Oct 2023, 16:51

The only reliable way to get information from YouTube is to use the YouTube API.
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: youtube playlist changes

02 Oct 2023, 15:07

For getting information from google services without authentication You dont need to use their api.
Just look at browser network what You send and try to repeat it with ahk.
teadrinker
Posts: 4364
Joined: 29 Mar 2015, 09:41
Contact:

Re: youtube playlist changes

02 Oct 2023, 15:20

But why? It's much easier to get a key and use the documented API.
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: youtube playlist changes

02 Oct 2023, 15:32

For example if You want to develop it for other users - You will need to share Your private key (not recommended) or get approve from google for Your application.
teadrinker
Posts: 4364
Joined: 29 Mar 2015, 09:41
Contact:

Re: youtube playlist changes

02 Oct 2023, 15:38

I'd just advise other users to get their own key. Hacking in this case is not the best option, as you'll have to redo the script every time the site changes.
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: youtube playlist changes

02 Oct 2023, 15:44

Yes, the main disadvantage of not using their api that google periodically changes its checks.
If 2 years ago we needed to send "CONSENT=YES" cookie, now we need to send SOCS=... cookie, as I see.
teadrinker
Posts: 4364
Joined: 29 Mar 2015, 09:41
Contact:

Re: youtube playlist changes

02 Oct 2023, 15:51

Yes, and for this case you don't even have to bother with OAuth 2.0 authorization, a key is enough.
mauritius
Posts: 25
Joined: 06 Nov 2020, 14:00
Contact:

Re: youtube playlist changes

04 Dec 2023, 21:04

I just want to thank everyone who answered in this thread. I managed to succeed and I did my first script using API 8-) Thanks, good ahk people, I can always count on you!

I want just to add that this api was a bit weird... One api request only returned 20* videos per request. And to get 200th video in a playlist you couldn't ask for positions 181-200. No. You needed to ask 10 times for earlier videos (which were not interesting for you at all) to get the last position. There were some quotas of requests to api. I didn't used it all, but i can imagine it would be different if playlist was composed of 500 or 800 videos... That's weird.. But anyway - thanks again guys.

* if i recall correctly
teadrinker
Posts: 4364
Joined: 29 Mar 2015, 09:41
Contact:

Re: youtube playlist changes

05 Dec 2023, 10:04

mauritius wrote: One api request only returned 20* videos per request
I see that there is a maxResults key that allows you to specify the number of results in the output, up to 50.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 88 guests