Code Monkey home page Code Monkey logo

ff2mpv's People

Contributors

ashyni avatar atemu avatar binarynoise avatar claudiofreitas avatar dansm-5 avatar dimithrandir avatar env25 avatar hexa29 avatar kirill9000 avatar remitamine avatar ryze312 avatar sheeit avatar summonholmes avatar thomastay avatar woodruffw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ff2mpv's Issues

Support for mpv flatpak

Is your feature request related to a problem? Please describe.
I am trying to make ff2mpv work with mpv flatpak, but i can´t make it work. I try edit the scripts, but i am not a dev.

Describe the solution you'd like
Make ff2mpv work with mpv flatpak., if someone can help i appreciate. Thanks!

Problems getting ff2mpv up and running on macOS

Describe the bug

I am trying to use ff2mpv extension on the most recent version of Firefox for macOS, but with no success. When I try to run videos with ff2mpv the mpv.app tries to open, but close immediately.

I followed the instructions in the following link:

[1] https://github.com/woodruffw/ff2mpv/wiki/Installation-on-macOS

I tried ff2mpv and ff2mpv.py both with no success. I prefer to use ff2mpv (the Ruby script). I opened it with nano editor to make the changes that is recommend in [1] because my mpv.app is on the /Applications folder. However, I have until now no success.

Even with python 3.9 installed, using ff2mpv.py, with changes recommended in [1], I had until now no success. However, like I said previously I prefer to use ff2mpv (the Ruby script) instead.

I tried also script ./install, but also with the same result. No sucess.

My mpv app version is 0.33 and youtude-dl version is 2021.03.14.

Reproduction steps

[1] https://github.com/woodruffw/ff2mpv/wiki/Installation-on-macOS

Platform information

  • OS information: macOS Catalina 10.15.7
  • Firefox version: 86.0.1 (64-bit)
  • MPV version: 0.33
  • youtube-dl version: 2021.03.14.

Extension doesn't work on YouTube in Chrome

Describe the bug

MPV is not opened when I try to use the extension on YouTube.

Reproduction steps

When I click on the extension in the extension bar, or click "Play in MPV" on a thumbnail, nothing at all happens.

Expected behavior

I expected mpv to open showing the video.

Screenshots

image
image
image
image
image
image
image
image

Platform information

  • OS information: Windows 10
  • Google Chrome version: 102.0.5005.115
  • MPV version: 0.34.0
  • yt-dlp version: 2022.06.22.1

Additional context

Doing "mpv [insert link]" in the command prompt works fine, but this extension has not worked a single time. I also tried this extension quickly on Vimeo and it did not work either, but I haven't tried my chances on Vimeo many times or on any other streaming services, simply because I'm just not interested. I messed around with the troubleshooting methods but I still can't get it to work. Have I done something wrong?

I installed the extension from the Chrome web store, and the code from the zip file at the top of the github page. I don't remember where I installed any of my programs, but I'm sure I could figure that out if it's necessary. Thank you in advance! Sorry, I'm not very technologically literate ig haha.

"Play in MPV" doesn't work with Youtube

  1. Right-click on a Youtube video link.
  2. Select "Play in MPV"
  3. Nothing happens.

MPV is installed in a system package, youtube-dl is also available in PATH. Running mpv from the command line with the same link works as expected.

Kubuntu 20.04, Firefox 80.0.1, ff2mpv 3.4.

Selecting resolution on YouTube (and possibly other sites)

Is your feature request related to a problem? Please describe.
Since this extension is very useful for those of us running on older machines, it would be nice to be able to limit (or select) a resolution, to avoid watching 4k videos on a Thinkpad T61.

Describe the solution you'd like
Be able to get a list of the resolution available, or at least be able to limit the resolution to a maximum.

Describe alternatives you've considered
Implement a preferences system in the extension page and sending the settings to the native client via native messaging, or as an alternative a config file read by the python script. I don't know which solution is the best one, but for sure the first one gives you more flexibility on what you can do.

Additional context

Clicking to Play with MPV does not work.

I've installed ff2mpv and the native client but nothing seem to change that I can't make ff2mpv open any youtube video, but I can open them with mpv and the video link in the terminal.
I'm using Kubuntu 20.04 and I have mpv installed tthrough apt and youtube-dl through pip3.
I'm thinking it has some problem with the url it's receiving from Firefox. but I can't confirm since I don't know how to send a message to the addon. I'll try to change the python script to run with a fixed url to see if it works

Firefox 60: Error: Attempt to postMessage on disconnected port

Mpv does not load with the latest firefox and your addon. Could you look into that?

This is the relevant part:
JavaScript error: moz-extension://28dfa88f-a733-40b7-911e-9313bd63c00e/ff2mpv.js, line 2: Error: Attempt to postMessage on disconnected port

Seek the time the video was at in the browser in mpv

Is your feature request related to a problem? Please describe.
I sometimes start watching a video in a website, before wanting to continue it in mpv, and sometimes I use timestamped video links, in those cases when I use ff2mpv I would like it to continue in mpv from the same point the video was at in the browser.

Describe the solution you'd like
The json message that is sent from the extension to the native host should include another field time which would be the time in seconds from the start of the video (the <video> tag has a property currentTime that supplies it), an example message would look like {"url":"https://www.youtube.com/watch?v=YE7VzlLtp-4","time":"47.348776"}. In the python side, you can retrieve it with message.get("time") and supply it to mpv with the --start=time flag.

Describe alternatives you've considered
Seeking the time manually, I'll rather ff2mpv do it for me.

Additional context
This is a really small change that I can implement pretty quickly, I want to see if this feature is wanted, if not I'll make it into a fork.

using ff2mpv with raspberry 3 b

im using archlinux armv7h raspberry pi 3 b, i can run mpv only from terminal To control mpv i can use keyboard keys, q=quit f=switch full video backspace=pause otherwise without terminal I can not stop mpv, add subtitles or change the audio .... At the moment once ff2mpv run mpv, i can only close with sudo killall mpv. To run mpv i need xterm + mpv, so i can use keyboard q, f, j , v , backspace when the focus is on the terminal window. If is possible to add an option , run in terminal using $term or the name defined in in the json file (xterm? lxterminal? ...).

HTTP Basic Auth passed to MPV

MPV recognizes HTTP basic auth logins in the form of mpv http://user:[email protected]/path/to/movie.mp4

However, this plugin currently doesn't pass HTTP basic auth information when "Play with MPV" is clicked on a domain that needs it.

Is there a way to possibly include this? Does Firefox disallow getting the HTTP Basic Auth password for the domain? I'm fine with setting a per-domain setting on the addon page.

New functionality ― Add video to a playlist.

Is your feature request related to a problem? Please describe.
When I'm watching some video through ffmpv Firefox Extension, for example, some series of tutorials, I can't add multiple videos to a playlist. In this case, I already have an instance of mpv open, and I can't add another video in the queue.

Describe the solution you'd like
It would be interesting if you had an option that would add a video to a playlist.

Describe alternatives you've considered
Create another option in the default context menu (when we right-click on the desired video), to add the video to a playlist.

Additional context
As an example case: I find a video of a programming tutorial, then I right click to play with mpv, then an mpv window opens. After I find another video, and with the other option to "add to playlist", the video goes to mpv playback queue, in the window that was previously opened, allowing me to go forward or backward in the playlist.
I hope I have been clear in the details, I also hope that this addition of functionality, helps to improve the usability of the project.

Some Youtube videos do not open

Hello, I have successfully installed ff2mpv. It works like a charm.
However, some videos do not open.

For example this one open fine :
https://www.youtube.com/watch?v=1Oku4KXWnuI
And this one doesn't open :
https://www.youtube.com/watch?v=A3VCxAFtP8c

I have Googled and if I understood well, it could be due to youtube-dl, see below :
mpv-player/mpv#5389

But to be honest, I understand NOTHING about their discussion. Too many codes and technical vocabulary.

Here is my mpv.conf file :

ontop=yes
border=yes
window-scale=0.2
geometry=100%:100%
ytdl-format=bestvideo[height<=?1080]+bestaudio/best
hwdec-codecs=all
hwdec=method

What is your opinion ? Is it related to this youtube-dl ? How can we solve this issue ?
Thank you very much for your kind help.

(MacOSX) mpv+X11 backend = no luck?

Hello ,

installed your new ff2mpv via ./install.sh
but the video would not play.

mpv is installed via macports with x11 backend;
the ff2mpv would call the x11 (xquartz) window, but mpv would not play.

could you give me some hint on where to start debug?

thanks.

cat over keyboard

IMPORTANT: Please check the Common problems page for debugging tips before submitting an issue. Duplicates of any information on that page will be closed.

IMPORTANT: Please fill out every section below. Bug reports with missing information will be
given a lower priority or closed outright.

Describe the bug

A clear and concise description of what the bug is.

Reproduction steps

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots (optional)

If applicable, add screenshots to help explain your problem.

Platform information

  • OS information:
  • Firefox version:
  • MPV version
  • youtube-dl version

Additional context (optional)

Add any other context about the problem here.

Should allow setting PATH when calling mpv

My Linux Firefox runs without the standard PATH set (it's usually started from a launcher which does not source the shell variables). Since mpv often needs to call other binaries (like youtube-dl), it fails in this case.

I fixed this in the Python script by calling Popen with shell=True and defining the PATH in the args, like this:

diff --git a/ff2mpv.py b/ff2mpv.py
index 67ba863..bd12d57 100755
--- a/ff2mpv.py
+++ b/ff2mpv.py
@@ -7,10 +7,12 @@ from subprocess import Popen, DEVNULL
 
 
 def main():
+    shpath = "PATH=/home/tpikonen/bin:/usr/bin"
     message = get_message()
     url = message.get("url")
     args = ["mpv", "--no-terminal", "--", url]
-    Popen(args, stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL)
+    shargs = " ".join([shpath] + args)
+    Popen(shargs, stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL, shell=True)
     # Need to respond something to avoid "Error: An unexpected error occurred"
     # in Browser Console.
     send_message("ok")

There are probably cleaner ways to set the environment and it would be nice to read the PATH automatically from somewhere, but I'll let someone else make a better fix.

Videos don't open at all

I had two problems with installation:

  1. install.sh script tried installing to "/home/william/scripts/ff2mpv", I had to install it manually and it still didn't work.
  2. I had to delete the argument "--no-terminal" (from the python script) to get it to work.

It might be related to the fact that I have zsh alias "mpv="devour mpv"".

My setup is:
Artix runit, dwm, st, mpv 1:0.33.0-3, youtube-dl 2020.12.22-1.

Hotkeys

Is there any hotkey functionality?

[Windows] Pressing Button Only Pauses Video

Describe the bug

Not sure if bug or user error. The addon does not open the currently playing video in MPV. It merely pauses the video in the browser or does nothing at all.

Reproduction steps

Browse to video url.
Click button to open the video into MPV.

Expected behavior

The video to start playing in MPV.

Screenshots (optional)

Troubleshoot

Platform information

  • OS information: Windows 10
  • Firefox version: 98.0 (64-bit)
  • MPV version - 0.34
  • youtube-dl version - 2021.12.17
  • yt-dlp version - 2022.03.08.1

Additional context (optional)

I don't know what I did wrong. I'm pretty sure I followed all the steps correctly in the Windows installation guide but it just will not open MPV for me.

fullscreen videos are stretched on my 21:9 display

Describe the bug

Videos will be stretched if they are not your native aspect ratio. 4:3 and 16:9 videos will be stretched to 21:9 on my display when playing fullscreen, and 32:9 videos will play condensed

Reproduction steps

Steps to reproduce the behavior:

  1. Open a video with a different than native aspect ratio with ff2mpv
  2. Your video will play stretched or condensed

Expected behavior

The video will play with the correct aspect ratio with black bars on the sides (or bottom and top, if the aspect ratio is higher than your own)
32:9 video for reference

Screenshots (optional)

2021-03-01_13-22
2021-03-01_13-23
2021-03-01_13-32

Platform information

  • OS information: 64 bit GNU/Linux
  • Firefox version: 85.0
  • MPV version: mpv 0.33.0-dirty
  • youtube-dl version: 2021.02.22

Windows support

Hi, can the add-on work with Windows? It says "This add-on is not available on your platform."

gnome-session-inhibit

This is a great add-on but the screen goes dark after a while even though I have gnome-session-inhibit line in mpv.desktop. Normal videos work fine.

Error: "undefined" on Mac

Hi, I've followed the necessary steps (installed the extension, put the json in the NativeMessagingHosts folder and changed it) but it doesn't work.

I enabled debugging and the only thing that shows up is this "Error: undefined" that happens on line 2.

I attempted to call that line directly like so:

browser.runtime.sendNativeMessage("ff2mpv", { url: 'https://www.youtube.com/watch?v=Nm5J_9FYU4o' }).then((err) => console.log(err)).catch(err => console.log(err));

This line successfully catches the error and console.logs it, but it only shows "Error: undefined".

Undefined looks like a javascript error. Any ideas on what I should look for next?

Installation tutorial (native-messaging-hosts not found)

Hello, first of all, thank you for your web extension.
I have an issue with the installation : I have downloaded the zip file from github.
I have put ff2mpv.py in a location. So far, so good.
Now, when I try to find the path ~/.mozilla/native-messaging-hosts/ I can't find it.
Maybe it is a new organization from Firefox, or because I use Linux (Xubuntu).

Please, do you know how to find it under Linux ? I have googled but nothing found. Thank you for your kind help.

Option for piping the video out via yt-dlp to mpv:

There are some serious caching issues in mpv due to ffmpeg. I've gone over every cache setting in mpv and found only minimum changes no matter what.

I'd like an option to play the video via yt-dlp and piping it out to mpv. I made a very simple alias myself for the terminal and it uses my bandwidth properly and caches the whole video in seconds.

play() {
yt-dlp -o - "$1" | mpv -
}

I have been using mpv for many years but only recently started watching youtube/invidious videos through ff2mpv which is great.
Also it would be helpful to make the firefox users aware that you need to download your scripts. I didn't know I needed to do that until I went to your home page from the addon page.

[Request] Ability to set or change the mnemonics shortcut on right click

Is your feature request related to a problem? Please describe.
Hello, I'm a new user here, and I see that "w" char is used as mnemonics on right click, I've container tabs and the container tabs use "w" char too, is there anyway to change the shortcut to something else on the fly or option to set to another character?

Describe the solution you'd like
If possible set to another char with option to fallback to "w"

Describe alternatives you've considered
Nothing, probably I will fork it and make my private addons with "v" as mnemonics

Additional context
See the screenshoot
image

Error: Extension not responding despite successful Windows 10 installation

Good evening, friends.
I have followed the installation instructions as outlined in the installation guide, including verifying all necessary software as being installed and present in my computer. The registry key has been created as per the provided instructions, and checking the installation as instructed through the Windows Command Prompt provides a positive response, as follows:

Microsoft Windows [versão 10.0.17763.55]
(c) 2018 Microsoft Corporation. Todos os direitos reservados.

C:\Windows\system32>python check-config-win.py
python: can't open file 'check-config-win.py': [Errno 2] No such file or directory

C:\Windows\system32>cd C:\Misc\mpvbrowserintegration\ff2mpv

C:\Misc\mpvbrowserintegration\ff2mpv>python check-config-win.py
Checking: HKEY_CURRENT_USER Software\Mozilla\NativeMessagingHosts\ff2mpv
Path from registry key is: C:\Misc\mpvbrowserintegration\ff2mpv\ff2mpv-windows.json
Path from JSON is: ff2mpv.bat
Path from batch file is: ff2mpv.py
Looks good! Give it a try from Firefox.

C:\Misc\mpvbrowserintegration\ff2mpv>

However, upon attempting to use the addon through the browser icon, I get no response. I would be grateful for any assistance in figuring out what I may have done wrong along the way and correcting it. Thank you in advance!

MPV window doesn't appear when choosing (no video) option

When I choose the new "Play in MPV (no video)" option for playing link, the sound just plays in background without showing MPV window so there's no way to easy stop or control playback. For example when I open sound file from hard drive instead there's normal empty/black window which I'd say is expected behavior.

Could it be fixed to play only audio track but still show window?

[Enhancement] Add option to play without video

An option to play without video would be useful when playing media in background. Mpv provides a way to achieve this via the --no-video argument.

I implemented this functionality by adding a new parameter to the function and then reading its value it in the script. A PR with proposed changes will be ready soon.

Pause youtube video when clicking

When clicking the button in the upper right corner, it will load the video in the background as expected and show it in a mpv window. But the video inside the browser will keep running and that makes 2 of the same video run at once.

Would it be possible to automatically pause the video inside the Firefox when clicking the ff2mpv button?

MacOS extension doesn't open player

Hi,
I'm using High Sierra, Firefox 65.0.1, mpv 0.29.1 and youtube-dl 2019.03.09.

Whenever I hit the button in Firefox or the context menu I see some movement in the Dock (seems as an icon wants to appear), but mpv won't start. Mpv and youtube-dl alone work fine from the terminal.

I used the wiki for the installation. I noticed, that my path is "path": /Users/username/ff2mpv.py, instead of /home/username/ff2mpv.py

I also changed the first line of the .py script to #!/usr/local/bin/python3.7. Without this change, I couldn't see any movement at all.

The same behaviour occurs with the ruby script.

I tried everything I could think of (reinstall, verify paths), but I can't spot the exact issue.

Multiple entrys for ff2mpv in the context menu

Is your feature request related to a problem? Please describe.
I wanna open my music playlists on YouTube with the parameters --shuffle and --no-video, which means I'm gonna have to do that in terminal and can't use ff2mpv to do that.

Describe the solution you'd like
I would like to be able to add a second entry in the context menu, to which I can add the parameters I need (also being able to name them would be nice).

Describe alternatives you've considered
Using the terminal is an alternative, but then again the whole point of this plugin is to not need the terminal for that kind of thing

ff2mpv not working on librewolf

Describe the bug

I press play in MPV and it works in firefox but if I try the same in librewolf it does nothing.

Reproduction steps

Steps to reproduce the behavior:

  1. Go to 'youtube.com'
  2. Click on 'play in MPV'
  3. Wait.
    4.Video plays (firefox), video never plays (librewolf)

Expected behavior

plays video in MPV

Platform information

  • OS information: Pop!_OS 21.04
  • Firefox version: librewolf 92.0.1
  • MPV version: newest (at the time of writing)
  • youtube-dl version: yt-dlp

Additional context (optional)

I followed every step on the wiki for linux and librewolf and ran "cp -r .mozilla/native-messaging-hosts/ .librewolf/" but it still doesn't work on librewolf.

[SOLVED] Not working with youtube videos.

As the title said it didn't work with yt, then I tried it with vimeo, it worked.
So I tried to manually play the video by passing the link to mpv, it also didn't work.
I got errors like

[ytdl_hook] youtube-dl failed: unexpected error ocurred
Failed to recognize file format.
[ytdl_hook] youtube-dl failed: unexpected error ocurred

Now I was sure that it's not ff2mpv's issue. It warned to check if I had the latest version of youtube-dl.
So I visit https://github.com/ytdl-org/youtube-dl/blob/master/README.md#how-do-i-update-youtube-dl and install it manually.
Now everything works like a charm.
Thank you @woodruffw for this gem.

tldr: Make sure your mpv and youtube-dl is latest version and enjoy.

[contribution] Controls for --no-video

Note: This is like a proposal for the wiki. Also i saw some issues related to this here.

Some times you just want to listen to the audio of a video and conveniently there --no-video flag on your ff2mpv.py saving some bandwidth and other resources. But (if using the addon function) there is no way to control the volume and other properties of the video, this can be solved with --force-windows=yes flag to display the mpv client.

These flags can be put in a profile too in your mpv.conf (as all your flags can). The appended lines would look like this

no-video
force-windows=yes

Add Compatibility for Pluto.tv streaming

Is your feature request related to a problem? Please describe.
No

Describe the solution you'd like
Compatibility with Pluto TV => https://pluto.tv

Describe alternatives you've considered
Firefox PiP, but prefer MPV usage.

Additional context
None.

about the new no-video menu

I don't realy know how many people use this new menu, for me I found it very anoing, as it adds an extra step to playing videos.
Can you provide it as an optional feather?
thanks for your awesome work.

Error feedback

Currently, when any part of the chain (ff2mpv.{js,py}, mpv[, youtube-dl]) encounters an error, ff2mpv silently fails.

Zero feedback. Either mpv opens or nothing happens.

This is especially annoying when an URL takes a while to be opened in MPV as one might wrongly conclude that it failed to open, try to open again and then be presented with two MPV instances of the same stream.

It would be very helpful if the addon told the user where things went wrong and provided a link to troubleshooting steps and the issue tracker.

Ruby script doesn't work

Following brian_ comment on the addon page, the Ruby script exits with errors. Relevant output from Firefox debugger:

stderr output from native app ff2mpv: /usr/lib64/ruby/2.2.0/json/common.rb:155:in `parse': 776: unexpected token at '"https://www.youtube.com/watch?v=9LK1jpkDh5Y"' (JSON::ParserError)
stderr output from native app ff2mpv: 	from /usr/lib64/ruby/2.2.0/json/common.rb:155:in `parse'
stderr output from native app ff2mpv: 	from /usr/local/bin/ff2mpv:7:in `<main>'
Error: An unexpected error occurred

As already pointed out, it works fine using the Python script from that other project.

ExtensionError: No such native application ff2mpv

Describe the bug

ff2mpv doesn't play video when use librewolf (a fork of firefox) but in the browser console, it says
ExtensionError: No such native application ff2mpv
with message
Error: Attempt to postMessage on disconnected port

Reproduction steps

Steps to reproduce the behavior:

  1. Install librewolf-bin
  2. Install ff2mpv following the instructions
  3. Use ff2mpv

Expected behavior

The video is played in mpv

Platform information

  • OS information: Aritx Linux
  • Firefox version: LibreWolf 91.0.1
  • MPV version: mpv 0.33.1-dirty
  • youtube-dl version: 2021.06.06

Additional context (optional)

At first, install.sh could not detect ~/.mozilla so I have to make it manually, the installation was successful. My mpv.conf is
[extension.webm] loop-file=inf

ADD ff2mpv button to Youtube Player controls

Is your feature request related to a problem? Please describe.

ff2mpv currently takes up room in Firefox's Toolbar, but I only use it in Youtube

Describe the solution you'd like

Youtube player controls would have a ff2mpv button in them

Describe alternatives you've considered

tolerating it

Additional context

speed_buttons

Add Browser Cookies to MPV

It would be great if the plugin would pass current browser cookies to mpv to allow watching private youtube videos etc.

Support for snap/flatpak distributions of Firefox

ff2mpv seems to no longer work in Firefox 99

starting from 99 firefox moved to snap, but their migration tool did not copy the native-messaging-hosts/ff2mpv.json (and others?) file.
the profile root that used to be ~/.mozilla is now in ~/snap/firefox/common/.mozilla/

Make context menu configurable

Since upgrading to 3.5 I've noticed that when right clicking individual links I need to access an additional context menu to actually play a video. I find this rather annoying, although with the no video option and potentially #20 being merged I do understand why this change was made.

Configuring which options are available to the user so I can just do "right click, play in mpv" would be greatly appreciated.

macOS support

A little help for anyone who wants to use this on a Mac:

According to https://wiki.mozilla.org/WebExtensions/Native_Messaging I moved ff2mpv.json to ~/Library/Application Support/Mozilla/NativeMessagingHosts/

With zero python knowledge, I modified ff2mpv.py to the lines below, saved it somewhere, made sure it's executable, then I modified the .json file to it's path, as described in the documentation: "path": "/wherever/you/put/it/ff2mpv.py",

#!/usr/bin/env python
import sys, struct, json
from subprocess import Popen

def main():
    message = get_message()
    url = message.get('url')
    args = ['/Applications/mpv.app/Contents/MacOS/mpv', '--no-terminal', '--', url ]
    # Popen( args )
    nully = open('/dev/null','w')
    Popen( args, stdin=nully, stdout=nully, stderr=nully )
    # Popen(args, stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL)
    # Need to respond something to avoid "Error: An unexpected error occurred"
    # in Browser Console.
    send_message('ok')


# https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Native_messaging#App_side
def get_message():
    raw_length = sys.stdin.read(4)
    if not raw_length:
        return {}
    length = struct.unpack('@I', raw_length)[0]
    message = sys.stdin.read(length).decode('utf-8')
    return json.loads(message)


def send_message(message):
    content = json.dumps(message).encode('utf-8')
    length = struct.pack('@I', len(content))
    sys.stdout.write(length)
    sys.stdout.write(content)
    sys.stdout.flush()


if __name__ == '__main__':
    main()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.