aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorSquibid <me@zacharyscheiman.com>2024-07-27 09:26:54 -0400
committerSquibid <me@zacharyscheiman.com>2024-07-27 09:26:54 -0400
commit16f32bdcdd10c3dc95519b5f0ab4d6818b3a3bfe (patch)
tree6edc384d7e72662dc1e58f0722353ce841f891cc /modules
parent878f0faaf7f472b96ab5a7f0e4db266111b2d3ce (diff)
downloadeat-it-16f32bdcdd10c3dc95519b5f0ab4d6818b3a3bfe.tar.gz
eat-it-16f32bdcdd10c3dc95519b5f0ab4d6818b3a3bfe.tar.bz2
eat-it-16f32bdcdd10c3dc95519b5f0ab4d6818b3a3bfe.zip
complete refactor see README for more infov3.0
Diffstat (limited to 'modules')
-rw-r--r--modules/README.md28
-rw-r--r--modules/lssi/LSSI.md16
-rw-r--r--modules/lssi/lssi.lua133
3 files changed, 0 insertions, 177 deletions
diff --git a/modules/README.md b/modules/README.md
deleted file mode 100644
index 614a9b2..0000000
--- a/modules/README.md
+++ /dev/null
@@ -1,28 +0,0 @@
-# Modules
-Modules are extentions to the EatIt plugin manager that aren't necessary for
-running it. Every module will be in it's own sub directory in order to keep
-documentation relative to the individual modules.
-
-## List of modules
-- `lssi.lua` Lua Script Script Injector for modifing files post install
-
-## Installing
-Installing a module can be done through EatIt like so:
-```lua
-plugins = { -- the plugins you want to load
- { 'https://git.squi.bid/eat-it',
- file = 'modules/moddir/module.lua',
- dir = 'scripts',
- },
-}
-```
-
-## For Devs
-Please add a table in the global scope called 'mod' as this may be used in the
-future. It should look like this:
-```lua
-mod = {
- version = 'version',
- author = 'autor name',
-}
-```
diff --git a/modules/lssi/LSSI.md b/modules/lssi/LSSI.md
deleted file mode 100644
index 5bcd65d..0000000
--- a/modules/lssi/LSSI.md
+++ /dev/null
@@ -1,16 +0,0 @@
-# Using lssi
-Any plugin can be modified by lssi by doing the following in the eatit-cfg.lua:
-```lua
-plugins = { -- the plugins you want to load
- { 'https://git.squi.bid/eat-it',
- file = 'eatit.lua',
- dir = 'scripts',
- lssi = {
- -- code line
- { 'print("hello world")', 'G' },
- }
- },
-}
-```
-The line option can be 'g' for top of file, 'G' for bottom of file, or any
-number in between.
diff --git a/modules/lssi/lssi.lua b/modules/lssi/lssi.lua
deleted file mode 100644
index 21f9536..0000000
--- a/modules/lssi/lssi.lua
+++ /dev/null
@@ -1,133 +0,0 @@
---[[
-Eat It - a Mpv plugin manager
-
-Copyright © 2023 squibid
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-]]
-
--- NOTE: This is a POC and will most likely be reimplimented using diff files
--- with git
--- or we might want to generate a diff file from the requested changes
--- and check if the diffs match in content
-
---[[
- Lua Script Script Injector
-Takes an input file and code then, it outputs a file with your code in there.
-]]--
-
-local mp = require('mp')
-
-mod = {
- version = 'ALPHA 1.1', -- the current version of lssi
- author = 'squibid',
-}
-
--- load the eatit config file
-dofile(mp.command_native({'expand-path', '~~/eatit-cfg.lua'}))
-
--- helper functions
-local function tablelength(T)
- local count = 0
- for _ in pairs(T) do count = count + 1 end
- return count
-end
-
-local function fileexists(name)
- local f = io.open(name, 'r')
- if f ~= nil then io.close(f) return true else return false end
-end
-
-local function logwrite(string)
- if opts.logging.log then
- io.write(os.date(opts.logging.logdate)..' '..string..'\n')
- end
-end
-
-local function openlog()
- if opts.logging.log then -- log if asked to
- -- get our logfile's full path
- fn = mp.command_native({'expand-path', opts.logging.logfile})
-
- f = io.open(fn, 'a') -- open file buffer
- if not f then return end
- io.output(f) -- set it as default
- end
-end
-
-local function closelog()
- if opts.logging.log then
- io.close(f)
- end
-end
-
-local function inject(infile, l, outfile)
- local inf = io.open(infile, 'r')
- local infcont = {}
- for i in inf:lines() do
- table.insert(infcont, i)
- end
- inf:close()
-
- -- don't do anything if there is already code injected into the file
- if string.find(infcont[1], "-- code injected by lssi") then
- logwrite('code is already injected into '..infile)
- return
- end
- logwrite('Injecting code into '..infile)
-
- for i in pairs(l) do
- -- add requested line below existing line
- if l[i][2] == 'G' then
- infcont[tablelength(infcont)] = infcont[tablelength(infcont)]..'\n'..l[i][1]
- elseif l[i][2] == 'g' then
- infcont[1] = l[i][1]..'\n'..infcont[1]
- else
- infcont[l[i][2]] = (infcont[l[i][2]])..'\n'..l[i][1]
- end
- end
-
- local outf = io.open(outfile, 'w')
-
- -- we inject metadata to prevent writing to the file more than once
- infcont[1] = "-- code injected by lssi "..mod.version..'\n'..infcont[1]
- for i, v in ipairs(infcont) do
- outf:write(v..'\n')
- end
-
- io.close(outf)
-end
-
-local function checkandinject()
- openlog()
-
- for i = 1, tablelength(plugins) do
- -- check if the plugin has been configured with lssi
- if plugins[i]['lssi'] ~= nil then
- -- get the file we want to inject our code into
- local f = mp.command_native({'expand-path', '~~/'}) ..
- '/'..(plugins[i]['dir'] or 'scripts') ..
- '/'..plugins[i]['file']
- -- and the file we are trying to modify actually exists
- if fileexists(f) then
- -- inject it! no going back now
- inject(f, plugins[i]['lssi'], f)
- else
- logwrite('Failed to inject code into "' ..
- plugins[i]['file']..'" file does not exist')
- end
- end
- end
-
- closelog()
-end
-
-checkandinject()