ff2mpv icon indicating copy to clipboard operation
ff2mpv copied to clipboard

Support for mpv flatpak

Open tjssoldier opened this issue 1 year ago • 6 comments

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!

tjssoldier avatar Aug 04 '22 20:08 tjssoldier

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.

woodruffw avatar Aug 04 '22 22:08 woodruffw

At least on the terminal, flatpak mpv works in a very similar way of regular mpv. Just run flatpak 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.

tjssoldier avatar Aug 05 '22 11:08 tjssoldier

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.

woodruffw avatar Aug 05 '22 15:08 woodruffw

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

tjssoldier avatar Aug 07 '22 23:08 tjssoldier

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.

rockerbacon avatar Sep 03 '22 14:09 rockerbacon

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:

woodruffw avatar Sep 06 '22 17:09 woodruffw

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": ["[email protected]"]
}

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.

pm4rcin avatar Sep 16 '22 17:09 pm4rcin

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.

woodruffw avatar Sep 16 '22 17:09 woodruffw

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

pm4rcin avatar Sep 19 '22 12:09 pm4rcin

I don't know how @rockerbacon managed to do this because sandboxed browser cannot spawn other flatpak processes. For example vscodium which is not sandboxed can run flatpak-spawn but the permission could be disabled and then it cannot do anything. It can't run regular flatpak commands at all. So the only thing that comes to my mind would be if mpv was in daemon mode and if it was listening on dbus. But I don't think that it's possible as of now. If someone has an idea or could provide a link and prove me wrong it would be greatly appreciated.

pm4rcin avatar Sep 28 '22 16:09 pm4rcin