Page 1 of 1

script to full screen YouTube videos

Posted: 22 Jul 2017, 16:04
by kmcintyre
Hello,

I'm visually impaired and use a lot of AHK scripts to aid in my use of my computer. But I have a problem and can use some help...

One thing I would love to automate is finding and clicking the button at the far right of the YouTube video player's control bar. I'm pretty sure there is no Windows handle or id for this control. And I'm pretty sure that I'd need to do an http Send with some command string to ask YouTube to go full screen. But those are just educated guesses,..

If any of you young, super studs can help an old blind guy out with a script to automate taking YouTube videos full screen, I'd be greatly appreciative...

(I have the same issue with Vimeo. I'm guessing if I can see how to do it with YouTube I'll be able to figure out Vimeo...)

Thanks in advance!

Keith

Re: script to full screen YouTube videos

Posted: 22 Jul 2017, 17:28
by jeeswg
This is the most annoying problem ever. Pressing f works to get fullscreen in Mozilla Firefox and Google Chrome, but not in Internet Explorer.

This works for YouTube in Internet Explorer, but if anyone has any other ideas or knowledge on the subject, I would like to know anything I can about this problem, thanks.

Code: Select all

#IfWinActive, ahk_class IEFrame
;[WBGet function]
;Basic Webpage Controls with JavaScript / COM - Tutorial - Tutorials - AutoHotkey Community
;https://autohotkey.com/board/topic/47052-basic-webpage-controls-with-javascript-com-tutorial/

~f::
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)
if InStr(oWB.document.url, "youtube.com/")
|| InStr(oWB.document.url, "youtu.be/")
{
	oWB.document.getElementsByClassName("ytp-fullscreen-button ytp-button").item[0].focus()
	;oWB.document.getElementsByClassName("ytp-fullscreen-button ytp-button").item[0].click() ;didn't work
	ControlSend, Internet Explorer_Server1, {Enter}, % "ahk_id " hWnd
}
oWB := ""
return
#IfWinActive
Re. annoying, in the UK at least, when watching playlists, YouTube kept playing the same 3 mini-Tyler Oakley adverts and 1 Lilly Singh advert constantly. This was really awful and so I set up a script to mute YouTube the second I heard one of those ads come on.

==================================================

I couldn't get Vimeo to work, I tried things like:

Code: Select all

	oWB.document.getElementsByClassName("fullscreen").item[0].focus()
	oWB.document.getElementsByClassName("fullscreen").item[0].click()
	oWB.document.getElementsByClassName("fullscreen-icon").item[0].focus()
	oWB.document.getElementsByClassName("fullscreen-icon").item[0].click()
Like YouTube, f works to set fullscreen on, on Mozilla Firefox and Google Chrome, but doesn't work on Internet Explorer 11.

Re: script to full screen YouTube videos

Posted: 22 Jul 2017, 18:20
by kmcintyre
Well that's totally awesome! I have been using Edge just because I like it and it's the default. But I have chrome and Firefox too.

Hopefully someone will add to the discussion with a workaround for IE 11 and/or Edge...

I used to be a programmer. I could follow your code quite easily. Thanks!

Keith

Re: script to full screen YouTube videos

Posted: 11 Aug 2017, 08:31
by jeeswg
It turns out that with YouTube you can double-click on the video to view it in fullscreen, but I am having trouble trying to invoke double-click on a web element, if anyone has any ideas.

E.g. *not* working, it reacts (toggles play/pause) but doesn't invoke fullscreen:

Code: Select all

	oWB.document.getElementById("movie_player").click()
	Sleep 100
	oWB.document.getElementById("movie_player").click()
(dblclick and doubleclick didn't work.)

==================================================

This is a version of the script above for YouTube, but which closes the notification bar via Acc.

Code: Select all

#IfWinActive, ahk_class IEFrame
;[WBGet function]
;Basic Webpage Controls with JavaScript / COM - Tutorial - Tutorials - AutoHotkey Community
;https://autohotkey.com/board/topic/47052-basic-webpage-controls-with-javascript-com-tutorial/
;Acc library (MSAA) and AccViewer download links - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

~f::
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)
if InStr(oWB.document.url, "youtube.com/")
|| InStr(oWB.document.url, "youtu.be/")
{
	oWB.document.getElementsByClassName("ytp-fullscreen-button ytp-button").item[0].focus()
	;oWB.document.getElementsByClassName("ytp-fullscreen-button ytp-button").item[0].click() ;didn't work
	ControlSend, Internet Explorer_Server1, {Enter}, % "ahk_id " hWnd
}
oWB := ""

;close notification bar
ControlGet, hCtl, Hwnd,, DirectUIHWND1, % "ahk_id " hWnd
oAcc := Acc_Get("Object", "4.4", 0, "ahk_id " hCtl)
if (oAcc.accName(0) = "Close")
	oAcc.accDoDefaultAction(0)
oAcc := ""
return
#IfWinActive

Re: script to full screen YouTube videos

Posted: 11 Aug 2017, 11:58
by tmplinshi
Nice jeeswg!

Just 2 tips:
  • You can use oWB.hwnd instead of WinGet, hWnd, ID, ahk_class IEFrame
  • You can use oAcc := oAcc.accChild(4) instead of oAcc := Acc_Get("Object", "4.4", 0, "ahk_id " hCtl)
BTW, the F key works for me in Edge browser.

Re: script to full screen YouTube videos

Posted: 11 Aug 2017, 13:32
by BoBo
Wasn't it F11 for all other IEs ??

Re: script to full screen YouTube videos

Posted: 11 Aug 2017, 14:47
by jeeswg
@tmplinshi: Thanks. It seems I left some extra lines in, from debugging, it's fixed now.

@BoBo: F11 sets fullscreen for Internet Explorer, f or double-click sets fullscreen for the YouTube video.

Re: script to full screen YouTube videos

Posted: 12 Aug 2017, 00:35
by Masonjar13
This may or may not work..

Code: Select all

oWB.document.dblclk.createEventObject()
oWB.document.dblclk.eventType:="dblclick"
oWB.document.eventName="dblclick"

; call it

; oWB.document.getElementsByClassName("ytp-fullscreen-button ytp-button").item[0].fireEvent("on" . oWB.document.dblclk.eventType, oWB.document.dblclk)
oWB.document.getElementById("movie_player").fireEvent("on" . oWB.document.dblclk.eventType, oWB.document.dblclk)
More likely to work.

Code: Select all

; oWB.navigate("javascript:var dblclk=document.createEventObject();dblclk.eventType='dblclick';document.getElementsByClassName('ytp-fullscreen-button ytp-button').item[0].fireEvent('on'+dblclk.eventType,dblclk);")
oWB.navigate("javascript:var dblclk=document.createEventObject();dblclk.eventType='dblclick';document.getElementById('movie_player').fireEvent('on'+dblclk.eventType,dblclk);")
Anyone know a way to directly execute JS via COM?