lua: Fix formatting with lua-format
This commit is contained in:
parent
b57db544b7
commit
0e34af1992
13 changed files with 3867 additions and 3385 deletions
|
@ -1,7 +1,9 @@
|
|||
local accounts = {}
|
||||
|
||||
local status, gmailuser = pipe_from('gpg2 --decrypt --no-tty --quiet --no-verbose --for-your-eyes-only --pinentry-mode ask ~/.local/share/pass/misc/aerc-gmail-app-password.gpg | grep username | cut -d: -f2')
|
||||
local status, gmailpass = pipe_from('gpg2 --decrypt --no-tty --quiet --no-verbose --for-your-eyes-only --pinentry-mode ask ~/.local/share/pass/misc/aerc-gmail-app-password.gpg | head -n1')
|
||||
local status, gmailuser = pipe_from(
|
||||
'gpg2 --decrypt --no-tty --quiet --no-verbose --for-your-eyes-only --pinentry-mode ask ~/.local/share/pass/misc/aerc-gmail-app-password.gpg | grep username | cut -d: -f2')
|
||||
local status, gmailpass = pipe_from(
|
||||
'gpg2 --decrypt --no-tty --quiet --no-verbose --for-your-eyes-only --pinentry-mode ask ~/.local/share/pass/misc/aerc-gmail-app-password.gpg | head -n1')
|
||||
-- Setup an imap account called gmail
|
||||
accounts.gmail = IMAP {
|
||||
server = "imap.gmail.com",
|
||||
|
|
|
@ -14,15 +14,13 @@ options.timeout = 120
|
|||
|
||||
-- whether to enter IDLE mode and conintuously check
|
||||
-- for new incoming mail to filter
|
||||
CONTINUOUS=false
|
||||
CONTINUOUS = false
|
||||
-- time to wait for next synchronization
|
||||
-- only used in case server does not support IDLE mode
|
||||
UPDATE_TIME=120
|
||||
UPDATE_TIME = 120
|
||||
|
||||
-- implement simple wait function in case server does not support IDLE mode
|
||||
function sleep(n)
|
||||
os.execute("sleep " .. tonumber(n))
|
||||
end
|
||||
function sleep(n) os.execute("sleep " .. tonumber(n)) end
|
||||
|
||||
-- will set filters to be grabbed from XDG-compliant filter directory
|
||||
-- can be overridden with env var IMAPFILTER_FILTERDIR
|
||||
|
@ -30,11 +28,11 @@ function getConfigDir()
|
|||
-- -- set directory for imapfilter files
|
||||
local configdir
|
||||
if os.getenv("IMAPFILTER_CONFIGDIR") then
|
||||
configdir=os.getenv("IMAPFILTER_CONFIGDIR")
|
||||
configdir = os.getenv("IMAPFILTER_CONFIGDIR")
|
||||
elseif os.getenv("XDG_CONFIG_HOME") then
|
||||
configdir=os.getenv("XDG_CONFIG_HOME") .. "/imapfilter"
|
||||
configdir = os.getenv("XDG_CONFIG_HOME") .. "/imapfilter"
|
||||
else
|
||||
configdir=os.getenv("HOME") .. "/.config/imapfilter"
|
||||
configdir = os.getenv("HOME") .. "/.config/imapfilter"
|
||||
end
|
||||
return configdir
|
||||
end
|
||||
|
@ -45,39 +43,44 @@ function getFilterDir()
|
|||
-- -- set directory for imapfilter files
|
||||
local imapfilterdir
|
||||
if os.getenv("IMAPFILTER_FILTERDIR") then
|
||||
imapfilterdir=os.getenv("IMAPFILTER_FILTERDIR")
|
||||
imapfilterdir = os.getenv("IMAPFILTER_FILTERDIR")
|
||||
else
|
||||
imapfilterdir=configDir .. "/filters"
|
||||
imapfilterdir = configDir .. "/filters"
|
||||
end
|
||||
return imapfilterdir
|
||||
end
|
||||
|
||||
-- dirlist, from https://stackoverflow.com/a/25266573
|
||||
function applyFilters(dir)
|
||||
local p = io.popen('find "'..dir..'" -type f -name "*.lua"') --Open directory look for files, save data in p. By giving '-type f' as parameter, it returns all files.
|
||||
for file in p:lines() do --Loop through all files
|
||||
local p = io.popen('find "' .. dir .. '" -type f -name "*.lua"') -- Open directory look for files, save data in p. By giving '-type f' as parameter, it returns all files.
|
||||
for file in p:lines() do -- Loop through all files
|
||||
loadfile(file)()
|
||||
end
|
||||
end
|
||||
|
||||
-- create global variable containing the configuration files
|
||||
configDir=getConfigDir()
|
||||
assert(configDir, "No configuration directory found. Ensure " .. os.getenv("HOME") .. "/.config/imapfilter exists.")
|
||||
configDir = getConfigDir()
|
||||
assert(configDir,
|
||||
"No configuration directory found. Ensure " .. os.getenv("HOME") ..
|
||||
"/.config/imapfilter exists.")
|
||||
|
||||
-- create global variable containing account access
|
||||
accounts = loadfile(configDir .. "/accounts.lua")()
|
||||
assert(accounts, "No accounts configured. Ensure accounts.lua exists and returns a table of accounts.")
|
||||
assert(accounts,
|
||||
"No accounts configured. Ensure accounts.lua exists and returns a table of accounts.")
|
||||
|
||||
-- immediately act on the filters once
|
||||
applyFilters(getFilterDir())
|
||||
|
||||
-- continuously watch for mail if needed
|
||||
while CONTINUOUS==true do
|
||||
local has_idle=accounts.gmail['Inbox']:enter_idle()
|
||||
while CONTINUOUS == true do
|
||||
local has_idle = accounts.gmail['Inbox']:enter_idle()
|
||||
applyFilters(getFilterDir())
|
||||
|
||||
if has_idle == false then
|
||||
print("Server does not support idle, application will be polling again in " .. UPDATE_TIME .. "minutes.")
|
||||
print(
|
||||
"Server does not support idle, application will be polling again in " ..
|
||||
UPDATE_TIME .. "minutes.")
|
||||
sleep(UPDATE_TIME)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
function sendToFolder(folderFrom, folderTo, senders)
|
||||
local messages = folderFrom:select_all()
|
||||
for _, sender in pairs(senders) do
|
||||
local filtered=messages:contain_from(sender)
|
||||
local filtered = messages:contain_from(sender)
|
||||
filtered:mark_seen()
|
||||
filtered:move_messages(folderTo)
|
||||
end
|
||||
|
@ -11,33 +11,30 @@ end
|
|||
-- can be overridden with env var IMAPFILTER_ROLLUPFILE
|
||||
function getRollupFile(fname)
|
||||
local f
|
||||
local fname=fname or "rollup.txt"
|
||||
local fname = fname or "rollup.txt"
|
||||
if os.getenv("IMAPFILTER_ROLLUPFILE") then
|
||||
f=os.getenv("IMAPFILTER_ROLLUPFILE")
|
||||
f = os.getenv("IMAPFILTER_ROLLUPFILE")
|
||||
elseif os.getenv("XDG_DATA_HOME") then
|
||||
f=os.getenv("XDG_DATA_HOME") .. "/imapfilter/" .. fname
|
||||
f = os.getenv("XDG_DATA_HOME") .. "/imapfilter/" .. fname
|
||||
else
|
||||
f=os.getenv("HOME") .. "/.local/share/imapfilter/" .. fname
|
||||
f = os.getenv("HOME") .. "/.local/share/imapfilter/" .. fname
|
||||
end
|
||||
return f
|
||||
end
|
||||
|
||||
function getSenderList(rollupfile)
|
||||
local rollupSenders={}
|
||||
local rollupSenders = {}
|
||||
|
||||
local file = io.open(rollupfile)
|
||||
if file then
|
||||
for line in file:lines() do
|
||||
table.insert(rollupSenders, line)
|
||||
end
|
||||
for line in file:lines() do table.insert(rollupSenders, line) end
|
||||
else
|
||||
print("ERROR: rollup did not find rollup.txt file containing mail addresses at " .. rollupfile or "" )
|
||||
print(
|
||||
"ERROR: rollup did not find rollup.txt file containing mail addresses at " ..
|
||||
rollupfile or "")
|
||||
end
|
||||
return rollupSenders
|
||||
end
|
||||
|
||||
sendToFolder (
|
||||
accounts.gmail["Inbox"],
|
||||
accounts.gmail["Dump"],
|
||||
getSenderList(getRollupFile())
|
||||
)
|
||||
sendToFolder(accounts.gmail["Inbox"], accounts.gmail["Dump"],
|
||||
getSenderList(getRollupFile()))
|
||||
|
|
|
@ -4,10 +4,8 @@ local lqprofile = "lowquality"
|
|||
local hqprofile = "highquality"
|
||||
|
||||
local function powerstate()
|
||||
local f =io.open("/sys/class/power_supply/AC/online")
|
||||
if f == nil then
|
||||
return
|
||||
end
|
||||
local f = io.open("/sys/class/power_supply/AC/online")
|
||||
if f == nil then return end
|
||||
local t = f:read("*n")
|
||||
f:close()
|
||||
return t
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,8 +2,7 @@
|
|||
--
|
||||
-- This script skips sponsored segments of YouTube videos
|
||||
-- using data from https://github.com/ajayyy/SponsorBlock
|
||||
|
||||
local ON_WINDOWS = package.config:sub(1,1) ~= '/'
|
||||
local ON_WINDOWS = package.config:sub(1, 1) ~= '/'
|
||||
|
||||
local options = {
|
||||
server_address = "https://sponsor.ajay.app",
|
||||
|
@ -71,9 +70,7 @@ mp.options = require "mp.options"
|
|||
mp.options.read_options(options, "sponsorblock")
|
||||
|
||||
local legacy = mp.command_native_async == nil
|
||||
if legacy then
|
||||
options.local_database = false
|
||||
end
|
||||
if legacy then options.local_database = false end
|
||||
|
||||
local utils = require "mp.utils"
|
||||
if mp.get_script_directory == nil then
|
||||
|
@ -83,7 +80,9 @@ else
|
|||
end
|
||||
local sponsorblock = utils.join_path(scripts_dir, "shared/sponsorblock.py")
|
||||
local uid_path = utils.join_path(scripts_dir, "shared/sponsorblock.txt")
|
||||
local database_file = options.local_database and utils.join_path(scripts_dir, "shared/sponsorblock.db") or ""
|
||||
local database_file = options.local_database and
|
||||
utils.join_path(scripts_dir, "shared/sponsorblock.db") or
|
||||
""
|
||||
local youtube_id = nil
|
||||
local ranges = {}
|
||||
local init = false
|
||||
|
@ -96,8 +95,13 @@ local fade_dir = nil
|
|||
local volume_before = mp.get_property_number("volume")
|
||||
|
||||
function file_exists(name)
|
||||
local f = io.open(name,"r")
|
||||
if f ~= nil then io.close(f) return true else return false end
|
||||
local f = io.open(name, "r")
|
||||
if f ~= nil then
|
||||
io.close(f)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function t_count(t)
|
||||
|
@ -106,15 +110,14 @@ function t_count(t)
|
|||
return count
|
||||
end
|
||||
|
||||
function time_sort(a, b)
|
||||
return a.time < b.time
|
||||
end
|
||||
function time_sort(a, b) return a.time < b.time end
|
||||
|
||||
function clean_chapters()
|
||||
local chapters = mp.get_property_native("chapter-list")
|
||||
local new_chapters = {}
|
||||
for _, chapter in pairs(chapters) do
|
||||
if chapter.title ~= "Preview segment start" and chapter.title ~= "Preview segment end" then
|
||||
if chapter.title ~= "Preview segment start" and chapter.title ~=
|
||||
"Preview segment end" then
|
||||
table.insert(new_chapters, chapter)
|
||||
end
|
||||
end
|
||||
|
@ -124,7 +127,11 @@ end
|
|||
function create_chapter(chapter_title, chapter_time)
|
||||
local chapters = mp.get_property_native("chapter-list")
|
||||
local duration = mp.get_property_native("duration")
|
||||
table.insert(chapters, {title=chapter_title, time=(duration == nil or duration > chapter_time) and chapter_time or duration - .001})
|
||||
table.insert(chapters, {
|
||||
title = chapter_title,
|
||||
time = (duration == nil or duration > chapter_time) and chapter_time or
|
||||
duration - .001
|
||||
})
|
||||
table.sort(chapters, time_sort)
|
||||
mp.set_property_native("chapter-list", chapters)
|
||||
end
|
||||
|
@ -134,7 +141,8 @@ function getranges(_, exists, db, more)
|
|||
if options.server_fallback then
|
||||
mp.add_timeout(0, function() getranges(true, true, "") end)
|
||||
else
|
||||
return mp.osd_message("[sponsorblock] database update failed, gave up")
|
||||
return mp.osd_message(
|
||||
"[sponsorblock] database update failed, gave up")
|
||||
end
|
||||
end
|
||||
if db ~= "" and db ~= database_file then db = database_file end
|
||||
|
@ -151,20 +159,23 @@ function getranges(_, exists, db, more)
|
|||
end
|
||||
local sponsors
|
||||
local args = {
|
||||
options.python_path,
|
||||
sponsorblock,
|
||||
"ranges",
|
||||
db,
|
||||
options.server_address,
|
||||
options.python_path, sponsorblock, "ranges", db, options.server_address,
|
||||
youtube_id
|
||||
}
|
||||
if not legacy then
|
||||
sponsors = mp.command_native({name = "subprocess", capture_stdout = true, playback_only = false, args = args})
|
||||
sponsors = mp.command_native({
|
||||
name = "subprocess",
|
||||
capture_stdout = true,
|
||||
playback_only = false,
|
||||
args = args
|
||||
})
|
||||
else
|
||||
sponsors = utils.subprocess({args = args})
|
||||
end
|
||||
if not string.match(sponsors.stdout, "^%s*(.*%S)") then return end
|
||||
if string.match(sponsors.stdout, "error") then return getranges(true, true) end
|
||||
if string.match(sponsors.stdout, "error") then
|
||||
return getranges(true, true)
|
||||
end
|
||||
local new_ranges = {}
|
||||
local r_count = 0
|
||||
if more then r_count = -1 end
|
||||
|
@ -176,7 +187,8 @@ function getranges(_, exists, db, more)
|
|||
start_time = tonumber(string.match(t, '[^,]+'))
|
||||
end_time = tonumber(string.sub(string.match(t, ',[^,]+'), 2))
|
||||
for o_uuid, o_t in pairs(ranges) do
|
||||
if (start_time >= o_t.start_time and start_time <= o_t.end_time) or (o_t.start_time >= start_time and o_t.start_time <= end_time) then
|
||||
if (start_time >= o_t.start_time and start_time <= o_t.end_time) or
|
||||
(o_t.start_time >= start_time and o_t.start_time <= end_time) then
|
||||
new_ranges[o_uuid] = o_t
|
||||
goto continue
|
||||
end
|
||||
|
@ -189,29 +201,31 @@ function getranges(_, exists, db, more)
|
|||
}
|
||||
end
|
||||
if options.make_chapters then
|
||||
create_chapter("Sponsor start (" .. string.sub(uuid, 1, 6) .. ")", start_time)
|
||||
create_chapter("Sponsor end (" .. string.sub(uuid, 1, 6) .. ")", end_time)
|
||||
create_chapter("Sponsor start (" .. string.sub(uuid, 1, 6) ..
|
||||
")", start_time)
|
||||
create_chapter("Sponsor end (" .. string.sub(uuid, 1, 6) .. ")",
|
||||
end_time)
|
||||
end
|
||||
end
|
||||
::continue::
|
||||
r_count = r_count + 1
|
||||
end
|
||||
local c_count = t_count(ranges)
|
||||
if c_count == 0 or r_count >= c_count then
|
||||
ranges = new_ranges
|
||||
end
|
||||
if c_count == 0 or r_count >= c_count then ranges = new_ranges end
|
||||
end
|
||||
|
||||
function fast_forward()
|
||||
local last_speed = mp.get_property_number("speed")
|
||||
local new_speed = math.min(last_speed + options.fast_forward_increase, options.fast_forward_cap)
|
||||
local new_speed = math.min(last_speed + options.fast_forward_increase,
|
||||
options.fast_forward_cap)
|
||||
if new_speed <= last_speed then return end
|
||||
mp.set_property("speed", new_speed)
|
||||
end
|
||||
|
||||
function fade_audio(step)
|
||||
local last_volume = mp.get_property_number("volume")
|
||||
local new_volume = math.max(options.audio_fade_cap, math.min(last_volume + step, volume_before))
|
||||
local new_volume = math.max(options.audio_fade_cap,
|
||||
math.min(last_volume + step, volume_before))
|
||||
if new_volume == last_volume then
|
||||
if step >= 0 then fade_dir = nil end
|
||||
if fade_timer ~= nil then fade_timer:kill() end
|
||||
|
@ -225,7 +239,8 @@ function skip_ads(name, pos)
|
|||
if pos == nil then return end
|
||||
local sponsor_ahead = false
|
||||
for uuid, t in pairs(ranges) do
|
||||
if (options.fast_forward == uuid or not options.skip_once or not t.skipped) and t.start_time <= pos and t.end_time > pos then
|
||||
if (options.fast_forward == uuid or not options.skip_once or
|
||||
not t.skipped) and t.start_time <= pos and t.end_time > pos then
|
||||
if options.fast_forward == uuid then return end
|
||||
if options.fast_forward == false then
|
||||
mp.osd_message("[sponsorblock] sponsor skipped")
|
||||
|
@ -237,20 +252,18 @@ function skip_ads(name, pos)
|
|||
last_skip = {uuid = uuid, dir = nil}
|
||||
if options.report_views or options.auto_upvote then
|
||||
local args = {
|
||||
options.python_path,
|
||||
sponsorblock,
|
||||
"stats",
|
||||
database_file,
|
||||
options.server_address,
|
||||
youtube_id,
|
||||
uuid,
|
||||
options.report_views and "1" or "",
|
||||
uid_path,
|
||||
options.user_id,
|
||||
options.auto_upvote and "1" or ""
|
||||
options.python_path, sponsorblock, "stats", database_file,
|
||||
options.server_address, youtube_id, uuid,
|
||||
options.report_views and "1" or "", uid_path,
|
||||
options.user_id, options.auto_upvote and "1" or ""
|
||||
}
|
||||
if not legacy then
|
||||
mp.command_native_async({name = "subprocess", playback_only = false, args = args}, function () end)
|
||||
mp.command_native_async(
|
||||
{
|
||||
name = "subprocess",
|
||||
playback_only = false,
|
||||
args = args
|
||||
}, function() end)
|
||||
else
|
||||
utils.subprocess_detached({args = args})
|
||||
end
|
||||
|
@ -260,22 +273,29 @@ function skip_ads(name, pos)
|
|||
speed_timer = mp.add_periodic_timer(1, fast_forward)
|
||||
end
|
||||
return
|
||||
elseif (not options.skip_once or not t.skipped) and t.start_time <= pos + 1 and t.end_time > pos + 1 then
|
||||
elseif (not options.skip_once or not t.skipped) and t.start_time <= pos +
|
||||
1 and t.end_time > pos + 1 then
|
||||
sponsor_ahead = true
|
||||
end
|
||||
end
|
||||
if options.audio_fade then
|
||||
if sponsor_ahead then
|
||||
if fade_dir ~= false then
|
||||
if fade_dir == nil then volume_before = mp.get_property_number("volume") end
|
||||
if fade_dir == nil then
|
||||
volume_before = mp.get_property_number("volume")
|
||||
end
|
||||
if fade_timer ~= nil then fade_timer:kill() end
|
||||
fade_dir = false
|
||||
fade_timer = mp.add_periodic_timer(.1, function() fade_audio(-options.audio_fade_step) end)
|
||||
fade_timer = mp.add_periodic_timer(.1, function()
|
||||
fade_audio(-options.audio_fade_step)
|
||||
end)
|
||||
end
|
||||
elseif fade_dir == false then
|
||||
fade_dir = true
|
||||
if fade_timer ~= nil then fade_timer:kill() end
|
||||
fade_timer = mp.add_periodic_timer(.1, function() fade_audio(options.audio_fade_step) end)
|
||||
fade_timer = mp.add_periodic_timer(.1, function()
|
||||
fade_audio(options.audio_fade_step)
|
||||
end)
|
||||
end
|
||||
end
|
||||
if options.fast_forward and options.fast_forward ~= true then
|
||||
|
@ -286,25 +306,27 @@ function skip_ads(name, pos)
|
|||
end
|
||||
|
||||
function vote(dir)
|
||||
if last_skip.uuid == "" then return mp.osd_message("[sponsorblock] no sponsors skipped, can't submit vote") end
|
||||
if last_skip.uuid == "" then
|
||||
return mp.osd_message(
|
||||
"[sponsorblock] no sponsors skipped, can't submit vote")
|
||||
end
|
||||
local updown = dir == "1" and "up" or "down"
|
||||
if last_skip.dir == dir then return mp.osd_message("[sponsorblock] " .. updown .. "vote already submitted") end
|
||||
if last_skip.dir == dir then
|
||||
return mp.osd_message("[sponsorblock] " .. updown ..
|
||||
"vote already submitted")
|
||||
end
|
||||
last_skip.dir = dir
|
||||
local args = {
|
||||
options.python_path,
|
||||
sponsorblock,
|
||||
"stats",
|
||||
database_file,
|
||||
options.server_address,
|
||||
youtube_id,
|
||||
last_skip.uuid,
|
||||
"",
|
||||
uid_path,
|
||||
options.user_id,
|
||||
dir
|
||||
options.python_path, sponsorblock, "stats", database_file,
|
||||
options.server_address, youtube_id, last_skip.uuid, "", uid_path,
|
||||
options.user_id, dir
|
||||
}
|
||||
if not legacy then
|
||||
mp.command_native_async({name = "subprocess", playback_only = false, args = args}, function () end)
|
||||
mp.command_native_async({
|
||||
name = "subprocess",
|
||||
playback_only = false,
|
||||
args = args
|
||||
}, function() end)
|
||||
else
|
||||
utils.subprocess({args = args})
|
||||
end
|
||||
|
@ -312,13 +334,14 @@ function vote(dir)
|
|||
end
|
||||
|
||||
function update()
|
||||
mp.command_native_async({name = "subprocess", playback_only = false, args = {
|
||||
options.python_path,
|
||||
sponsorblock,
|
||||
"update",
|
||||
database_file,
|
||||
mp.command_native_async({
|
||||
name = "subprocess",
|
||||
playback_only = false,
|
||||
args = {
|
||||
options.python_path, sponsorblock, "update", database_file,
|
||||
options.server_address
|
||||
}}, getranges)
|
||||
}
|
||||
}, getranges)
|
||||
end
|
||||
|
||||
function file_loaded()
|
||||
|
@ -327,15 +350,18 @@ function file_loaded()
|
|||
segment = {a = 0, b = 0, progress = 0, first = true}
|
||||
last_skip = {uuid = "", dir = nil}
|
||||
local video_path = mp.get_property("path")
|
||||
local youtube_id1 = string.match(video_path, "https?://youtu%.be/([%a%d%-_]+).*")
|
||||
local youtube_id2 = string.match(video_path, "https?://w?w?w?%.?youtube%.com/v/([%a%d%-_]+).*")
|
||||
local youtube_id1 = string.match(video_path,
|
||||
"https?://youtu%.be/([%a%d%-_]+).*")
|
||||
local youtube_id2 = string.match(video_path,
|
||||
"https?://w?w?w?%.?youtube%.com/v/([%a%d%-_]+).*")
|
||||
local youtube_id3 = string.match(video_path, "/watch%?v=([%a%d%-_]+).*")
|
||||
local youtube_id4 = string.match(video_path, "/embed/([%a%d%-_]+).*")
|
||||
local local_pattern = nil
|
||||
if options.local_pattern ~= "" then
|
||||
local_pattern = string.match(video_path, options.local_pattern)
|
||||
end
|
||||
youtube_id = youtube_id1 or youtube_id2 or youtube_id3 or youtube_id4 or local_pattern
|
||||
youtube_id = youtube_id1 or youtube_id2 or youtube_id3 or youtube_id4 or
|
||||
local_pattern
|
||||
if not youtube_id then return end
|
||||
init = true
|
||||
if not options.local_database then
|
||||
|
@ -344,7 +370,9 @@ function file_loaded()
|
|||
local exists = file_exists(database_file)
|
||||
if exists and options.server_fallback then
|
||||
getranges(true, true)
|
||||
mp.add_timeout(0, function() getranges(true, true, "", true) end)
|
||||
mp.add_timeout(0, function()
|
||||
getranges(true, true, "", true)
|
||||
end)
|
||||
elseif exists then
|
||||
getranges(true, true)
|
||||
elseif options.server_fallback then
|
||||
|
@ -352,30 +380,25 @@ function file_loaded()
|
|||
end
|
||||
end
|
||||
if initialized then return end
|
||||
if options.skip then
|
||||
mp.observe_property("time-pos", "native", skip_ads)
|
||||
end
|
||||
if options.skip then mp.observe_property("time-pos", "native", skip_ads) end
|
||||
if options.display_name ~= "" then
|
||||
local args = {
|
||||
options.python_path,
|
||||
sponsorblock,
|
||||
"username",
|
||||
database_file,
|
||||
options.server_address,
|
||||
youtube_id,
|
||||
"",
|
||||
"",
|
||||
uid_path,
|
||||
options.user_id,
|
||||
options.display_name
|
||||
options.python_path, sponsorblock, "username", database_file,
|
||||
options.server_address, youtube_id, "", "", uid_path,
|
||||
options.user_id, options.display_name
|
||||
}
|
||||
if not legacy then
|
||||
mp.command_native_async({name = "subprocess", playback_only = false, args = args}, function () end)
|
||||
mp.command_native_async({
|
||||
name = "subprocess",
|
||||
playback_only = false,
|
||||
args = args
|
||||
}, function() end)
|
||||
else
|
||||
utils.subprocess_detached({args = args})
|
||||
end
|
||||
end
|
||||
if not options.local_database or (not options.auto_update and file_exists(database_file)) then return end
|
||||
if not options.local_database or
|
||||
(not options.auto_update and file_exists(database_file)) then return end
|
||||
update()
|
||||
end
|
||||
|
||||
|
@ -383,17 +406,19 @@ function set_segment()
|
|||
if not youtube_id then return end
|
||||
local pos = mp.get_property_number("time-pos")
|
||||
if pos == nil then return end
|
||||
if segment.progress > 1 then
|
||||
segment.progress = segment.progress - 2
|
||||
end
|
||||
if segment.progress > 1 then segment.progress = segment.progress - 2 end
|
||||
if segment.progress == 1 then
|
||||
segment.progress = 0
|
||||
segment.b = pos
|
||||
mp.osd_message("[sponsorblock] segment boundary B set, press again for boundary A", 3)
|
||||
mp.osd_message(
|
||||
"[sponsorblock] segment boundary B set, press again for boundary A",
|
||||
3)
|
||||
else
|
||||
segment.progress = 1
|
||||
segment.a = pos
|
||||
mp.osd_message("[sponsorblock] segment boundary A set, press again for boundary B", 3)
|
||||
mp.osd_message(
|
||||
"[sponsorblock] segment boundary A set, press again for boundary B",
|
||||
3)
|
||||
end
|
||||
if options.make_chapters and not segment.first then
|
||||
local start_time = math.min(segment.a, segment.b)
|
||||
|
@ -414,25 +439,30 @@ function submit_segment()
|
|||
if end_time - start_time == 0 or end_time == 0 then
|
||||
mp.osd_message("[sponsorblock] empty segment, not submitting")
|
||||
elseif segment.progress <= 1 then
|
||||
mp.osd_message(string.format("[sponsorblock] press Shift+G again to confirm: %.2d:%.2d:%.2d to %.2d:%.2d:%.2d", math.floor(start_time/(60*60)), math.floor(start_time/60%60), math.floor(start_time%60), math.floor(end_time/(60*60)), math.floor(end_time/60%60), math.floor(end_time%60)), 5)
|
||||
mp.osd_message(string.format(
|
||||
"[sponsorblock] press Shift+G again to confirm: %.2d:%.2d:%.2d to %.2d:%.2d:%.2d",
|
||||
math.floor(start_time / (60 * 60)),
|
||||
math.floor(start_time / 60 % 60),
|
||||
math.floor(start_time % 60),
|
||||
math.floor(end_time / (60 * 60)),
|
||||
math.floor(end_time / 60 % 60),
|
||||
math.floor(end_time % 60)), 5)
|
||||
segment.progress = segment.progress + 2
|
||||
else
|
||||
mp.osd_message("[sponsorblock] submitting segment...", 30)
|
||||
local submit
|
||||
local args = {
|
||||
options.python_path,
|
||||
sponsorblock,
|
||||
"submit",
|
||||
database_file,
|
||||
options.server_address,
|
||||
youtube_id,
|
||||
tostring(start_time),
|
||||
tostring(end_time),
|
||||
uid_path,
|
||||
options.user_id
|
||||
options.python_path, sponsorblock, "submit", database_file,
|
||||
options.server_address, youtube_id, tostring(start_time),
|
||||
tostring(end_time), uid_path, options.user_id
|
||||
}
|
||||
if not legacy then
|
||||
submit = mp.command_native({name = "subprocess", capture_stdout = true, playback_only = false, args = args})
|
||||
submit = mp.command_native({
|
||||
name = "subprocess",
|
||||
capture_stdout = true,
|
||||
playback_only = false,
|
||||
args = args
|
||||
})
|
||||
else
|
||||
submit = utils.subprocess({args = args})
|
||||
end
|
||||
|
@ -445,14 +475,21 @@ function submit_segment()
|
|||
create_chapter("Submitted segment end", end_time)
|
||||
end
|
||||
elseif string.match(submit.stdout, "error") then
|
||||
mp.osd_message("[sponsorblock] segment submission failed, server may be down. try again", 5)
|
||||
mp.osd_message(
|
||||
"[sponsorblock] segment submission failed, server may be down. try again",
|
||||
5)
|
||||
elseif string.match(submit.stdout, "502") then
|
||||
mp.osd_message("[sponsorblock] segment submission failed, server is down. try again", 5)
|
||||
mp.osd_message(
|
||||
"[sponsorblock] segment submission failed, server is down. try again",
|
||||
5)
|
||||
elseif string.match(submit.stdout, "400") then
|
||||
mp.osd_message("[sponsorblock] segment submission failed, impossible inputs", 5)
|
||||
mp.osd_message(
|
||||
"[sponsorblock] segment submission failed, impossible inputs", 5)
|
||||
segment = {a = 0, b = 0, progress = 0, first = true}
|
||||
elseif string.match(submit.stdout, "429") then
|
||||
mp.osd_message("[sponsorblock] segment submission failed, rate limited. try again", 5)
|
||||
mp.osd_message(
|
||||
"[sponsorblock] segment submission failed, rate limited. try again",
|
||||
5)
|
||||
elseif string.match(submit.stdout, "409") then
|
||||
mp.osd_message("[sponsorblock] segment already submitted", 3)
|
||||
segment = {a = 0, b = 0, progress = 0, first = true}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -14,9 +14,11 @@ function M.blameVirtText()
|
|||
|
||||
local currFile = vim.fn.expand('%')
|
||||
local line = api.nvim_win_get_cursor(0)
|
||||
local blame = vim.fn.system(string.format('git blame -c -L %d,%d %s', line[1], line[1], currFile))
|
||||
local blame = vim.fn.system(string.format('git blame -c -L %d,%d %s',
|
||||
line[1], line[1], currFile))
|
||||
local hash = vim.split(blame, '%s')[1]
|
||||
local cmd = string.format("git show %s ", hash).."--format='%an | %ar | %s'"
|
||||
local cmd = string.format("git show %s ", hash) ..
|
||||
"--format='%an | %ar | %s'"
|
||||
|
||||
if hash == '00000000' then
|
||||
text = 'Not Committed Yet'
|
||||
|
@ -29,7 +31,7 @@ function M.blameVirtText()
|
|||
end
|
||||
|
||||
-- set virtual text for namespace 2 with the content from git and assign it to the higlight group 'GitLens'
|
||||
api.nvim_buf_set_virtual_text(0, 2, line[1] - 1, {{ text,'GitLens' }}, {})
|
||||
api.nvim_buf_set_virtual_text(0, 2, line[1] - 1, {{text, 'GitLens'}}, {})
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -1,22 +1,34 @@
|
|||
|
||||
local on_attach = function(client, bufnr)
|
||||
-- Keybindings for LSPs
|
||||
-- Note these are in on_attach so that they don't override bindings in a non-LSP setting
|
||||
vim.fn.nvim_set_keymap("n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", {noremap = true, silent = true})
|
||||
vim.fn.nvim_set_keymap("n", "gD", "<cmd>lua vim.lsp.buf.implementation()<CR>", {noremap = true, silent = true})
|
||||
vim.fn.nvim_set_keymap("n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", {noremap = true, silent = true})
|
||||
vim.fn.nvim_set_keymap("n", "gK", "<cmd>lua vim.lsp.buf.signature_help()<CR>", {noremap = true, silent = true})
|
||||
vim.fn.nvim_set_keymap("n", "1gD", "<cmd>lua vim.lsp.buf.type_definition()<CR>", {noremap = true, silent = true})
|
||||
vim.fn.nvim_set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", {noremap = true, silent = true})
|
||||
vim.fn.nvim_set_keymap("n", "g0", "<cmd>lua vim.lsp.buf.document_symbol()<CR>", {noremap = true, silent = true})
|
||||
vim.fn.nvim_set_keymap("n", "gW", "<cmd>lua vim.lsp.buf.workspace_symbol()<CR>", {noremap = true, silent = true})
|
||||
vim.fn.nvim_set_keymap("n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>",
|
||||
{noremap = true, silent = true})
|
||||
vim.fn.nvim_set_keymap("n", "gD",
|
||||
"<cmd>lua vim.lsp.buf.implementation()<CR>",
|
||||
{noremap = true, silent = true})
|
||||
vim.fn.nvim_set_keymap("n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>",
|
||||
{noremap = true, silent = true})
|
||||
vim.fn.nvim_set_keymap("n", "gK",
|
||||
"<cmd>lua vim.lsp.buf.signature_help()<CR>",
|
||||
{noremap = true, silent = true})
|
||||
vim.fn.nvim_set_keymap("n", "1gD",
|
||||
"<cmd>lua vim.lsp.buf.type_definition()<CR>",
|
||||
{noremap = true, silent = true})
|
||||
vim.fn.nvim_set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>",
|
||||
{noremap = true, silent = true})
|
||||
vim.fn.nvim_set_keymap("n", "g0",
|
||||
"<cmd>lua vim.lsp.buf.document_symbol()<CR>",
|
||||
{noremap = true, silent = true})
|
||||
vim.fn.nvim_set_keymap("n", "gW",
|
||||
"<cmd>lua vim.lsp.buf.workspace_symbol()<CR>",
|
||||
{noremap = true, silent = true})
|
||||
end
|
||||
|
||||
require'nvim_lsp'.pyls.setup{on_attach=on_attach}
|
||||
require'nvim_lsp'.vimls.setup{on_attach=on_attach}
|
||||
require'nvim_lsp'.bashls.setup{on_attach=on_attach}
|
||||
require'nvim_lsp'.gopls.setup{on_attach=on_attach}
|
||||
require'nvim_lsp'.texlab.setup{on_attach=on_attach}
|
||||
require'nvim_lsp'.pyls.setup {on_attach = on_attach}
|
||||
require'nvim_lsp'.vimls.setup {on_attach = on_attach}
|
||||
require'nvim_lsp'.bashls.setup {on_attach = on_attach}
|
||||
require'nvim_lsp'.gopls.setup {on_attach = on_attach}
|
||||
require'nvim_lsp'.texlab.setup {on_attach = on_attach}
|
||||
|
||||
-- To get builtin LSP running, do something like:
|
||||
-- NOTE: This replaces the calls where you would have before done `require('nvim_lsp').sumneko_lua.setup()`
|
||||
|
@ -26,6 +38,6 @@ require('nlua.lsp.nvim').setup(require('nvim_lsp'), {
|
|||
-- Include globals you want to tell the LSP are real :)
|
||||
globals = {
|
||||
-- Colorbuddy
|
||||
"Color", "c", "Group", "g", "s",
|
||||
"Color", "c", "Group", "g", "s"
|
||||
}
|
||||
})
|
||||
|
|
|
@ -2,12 +2,11 @@ local M = {}
|
|||
|
||||
function M.getCompletionItems(prefix)
|
||||
-- define your total completion items
|
||||
local items = vim.api.nvim_call_function('pandoc#completion#Complete',{0, prefix})
|
||||
local items = vim.api.nvim_call_function('pandoc#completion#Complete',
|
||||
{0, prefix})
|
||||
return items
|
||||
end
|
||||
|
||||
M.complete_item = {
|
||||
item = M.getCompletionItems
|
||||
}
|
||||
M.complete_item = {item = M.getCompletionItems}
|
||||
|
||||
return M
|
||||
|
|
|
@ -9,28 +9,30 @@ window, otherwise opens a new split.
|
|||
The buffer, by default is set to the pandoc filetype.
|
||||
This can be changed by setting the `g:scratchpad_ft` variable or the `b:scratchpad_ft`
|
||||
variable to the intended filetype.
|
||||
]]--
|
||||
]] --
|
||||
local api = vim.api
|
||||
local M= {}
|
||||
local M = {}
|
||||
|
||||
local function isempty(s)
|
||||
return s == nil or s == ''
|
||||
end
|
||||
local function isempty(s) return s == nil or s == '' end
|
||||
|
||||
function M.create(split, ft)
|
||||
-- should we create a new split or switch out the current buffer?
|
||||
if isempty(split) then split = false else split = true end
|
||||
if isempty(split) then
|
||||
split = false
|
||||
else
|
||||
split = true
|
||||
end
|
||||
-- which filetype to set for the scratchpad, defaults to pandoc
|
||||
if isempty(ft) then ft = vim.b["scratchpad_ft"] or vim.g["scratchpad_ft"] or "pandoc" end
|
||||
if isempty(ft) then
|
||||
ft = vim.b["scratchpad_ft"] or vim.g["scratchpad_ft"] or "pandoc"
|
||||
end
|
||||
|
||||
local buf = api.nvim_create_buf(false, true)
|
||||
if buf == 0 then
|
||||
print("Error opening scratch buffer.")
|
||||
end
|
||||
if buf == 0 then print("Error opening scratch buffer.") end
|
||||
api.nvim_buf_set_option(buf, "bufhidden", "hide")
|
||||
api.nvim_buf_set_option(buf, "buftype", "nofile")
|
||||
api.nvim_buf_set_option(buf, "swapfile",false)
|
||||
api.nvim_buf_set_option(buf, "filetype",ft)
|
||||
api.nvim_buf_set_option(buf, "swapfile", false)
|
||||
api.nvim_buf_set_option(buf, "filetype", ft)
|
||||
|
||||
if split then api.nvim_command('vsplit new') end -- i think this is the only way to interact with the buffers creating a new split
|
||||
-- switch to scratchpad
|
||||
|
|
|
@ -7,10 +7,8 @@ local function on_change(err, fname, status)
|
|||
watch_file(fname)
|
||||
end
|
||||
function watch_file(fname)
|
||||
local fullpath = vim.api.nvim_call_function(
|
||||
'fnamemodify', {fname, ':p'})
|
||||
w:start(fullpath, {}, vim.schedule_wrap(function(...)
|
||||
on_change(...) end))
|
||||
local fullpath = vim.api.nvim_call_function('fnamemodify', {fname, ':p'})
|
||||
w:start(fullpath, {}, vim.schedule_wrap(function(...) on_change(...) end))
|
||||
end
|
||||
vim.api.nvim_command(
|
||||
"command! -nargs=1 Watch call luaeval('watch_file(_A)', expand('<args>'))")
|
||||
|
|
Loading…
Reference in a new issue