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:
zenyd 2020-04-26 21:31:40 +02:00
parent 68733c81f3
commit 4c237b17cf
2 changed files with 38 additions and 12 deletions

View File

@ -65,15 +65,24 @@ end
function get_python_binary() function get_python_binary()
python = nil python = nil
python_error = "" python_error = ""
python_version = utils.subprocess({ args = { "python", "--version" }}) python_version = mp.command_native({
if python_version.status < 0 then name = "subprocess",
args = { "python", "--version"},
capture_stdout = true
})
if python_version.error_string ~= "" then
python_error = "python not found" python_error = "python not found"
else else
if python_version.stdout:find("3%.") ~= nil then if python_version.stdout:find("3%.") ~= nil then
python = "python" python = "python"
else else
python_version = utils.subprocess({ args = { "python3", "--version" }}) python_version = mp.command_native({
if python_version.status < 0 then name = "subprocess",
args = { "python3", "--version" }
})
if python_version.error_string ~= "" then
python_error = "python3 not installed" python_error = "python3 not installed"
else else
python = "python3" python = "python3"
@ -83,14 +92,18 @@ function get_python_binary()
return python, python_error return python, python_error
end end
python, python_error = get_python_binary()
read_options(options) read_options(options)
function search_subs() function search_subs()
set_down_dir(options) 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 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 else
mp.osd_message(python_error) mp.osd_message(python_error)
return return

View File

@ -25,9 +25,22 @@ class subselect :
self.result_listbox.delete(0, END) self.result_listbox.delete(0, END)
self.subtitles_in_list = [] self.subtitles_in_list = []
for s in subtitles : for s in subtitles :
if hasattr(s, "filename") : listname = ""
self.result_listbox.insert(END, s.filename) if s.provider_name == "opensubtitles" :
self.subtitles_in_list += [s] 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) self.result_listbox.grid(row=1, column=0, columnspan=3, sticky=E+W)
if not hasattr(self, "download_button") : if not hasattr(self, "download_button") :
@ -52,7 +65,7 @@ class subselect :
def search(self) : def search(self) :
try : try :
self.video = self.get_video_from_title() 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 : except ValueError as exc :
self.show_message("Error", str(exc)) self.show_message("Error", str(exc))
else : else :
@ -81,7 +94,7 @@ class subselect :
self.save_subtitle(self.video, True, selected_subtitle) self.save_subtitle(self.video, True, selected_subtitle)
def save_subtitle(self, video, change_filename, subtitle) : def save_subtitle(self, video, change_filename, subtitle) :
if change_filename : if change_filename and subtitle.provider_name == "opensubtitles" :
video.name = subtitle.filename video.name = subtitle.filename
title = os.path.splitext(subtitle.filename)[0]+".srt" title = os.path.splitext(subtitle.filename)[0]+".srt"
else : else :