barak manos barak manos - 27 days ago 15
Python Question

Python: How to access a YouTube web page?

I am opening a YouTube web page using the 'webbrowser' module:

controller = webbrowser.get()
controller.open("http://www.youtube.com/watch?v=SMwZsFKIXa8&feature=fvst")


The video begins to play, and I would like my Python application to resume as soon as the video ends or the browser is closed.

Now, I cannot use
time.sleep
for that, because it will force me to wait until the song is over (the app will not continue if I "fast-forward" the video, or if I simply close the browser).

So I basically need to get some indication from the web page, regarding the status of the video, and another indication in case the web page is suddenly closed.

Can I use the handle I have created using
webbrowser.get
, in order to do that?

Thanks

Answer

You can't at all. The webbrowser module hands it over to a browser over which it has no control whatsoever.

You'd need to host your own browser control through something like QtWebkit in PySide or an equivalent in pygtk/wxPython. Then you could interact with it as you would own it.

Comments