davidde / mpv-autosub

Fully automatic subtitle downloading for the MPV media player
https://mpv.io/
MIT License
295 stars 42 forks source link

Question: how to add more languages and keys to favorites? #38

Closed cipricus closed 1 year ago

cipricus commented 1 year ago

How could the script be modified so that more than 2 languages can be set as favorites with more keys ?

Beside English and French I would like to have the option to select Italian and Romanian.

cipricus commented 1 year ago

I have found the answer. Here's an example for 4 languages:

local languages = {
--          If subtitles are found for the first language,
--          other languages will NOT be downloaded,
--          so put your preferred language first:
            { 'English', 'en', 'eng' },
            { 'French', 'fr', 'fre' },
            { 'Romanian', 'ro', 'ron' },
            { 'Italian', 'it', 'ita' },

Add the options for 3rd and 4th languages under the settings for the second (I have modified the default key bindings to 1,2,3,4):

-- Manually download second language subs by pressing '2':
function download_subs2()
    download_subs(languages[2])
end

-- Manually download third language subs by pressing '3':
function download_subs3()
    download_subs(languages[3])
end

-- Manually download 4th language subs by pressing '4':
function download_subs4()
    download_subs(languages[4])
end

Add the options for the 3rd and 4th key bindings after those for the second (example includes my changed keys):

mp.add_key_binding('1', 'download_subs', download_subs)
mp.add_key_binding('2', 'download_subs2', download_subs2)
mp.add_key_binding('3', 'download_subs3', download_subs3)
mp.add_key_binding('4', 'download_subs4', download_subs4)

(By the way, more intuitive language-specific key-combinations can be used, like Ctrl+i for Italian, Ctrl+f for French, etc.)

Probably the best way to use keys for specific languages is to disable the automatic download, something which I think should be the default (as one may not want the subtitle):

local bools = {
    auto = false,   -- Automatically download subtitles, no hotkeys required