Skip to content

Commit 87a3e14

Browse files
committed
Improve terminal print
1 parent 1209618 commit 87a3e14

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

youtube-upnext.lua

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,33 @@ if not input_import then
124124
-- If mp.input is not available, use an empty implementation
125125
input = {
126126
get = function(foo) end,
127-
terminate = function() end,
127+
terminate = function()
128+
mp.osd_message("", 1)
129+
-- Print media info (in case the input box is closed without playing a new video)
130+
local media_title = mp.get_property("media-title")
131+
local metadata = mp.get_property_native("metadata")
132+
if metadata then
133+
if metadata["uploader"] then
134+
mp.commandv("print-text", " Uploader: " .. metadata["uploader"])
135+
end
136+
if metadata["channel_url"] then
137+
mp.commandv("print-text", " Channel URL: " .. metadata["channel_url"])
138+
end
139+
end
140+
if media_title then
141+
mp.commandv("print-text", " Title: " .. media_title)
142+
end
143+
end,
128144
set_log = function(lines)
129145
local text = ""
130146
for i = 1, #lines do
131-
text = text .. "\n" .. lines[i].terminal_style .. lines[i].text .. "\027[0m"
147+
if type(lines[i]) == 'table' then
148+
text = text .. "\n" .. lines[i].terminal_style .. lines[i].text .. "\027[0m"
149+
else
150+
text = text .. "\n" .. tostring(lines[i])
151+
end
132152
end
133-
mp.osd_message("\n" .. text)
153+
mp.osd_message(text, 999)
134154
end
135155
}
136156
end
@@ -827,7 +847,6 @@ local function show_menu()
827847
if destroyer ~= nil then
828848
destroyer()
829849
end
830-
input.terminate()
831850
end
832851

833852
local function terminal_submit(text, text_override)
@@ -920,6 +939,21 @@ local function show_menu()
920939
ass:append(opts.style_ass_tags)
921940

922941
local terminal_lines = {}
942+
-- Print media info
943+
local media_title = mp.get_property("media-title")
944+
local metadata = mp.get_property_native("metadata")
945+
if metadata then
946+
if metadata["uploader"] then
947+
table.insert(terminal_lines, " Uploader: " .. metadata["uploader"])
948+
end
949+
if metadata["channel_url"] then
950+
table.insert(terminal_lines, " Channel URL: " .. metadata["channel_url"])
951+
end
952+
end
953+
if media_title then
954+
table.insert(terminal_lines, " Title: " .. media_title)
955+
end
956+
923957
table.insert(terminal_lines, {
924958
text = "░░░░░░░░░░░░░░░░░░░░░░░░ Up Next ░░░░░░░░░░░░░░░░░░░░░░░░",
925959
terminal_style = "\027[1m",
@@ -1017,9 +1051,14 @@ local function show_menu()
10171051
mp.observe_property("osd-dimensions", "native", update_dimensions)
10181052

10191053
local function destroy()
1054+
destroyer = nil
1055+
redraw_menu = nil
10201056
if timeout ~= nil then
10211057
timeout:kill()
10221058
end
1059+
if no_video then
1060+
input.terminate()
1061+
end
10231062
mp.set_osd_ass(0, 0, "")
10241063
mp.remove_key_binding("move_up")
10251064
mp.remove_key_binding("move_down")
@@ -1028,8 +1067,6 @@ local function show_menu()
10281067
mp.remove_key_binding("escape")
10291068
mp.remove_key_binding("quit")
10301069
mp.unobserve_property(update_dimensions)
1031-
destroyer = nil
1032-
redraw_menu = nil
10331070
end
10341071

10351072
if not no_video then

0 commit comments

Comments
 (0)