Skip to content

Commit

Permalink
Improve terminal print
Browse files Browse the repository at this point in the history
  • Loading branch information
cvzi committed Mar 16, 2024
1 parent 1209618 commit 87a3e14
Showing 1 changed file with 43 additions and 6 deletions.
49 changes: 43 additions & 6 deletions youtube-upnext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,33 @@ if not input_import then
-- If mp.input is not available, use an empty implementation
input = {
get = function(foo) end,
terminate = function() end,
terminate = function()
mp.osd_message("", 1)
-- Print media info (in case the input box is closed without playing a new video)
local media_title = mp.get_property("media-title")
local metadata = mp.get_property_native("metadata")
if metadata then
if metadata["uploader"] then
mp.commandv("print-text", " Uploader: " .. metadata["uploader"])
end
if metadata["channel_url"] then
mp.commandv("print-text", " Channel URL: " .. metadata["channel_url"])
end
end
if media_title then
mp.commandv("print-text", " Title: " .. media_title)
end
end,
set_log = function(lines)
local text = ""
for i = 1, #lines do
text = text .. "\n" .. lines[i].terminal_style .. lines[i].text .. "\027[0m"
if type(lines[i]) == 'table' then
text = text .. "\n" .. lines[i].terminal_style .. lines[i].text .. "\027[0m"
else
text = text .. "\n" .. tostring(lines[i])
end
end
mp.osd_message("\n" .. text)
mp.osd_message(text, 999)
end
}
end
Expand Down Expand Up @@ -827,7 +847,6 @@ local function show_menu()
if destroyer ~= nil then
destroyer()
end
input.terminate()
end

local function terminal_submit(text, text_override)
Expand Down Expand Up @@ -920,6 +939,21 @@ local function show_menu()
ass:append(opts.style_ass_tags)

local terminal_lines = {}
-- Print media info
local media_title = mp.get_property("media-title")
local metadata = mp.get_property_native("metadata")
if metadata then
if metadata["uploader"] then
table.insert(terminal_lines, " Uploader: " .. metadata["uploader"])
end
if metadata["channel_url"] then
table.insert(terminal_lines, " Channel URL: " .. metadata["channel_url"])
end
end
if media_title then
table.insert(terminal_lines, " Title: " .. media_title)
end

table.insert(terminal_lines, {
text = "░░░░░░░░░░░░░░░░░░░░░░░░ Up Next ░░░░░░░░░░░░░░░░░░░░░░░░",
terminal_style = "\027[1m",
Expand Down Expand Up @@ -1017,9 +1051,14 @@ local function show_menu()
mp.observe_property("osd-dimensions", "native", update_dimensions)

local function destroy()
destroyer = nil
redraw_menu = nil
if timeout ~= nil then
timeout:kill()
end
if no_video then
input.terminate()
end
mp.set_osd_ass(0, 0, "")
mp.remove_key_binding("move_up")
mp.remove_key_binding("move_down")
Expand All @@ -1028,8 +1067,6 @@ local function show_menu()
mp.remove_key_binding("escape")
mp.remove_key_binding("quit")
mp.unobserve_property(update_dimensions)
destroyer = nil
redraw_menu = nil
end

if not no_video then
Expand Down

0 comments on commit 87a3e14

Please sign in to comment.