snap 2.27.6
snapd 2.27.6
series 16
ubuntu 17.04
kernel 4.10.0-35-generic
Lua script for fetching subtitles from the internet does not work. The script invokes a separately installed program called subdownloader to download an appropriate sub file into the location of a video file.
As a layman I can see two issues here, first, snap confinement prevents mpv from invoking other applications, and second, it does not have write access to the location where videos are stored (paths outside of $HOME; though I connected mpv to removable-media).
since the script fails immediately after I press the hotkey, I can only presume there is an issue with invoking subdownloader. If needed I can provide the script in question.
Any ideas on how to make this work will be much appreciated.
@Wimpress The problem that might arise with this, is the inability to predict and/or package all possible auxillary applications that users might employ to extend mpv's functionality using lua.
As a workaround to this problem, I tried creating a bash script in $HOME/bin (it’s in the $PATH) that calls subdownloader, and pointed lua script to that bash script. Still didn’t work though.
This is why I’m hesitant to utilize @Wimpress’s solution. I don’t think this can be solved for all use cases without changes in snapd that go against it’s design principles (for example, appending the host’s PATH to the snap and letting it access the binaries).
I guess I could append a directory within the snap’s directory in $HOME to the $PATH and the user could drop binaries there. That’d still leave open the question on how to communicate this difference to the upstream approach to users who don’t stumble across this thread (and it probably wouldn’t work with software dependent on shared libs not in the snap. Solving that would require more-or-less mirroring an entire linux distro’s FS hierarchy).
I’ve made a build with this modification and uploaded it into the edge channel so you can at least test whether it solves your issue.
Run snap refresh mpv --channel edge, then drop the subdownloader binary into the ~/snap/mpv/current/.config/mpv/bin/ directory.
local utils = require 'mp.utils'
function load_sub_fn()
subd = "/home/$USER/snap/mpv/current/.config/mpv/bin/subdownloader"
mp.msg.info("Searching subtitle")
mp.osd_message("Searching subtitle")
t = {}
t.args = {subd, "-c", "-l", "en", "--rename-subs", "-V", mp.get_property("path")}
res = utils.subprocess(t)
if res.status == 0 then
mp.commandv("rescan_external_files", "reselect")
mp.msg.info("Subtitle download succeeded")
mp.osd_message("Subtitle download succeeded")
else
mp.msg.warn("Subtitle download failed")
mp.osd_message("Subtitle download failed")
end
end
mp.add_key_binding("b", "auto_load_subs", load_sub_fn)
I get subtitle download failed right after hitting the hotkey. I am testing it on movies in my /media/data/movies folder. mpv is connected to removable-media.
In my case, if this solution with copying executables into snap’s bin folder worked, I myself would be content. But as You said, there would be no way to communicate this to other mpv users, nor is this a hands-off user-friendly solution.
well, have a look at syslog or dmesg (or add some own logging code to your snap to wite its own log in some debug mode), you need the info what happens between you hitting it and the app printing that message
my suspicion would be that it tries to write the subtitle files to a space it has no write access to …
thanks, I was suspecting the lack of write access too, but still not sure, maybe I’m doing sth wrong.
Please note that I am only a linux desktop user. I’m not a developer or a coder by any stretch of the imagination (I also am not the author of the lua script above). Unless You provide me with specific commands/instructions, there is little I can debug or investigate by myself.
@ogra
Are You sure that non-root user actions like opening a movie get registered in system logs?
Anyway, both outputs are polluted with constant messages apparently from my firewall, they appear every couple of secs and look like this:
all confinement related denials from snap apps get logged there … obviously you do not get any, so we can exclude that bit from the possible causes
there seems to be an environment variable in mpv you can set to get verbose debug output, try to add
MPV_VERBOSE=debug
to the environment settings of your snap app to see if you get anything more … also try to run the mvp snap from within a terminal, that should also get you more output …
well, thats a pretty obvious error then … the app can not find this specific python module (is it missing completely ? is it there in the snap but not covered in the python search path ?)
If that is the case, then I guess that in order for all this to work, I would have to have python binaries in the ~/snap/mpv/current/.config/mpv/bin in addition to subdownloader.
It’s starting to look like a wrong way to tackle this problem.
the best way (from my point of view) would be to release the restrictions and allow the snap to access system binaries. But as @casept said, this might be against the snap philosophy.
well, the best “snap” way is to bundle all bits your app needs and configure them to use proper writable paths … (or alternatively share bits and binaries via the content interface)
But is that possible in this case? through mpv’s lua scripting, You can call any program that You can think of and use it to extend or create custom features.
For example someone comes forward with a script that takes a screenshot from the movie, uses feh to make it as a wallpaper, and some other app to upload it to imgur. How does the packager deal with this scenario? the snap packager would have to package entire ubuntu repos to cover all possibilities.
This thread is indeed on the topic of fetching subtitles with mpv, but it would be a bit selfish of me to make the packager just include stuff that I want, and not care about more robust solutions for others.