···66 filename=$1
77 cd "$(dirname "$filename")"
88 filename=$(basename "$filename")
99- ${pkgs.subdl}/bin/subdl --output='/tmp/{m}.{M}.sub' "$filename" 1>&2
99+ ${pkgs.subdl}/bin/subdl --download=best-rating --output='/tmp/{m}.{M}.sub' "$filename" 1>&2
1010 echo "/tmp/$filename.sub"
1111 '';
12121313 autosub = pkgs.writeText "autosub.lua" ''
1414- -- Requires Subliminal version 1.0 or newer
1515- -- Make sure to specify your system's Subliminal location below:
1616- local utils = require 'mp.utils'
1414+ utils = require 'mp.utils'
17151816 -- Log function: log to both terminal and mpv OSD (On-Screen Display)
1917 function log(string, secs)
···3432 else
3533 log('Subtitles failed downloading')
3634 end
3737- end
3838-3939- -- Control function: only download if necessary
4040- function control_download()
4141- duration = tonumber(mp.get_property('duration'))
4242- if duration < 900 then
4343- mp.msg.warn('Video is less than 15 minutes\n', '=> NOT downloading any subtitles')
4444- return
4545- end
4646- -- There does not seem to be any documentation for the 'sub' property,
4747- -- but it works on both internally encoded as well as external subtitle files!
4848- -- -> sub = '1' when subtitles are present
4949- -- -> sub = 'no' when subtitles are not present
5050- -- -> sub = 'auto' when called before the 'file-loaded' event is triggered
5151- sub = mp.get_property('sub')
5252- if sub == '1' then
5353- mp.msg.warn('Sub track is already present\n', '=> NOT downloading other subtitles')
5454- return
5555- end
5656- mp.msg.warn('No sub track was detected\n', '=> Proceeding to download subtitles:')
5757- download()
5835 end
59366037 mp.add_key_binding('S', "download_subs", download)