Youtube Event

If you have a question or need help, this is the place to be.
User avatar
kgschlosser
Site Admin
Posts: 4424
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Youtube Event

Post by kgschlosser » Sat Aug 18, 2018 7:07 am

checking for fullscreen can be done using the task monitor plus plugin.

the payload of the event is an object that can perform many tasks on a window. one of them being getting the size. as an example of a python script to do this.

Code: Select all

from eg.WinApi.Utils import GetMonitorDimensions

window = eg.event.payload
rect_tuple = window.GetRectTuple()

for i, screen_tuple in enumerate(GetMonitorDimensions()):
    if tuple(screen_tuple) == rect_tuple:
        print '{0} is in fullscreen mode on monitor {1}'.format(window.title, i + 1)
         break
else:
    print '{0} is not in fullscreen mode, it has a size of {1}x{2}'.format(window.title, *rect_tuple[2:])
        
the window object can be stored if you want to access the data from another event/macro. you would place this code into a python script with the event for the creation of the window/task

Code: Select all

eg.globals.some_window = eg.event.payload
and for the destruction of the window/task

Code: Select all

eg.globals.some_window = None
and to use the object i will repeat the above fullscreen check using the saved object

Code: Select all

from eg.WinApi.Utils import GetMonitorDimensions

window = getattr(eg.globals, 'some_window', None)

if window is None:
    print 'The window is not open'
else:
    rect_tuple = window.GetRectTuple()
    for i, screen_tuple in enumerate(GetMonitorDimensions()):
        if tuple(screen_tuple) == rect_tuple:
            print '{0} is in fullscreen mode on monitor {1}'.format(window.title, i + 1)
            break
    else:
        print '{0} is not in fullscreen mode, it has a size of {1}x{2}'.format(window.title, *rect_tuple[2:])

If you like the work I have been doing then feel free to Image

Medy
Posts: 42
Joined: Sat Nov 15, 2014 8:33 pm
Location: Germany

Re: Youtube Event

Post by Medy » Sat Aug 18, 2018 8:20 am

ahh thats interisting.

Though it is not what I had in mind exactly.

I was thinking of getting the actual fullscreen mode from the youtube video iframe , not the firefox window size itself.
In hindsight its probably not doable , because you would need some sort of listener for actual source code. ( I dont think task minitor can do that ?
Didnt think that through ... also it is not really that important .. just an idea.
I dont even know if these kind of variables are to be found inside the youtube html..

Thanks anyway.

User avatar
kgschlosser
Site Admin
Posts: 4424
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Youtube Event

Post by kgschlosser » Sat Aug 18, 2018 1:57 pm

the problem with browsers in specific is that they are a custom drawn UI and have no use of any standard widgets. there for they do not use any of the Windows API except for the raw frame. Now I know that firefox is designed to be pretty open in respect to designing plugins and the like. I would bet there would be a way to create some kind of a function inside of firefox that would expose this information.
If you like the work I have been doing then feel free to Image

Medy
Posts: 42
Joined: Sat Nov 15, 2014 8:33 pm
Location: Germany

Re: Youtube Event

Post by Medy » Tue Aug 21, 2018 4:29 am

in case anyone wants the same functionality for chrome

just change the find active tab code to :

Code: Select all

if eg.lastFoundWindows:
    number = len(eg.lastFoundWindows)
    eg.plugins.Window.FindWindow(u'chrome.exe', None, u'Chrome_WidgetWin_1', None, None, number, True, 0.0, 2)
    print 'Tab title: ' + eg.WinApi.GetWindowText(int(eg.lastFoundWindows[0]))

Also the find window needs to be changed accordingly.
Last edited by Medy on Tue Aug 21, 2018 7:16 am, edited 2 times in total.

User avatar
kgschlosser
Site Admin
Posts: 4424
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Youtube Event

Post by kgschlosser » Tue Aug 21, 2018 5:56 am

Here are 2 other ways of checking if a window is in full screen mode. it does not require the use of task monitor plus. Both of these query the Windows API directly. You do need to use the Find Window action. If the Window is not a custom drawn window both methods should work. if it is a custom drawn window and that window does not let windows handle it's full screen mode, the first method will not work but the second will.

Method 1

Code: Select all

import ctypes
from ctypes.wintypes import LONG

GWL_STYLE = -16
WS_POPUP = 0x80000000

user32 = ctypes.windll.User32
GetWindowLong = user32.GetWindowLongW
GetWindowLong.restype == LONG

if eg.lastFoundWindows:
    style = GetWindowLong(eg.lastFoundWindows[0], GWL_STYLE)
    if style & WS_POPUP:
        print 'Test Type 1: Full Screen Mode'
    else:
        print 'Test Type 1: Windowed Mode'

method 2

Code: Select all

import ctypes
from ctypes.wintypes import BOOL, LONG
from eg.WinApi.Utils import GetMonitorDimensions

user32 = ctypes.windll.User32

GetWindowRect = user32.GetWindowRect
GetWindowRect.restype = BOOL

class _RECT(ctypes.Structure):
  _fields_ = [
    ('left', LONG),
    ('top', LONG),
    ('right', LONG),
    ('bottom', LONG)
  ]

RECT = _RECT

if eg.lastFoundWindows:
    rect = RECT()
    GetWindowRect(eg.lastFoundWindows[0], ctypes.byref(rect))
    rect_tuple = (rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top)

    for i, screen_tuple in enumerate(GetMonitorDimensions()):
        if tuple(screen_tuple) == rect_tuple:
            print 'Test Type 2: Full Screen Mode'
            break
    else:
        print 'Test Type 2: Windowed Mode'
If you like the work I have been doing then feel free to Image

Medy
Posts: 42
Joined: Sat Nov 15, 2014 8:33 pm
Location: Germany

Re: Youtube Event

Post by Medy » Thu Aug 23, 2018 9:32 am

kgschlosser wrote:
Sat Aug 18, 2018 1:57 pm
the problem with browsers in specific is that they are a custom drawn UI and have no use of any standard widgets. there for they do not use any of the Windows API except for the raw frame. Now I know that firefox is designed to be pretty open in respect to designing plugins and the like. I would bet there would be a way to create some kind of a function inside of firefox that would expose this information.
You were right ... I just created a plugin for chrome ( my first ) .

I put a eventlistener on the fullscreen event then send a http post to eg.
I have 2 events now :

HTTP.EG-Chrome-Plugin-fullscreen []
HTTP.EG-Chrome-Plugin-not_fullscreen []


The thing I havent figured out yet is why the events come with "[]" ....

can this be avoided ?

this is my code for POST :

Code: Select all

     // Mode has changed.
     var http = new XMLHttpRequest();
     var url = 'http://127.0.0.1:80';
     let params = 'EG-Chrome-Plugin-fullscreen';
     http.open('POST', url, true);
     
     //Send the proper header information along with the request
     http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
     
     http.onreadystatechange = function() {//Call a function when the state changes.
         if(http.readyState == 4 && http.status == 200) {
            // alert(http.responseText);
         }
     }
     http.send(params);

if not , maybe I will just use this to put some more data into the payload...

User avatar
kgschlosser
Site Admin
Posts: 4424
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Youtube Event

Post by kgschlosser » Thu Aug 23, 2018 2:10 pm

ok so what is happening is you are using the webserver plugin.

the HTTP url of the EG webserver with how you are doing the POST is.

(You can use GET as well)

Code: Select all

http://127.0.0.1:80/?EG-Chrome-Plugin-fullscreen
when using the webserver plugin you have the availability of adding payload data. you can add several items of payload data.
You may consider using the POST portion of your code to put in the title of the browser tab. maybe the window size. whatever it is you like

Code: Select all

http://127.0.0.1:80/?EG-Chrome-Plugin-fullscreen&some-title&some-resolution
the event is going to come out as

Code: Select all

HTTP.EG-Chrome-Plugin-fullscreen ['some-title', 'some-resolution']
you are able to access the 2 bots of data from a python script

Code: Select all

# the [:] copies the data to the payload variable.
# we want to do this because a list [] is mutable and can change. 
# we want to preserve the original data set if we happen to make
# a change but still need to reference the data set
payload = eg.event.payload[:]

# this sets the 2 pieces of data into 2 variables
# the [:2] on the end is so that it returns the first 2 pieces of data in the set. 
# if your data is only 2 long then you do not need this
# i put it here for completeness of the example but if by chance you at some point add a 3rd
# and you do not have the [:2] your script will break and you will get a ValueError exception
# so because of a little bit of planning we can make sure this does not occur
title, resolution = payload[:2]
and you cannot remove the [] from the event in this case. it is the way that the webserver plugin was made to operate.

well. I do not think you can remove it. the only thing I can think of is if you try adding a parameter of None to be sent in the POST.

You can test this by simply navigating to this web address

Code: Select all

http://127.0.0.1:80/?EG-Chrome-Plugin-fullscreen&None
If you like the work I have been doing then feel free to Image

Medy
Posts: 42
Joined: Sat Nov 15, 2014 8:33 pm
Location: Germany

Re: Youtube Event

Post by Medy » Thu Aug 23, 2018 3:07 pm

This is good stuff
& may add some of these as features.

Thanks for suggestions.


There is quite some potential in these chrome extensions. Im abit suprised tbh.
Will be fun to play with :D

User avatar
kgschlosser
Site Admin
Posts: 4424
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Youtube Event

Post by kgschlosser » Thu Aug 23, 2018 3:16 pm

Take a look at this.

viewtopic.php?f=9&t=6603&p=33642&hilit= ... ako#p33642

if you can think of it there is a good chance it has already been done!
If you like the work I have been doing then feel free to Image

Medy
Posts: 42
Joined: Sat Nov 15, 2014 8:33 pm
Location: Germany

Re: Youtube Event

Post by Medy » Thu Aug 23, 2018 4:10 pm

Yes. Actually this was the first thing I found when searching the chrome webstore for eventghost.

The UI seemed to be bugged ;) .. no longer functional.


Wasnt the stuff I wanted anyway ... still would have liked to fiddle :D...

User avatar
kgschlosser
Site Admin
Posts: 4424
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Youtube Event

Post by kgschlosser » Thu Aug 23, 2018 5:05 pm

it's good for example then perhaps?

or maybe some ideas.
If you like the work I have been doing then feel free to Image

Medy
Posts: 42
Joined: Sat Nov 15, 2014 8:33 pm
Location: Germany

Re: Youtube Event

Post by Medy » Fri Aug 24, 2018 4:39 pm

EG is a great app and also a inspiration...

I want to build full fledged apps at some point . Consuming API's is fun & Chrome extension seems to be the perfect tool in that regard.
Dont see much use for a EG chrome extension apart from my very specific needs :D ...

We'll see

User avatar
kgschlosser
Site Admin
Posts: 4424
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Youtube Event

Post by kgschlosser » Fri Aug 24, 2018 4:52 pm

an extension for chrome to EG would be to pass data from websites to EG. and maybe passing back items to be clicked on programmatically. because of the custom drawn UI of most browsers EG lacks the ability to specifically click on web components or even buttons them selves inside of a browser. If this is an ability that can be done with a chrome extension then allowing EG to access those specific features would be cool.

If an extension can be made that would expose the internal API of chrome to EG that would be an even better idea. because now all/most chrome API components would become available for EG to use. There are a lot of users wanting to be able to click on specific web elements or to be ale to capture data from a specific web element. There is a world of things that can be done if something like that existed.
If you like the work I have been doing then feel free to Image

Medy
Posts: 42
Joined: Sat Nov 15, 2014 8:33 pm
Location: Germany

Re: Youtube Event

Post by Medy » Sat Aug 25, 2018 6:45 pm

Giving Eg power over browser sounds intersting I give you that.

I would need somewhat of a webserver in the chrome extension so eg could send messages to it ? Or alternatively using google messaging service through google account. I guess there will be ways...

Other than that looks doable.



Will look back at this once im familiar with the DOM & basics of javascript.
This would probably be a project I can do for fun.

Though I certainly would need help for creating a EG plugin( giving the user a small interface to input the data etc...) ... cant learn it all :D

User avatar
kgschlosser
Site Admin
Posts: 4424
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Youtube Event

Post by kgschlosser » Sun Aug 26, 2018 12:15 am

Well why cant you learn it all??

3 years ago only thing i programmed was a remote . Now i know Python, C, C#, C++, PHP, HTML, CSS, and enough JavaScript to get me into trouble. Just to name a few.

I was introduced to EG two and a half years ago. Its a shame that i found something i really like doing at age 43, little late in the game, but never to old to learn.

I will help you out on the EG/python end of things.
If you like the work I have been doing then feel free to Image

Post Reply