@@ -123,12 +123,12 @@ local input_import, input = pcall(require, "mp.input")
123
123
if not input_import then
124
124
-- If mp.input is not available, use an empty implementation
125
125
input = {
126
- get = function () end ,
126
+ get = function (foo ) end ,
127
127
terminate = function () end ,
128
128
set_log = function (lines )
129
129
local text = " "
130
130
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"
132
132
end
133
133
mp .osd_message (" \n " .. text )
134
134
end
@@ -172,14 +172,14 @@ end
172
172
local function exec (args , capture_stdout , capture_stderr )
173
173
local ret =
174
174
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
+ )
183
183
return ret .status , ret .stdout , ret .stderr , ret
184
184
end
185
185
@@ -254,7 +254,7 @@ local function download_upnext(url, post_data)
254
254
mp .osd_message (" fetching 'up next' with curl..." , 60 )
255
255
end
256
256
257
- local command = {" curl" , " --silent" , " --location" }
257
+ local command = { " curl" , " --silent" , " --location" }
258
258
if post_data then
259
259
table.insert (command , " --request" )
260
260
table.insert (command , " POST" )
@@ -276,7 +276,7 @@ local function download_upnext(url, post_data)
276
276
-- MP_SUBPROCESS_EINIT is -3 which can mean the command was not found:
277
277
-- https://github.com/mpv-player/mpv/blob/24dcb5d167ba9580119e0b9cc26f79b1d155fcdc/osdep/subprocess-posix.c#L335-L336
278
278
msg .debug (" curl not found, trying wget" )
279
- local command_wget = {" wget" , " -q" , " -O" , " -" }
279
+ local command_wget = { " wget" , " -q" , " -O" , " -" }
280
280
if not opts .check_certificate then
281
281
table.insert (command_wget , " --no-check-certificate" )
282
282
end
@@ -330,7 +330,7 @@ local function download_upnext(url, post_data)
330
330
end
331
331
msg .warn (
332
332
' 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'
334
334
)
335
335
end
336
336
return download_upnext (" https://consent.youtube.com/s" , post_str )
@@ -362,7 +362,7 @@ local function get_invidious(url)
362
362
url = string.gsub (url , " https://youtu%.be/" , opts .invidious_instance .. " /api/v1/videos/" )
363
363
msg .debug (" Invidious url:" .. url )
364
364
365
- local command = {" curl" , " --silent" , " --location" }
365
+ local command = { " curl" , " --silent" , " --location" }
366
366
if not opts .check_certificate then
367
367
table.insert (command , " --no-check-certificate" )
368
368
end
@@ -373,7 +373,7 @@ local function get_invidious(url)
373
373
if (es ~= 0 ) or (s == nil ) or (s == " " ) then
374
374
if es == - 1 or es == - 3 or es == 127 or es == 9009 then
375
375
msg .debug (" curl not found, trying wget" )
376
- local command_wget = {" wget" , " -q" , " -O" , " -" }
376
+ local command_wget = { " wget" , " -q" , " -O" , " -" }
377
377
if not opts .check_certificate then
378
378
table.insert (command_wget , " --no-check-certificate" )
379
379
end
@@ -388,7 +388,6 @@ local function get_invidious(url)
388
388
msg .error (" failed to get invidious: error=" .. tostring (es ))
389
389
return {}
390
390
end
391
-
392
391
end
393
392
394
393
local data
@@ -470,18 +469,20 @@ local function parse_upnext(json_str, current_video_url)
470
469
local autoplay_id = nil
471
470
if
472
471
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
477
477
local title = playerOverlayAutoplayRenderer .videoTitle .simpleText
478
478
local video_id = playerOverlayAutoplayRenderer .videoId
479
479
local duration = - 1
480
480
if playerOverlayAutoplayRenderer .thumbnailOverlays and playerOverlayAutoplayRenderer .thumbnailOverlays [1 ] and
481
481
playerOverlayAutoplayRenderer .thumbnailOverlays [1 ].thumbnailOverlayTimeStatusRenderer and
482
482
playerOverlayAutoplayRenderer .thumbnailOverlays [1 ].thumbnailOverlayTimeStatusRenderer .text
483
483
then
484
- duration = parse_yt_time (playerOverlayAutoplayRenderer .thumbnailOverlays [1 ].thumbnailOverlayTimeStatusRenderer .text .simpleText )
484
+ duration = parse_yt_time (playerOverlayAutoplayRenderer .thumbnailOverlays [1 ]
485
+ .thumbnailOverlayTimeStatusRenderer .text .simpleText )
485
486
end
486
487
487
488
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)
512
513
513
514
if
514
515
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
519
520
local n = table_size (data .playerOverlays .playerOverlayRenderer .endScreen .watchNextEndScreenRenderer .results )
520
521
for i , v in ipairs (data .playerOverlays .playerOverlayRenderer .endScreen .watchNextEndScreenRenderer .results ) do
521
522
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)
554
555
555
556
if
556
557
data .contents and data .contents .twoColumnWatchNextResults and
557
- data .contents .twoColumnWatchNextResults .secondaryResults
558
- then
558
+ data .contents .twoColumnWatchNextResults .secondaryResults
559
+ then
559
560
local secondaryResults = data .contents .twoColumnWatchNextResults .secondaryResults
560
561
if secondaryResults .secondaryResults then
561
562
secondaryResults = secondaryResults .secondaryResults
@@ -565,17 +566,17 @@ local function parse_upnext(json_str, current_video_url)
565
566
local watchnextindex = index
566
567
if
567
568
v .compactAutoplayRenderer and v .compactAutoplayRenderer and v .compactAutoplayRenderer .contents and
568
- v .compactAutoplayRenderer .contents .compactVideoRenderer
569
- then
569
+ v .compactAutoplayRenderer .contents .compactVideoRenderer
570
+ then
570
571
compactVideoRenderer = v .compactAutoplayRenderer .contents .compactVideoRenderer
571
572
watchnextindex = 0
572
573
elseif v .compactVideoRenderer then
573
574
compactVideoRenderer = v .compactVideoRenderer
574
575
end
575
576
if
576
577
compactVideoRenderer and compactVideoRenderer .videoId and compactVideoRenderer .title and
577
- compactVideoRenderer .title .simpleText
578
- then
578
+ compactVideoRenderer .title .simpleText
579
+ then
579
580
local title = compactVideoRenderer .title .simpleText
580
581
local video_id = compactVideoRenderer .videoId
581
582
local duration = - 1
@@ -637,7 +638,7 @@ local function parse_upnext(json_str, current_video_url)
637
638
)
638
639
639
640
-- 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
641
642
local new_res = {}
642
643
for i = 1 , opts .suggestions_limit do
643
644
new_res [i ] = res [i ]
@@ -655,10 +656,10 @@ local function load_upnext()
655
656
url = " "
656
657
end
657
658
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=.
660
661
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.
662
663
663
664
if string.find (url , " //youtu.be/" ) == nil and string.find (url , " //youtube.com/" ) == nil then
664
665
-- SVP calls mpv like this:
@@ -719,10 +720,10 @@ end
719
720
local function on_file_start (_ )
720
721
local url = mp .get_property (" path" )
721
722
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=.
724
725
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.
726
727
727
728
if string.find (url , " youtu" ) ~= nil then
728
729
-- Try to add current video ID to watched list
@@ -736,7 +737,6 @@ local function on_file_start(_)
736
737
737
738
local upnext , num_upnext = load_upnext ()
738
739
if num_upnext > 0 then
739
-
740
740
if skip_shorter_than > - 1 or skip_longer_than > - 1 then
741
741
-- Append first video that is not too long or too short
742
742
for _ , v in ipairs (upnext ) do
@@ -758,7 +758,7 @@ local function on_file_start(_)
758
758
end
759
759
end
760
760
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" )
762
762
end
763
763
-- Append first video
764
764
add_to_playlist (upnext [1 ].file , upnext [1 ].label , upnext [1 ].length , " append" )
@@ -841,14 +841,14 @@ local function show_menu()
841
841
return
842
842
end
843
843
844
- number = tonumber (text :sub (handled_cursor ))
844
+ local number = tonumber (text :sub (handled_cursor ))
845
845
if number ~= nil and number > 0 and number <= num_upnext then
846
846
selected = number
847
847
end
848
848
849
849
if text :sub (- 1 ) == " " then
850
850
-- Append video to playlist
851
- msg .info (" Appending " .. upnext [selected ].label .. " to playlist" )
851
+ msg .info (" Appending " .. upnext [selected ].label .. " to playlist" )
852
852
-- prevent appending the same video twice
853
853
if appended_to_playlist [upnext [selected ].file ] == true then
854
854
if timeout ~= nil then
@@ -863,7 +863,7 @@ local function show_menu()
863
863
end
864
864
elseif opts .keep_playlist_on_selectthen then
865
865
-- Play (append to playlist)
866
- msg .info (" Playing " .. tostring (upnext [selected ].label ))
866
+ msg .info (" Playing " .. tostring (upnext [selected ].label ))
867
867
add_to_playlist (upnext [selected ].file , upnext [selected ].label , upnext [selected ].length , " append-play" )
868
868
local playlist_index_current = tonumber (mp .get_property (" playlist-current-pos" , " 1" ))
869
869
local playlist_index_newfile = tonumber (mp .get_property (" playlist-count" , " 1" )) - 1
@@ -873,14 +873,14 @@ local function show_menu()
873
873
end_terminal_menu ()
874
874
else
875
875
-- Play (replace playlist)
876
- msg .info (" Playing " .. tostring (upnext [selected ].label ))
876
+ msg .info (" Playing " .. tostring (upnext [selected ].label ))
877
877
add_to_playlist (upnext [selected ].file , upnext [selected ].label , upnext [selected ].length , " replace" )
878
878
end_terminal_menu ()
879
879
end
880
880
end
881
881
882
882
local function terminal_edited (text )
883
- number = tonumber (text :sub (handled_cursor ))
883
+ local number = tonumber (text :sub (handled_cursor ))
884
884
if number ~= nil and number > 0 and number <= num_upnext then
885
885
selected = number
886
886
if redraw_menu ~= nil then
@@ -942,7 +942,6 @@ local function show_menu()
942
942
skip_it = true
943
943
end
944
944
end
945
-
946
945
end
947
946
if not skip_it then
948
947
ass :append (choose_prefix (i , appended_to_playlist [v .file ] ~= nil ) .. v .label .. duration .. " \\ N" )
@@ -951,21 +950,22 @@ local function show_menu()
951
950
local number = tostring (entries )
952
951
number = string.rep (" " , 2 - # number ) .. number .. " "
953
952
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 ,
955
955
terminal_style = " \027 [" .. choose_style (i , appended_to_playlist [v .file ] ~= nil ) .. " m" ,
956
956
})
957
-
958
957
end
959
958
end
960
959
end
961
960
962
961
if entries == 0 and skipped > 0 then
963
962
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" )
965
965
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" )
967
967
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" )
969
969
end
970
970
end
971
971
@@ -994,15 +994,15 @@ local function show_menu()
994
994
function ()
995
995
selected_move (- 1 )
996
996
end ,
997
- {repeatable = true }
997
+ { repeatable = true }
998
998
)
999
999
mp .add_forced_key_binding (
1000
1000
opts .down_binding ,
1001
1001
" move_down" ,
1002
1002
function ()
1003
1003
selected_move (1 )
1004
1004
end ,
1005
- {repeatable = true }
1005
+ { repeatable = true }
1006
1006
)
1007
1007
end )
1008
1008
end
@@ -1072,19 +1072,19 @@ local function show_menu()
1072
1072
function ()
1073
1073
selected_move (- 1 )
1074
1074
end ,
1075
- {repeatable = true }
1075
+ { repeatable = true }
1076
1076
)
1077
1077
mp .add_forced_key_binding (
1078
1078
opts .down_binding ,
1079
1079
" move_down" ,
1080
1080
function ()
1081
1081
selected_move (1 )
1082
1082
end ,
1083
- {repeatable = true }
1083
+ { repeatable = true }
1084
1084
)
1085
1085
if not no_video or not input_import then
1086
1086
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 })
1088
1088
end
1089
1089
mp .add_forced_key_binding (opts .close_binding , " quit" , destroy )
1090
1090
mp .add_forced_key_binding (opts .toggle_menu_binding , " escape" , destroy )
@@ -1137,7 +1137,7 @@ local function on_dwidth_change(_, value)
1137
1137
end
1138
1138
1139
1139
local function menu_command (...)
1140
- return {" script-message-to" , script_name , ... }
1140
+ return { " script-message-to" , script_name , ... }
1141
1141
end
1142
1142
1143
1143
local function open_uosc_menu ()
@@ -1187,7 +1187,7 @@ local function open_uosc_menu()
1187
1187
if v ~= nil then
1188
1188
local hint = " "
1189
1189
if appended_to_playlist [v .file ] == true then
1190
- hint = ' ▷ ' .. hint
1190
+ hint = " ▷ " .. hint
1191
1191
end
1192
1192
local video_item = {
1193
1193
title = v .label ,
@@ -1218,19 +1218,19 @@ local function open_uosc_menu()
1218
1218
title = " Play" ,
1219
1219
value = menu_command (play_action , v .file , v .label , v .length ),
1220
1220
keep_open = opts .uosc_keep_menu_open ,
1221
- icon = ' play_circle' ,
1221
+ icon = " play_circle" ,
1222
1222
},
1223
1223
{
1224
1224
title = " Up Next" ,
1225
1225
value = menu_command (" insert" , v .file , v .label , v .length ),
1226
1226
keep_open = opts .uosc_keep_menu_open ,
1227
- icon = ' queue' ,
1227
+ icon = " queue" ,
1228
1228
},
1229
1229
{
1230
1230
title = " Add to playlist" ,
1231
1231
value = menu_command (" append" , v .file , v .label , v .length ),
1232
1232
keep_open = opts .uosc_keep_menu_open ,
1233
- icon = ' add_circle'
1233
+ icon = " add_circle" ,
1234
1234
}
1235
1235
}
1236
1236
else
@@ -1269,11 +1269,11 @@ local function open_uosc_menu()
1269
1269
}
1270
1270
)
1271
1271
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"
1273
1273
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"
1275
1275
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"
1277
1277
end
1278
1278
table.insert (
1279
1279
menu_data [" items" ],
0 commit comments