1

I have a python cgi/html that takes url and launches on epiphany-browser. However, after the media/video is over, I need the browser to terminate. On other posts, it seems there are ways to do this with vlc-media and other players. But I haven't found one with a browser.

Basic framework around the command looks like:

msg = form.getvalue("msg", "(no msg)")
.......
## in-progress of msg = "sudo -u vnc " + msg + " " 
.......
from subprocess import *
print Popen(msg, shell=True, stdin=PIPE, stdout=PIPE).communicate()[0]

How do I implement such that the command (url) that gets executed shuts down after the streaming(youtube,cnn, etc) has been finished?

Thanks.

  • You need to know the length of the video and then kill the process – Padraic Cunningham Jul 07 '16 at 22:03
  • so write something that fetched the length (minute,second) each time? –  Jul 07 '16 at 22:09
  • To be honest this really does not seem like job for subprocess, the browser cannot tell python that the file has completed so you have no way through the subprocess to know when the song/video etc.. has completed. With something like vlc you can monitor the output and from memory i think it terminates itself when the media ends. What plays the media in the browser? – Padraic Cunningham Jul 07 '16 at 22:24
  • youtube most of the time. I guess I can stream that through VLC? –  Jul 07 '16 at 22:39
  • To be honest i really don't know what the best approach would be. All I know is that it won't be trivial to implement using subprocess. – Padraic Cunningham Jul 07 '16 at 23:10
  • Would it not be better use something like selenium ? – Padraic Cunningham Jul 07 '16 at 23:20
  • I might just make a button that resets it or have user put in time along with url. (Then invoke the kill command after specified command. I think bringing in selenium is too much extra work, but thank you). –  Jul 08 '16 at 00:53

1 Answers1

-1

The simplest way to do this would be to use pkill. As you're looking to kill an instance of epiphany, a browser in the Unix family of operating systems, you'd use something like:

import os
os.system("pkill epiphany-browser")

If you executable is named something other than epiphany-browser change the second part of the pkill command to match.

Also bear in mind this will kill all processes with that name. To only kill the newest you can do something like:

import os
os.system("pkill -n epiphany-browser")

If you want to be really clever, you can try to graph the actual process number after you launch it:

import os
# launch stuff...
epiphanyPID=os.system("pgrep -n epiphany-browser")[2]
# do other stuff...
os.system("kill -9 " + epiphanyPID)

Also you should probably use the webbrowser object rather than opening with Popen. It lacks a close as far as I understand from the documentation, but for opening sessions it's the preferred solution. Epiphany is supported via the Galeon object:

20.1. webbrowser — Convenient Web-browser controller

Jason R. Mick
  • 5,177
  • 4
  • 40
  • 69
  • Thank you but I still need to figure out when it should invoke the "pkill" you recommended? (as in when the video stops?). –  Jul 07 '16 at 22:40
  • FYI, `pkill` is just a Linux shell utility to kill processes by name. If you can get the video time, you can either schedule the `pkill` as a `cron` job (via a similar system call) or use a `sleep` to delay the command. It's going to be difficult to get the timing right, though, as the user could always pause the video. Without a direct signal from your video hosting service the best you can do is make an educated guess. – Jason R. Mick Jul 08 '16 at 04:33
  • 1
    Ok, thanks. I'm going to make users put length of video or default it. –  Jul 08 '16 at 05:02