subselect.lua: * use mp.command_native instead of deprecated utils.subprocess
* send filename to python script instead of media-title * status returned from subprocess can be negative even if command succeeds -> check error_string instead subselect.py: use all the available subtitle providers for search
This commit is contained in:
parent
68733c81f3
commit
4c237b17cf
|
@ -65,15 +65,24 @@ end
|
|||
function get_python_binary()
|
||||
python = nil
|
||||
python_error = ""
|
||||
python_version = utils.subprocess({ args = { "python", "--version" }})
|
||||
if python_version.status < 0 then
|
||||
python_version = mp.command_native({
|
||||
name = "subprocess",
|
||||
args = { "python", "--version"},
|
||||
capture_stdout = true
|
||||
})
|
||||
|
||||
if python_version.error_string ~= "" then
|
||||
python_error = "python not found"
|
||||
else
|
||||
if python_version.stdout:find("3%.") ~= nil then
|
||||
python = "python"
|
||||
else
|
||||
python_version = utils.subprocess({ args = { "python3", "--version" }})
|
||||
if python_version.status < 0 then
|
||||
python_version = mp.command_native({
|
||||
name = "subprocess",
|
||||
args = { "python3", "--version" }
|
||||
})
|
||||
|
||||
if python_version.error_string ~= "" then
|
||||
python_error = "python3 not installed"
|
||||
else
|
||||
python = "python3"
|
||||
|
@ -83,14 +92,18 @@ function get_python_binary()
|
|||
return python, python_error
|
||||
end
|
||||
|
||||
python, python_error = get_python_binary()
|
||||
read_options(options)
|
||||
|
||||
function search_subs()
|
||||
set_down_dir(options)
|
||||
video = mp.get_property_native("media-title", "")
|
||||
video = mp.get_property_native("filename/no-ext", "")
|
||||
python, python_error = get_python_binary()
|
||||
if python ~= nil then
|
||||
ret = utils.subprocess({ args = { python, options.subselect_path, video, options.down_dir, options.sub_language }})
|
||||
ret = mp.command_native({
|
||||
name = "subprocess",
|
||||
args = { python, options.subselect_path, video, options.down_dir, options.sub_language },
|
||||
capture_stdout = true
|
||||
})
|
||||
else
|
||||
mp.osd_message(python_error)
|
||||
return
|
||||
|
|
23
subselect.py
23
subselect.py
|
@ -25,9 +25,22 @@ class subselect :
|
|||
self.result_listbox.delete(0, END)
|
||||
self.subtitles_in_list = []
|
||||
for s in subtitles :
|
||||
if hasattr(s, "filename") :
|
||||
self.result_listbox.insert(END, s.filename)
|
||||
self.subtitles_in_list += [s]
|
||||
listname = ""
|
||||
if s.provider_name == "opensubtitles" :
|
||||
listname = "[opensubtitles]: {}".format(s.filename)
|
||||
elif (s.provider_name == "podnapisi"
|
||||
or s.provider_name == "addic7ed"
|
||||
or s.provider_name == "subscenter") :
|
||||
listname = "[{}]: {}".format(s.provider_name, s.title)
|
||||
elif s.provider_name == "legendastv" :
|
||||
listname = "[legendastv]: {}".format(s.name)
|
||||
elif s.provider_name == "tvsubtitles" :
|
||||
listname = "[tvsubtitles]: {}".format(s.release)
|
||||
else :
|
||||
listname = "[{}]: {}".format(s.provider_name, s.id)
|
||||
|
||||
self.result_listbox.insert(END, listname)
|
||||
self.subtitles_in_list += [s]
|
||||
self.result_listbox.grid(row=1, column=0, columnspan=3, sticky=E+W)
|
||||
|
||||
if not hasattr(self, "download_button") :
|
||||
|
@ -52,7 +65,7 @@ class subselect :
|
|||
def search(self) :
|
||||
try :
|
||||
self.video = self.get_video_from_title()
|
||||
subtitles = list_subtitles([self.video], {Language(self.language)}, providers=["opensubtitles"])
|
||||
subtitles = list_subtitles([self.video], {Language(self.language)}, providers=None)
|
||||
except ValueError as exc :
|
||||
self.show_message("Error", str(exc))
|
||||
else :
|
||||
|
@ -81,7 +94,7 @@ class subselect :
|
|||
self.save_subtitle(self.video, True, selected_subtitle)
|
||||
|
||||
def save_subtitle(self, video, change_filename, subtitle) :
|
||||
if change_filename :
|
||||
if change_filename and subtitle.provider_name == "opensubtitles" :
|
||||
video.name = subtitle.filename
|
||||
title = os.path.splitext(subtitle.filename)[0]+".srt"
|
||||
else :
|
||||
|
|
Loading…
Reference in New Issue