Is there a way to make firefox stream youtube videos in an external player (eg vlc) when you click on a youtube video? More generally, is it possible to run an external script upon clicking certain types of links, eg those that are of the form www.youtube.com/watch?v=* ?

Even more ambitiously, when I click on a youtube video while pressing down CTRL, I want to automatically ssh into my raspberry pi and stream the video on the pi with omxplayer.

Any help will be much appreciated.

  • 1
    you could try to have a look to the settings of firefox and see if you can set a given MIME type to be open in an external software. – PinkFloyd May 12 '15 at 6:28

Primarily what you require is issuing an external command on your OS from your browser. But this is usually tough due to obvious security reasons. However, there is an add-on for Firefox which can achieve this : Commandrun. But I haven't tried this addon so can't comment on it.

A Reasonably Good Solution

However, I'd suggest another alternative solution using Autokey. This is not going to be the best solution as per your needs but it can be a reasonable one.

So, first install autokey:

sudo apt-get install autokey-gtk #Assuming you're on a Debian-based linux

Now, in Autokey, create a new script and write the following lines in that script:

import subprocess
keyboard.send_keys("<ctrl>+l") #Bring cursor to the location bar
keyboard.send_keys("<ctrl>+c") #Now copy the location from the location bar
keyboard.send_keys("<ctrl>+w") #Now close the window

text = clipboard.get_selection() #copy the clipboard content i.e. the URL

subprocess.call(["vlc", text]) #Make the call to vlc player

Now, assign some hotkey to this script such as SuperL or anything else that you prefer. Also, assign a filter so that this script will run only on Firefox windows and not any other window. To apply the filter just add .*Firefox.* in the Filter.

How this works:

Whenever you are on a youtube video page on Firefox, you can now press SuperL and this script will run. It will first copy the url and then close the youtube tab. Then it will take this url and make a call to vlc to run this video.

Further extension

You can further easily extend the script to make an ssh connection to your RaspberryPi and run the video there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.