Skip to content

Commit

Permalink
fix: the main menu item of the extension stops working after the exte…
Browse files Browse the repository at this point in the history
…nsion window is closed when no video is playing (#9)
  • Loading branch information
tcrespog committed Nov 4, 2023
1 parent 3064bbb commit ca8dad7
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions subtitle_word_search.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ function load_subtitle_file()
end
else
local video_directory, video_filename = get_video_file_location()
gui:print_error_message("No subtitle files found at '" .. video_directory .. "' for the file '" .. video_filename .. "'")
if (video_directory) then
gui:print_error_message("No subtitle files found at '" .. video_directory .. "' for the file '" .. video_filename .. "'")
else
gui:print_error_message("No item playing")
end
end
end

Expand Down Expand Up @@ -444,6 +448,10 @@ function SubtitleFileDiscoverer:discover_files()
local subtitle_files = {}

local video_dir_path, video_filename = get_video_file_location()
if (not video_dir_path) then
return subtitle_files
end

local video_filename_no_ext = video_filename:match("^(.+)%..+$")
if (is_unix_os()) then
video_dir_path = "/" .. video_dir_path
Expand Down Expand Up @@ -527,7 +535,7 @@ function SubtitleFile:get_path()
return self.path
end

-- Search the subtitle line at the give timestamp.
-- Search the subtitle line at the given timestamp.
-- Performs a binary search over the ordered subtitle lines.
-- Updates the value of the current line index, which would point to an index with fractional part if nothing was found.
-- @param {Timestamp} The timestamp to search the subtitle at.
Expand Down Expand Up @@ -1006,6 +1014,10 @@ end
-- @return {string} The absolute directory path where the file is located (separated by slashes and without root slash).
-- @return {string} The name of the video file.
function get_video_file_location()
if (not vlc.input.item()) then
return nil, nil
end

local decoded_media_uri = vlc.strings.decode_uri(vlc.input.item():uri())
local directory_path, filename = decoded_media_uri:match("^file:///(.+/)(.+%..+)$")

Expand Down

0 comments on commit ca8dad7

Please sign in to comment.