From a27d754d548a20fa604c954bad204932503a92d6 Mon Sep 17 00:00:00 2001 From: dyphire Date: Thu, 25 Apr 2024 00:34:19 +0800 Subject: [PATCH] optimizations and fixes --- scripts/SimpleBookmark.lua | 4 ++-- scripts/SimpleHistory.lua | 6 ++++-- scripts/SmartCopyPaste.lua | 14 +++++--------- scripts/SmartCopyPaste_II.lua | 18 +++++++----------- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/scripts/SimpleBookmark.lua b/scripts/SimpleBookmark.lua index 3f6a154..c5a6ec3 100644 --- a/scripts/SimpleBookmark.lua +++ b/scripts/SimpleBookmark.lua @@ -561,9 +561,9 @@ function list_sort(tab, sort) local function padnum(d) local dec, n = string.match(d, "(%.?)0*(.+)") return #dec > 0 and ("%.12f"):format(d) or ("%s%03d%s"):format(dec, #n, n) end if sort == 'alphanum-asc' then - table.sort(tab, function(a, b) return tostring(a['found_path']):gsub("%.?%d+", padnum) .. ("%3d"):format(#b) > tostring(b['found_path']):gsub("%.?%d+", padnum) .. ("%3d"):format(#a) end) + table.sort(tab, function(a, b) return tostring(a['found_path']):lower():gsub("%.?%d+", padnum) .. ("%3d"):format(#b) > tostring(b['found_path']):lower():gsub("%.?%d+", padnum) .. ("%3d"):format(#a) end) elseif sort == 'alphanum-desc' then - table.sort(tab, function(a, b) return tostring(a['found_path']):gsub("%.?%d+", padnum) .. ("%3d"):format(#b) < tostring(b['found_path']):gsub("%.?%d+", padnum) .. ("%3d"):format(#a) end) + table.sort(tab, function(a, b) return tostring(a['found_path']):lower():gsub("%.?%d+", padnum) .. ("%3d"):format(#b) < tostring(b['found_path']):lower():gsub("%.?%d+", padnum) .. ("%3d"):format(#a) end) end end diff --git a/scripts/SimpleHistory.lua b/scripts/SimpleHistory.lua index b17d5a3..f76914a 100644 --- a/scripts/SimpleHistory.lua +++ b/scripts/SimpleHistory.lua @@ -384,6 +384,8 @@ end function get_file() local path = mp.get_property('path') if not path then return end + -- ignoring protocols that do not support playback recovery + if path:match("bd://") or path:match("dvd://") or path:match("dvb://") or path:match("cdda://") then return end local length = (mp.get_property_number('duration') or 0) @@ -482,9 +484,9 @@ function list_sort(tab, sort) local function padnum(d) local dec, n = string.match(d, "(%.?)0*(.+)") return #dec > 0 and ("%.12f"):format(d) or ("%s%03d%s"):format(dec, #n, n) end if sort == 'alphanum-asc' then - table.sort(tab, function(a, b) return tostring(a['found_path']):gsub("%.?%d+", padnum) .. ("%3d"):format(#b) > tostring(b['found_path']):gsub("%.?%d+", padnum) .. ("%3d"):format(#a) end) + table.sort(tab, function(a, b) return tostring(a['found_path']):lower():gsub("%.?%d+", padnum) .. ("%3d"):format(#b) > tostring(b['found_path']):lower():gsub("%.?%d+", padnum) .. ("%3d"):format(#a) end) elseif sort == 'alphanum-desc' then - table.sort(tab, function(a, b) return tostring(a['found_path']):gsub("%.?%d+", padnum) .. ("%3d"):format(#b) < tostring(b['found_path']):gsub("%.?%d+", padnum) .. ("%3d"):format(#a) end) + table.sort(tab, function(a, b) return tostring(a['found_path']):lower():gsub("%.?%d+", padnum) .. ("%3d"):format(#b) < tostring(b['found_path']):lower():gsub("%.?%d+", padnum) .. ("%3d"):format(#a) end) end end diff --git a/scripts/SmartCopyPaste.lua b/scripts/SmartCopyPaste.lua index 41af740..a3ba042 100644 --- a/scripts/SmartCopyPaste.lua +++ b/scripts/SmartCopyPaste.lua @@ -239,9 +239,11 @@ end function make_raw(s) if not s then return end + s = string.gsub(s, '^[\'\"]', '') + s = string.gsub(s, '[\'\"]$', '') s = string.gsub(s, '^%s+', '') s = string.gsub(s, '%s+$', '') - s = string.gsub(s, '[\n\r]+', ' ') + s = string.gsub(s, '[\r\n]+', ' ') return s end @@ -360,7 +362,7 @@ function parse_clipboard(text) clip = text - for c in clip:gmatch("[^\n\r]+") do --3.2.1# fix for #80 , accidentally additional "+" was added to the gmatch + for c in clip:gmatch("[^\r\n]+") do --3.2.1# fix for #80 , accidentally additional "+" was added to the gmatch local c_pre_attribute, c_clip_file, c_clip_time, c_clip_extension c = make_raw(c) @@ -371,8 +373,6 @@ function parse_clipboard(text) if string.match(c, '(.*)'..c_pre_attribute) then c_clip_file = string.match(c_protocols, '(.*)'..c_pre_attribute) c_clip_time = tonumber(string.match(c_protocols, c_pre_attribute..'(%d*%.?%d*)')) - elseif string.match(c, '^\"(.*)\"$') then - c_clip_file = string.match(c, '^\"(.*)\"$') else c_clip_file = c_protocols end @@ -385,8 +385,6 @@ function parse_clipboard(text) if string.match(c, '(.*)'..c_pre_attribute) then c_clip_file = string.match(c, '(.*)'..c_pre_attribute) c_clip_time = tonumber(string.match(c, c_pre_attribute..'(%d*%.?%d*)')) - elseif string.match(c, '^\"(.*)\"$') then - c_clip_file = string.match(c, '^\"(.*)\"$') else c_clip_file = c end @@ -402,8 +400,6 @@ function parse_clipboard(text) if string.match(clip, '(.*)'..pre_attribute) then clip_file = string.match(clip, '(.*)'..pre_attribute) clip_time = tonumber(string.match(clip, pre_attribute..'(%d*%.?%d*)')) - elseif string.match(clip, '^\"(.*)\"$') then - clip_file = string.match(clip, '^\"(.*)\"$') else clip_file = clip end @@ -413,7 +409,7 @@ end function copy() if filePath ~= nil then - if o.copy_time_method == 'none' or copy_time_method == '' then + if o.copy_time_method == 'none' or o.copy_time_method == '' then copy_specific('path') return elseif o.copy_time_method == 'protocols' and not starts_protocol(protocols, filePath) then diff --git a/scripts/SmartCopyPaste_II.lua b/scripts/SmartCopyPaste_II.lua index 16bbda0..19ff181 100644 --- a/scripts/SmartCopyPaste_II.lua +++ b/scripts/SmartCopyPaste_II.lua @@ -514,9 +514,9 @@ function list_sort(tab, sort) local function padnum(d) local dec, n = string.match(d, "(%.?)0*(.+)") return #dec > 0 and ("%.12f"):format(d) or ("%s%03d%s"):format(dec, #n, n) end if sort == 'alphanum-asc' then - table.sort(tab, function(a, b) return tostring(a['found_path']):gsub("%.?%d+", padnum) .. ("%3d"):format(#b) > tostring(b['found_path']):gsub("%.?%d+", padnum) .. ("%3d"):format(#a) end) + table.sort(tab, function(a, b) return tostring(a['found_path']):lower():gsub("%.?%d+", padnum) .. ("%3d"):format(#b) > tostring(b['found_path']):lower():gsub("%.?%d+", padnum) .. ("%3d"):format(#a) end) elseif sort == 'alphanum-desc' then - table.sort(tab, function(a, b) return tostring(a['found_path']):gsub("%.?%d+", padnum) .. ("%3d"):format(#b) < tostring(b['found_path']):gsub("%.?%d+", padnum) .. ("%3d"):format(#a) end) + table.sort(tab, function(a, b) return tostring(a['found_path']):lower():gsub("%.?%d+", padnum) .. ("%3d"):format(#b) < tostring(b['found_path']):lower():gsub("%.?%d+", padnum) .. ("%3d"):format(#a) end) end end @@ -2142,9 +2142,11 @@ end function make_raw(s) if not s then return end + s = string.gsub(s, '^[\'\"]', '') + s = string.gsub(s, '[\'\"]$', '') s = string.gsub(s, '^%s+', '') s = string.gsub(s, '%s+$', '') - s = string.gsub(s, '[\n\r]+', ' ') + s = string.gsub(s, '[\r\n]+', ' ') return s end @@ -2261,7 +2263,7 @@ function parse_clipboard(text) clip = text - for c in clip:gmatch("[^\n\r]+") do --3.2.1# fix for #80 , accidentally additional "+" was added to the gmatch + for c in clip:gmatch("[^\r\n]+") do --3.2.1# fix for #80 , accidentally additional "+" was added to the gmatch local c_pre_attribute, c_clip_file, c_clip_time, c_clip_extension c = make_raw(c) @@ -2272,8 +2274,6 @@ function parse_clipboard(text) if string.match(c, '(.*)'..c_pre_attribute) then c_clip_file = string.match(c_protocols, '(.*)'..c_pre_attribute) c_clip_time = tonumber(string.match(c_protocols, c_pre_attribute..'(%d*%.?%d*)')) - elseif string.match(c, '^\"(.*)\"$') then - c_clip_file = string.match(c, '^\"(.*)\"$') else c_clip_file = c_protocols end @@ -2286,8 +2286,6 @@ function parse_clipboard(text) if string.match(c, '(.*)'..c_pre_attribute) then c_clip_file = string.match(c, '(.*)'..c_pre_attribute) c_clip_time = tonumber(string.match(c, c_pre_attribute..'(%d*%.?%d*)')) - elseif string.match(c, '^\"(.*)\"$') then - c_clip_file = string.match(c, '^\"(.*)\"$') else c_clip_file = c end @@ -2303,8 +2301,6 @@ function parse_clipboard(text) if string.match(clip, '(.*)'..pre_attribute) then clip_file = string.match(clip, '(.*)'..pre_attribute) clip_time = tonumber(string.match(clip, pre_attribute..'(%d*%.?%d*)')) - elseif string.match(clip, '^\"(.*)\"$') then - clip_file = string.match(clip, '^\"(.*)\"$') else clip_file = clip end @@ -2314,7 +2310,7 @@ end function copy() if filePath ~= nil then - if o.copy_time_method == 'none' or copy_time_method == '' then + if o.copy_time_method == 'none' or o.copy_time_method == '' then copy_specific('path') return elseif o.copy_time_method == 'protocols' and not starts_protocol(protocols, filePath) then