Last active
June 9, 2022 11:57
-
-
Save DrLulz/40b565160b1247319cbc to your computer and use it in GitHub Desktop.
Creates .edl file for MPV player used here as a bookmarked playlist. Binds "x" so that first press is start of "bookmark" and second press is end of "bookmark." The file produced can then be played using "mpv --playlist=file.edl".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function file_exists(playlist) | |
local f=io.open(playlist, "r") | |
if f~=nil then io.close(f) return true else return false end | |
end | |
function entry_complete(playlist) | |
local f=io.open(playlist, "r") | |
chars = f:read("*all") | |
last_char = string.sub(chars, -1) | |
if last_char == ";" then io.close(f) return true else return false end | |
end | |
function end_time(playlist, time) | |
local f=io.open(playlist, "r") | |
chars = f:read("*all") | |
local start_time = chars:match(".+,(.+)") | |
return time - start_time | |
end | |
function time_frame() | |
time = mp.get_property("time-pos") | |
path = mp.get_property("path") | |
ext = mp.get_property("filename") | |
file_dir = path:match("(.*[\\/\\/])") | |
list_dir = (file_dir .. "_playlists/") | |
name = ext:match("([^.]+)") | |
playlist = (list_dir .. name .. ".edl") | |
if file_exists(playlist) == true then | |
if entry_complete(playlist) == true then | |
local file = io.open(playlist, "a") | |
file:write(path .. "," .. time) | |
file:close() | |
mp.osd_message("Start") | |
else | |
local file = io.open(playlist, "a") | |
file:write("," .. end_time(playlist, time) .. ";") | |
file:close() | |
mp.osd_message("End") | |
end | |
else | |
os.execute("mkdir " .. "\"" .. list_dir .. "\"") | |
local file = io.open(playlist, "w") | |
file:write("# mpv EDL v0\n" .. "edl://" .. path .. "," .. time) | |
file:close() | |
mp.osd_message("Start") | |
end | |
end | |
function time_mark() | |
time = mp.get_property("time-pos") | |
path = mp.get_property("path") | |
ext = mp.get_property("filename") | |
file_dir = path:match("(.*[\\/\\/])") | |
list_dir = (file_dir .. "_playlists/") | |
name = ext:match("([^.]+)") | |
playlist = (list_dir .. name .. ".edl") | |
if file_exists(playlist) == true then | |
file = io.open(playlist, "a") | |
file:write(path .. "," .. time .. ";") | |
file:close() | |
mp.osd_message("Marked Video") | |
else | |
os.execute("mkdir " .. "\"" .. list_dir .. "\"") | |
file = io.open(playlist, "w") | |
file:write("# mpv EDL v0\n" .. "edl://" .. path .. "," .. time .. ";") | |
file:close() | |
mp.osd_message("Marked Video") | |
end | |
end | |
mp.add_key_binding("x", "time_frame", time_frame) | |
mp.add_key_binding("Shift+x", "time_mark", time_mark) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment