Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimizations and fixes #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/SimpleBookmark.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions scripts/SimpleHistory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this only to ignore these protocols from saving to history?
Or these protocols cause a problem if it was added to history?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the limitations of mpv these protocols can't resume playback from a record, and there's little benefit to saving these invalid entries other than polluting the history list.
Ref: https://mpv.io/manual/master/#protocols

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)

Expand Down Expand Up @@ -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

Expand Down
14 changes: 5 additions & 9 deletions scripts/SmartCopyPaste.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand All @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for the removal of this condition?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now this has been processed in the make_raw function, no additional processing is required.

c_clip_file = string.match(c, '^\"(.*)\"$')
else
c_clip_file = c_protocols
end
Expand All @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for the removal of this condition?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same reason

c_clip_file = string.match(c, '^\"(.*)\"$')
else
c_clip_file = c
end
Expand All @@ -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
Expand All @@ -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
Expand Down
18 changes: 7 additions & 11 deletions scripts/SmartCopyPaste_II.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down