woodruffw / ff2mpv

A Firefox/Chrome add-on for playing URLs in mpv.
https://addons.mozilla.org/en-US/firefox/addon/ff2mpv/
Other
521 stars 52 forks source link

Support for mpv flatpak #87

Closed tjssoldier closed 1 year ago

tjssoldier commented 2 years ago

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!

woodruffw commented 2 years ago

I don't use Flatpaks and I have no idea how they work, but I'm happy to review changes if any are required to support them. That being said, I'm not sure what this extension should do -- all we do is call out to the mpv binary, which shouldn't care whether it's a Flatpak or anything else.

tjssoldier commented 2 years ago

At least on the terminal, flatpak mpv works in a very similar way of regular mpv. Just runflatpak run io.mpv.Mpv and the url and the video will play. So i was thinking that will be just a matter of make the extension call for the flatpak command to make it work.

woodruffw commented 2 years ago

Oh, it needs to go through some kind of runner?

In that case, depending on which native client you're using (Python or Ruby), you should only need a one line change.

For Ruby, this line:

https://github.com/woodruffw/ff2mpv/blob/1f6cfc480270ef2c8eae81a37d470251b5d2cf31/ff2mpv#L21

should become:

pid = spawn "flatpak", "run", "io.mpv.Mpv", *args, "--", url, in: :close, out: "/dev/null", err: "/dev/null" 

and for Python, this line:

https://github.com/woodruffw/ff2mpv/blob/1f6cfc480270ef2c8eae81a37d470251b5d2cf31/ff2mpv.py#L15

should become:

args = ["flatpark", "run", "io.mpv.Mpv", "--no-terminal", "--", url]

I haven't tested either of those, but that's what I'd expect.

tjssoldier commented 2 years ago

I tried lines above but it does not work. There is some way having some kind of log to know why its not working ?

rockerbacon commented 2 years ago

I achieved this with a simple script to alias the command mpv to its Flatpak counterpart. Just place this in a file named mpv in one of your executable locations (I'd recommend ~/.local/bin, make sure it is in your $PATH environment variable):

#!/usr/bin/env sh

flatpak run io.mpv.Mpv "$@"

You can test whether the script is working or not with the command:

mpv --no-terminal -- 'https://youtu.be/dQw4w9WgXcQ'

@woodruffw Not sure if there are Flatpak libraries out there for Python/Ruby (probably yes) but one can detect whether mpv is installed on Flatpak with the command:

flatpak info io.mpv.Mpv

It will exit with code 0 if mpv is installed and 1 if it's not. If Flatpak itself isn't available, the exit code should be some other non-zero value (127 on my machine).

Running this in the script and checking the exit code to determine which arguments to use is an option. If you'd be ok with such solution, I can send a pull request with the changes for the Python script. From there I believe you could easily port the changes to the Ruby script.

woodruffw commented 2 years ago

Thanks for posting your solution!

I'm currently inclined to treat this as a "patch your local client" case, since I don't have a good sense of how many users are actually using ff2mpv with Flatpak. If more chime in and desire this feature, I'd be happy to accept a PR for it (and update the Ruby client in the same way).

In the mean time, documenting your patch on the Wiki would be greatly appreciated :slightly_smiling_face:

pm4rcin commented 2 years ago

I achieved this with a simple script to alias the command mpv to its Flatpak counterpart. Just place this in a file named mpv in one of your executable locations (I'd recommend ~/.local/bin, make sure it is in your $PATH environment variable):

#!/usr/bin/env sh

flatpak run io.mpv.Mpv "$@"

You can test whether the script is working or not with the command:

mpv --no-terminal -- 'https://youtu.be/dQw4w9WgXcQ'

@woodruffw Not sure if there are Flatpak libraries out there for Python/Ruby (probably yes) but one can detect whether mpv is installed on Flatpak with the command:

flatpak info io.mpv.Mpv

It will exit with code 0 if mpv is installed and 1 if it's not. If Flatpak itself isn't available, the exit code should be some other non-zero value (127 on my machine).

Running this in the script and checking the exit code to determine which arguments to use is an option. If you'd be ok with such solution, I can send a pull request with the changes for the Python script. From there I believe you could easily port the changes to the Ruby script.

Hi, could you tell how did you configure whole thing? I mean I have placed ff2mpv.json and ff2mpv.py in /var/lib/flatpak/app/io.gitlab.librewolf-community/current/active/files/lib/librewolf/native-messaging-hosts

ff2mpv.json:

{
    "name": "ff2mpv",
    "description": "ff2mpv's external manifest",
    "path": "./ff2mpv.py",
    "type": "stdio",
    "allowed_extensions": ["ff2mpv@yossarian.net"]
}

ff2mpv.py the same as in repo

-rw-r--r-- 1 root root  174 09-16 18:27 ff2mpv.json
-rw-r-xr-x 1 root root 1,9K 09-16 18:57 ff2mpv.py*

I have created the mpv in /usr/local/bin like you which works. But from librewolf I still can't play videos when clicking button.

woodruffw commented 2 years ago

I'm not sure if relative paths work in native messaging host configurations (they might, I have no idea). So turning that ./ff2mpv.py path into an absolute path might be worth trying.

Other than that, I'm not really familiar with Flatpak or how it works. Maybe it's a permission thing? I know snaps use the same permission model and the recent Ubuntu LTS release caused a whole bunch of pain around that.

pm4rcin commented 2 years ago

I've tried absolute paths and even tried to allow full system and session bus but no luck.

vmath3us commented 1 year ago

for use flatpak to mpv and browser (brave here):

  1. ./install custom-chromium ~/.var/app/com.brave.Browser/config/BraveSoftware/Brave-Browser/ edit .var/app/com.brave.Browser/config/BraveSoftware/Brave-Browser/NativeMessagingHosts/ff2mpv.json , replace path to:

    "path": "/home//Documents/ff2mpv"

(need path visible on sandbox; inspect using flatpak run --comand=bash id.your.browser)

/home//Documentos/ff2mpv is a python file.

  1. replace args to:

    args = ["flatpak-spawn", "--host", "io.mpv.Mpv", "--no-terminal", "--", url]

  1. on flatseal, add session dbus (talk)

    org.freedesktop.Flatpak on your browser

https://flatpak.github.io/xdg-desktop-portal/#gdbus-org.freedesktop.portal.Flatpak

ugurbolat commented 1 year ago

@vmath3us thanks for sharing it.

the only difference in my setup was to change the argument list to:

args = ["flatpak-spawn", "--host", "flatpak", "run" ,"io.mpv.Mpv", "--no-terminal", "--", URL]

instead of

args = ["flatpak-spawn", "--host", "io.mpv.Mpv", "--no-terminal", "--", url]

vmath3us commented 1 year ago

add var/lib/flatpak/exports/bin and ~/.local/share/flatpak/exports/bin on your path, to not need the intermediary 'flatpak run'. another advantage of doing this is being able to run any program via terminal using only its id (without flatpak run). A shell completion (type fire, press tab to org.mozilla.firefox) is desirable

tazihad commented 1 year ago

@vmath3us @ugurbolat Not sure what I am doing wrong. But for me it's not working with brave browser. Can you tell me what am I doing wrong?

  1. native messaging location : /home/zihad/.var/app/com.brave.Browser/config/BraveSoftware/Brave-Browser/NativeMessagingHosts/ff2mpv.json
    
    {
    "name": "ff2mpv",
    "description": "ff2mpv's external manifest",
    "path": "/home/zihad/.var/app/com.brave.Browser/config/BraveSoftware/Brave-Browser/NativeMessagingHosts/ff2mpv",
    "type": "stdio",
    "allowed_origins": [
        "chrome-extension://ephjcajbkgplkjmelpglennepbpmdpjg/"
    ]
    }

2. renamed `ff2mpv.py` to `ff2mpv`
and edited the `args` inside it.
I tried both.
    `args = ["flatpak-spawn", "--host", "flatpak", "run" ,"io.mpv.Mpv", "--no-terminal", "--", URL]`
    `args = ["flatpak-spawn", "--host", "io.mpv.Mpv", "--no-terminal", "--", url]`
3. 
![Screenshot_20230511_001453](https://github.com/woodruffw/ff2mpv/assets/19417232/f714c393-64b3-46f3-9670-94c5d45635df)
vmath3us commented 1 year ago

make sure you followed the first step correctly

tazihad commented 1 year ago

@vmath3us should I rename ff2mpv.py to ff2mpv?

tazihad commented 1 year ago

okay I fixed the problem. In the ff2mpv.py at args URL should become url. I think flatpak is case sensitive. so.. args = ["flatpak-spawn", "--host", "flatpak", "run" ,"io.mpv.Mpv", "--no-terminal", "--", url]

woodruffw commented 1 year ago

All: if you've found a collection of hacks that work here, please add them to the wiki. I plan to close this issue in a few days and begin redirecting people there.

azizLIGHT commented 1 year ago

On fedora silverblue/kinoite, there was no flatpak-spawn. This worked for me in ff2mpv.py:

args = ["flatpak", "run" ,"io.mpv.Mpv", "--no-terminal", "--", url]

Another consideration is that your browser may be installed natively and not via flatpak and so it would not need steps like flatpak accessible dirs for native messaging or having to give permissions in flatseal