Cannot fetch subtitles on mpv

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.

The snap info output says this is something from @casept.

@casept Can you help @v1kn here?

@casept I’ve overcome this issue is snaps of my own applications by bundling auxiliary applications in the snap and not exposing them via a command:

Alternatively you could snap any auxiliary applications separately and connect them via a content interface.

1 Like

@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.

1 Like

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).

@casept Do You have any ideas for a workaround?

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.

It doesn’t seem to work

mpv         0.27.0     2     casept          -       

here’s the script

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 :wink:

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.

to get kernel messages printed while you hit the hotkey, open a terminal window and type:

dmesg -w

(you can exit it with ctrl-C )

At the same time, open another terminal window and type:

tail -f /var/log/syslog

… to print the usespace messages … (same thing, to exit this, hit ctrl-C)

this will show you what gets printed to the logs in real time when you hit your key…

@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:

Oct  9 13:17:44 <hostname> kernel: [63140.333189] [UFW BLOCK] IN=vmnet1 OUT= MAC= SRC=fe80:0000:0000:0000:0250:56ff:fec0:0001 DST=ff15:0000:0000:0000:0000:0000:efc0:988f LEN=186 TC=0 HOPLIMIT=1 FLOWLBL=845154 PROTO=UDP SPT=42913 DPT=6771 LEN=146
Oct  9 13:21:24 <hostname> kernel: [63360.289604] [UFW BLOCK] IN=wlp2s0 OUT= MAC=4c:0f:6e:d8:45:71:00:1f:33:36:fc:3a:08:00 SRC=36.80.31.74 DST=192.168.1.4 LEN=48 TOS=0x00 PREC=0x00 TTL=110 ID=9759 PROTO=UDP SPT=1093 DPT=8999 LEN=28
Oct  9 13:21:43 <hostname> kernel: [63378.986143] [UFW BLOCK] IN=wlp2s0 OUT= MAC=4c:0f:6e:d8:45:71:00:1f:33:36:fc:3a:08:00 SRC=213.149.51.116 DST=192.168.1.4 LEN=48 TOS=0x00 PREC=0x00 TTL=115 ID=29291 PROTO=UDP SPT=44831 DPT=8999 LEN=28

Other than these ufw messages, nothing happens when I press the hotkey for downloading subs.
for the record, I’m running xubuntu 17.04.

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 :slight_smile:

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 …

there is some error output when running mpv from the commandline:

[autosub] Traceback (most recent call last):
[autosub]   File "/home/<user>/snap/mpv/current/.config/mpv/bin/subdownloader", line 20, in <module>
[autosub]     import modules.configuration as conf
[autosub] ImportError: No module named modules.configuration
[autosub] Subtitle download failed 

As for snap environment variables. how do I add it to the environment settings?

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.

yes, shipping subdownloader in the mpv snap would clearly be the better option here …

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.