Skip to content

Commit

Permalink
fix error due to adding video to queue already surrounded by quotes (#8)
Browse files Browse the repository at this point in the history
- fix surround with quotes function to only surround with quotes if not already there
- remove quotes before adding to video_queue
  • Loading branch information
ksyasuda authored Aug 8, 2023
1 parent 64bde58 commit 6ca5de8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions mpv-youtube-queue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,16 @@ local current_video = nil

-- HELPERS {{{

-- surround string with single quotes
local function surround_with_quotes(s) return '\'' .. s .. '\'' end
-- surround string with single quotes if it does not already have them
local function surround_with_quotes(s)
if string.sub(s, 0, 1) == "'" and string.sub(s, -1) == "'" then
return s
else
return "'" .. s .. "'"
end
end

local function remove_quotes(s) return string.gsub(s, "'", "") end

-- run sleep shell command for n seconds
local function sleep(n) os.execute("sleep " .. tonumber(n)) end
Expand Down Expand Up @@ -457,6 +465,7 @@ function YouTubeQueue.add_to_queue(url, update_internal_playlist)
}
else
channel_url, channel_name, video_name = YouTubeQueue.get_video_info(url)
url = remove_quotes(url)
if (channel_url == nil or channel_name == nil or video_name == nil) or
(channel_url == "" or channel_name == "" or video_name == "") then
print_osd_message("Error getting video info.", MSG_DURATION,
Expand Down

0 comments on commit 6ca5de8

Please sign in to comment.