Skip to content

Commit 1209618

Browse files
committed
Format code
1 parent aceceb5 commit 1209618

File tree

1 file changed

+64
-64
lines changed

1 file changed

+64
-64
lines changed

youtube-upnext.lua

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ local input_import, input = pcall(require, "mp.input")
123123
if not input_import then
124124
-- If mp.input is not available, use an empty implementation
125125
input = {
126-
get = function() end,
126+
get = function(foo) end,
127127
terminate = function() end,
128128
set_log = function(lines)
129129
local text = ""
130130
for i = 1, #lines do
131-
text = text .. "\n" ..lines[i].terminal_style .. lines[i].text .."\027[0m"
131+
text = text .. "\n" .. lines[i].terminal_style .. lines[i].text .. "\027[0m"
132132
end
133133
mp.osd_message("\n" .. text)
134134
end
@@ -172,14 +172,14 @@ end
172172
local function exec(args, capture_stdout, capture_stderr)
173173
local ret =
174174
mp.command_native(
175-
{
176-
name = "subprocess",
177-
playback_only = false,
178-
capture_stdout = capture_stdout,
179-
capture_stderr = capture_stderr,
180-
args = args
181-
}
182-
)
175+
{
176+
name = "subprocess",
177+
playback_only = false,
178+
capture_stdout = capture_stdout,
179+
capture_stderr = capture_stderr,
180+
args = args
181+
}
182+
)
183183
return ret.status, ret.stdout, ret.stderr, ret
184184
end
185185

@@ -254,7 +254,7 @@ local function download_upnext(url, post_data)
254254
mp.osd_message("fetching 'up next' with curl...", 60)
255255
end
256256

257-
local command = {"curl", "--silent", "--location"}
257+
local command = { "curl", "--silent", "--location" }
258258
if post_data then
259259
table.insert(command, "--request")
260260
table.insert(command, "POST")
@@ -276,7 +276,7 @@ local function download_upnext(url, post_data)
276276
-- MP_SUBPROCESS_EINIT is -3 which can mean the command was not found:
277277
-- https://github.com/mpv-player/mpv/blob/24dcb5d167ba9580119e0b9cc26f79b1d155fcdc/osdep/subprocess-posix.c#L335-L336
278278
msg.debug("curl not found, trying wget")
279-
local command_wget = {"wget", "-q", "-O", "-"}
279+
local command_wget = { "wget", "-q", "-O", "-" }
280280
if not opts.check_certificate then
281281
table.insert(command_wget, "--no-check-certificate")
282282
end
@@ -330,7 +330,7 @@ local function download_upnext(url, post_data)
330330
end
331331
msg.warn(
332332
'Created a cookies jar file at "' ..
333-
tostring(opts.cookies) .. '". To hide this warning, set a cookies file in the script configuration'
333+
tostring(opts.cookies) .. '". To hide this warning, set a cookies file in the script configuration'
334334
)
335335
end
336336
return download_upnext("https://consent.youtube.com/s", post_str)
@@ -362,7 +362,7 @@ local function get_invidious(url)
362362
url = string.gsub(url, "https://youtu%.be/", opts.invidious_instance .. "/api/v1/videos/")
363363
msg.debug("Invidious url:" .. url)
364364

365-
local command = {"curl", "--silent", "--location"}
365+
local command = { "curl", "--silent", "--location" }
366366
if not opts.check_certificate then
367367
table.insert(command, "--no-check-certificate")
368368
end
@@ -373,7 +373,7 @@ local function get_invidious(url)
373373
if (es ~= 0) or (s == nil) or (s == "") then
374374
if es == -1 or es == -3 or es == 127 or es == 9009 then
375375
msg.debug("curl not found, trying wget")
376-
local command_wget = {"wget", "-q", "-O", "-"}
376+
local command_wget = { "wget", "-q", "-O", "-" }
377377
if not opts.check_certificate then
378378
table.insert(command_wget, "--no-check-certificate")
379379
end
@@ -388,7 +388,6 @@ local function get_invidious(url)
388388
msg.error("failed to get invidious: error=" .. tostring(es))
389389
return {}
390390
end
391-
392391
end
393392

394393
local data
@@ -470,18 +469,20 @@ local function parse_upnext(json_str, current_video_url)
470469
local autoplay_id = nil
471470
if
472471
data.playerOverlays and data.playerOverlays.playerOverlayRenderer and
473-
data.playerOverlays.playerOverlayRenderer.autoplay and
474-
data.playerOverlays.playerOverlayRenderer.autoplay.playerOverlayAutoplayRenderer
475-
then
476-
local playerOverlayAutoplayRenderer = data.playerOverlays.playerOverlayRenderer.autoplay.playerOverlayAutoplayRenderer
472+
data.playerOverlays.playerOverlayRenderer.autoplay and
473+
data.playerOverlays.playerOverlayRenderer.autoplay.playerOverlayAutoplayRenderer
474+
then
475+
local playerOverlayAutoplayRenderer = data.playerOverlays.playerOverlayRenderer.autoplay
476+
.playerOverlayAutoplayRenderer
477477
local title = playerOverlayAutoplayRenderer.videoTitle.simpleText
478478
local video_id = playerOverlayAutoplayRenderer.videoId
479479
local duration = -1
480480
if playerOverlayAutoplayRenderer.thumbnailOverlays and playerOverlayAutoplayRenderer.thumbnailOverlays[1] and
481481
playerOverlayAutoplayRenderer.thumbnailOverlays[1].thumbnailOverlayTimeStatusRenderer and
482482
playerOverlayAutoplayRenderer.thumbnailOverlays[1].thumbnailOverlayTimeStatusRenderer.text
483483
then
484-
duration = parse_yt_time(playerOverlayAutoplayRenderer.thumbnailOverlays[1].thumbnailOverlayTimeStatusRenderer.text.simpleText)
484+
duration = parse_yt_time(playerOverlayAutoplayRenderer.thumbnailOverlays[1]
485+
.thumbnailOverlayTimeStatusRenderer.text.simpleText)
485486
end
486487

487488
if watched_ids[video_id] == nil then -- Skip if the video was already watched
@@ -512,10 +513,10 @@ local function parse_upnext(json_str, current_video_url)
512513

513514
if
514515
data.playerOverlays and data.playerOverlays.playerOverlayRenderer and
515-
data.playerOverlays.playerOverlayRenderer.endScreen and
516-
data.playerOverlays.playerOverlayRenderer.endScreen.watchNextEndScreenRenderer and
517-
data.playerOverlays.playerOverlayRenderer.endScreen.watchNextEndScreenRenderer.results
518-
then
516+
data.playerOverlays.playerOverlayRenderer.endScreen and
517+
data.playerOverlays.playerOverlayRenderer.endScreen.watchNextEndScreenRenderer and
518+
data.playerOverlays.playerOverlayRenderer.endScreen.watchNextEndScreenRenderer.results
519+
then
519520
local n = table_size(data.playerOverlays.playerOverlayRenderer.endScreen.watchNextEndScreenRenderer.results)
520521
for i, v in ipairs(data.playerOverlays.playerOverlayRenderer.endScreen.watchNextEndScreenRenderer.results) do
521522
if v.endScreenVideoRenderer and v.endScreenVideoRenderer.title and v.endScreenVideoRenderer.title.simpleText then
@@ -554,8 +555,8 @@ local function parse_upnext(json_str, current_video_url)
554555

555556
if
556557
data.contents and data.contents.twoColumnWatchNextResults and
557-
data.contents.twoColumnWatchNextResults.secondaryResults
558-
then
558+
data.contents.twoColumnWatchNextResults.secondaryResults
559+
then
559560
local secondaryResults = data.contents.twoColumnWatchNextResults.secondaryResults
560561
if secondaryResults.secondaryResults then
561562
secondaryResults = secondaryResults.secondaryResults
@@ -565,17 +566,17 @@ local function parse_upnext(json_str, current_video_url)
565566
local watchnextindex = index
566567
if
567568
v.compactAutoplayRenderer and v.compactAutoplayRenderer and v.compactAutoplayRenderer.contents and
568-
v.compactAutoplayRenderer.contents.compactVideoRenderer
569-
then
569+
v.compactAutoplayRenderer.contents.compactVideoRenderer
570+
then
570571
compactVideoRenderer = v.compactAutoplayRenderer.contents.compactVideoRenderer
571572
watchnextindex = 0
572573
elseif v.compactVideoRenderer then
573574
compactVideoRenderer = v.compactVideoRenderer
574575
end
575576
if
576577
compactVideoRenderer and compactVideoRenderer.videoId and compactVideoRenderer.title and
577-
compactVideoRenderer.title.simpleText
578-
then
578+
compactVideoRenderer.title.simpleText
579+
then
579580
local title = compactVideoRenderer.title.simpleText
580581
local video_id = compactVideoRenderer.videoId
581582
local duration = -1
@@ -637,7 +638,7 @@ local function parse_upnext(json_str, current_video_url)
637638
)
638639

639640
-- Limit amount of suggestions
640-
if opts.suggestions_limit ~= nil and opts.suggestions_limit > 0 and table_size(res) > opts.suggestions_limit then
641+
if opts.suggestions_limit ~= nil and opts.suggestions_limit > 0 and table_size(res) > opts.suggestions_limit then
641642
local new_res = {}
642643
for i = 1, opts.suggestions_limit do
643644
new_res[i] = res[i]
@@ -655,10 +656,10 @@ local function load_upnext()
655656
url = ""
656657
end
657658

658-
url = string.gsub(url, "ytdl://", "") -- Strip possible ytdl:// prefix.
659-
url = string.gsub(url, "/shorts/", "/watch?v=") -- Convert shorts to watch?v=.
659+
url = string.gsub(url, "ytdl://", "") -- Strip possible ytdl:// prefix.
660+
url = string.gsub(url, "/shorts/", "/watch?v=") -- Convert shorts to watch?v=.
660661
url = string.gsub(url, "//.*/watch%?v=", "//youtube.com/watch?v=") -- Account for alternative frontends.
661-
url = string.gsub(url, "%?feature=share", "") -- Strip possible ?feature=share suffix.
662+
url = string.gsub(url, "%?feature=share", "") -- Strip possible ?feature=share suffix.
662663

663664
if string.find(url, "//youtu.be/") == nil and string.find(url, "//youtube.com/") == nil then
664665
-- SVP calls mpv like this:
@@ -719,10 +720,10 @@ end
719720
local function on_file_start(_)
720721
local url = mp.get_property("path")
721722

722-
url = string.gsub(url, "ytdl://", "") -- Strip possible ytdl:// prefix.
723-
url = string.gsub(url, "/shorts/", "/watch?v=") -- Convert shorts to watch?v=.
723+
url = string.gsub(url, "ytdl://", "") -- Strip possible ytdl:// prefix.
724+
url = string.gsub(url, "/shorts/", "/watch?v=") -- Convert shorts to watch?v=.
724725
url = string.gsub(url, "//.*/watch%?v=", "//youtube.com/watch?v=") -- Account for alternative frontends.
725-
url = string.gsub(url, "%?feature=share", "") -- Strip possible ?feature=share suffix.
726+
url = string.gsub(url, "%?feature=share", "") -- Strip possible ?feature=share suffix.
726727

727728
if string.find(url, "youtu") ~= nil then
728729
-- Try to add current video ID to watched list
@@ -736,7 +737,6 @@ local function on_file_start(_)
736737

737738
local upnext, num_upnext = load_upnext()
738739
if num_upnext > 0 then
739-
740740
if skip_shorter_than > -1 or skip_longer_than > -1 then
741741
-- Append first video that is not too long or too short
742742
for _, v in ipairs(upnext) do
@@ -758,7 +758,7 @@ local function on_file_start(_)
758758
end
759759
end
760760
end
761-
msg.warn("No video between ".. opts.skip_shorter_than .. " and " .. opts.skip_longer_than .. " found")
761+
msg.warn("No video between " .. opts.skip_shorter_than .. " and " .. opts.skip_longer_than .. " found")
762762
end
763763
-- Append first video
764764
add_to_playlist(upnext[1].file, upnext[1].label, upnext[1].length, "append")
@@ -841,14 +841,14 @@ local function show_menu()
841841
return
842842
end
843843

844-
number = tonumber(text:sub(handled_cursor))
844+
local number = tonumber(text:sub(handled_cursor))
845845
if number ~= nil and number > 0 and number <= num_upnext then
846846
selected = number
847847
end
848848

849849
if text:sub(-1) == " " then
850850
-- Append video to playlist
851-
msg.info("Appending ".. upnext[selected].label .." to playlist")
851+
msg.info("Appending " .. upnext[selected].label .. " to playlist")
852852
-- prevent appending the same video twice
853853
if appended_to_playlist[upnext[selected].file] == true then
854854
if timeout ~= nil then
@@ -863,7 +863,7 @@ local function show_menu()
863863
end
864864
elseif opts.keep_playlist_on_selectthen then
865865
-- Play (append to playlist)
866-
msg.info("Playing "..tostring(upnext[selected].label))
866+
msg.info("Playing " .. tostring(upnext[selected].label))
867867
add_to_playlist(upnext[selected].file, upnext[selected].label, upnext[selected].length, "append-play")
868868
local playlist_index_current = tonumber(mp.get_property("playlist-current-pos", "1"))
869869
local playlist_index_newfile = tonumber(mp.get_property("playlist-count", "1")) - 1
@@ -873,14 +873,14 @@ local function show_menu()
873873
end_terminal_menu()
874874
else
875875
-- Play (replace playlist)
876-
msg.info("Playing "..tostring(upnext[selected].label))
876+
msg.info("Playing " .. tostring(upnext[selected].label))
877877
add_to_playlist(upnext[selected].file, upnext[selected].label, upnext[selected].length, "replace")
878878
end_terminal_menu()
879879
end
880880
end
881881

882882
local function terminal_edited(text)
883-
number = tonumber(text:sub(handled_cursor))
883+
local number = tonumber(text:sub(handled_cursor))
884884
if number ~= nil and number > 0 and number <= num_upnext then
885885
selected = number
886886
if redraw_menu ~= nil then
@@ -942,7 +942,6 @@ local function show_menu()
942942
skip_it = true
943943
end
944944
end
945-
946945
end
947946
if not skip_it then
948947
ass:append(choose_prefix(i, appended_to_playlist[v.file] ~= nil) .. v.label .. duration .. "\\N")
@@ -951,21 +950,22 @@ local function show_menu()
951950
local number = tostring(entries)
952951
number = string.rep(" ", 2 - #number) .. number .. " "
953952
table.insert(terminal_lines, {
954-
text = number .. choose_prefix(i, appended_to_playlist[v.file] ~= nil) .. duration .." " .. padded_label,
953+
text = number ..
954+
choose_prefix(i, appended_to_playlist[v.file] ~= nil) .. duration .. " " .. padded_label,
955955
terminal_style = "\027[" .. choose_style(i, appended_to_playlist[v.file] ~= nil) .. "m",
956956
})
957-
958957
end
959958
end
960959
end
961960

962961
if entries == 0 and skipped > 0 then
963962
if skip_shorter_than > -1 and skip_longer_than > -1 then
964-
ass:append("No videos between ".. opts.skip_shorter_than .. " and " .. opts.skip_longer_than .. " found\\N")
963+
ass:append("No videos between " ..
964+
opts.skip_shorter_than .. " and " .. opts.skip_longer_than .. " found\\N")
965965
elseif skip_shorter_than > -1 then
966-
ass:append("No videos shorter than ".. opts.skip_shorter_than .. " found\\N")
966+
ass:append("No videos shorter than " .. opts.skip_shorter_than .. " found\\N")
967967
else
968-
ass:append("No videos longer than ".. opts.skip_longer_than .. " found\\N")
968+
ass:append("No videos longer than " .. opts.skip_longer_than .. " found\\N")
969969
end
970970
end
971971

@@ -994,15 +994,15 @@ local function show_menu()
994994
function()
995995
selected_move(-1)
996996
end,
997-
{repeatable = true}
997+
{ repeatable = true }
998998
)
999999
mp.add_forced_key_binding(
10001000
opts.down_binding,
10011001
"move_down",
10021002
function()
10031003
selected_move(1)
10041004
end,
1005-
{repeatable = true}
1005+
{ repeatable = true }
10061006
)
10071007
end)
10081008
end
@@ -1072,19 +1072,19 @@ local function show_menu()
10721072
function()
10731073
selected_move(-1)
10741074
end,
1075-
{repeatable = true}
1075+
{ repeatable = true }
10761076
)
10771077
mp.add_forced_key_binding(
10781078
opts.down_binding,
10791079
"move_down",
10801080
function()
10811081
selected_move(1)
10821082
end,
1083-
{repeatable = true}
1083+
{ repeatable = true }
10841084
)
10851085
if not no_video or not input_import then
10861086
mp.add_forced_key_binding(opts.select_binding, "select", on_key_select)
1087-
mp.add_forced_key_binding(opts.append_binding, "append", on_key_append, {repeatable = true})
1087+
mp.add_forced_key_binding(opts.append_binding, "append", on_key_append, { repeatable = true })
10881088
end
10891089
mp.add_forced_key_binding(opts.close_binding, "quit", destroy)
10901090
mp.add_forced_key_binding(opts.toggle_menu_binding, "escape", destroy)
@@ -1137,7 +1137,7 @@ local function on_dwidth_change(_, value)
11371137
end
11381138

11391139
local function menu_command(...)
1140-
return {"script-message-to", script_name, ...}
1140+
return { "script-message-to", script_name, ... }
11411141
end
11421142

11431143
local function open_uosc_menu()
@@ -1187,7 +1187,7 @@ local function open_uosc_menu()
11871187
if v ~= nil then
11881188
local hint = ""
11891189
if appended_to_playlist[v.file] == true then
1190-
hint = '' .. hint
1190+
hint = "" .. hint
11911191
end
11921192
local video_item = {
11931193
title = v.label,
@@ -1218,19 +1218,19 @@ local function open_uosc_menu()
12181218
title = "Play",
12191219
value = menu_command(play_action, v.file, v.label, v.length),
12201220
keep_open = opts.uosc_keep_menu_open,
1221-
icon = 'play_circle',
1221+
icon = "play_circle",
12221222
},
12231223
{
12241224
title = "Up Next",
12251225
value = menu_command("insert", v.file, v.label, v.length),
12261226
keep_open = opts.uosc_keep_menu_open,
1227-
icon = 'queue',
1227+
icon = "queue",
12281228
},
12291229
{
12301230
title = "Add to playlist",
12311231
value = menu_command("append", v.file, v.label, v.length),
12321232
keep_open = opts.uosc_keep_menu_open,
1233-
icon = 'add_circle'
1233+
icon = "add_circle",
12341234
}
12351235
}
12361236
else
@@ -1269,11 +1269,11 @@ local function open_uosc_menu()
12691269
}
12701270
)
12711271
elseif entries == 0 and skipped > 0 then
1272-
local title = "No videos longer than ".. opts.skip_longer_than .. " found"
1272+
local title = "No videos longer than " .. opts.skip_longer_than .. " found"
12731273
if skip_shorter_than > -1 and skip_longer_than > -1 then
1274-
title = "No videos between ".. opts.skip_shorter_than .. " and " .. opts.skip_longer_than .. " found"
1274+
title = "No videos between " .. opts.skip_shorter_than .. " and " .. opts.skip_longer_than .. " found"
12751275
elseif skip_shorter_than > -1 then
1276-
title = "No videos shorter than ".. opts.skip_shorter_than .. " found"
1276+
title = "No videos shorter than " .. opts.skip_shorter_than .. " found"
12771277
end
12781278
table.insert(
12791279
menu_data["items"],

0 commit comments

Comments
 (0)