History

lua: remove a ton of unneeded parentheses

For whatever reason, some of the lua code (particularly the osc and ytdl_hook) is full of a bunch of stuff like if (foo), if not (foo == nil), etc. The parenthesis aren't needed in lua and actually just look weird since nobody actually writes lua like this. You can see most of the other conditionals are written normally. So cleanup the style to match when the parenthesis clearly aren't doing anything. Not directly related, but also add some spaces on a few math operations while we're at it.

Dudemanguy committed 3 years ago

Commit fcc67cc1 parent 56fada15 files · +146 −147Browse files

Unified · Split

5 files
  1. player/lua/defaults.lua +4 −4
  2. player/lua/options.lua +1 −1
  3. player/lua/osc.lua +98 −99
  4. player/lua/stats.lua +3 −3
  5. player/lua/ytdl_hook.lua +40 −40
player/lua/defaults.lua+4−4
@@ -175,7 +175,7 @@ function mp.flush_keybindings() · 174 unmodified lines
175end175end
176 176
177local function add_binding(attrs, key, name, fn, rp)177local function add_binding(attrs, key, name, fn, rp)
178 if (type(name) ~= "string") and (name ~= nil) then178 if type(name) ~= "string" and name ~= nil then
179 rp = fn179 rp = fn
180 fn = name180 fn = name
181 name = nil181 name = nil
@@ -226,7 +226,7 @@ local function add_binding(attrs, key, name, fn, rp) · 44 unmodified lines
226 end226 end
227 if is_mouse and (event == "u" or event == "p") then227 if is_mouse and (event == "u" or event == "p") then
228 fn()228 fn()
229 elseif (not is_mouse) and (event == "d" or event == "r" or event == "p") then229 elseif not is_mouse and (event == "d" or event == "r" or event == "p") then
230 fn()230 fn()
231 end231 end
232 end232 end
@@ -316,7 +316,7 @@ end · 83 unmodified lines
316local function get_next_timer()316local function get_next_timer()
317 local best = nil317 local best = nil
318 for t, _ in pairs(timers) do318 for t, _ in pairs(timers) do
319 if (best == nil) or (t.next_deadline < best.next_deadline) then319 if best == nil or t.next_deadline < best.next_deadline then
320 best = t320 best = t
321 end321 end
322 end322 end
@@ -598,7 +598,7 @@ mp.register_event("hook", function(ev) · 275 unmodified lines
598 if fn then598 if fn then
599 fn(hookobj)599 fn(hookobj)
600 end600 end
601 if (not hookobj._defer) and hookobj._id ~= nil then601 if not hookobj._defer and hookobj._id ~= nil then
602 hookobj:cont()602 hookobj:cont()
603 end603 end
604end)604end)
player/lua/options.lua+1−1
@@ -12,7 +12,7 @@ local function typeconv(desttypeval, val) · 11 unmodified lines
12 val = nil12 val = nil
13 end13 end
14 elseif type(desttypeval) == "number" then14 elseif type(desttypeval) == "number" then
15 if not (tonumber(val) == nil) then15 if tonumber(val) ~= nil then
16 val = tonumber(val)16 val = tonumber(val)
17 else17 else
18 msg.error("Error: Can't convert '" .. val .. "' to number!")18 msg.error("Error: Can't convert '" .. val .. "' to number!")
player/lua/osc.lua+98−99
@@ -280,7 +280,7 @@ function get_slider_value(element) · 279 unmodified lines
280end280end
281 281
282function countone(val)282function countone(val)
283 if not (user_opts.iamaprogrammer) then283 if not user_opts.iamaprogrammer then
284 val = val + 1284 val = val + 1
285 end285 end
286 return val286 return val
@@ -301,7 +301,7 @@ end · 14 unmodified lines
301 301
302function add_area(name, x1, y1, x2, y2)302function add_area(name, x1, y1, x2, y2)
303 -- create area if needed303 -- create area if needed
304 if (osc_param.areas[name] == nil) then304 if osc_param.areas[name] == nil then
305 osc_param.areas[name] = {}305 osc_param.areas[name] = {}
306 end306 end
307 table.insert(osc_param.areas[name], {x1=x1, y1=y1, x2=x2, y2=y2})307 table.insert(osc_param.areas[name], {x1=x1, y1=y1, x2=x2, y2=y2})
@@ -356,7 +356,7 @@ function update_tracklist() · 48 unmodified lines
356 tracks_mpv = {}356 tracks_mpv = {}
357 tracks_mpv.video, tracks_mpv.audio, tracks_mpv.sub = {}, {}, {}357 tracks_mpv.video, tracks_mpv.audio, tracks_mpv.sub = {}, {}, {}
358 for n = 1, #tracktable do358 for n = 1, #tracktable do
359 if not (tracktable[n].type == "unknown") then359 if tracktable[n].type ~= "unknown" then
360 local type = tracktable[n].type360 local type = tracktable[n].type
361 local mpv_id = tonumber(tracktable[n].id)361 local mpv_id = tonumber(tracktable[n].id)
362 362
@@ -379,9 +379,9 @@ function get_tracklist(type) · 16 unmodified lines
379 for n = 1, #tracks_osc[type] do379 for n = 1, #tracks_osc[type] do
380 local track = tracks_osc[type][n]380 local track = tracks_osc[type][n]
381 local lang, title, selected = "unknown", "", "○"381 local lang, title, selected = "unknown", "", "○"
382 if not(track.lang == nil) then lang = track.lang end382 if track.lang ~= nil then lang = track.lang end
383 if not(track.title == nil) then title = track.title end383 if track.title ~= nil then title = track.title end
384 if (track.id == tonumber(mp.get_property(type))) then384 if track.id == tonumber(mp.get_property(type)) then
385 selected = "●"385 selected = "●"
386 end386 end
387 msg = msg.."\n"..selected.." "..n..": ["..lang.."] "..title387 msg = msg.."\n"..selected.." "..n..": ["..lang.."] "..title
@@ -394,7 +394,7 @@ end · 6 unmodified lines
394 --(+1 -> next, -1 -> previous)394 --(+1 -> next, -1 -> previous)
395function set_track(type, next)395function set_track(type, next)
396 local current_track_mpv, current_track_osc396 local current_track_mpv, current_track_osc
397 if (mp.get_property(type) == "no") then397 if mp.get_property(type) == "no" then
398 current_track_osc = 0398 current_track_osc = 0
399 else399 else
400 current_track_mpv = tonumber(mp.get_property(type))400 current_track_mpv = tonumber(mp.get_property(type))
@@ -410,7 +410,7 @@ function set_track(type, next) · 9 unmodified lines
410 410
411 mp.commandv("set", type, new_track_mpv)411 mp.commandv("set", type, new_track_mpv)
412 412
413 if (new_track_osc == 0) then413 if new_track_osc == 0 then
414 show_message(nicetypes[type] .. " Track: none")414 show_message(nicetypes[type] .. " Track: none")
415 else415 else
416 show_message(nicetypes[type] .. " Track: "416 show_message(nicetypes[type] .. " Track: "
@@ -457,7 +457,7 @@ function prepare_elements() · 40 unmodified lines
457 -- remove elements without layout or invisible457 -- remove elements without layout or invisible
458 local elements2 = {}458 local elements2 = {}
459 for n, element in pairs(elements) do459 for n, element in pairs(elements) do
460 if not (element.layout == nil) and (element.visible) then460 if element.layout ~= nil and element.visible then
461 table.insert(elements2, element)461 table.insert(elements2, element)
462 end462 end
463 end463 end
@@ -492,14 +492,14 @@ function prepare_elements() · 28 unmodified lines
492 local static_ass = assdraw.ass_new()492 local static_ass = assdraw.ass_new()
493 493
494 494
495 if (element.type == "box") then495 if element.type == "box" then
496 --draw box496 --draw box
497 static_ass:draw_start()497 static_ass:draw_start()
498 ass_draw_rr_h_cw(static_ass, 0, 0, elem_geo.w, elem_geo.h,498 ass_draw_rr_h_cw(static_ass, 0, 0, elem_geo.w, elem_geo.h,
499 element.layout.box.radius, element.layout.box.hexagon)499 element.layout.box.radius, element.layout.box.hexagon)
500 static_ass:draw_stop()500 static_ass:draw_stop()
501 501
502 elseif (element.type == "slider") then502 elseif element.type == "slider" then
503 --draw static slider parts503 --draw static slider parts
504 504
505 local r1 = 0505 local r1 = 0
@@ -509,13 +509,13 @@ function prepare_elements() · 3 unmodified lines
509 local foV = slider_lo.border + slider_lo.gap509 local foV = slider_lo.border + slider_lo.gap
510 510
511 -- calculate positions of min and max points511 -- calculate positions of min and max points
512 if (slider_lo.stype ~= "bar") then512 if slider_lo.stype ~= "bar" then
513 r1 = elem_geo.h / 2513 r1 = elem_geo.h / 2
514 element.slider.min.ele_pos = elem_geo.h / 2514 element.slider.min.ele_pos = elem_geo.h / 2
515 element.slider.max.ele_pos = elem_geo.w - (elem_geo.h / 2)515 element.slider.max.ele_pos = elem_geo.w - (elem_geo.h / 2)
516 if (slider_lo.stype == "diamond") then516 if slider_lo.stype == "diamond" then
517 r2 = (elem_geo.h - 2 * slider_lo.border) / 2517 r2 = (elem_geo.h - 2 * slider_lo.border) / 2
518 elseif (slider_lo.stype == "knob") then518 elseif slider_lo.stype == "knob" then
519 r2 = r1519 r2 = r1
520 end520 end
521 else521 else
@@ -543,45 +543,45 @@ function prepare_elements() · 21 unmodified lines
543 r2, slider_lo.stype == "diamond")543 r2, slider_lo.stype == "diamond")
544 544
545 -- marker nibbles545 -- marker nibbles
546 if not (element.slider.markerF == nil) and (slider_lo.gap > 0) then546 if element.slider.markerF ~= nil and slider_lo.gap > 0 then
547 local markers = element.slider.markerF()547 local markers = element.slider.markerF()
548 for _,marker in pairs(markers) do548 for _,marker in pairs(markers) do
549 if (marker > element.slider.min.value) and549 if marker > element.slider.min.value and
550 (marker < element.slider.max.value) then550 marker < element.slider.max.value then
551 551
552 local s = get_slider_ele_pos_for(element, marker)552 local s = get_slider_ele_pos_for(element, marker)
553 553
554 if (slider_lo.gap > 1) then -- draw triangles554 if slider_lo.gap > 1 then -- draw triangles
555 555
556 local a = slider_lo.gap / 0.5 --0.866556 local a = slider_lo.gap / 0.5 --0.866
557 557
558 --top558 --top
559 if (slider_lo.nibbles_top) then559 if slider_lo.nibbles_top then
560 static_ass:move_to(s - (a/2), slider_lo.border)560 static_ass:move_to(s - (a / 2), slider_lo.border)
561 static_ass:line_to(s + (a/2), slider_lo.border)561 static_ass:line_to(s + (a / 2), slider_lo.border)
562 static_ass:line_to(s, foV)562 static_ass:line_to(s, foV)
563 end563 end
564 564
565 --bottom565 --bottom
566 if (slider_lo.nibbles_bottom) then566 if slider_lo.nibbles_bottom then
567 static_ass:move_to(s - (a/2),567 static_ass:move_to(s - (a / 2),
568 elem_geo.h - slider_lo.border)568 elem_geo.h - slider_lo.border)
569 static_ass:line_to(s,569 static_ass:line_to(s,
570 elem_geo.h - foV)570 elem_geo.h - foV)
571 static_ass:line_to(s + (a/2),571 static_ass:line_to(s + (a / 2),
572 elem_geo.h - slider_lo.border)572 elem_geo.h - slider_lo.border)
573 end573 end
574 574
575 else -- draw 2x1px nibbles575 else -- draw 2x1px nibbles
576 576
577 --top577 --top
578 if (slider_lo.nibbles_top) then578 if slider_lo.nibbles_top then
579 static_ass:rect_cw(s - 1, slider_lo.border,579 static_ass:rect_cw(s - 1, slider_lo.border,
580 s + 1, slider_lo.border + slider_lo.gap);580 s + 1, slider_lo.border + slider_lo.gap);
581 end581 end
582 582
583 --bottom583 --bottom
584 if (slider_lo.nibbles_bottom) then584 if slider_lo.nibbles_bottom then
585 static_ass:rect_cw(s - 1,585 static_ass:rect_cw(s - 1,
586 elem_geo.h -slider_lo.border -slider_lo.gap,586 elem_geo.h -slider_lo.border -slider_lo.gap,
587 s + 1, elem_geo.h - slider_lo.border);587 s + 1, elem_geo.h - slider_lo.border);
@@ -597,7 +597,7 @@ function prepare_elements() · 9 unmodified lines
597 597
598 -- if the element is supposed to be disabled,598 -- if the element is supposed to be disabled,
599 -- style it accordingly and kill the eventresponders599 -- style it accordingly and kill the eventresponders
600 if not (element.enabled) then600 if not element.enabled then
601 element.layout.alpha[1] = 136601 element.layout.alpha[1] = 136
602 element.eventresponder = nil602 element.eventresponder = nil
603 end603 end
@@ -648,18 +648,18 @@ function render_elements(master_ass) · 44 unmodified lines
648 if element.eventresponder and (state.active_element == n) then648 if element.eventresponder and (state.active_element == n) then
649 649
650 -- run render event functions650 -- run render event functions
651 if not (element.eventresponder.render == nil) then651 if element.eventresponder.render ~= nil then
652 element.eventresponder.render(element)652 element.eventresponder.render(element)
653 end653 end
654 654
655 if mouse_hit(element) then655 if mouse_hit(element) then
656 -- mouse down styling656 -- mouse down styling
657 if (element.styledown) then657 if element.styledown then
658 style_ass:append(osc_styles.elementDown)658 style_ass:append(osc_styles.elementDown)
659 end659 end
660 660
661 if (element.softrepeat) and (state.mouse_down_counter >= 15661 if element.softrepeat and state.mouse_down_counter >= 15
662 and state.mouse_down_counter % 5 == 0) then662 and state.mouse_down_counter % 5 == 0 then
663 663
664 element.eventresponder[state.active_event_source.."_down"](element)664 element.eventresponder[state.active_event_source.."_down"](element)
665 end665 end
@@ -672,11 +672,11 @@ function render_elements(master_ass) · 6 unmodified lines
672 672
673 elem_ass:merge(style_ass)673 elem_ass:merge(style_ass)
674 674
675 if not (element.type == "button") then675 if element.type ~= "button" then
676 elem_ass:merge(element.static_ass)676 elem_ass:merge(element.static_ass)
677 end677 end
678 678
679 if (element.type == "slider") then679 if element.type == "slider" then
680 680
681 local slider_lo = element.layout.slider681 local slider_lo = element.layout.slider
682 local elem_geo = element.layout.geometry682 local elem_geo = element.layout.geometry
@@ -794,8 +794,7 @@ function render_elements(master_ass) · 111 unmodified lines
794 elem_ass:draw_stop()794 elem_ass:draw_stop()
795 795
796 -- add tooltip796 -- add tooltip
797 if not (element.slider.tooltipF == nil) then797 if element.slider.tooltipF ~= nil then
798
799 if mouse_hit(element) then798 if mouse_hit(element) then
800 local sliderpos = get_slider_value(element)799 local sliderpos = get_slider_value(element)
801 local tooltiplabel = element.slider.tooltipF(sliderpos)800 local tooltiplabel = element.slider.tooltipF(sliderpos)
@@ -804,21 +803,21 @@ function render_elements(master_ass) · 2 unmodified lines
804 803
805 local ty804 local ty
806 805
807 if (an == 2) then806 if an == 2 then
808 ty = element.hitbox.y1 - slider_lo.border807 ty = element.hitbox.y1 - slider_lo.border
809 else808 else
810 ty = element.hitbox.y1 + elem_geo.h/2809 ty = element.hitbox.y1 + elem_geo.h / 2
811 end810 end
812 811
813 local tx = get_virt_mouse_pos()812 local tx = get_virt_mouse_pos()
814 if (slider_lo.adjust_tooltip) then813 if slider_lo.adjust_tooltip then
815 if (an == 2) then814 if an == 2 then
816 if (sliderpos < (s_min + 3)) then815 if sliderpos < (s_min + 3) then
817 an = an - 1816 an = an - 1
818 elseif (sliderpos > (s_max - 3)) then817 elseif sliderpos > (s_max - 3) then
819 an = an + 1818 an = an + 1
820 end819 end
821 elseif (sliderpos > (s_max+s_min)/2) then820 elseif sliderpos > (s_max+s_min) / 2 then
822 an = an + 1821 an = an + 1
823 tx = tx - 5822 tx = tx - 5
824 else823 else
@@ -838,20 +837,20 @@ function render_elements(master_ass) · 13 unmodified lines
838 end837 end
839 end838 end
840 839
841 elseif (element.type == "button") then840 elseif element.type == "button" then
842 841
843 local buttontext842 local buttontext
844 if type(element.content) == "function" then843 if type(element.content) == "function" then
845 buttontext = element.content() -- function objects844 buttontext = element.content() -- function objects
846 elseif not (element.content == nil) then845 elseif element.content ~= nil then
847 buttontext = element.content -- text objects846 buttontext = element.content -- text objects
848 end847 end
849 848
850 local maxchars = element.layout.button.maxchars849 local maxchars = element.layout.button.maxchars
851 if not (maxchars == nil) and (#buttontext > maxchars) then850 if maxchars ~= nil and #buttontext > maxchars then
852 local max_ratio = 1.25 -- up to 25% more chars while shrinking851 local max_ratio = 1.25 -- up to 25% more chars while shrinking
853 local limit = math.max(0, math.floor(maxchars * max_ratio) - 3)852 local limit = math.max(0, math.floor(maxchars * max_ratio) - 3)
854 if (#buttontext > limit) then853 if #buttontext > limit then
855 while (#buttontext > limit) do854 while (#buttontext > limit) do
856 buttontext = buttontext:gsub(".[\128-\191]*$", "")855 buttontext = buttontext:gsub(".[\128-\191]*$", "")
857 end856 end
@@ -1007,7 +1006,7 @@ function new_element(name, type) · 149 unmodified lines
1007 elements[name].styledown = (type == "button")1006 elements[name].styledown = (type == "button")
1008 elements[name].state = {}1007 elements[name].state = {}
1009 1008
1010 if (type == "slider") then1009 if type == "slider" then
1011 elements[name].slider = {min = {value = 0}, max = {value = 100}}1010 elements[name].slider = {min = {value = 0}, max = {value = 100}}
1012 end1011 end
1013 1012
@@ -1016,7 +1015,7 @@ function new_element(name, type) · 2 unmodified lines
1016end1015end
1017 1016
1018function add_layout(name)1017function add_layout(name)
1019 if not (elements[name] == nil) then1018 if elements[name] ~= nil then
1020 -- new layout1019 -- new layout
1021 elements[name].layout = {}1020 elements[name].layout = {}
1022 1021
@@ -1024,11 +1023,11 @@ function add_layout(name) · 1 unmodified line
1024 elements[name].layout.layer = 501023 elements[name].layout.layer = 50
1025 elements[name].layout.alpha = {[1] = 0, [2] = 255, [3] = 255, [4] = 255}1024 elements[name].layout.alpha = {[1] = 0, [2] = 255, [3] = 255, [4] = 255}
1026 1025
1027 if (elements[name].type == "button") then1026 if elements[name].type == "button" then
1028 elements[name].layout.button = {1027 elements[name].layout.button = {
1029 maxchars = nil,1028 maxchars = nil,
1030 }1029 }
1031 elseif (elements[name].type == "slider") then1030 elseif elements[name].type == "slider" then
1032 -- slider defaults1031 -- slider defaults
1033 elements[name].layout.slider = {1032 elements[name].layout.slider = {
1034 border = 1,1033 border = 1,
@@ -1041,7 +1040,7 @@ function add_layout(name) · 6 unmodified lines
1041 tooltip_an = 2,1040 tooltip_an = 2,
1042 alpha = {[1] = 0, [2] = 255, [3] = 88, [4] = 255},1041 alpha = {[1] = 0, [2] = 255, [3] = 88, [4] = 255},
1043 }1042 }
1044 elseif (elements[name].type == "box") then1043 elseif elements[name].type == "box" then
1045 elements[name].layout.box = {radius = 0, hexagon = false}1044 elements[name].layout.box = {radius = 0, hexagon = false}
1046 end1045 end
1047 1046
@@ -1196,8 +1195,8 @@ layouts["box"] = function () · 148 unmodified lines
1196 }1195 }
1197 1196
1198 -- make sure the OSC actually fits into the video1197 -- make sure the OSC actually fits into the video
1199 if (osc_param.playresx < (osc_geo.w + (2 * osc_geo.p))) then1198 if osc_param.playresx < (osc_geo.w + (2 * osc_geo.p)) then
1200 osc_param.playresy = (osc_geo.w+(2*osc_geo.p))/osc_param.display_aspect1199 osc_param.playresy = (osc_geo.w + (2 * osc_geo.p)) / osc_param.display_aspect
1201 osc_param.playresx = osc_param.playresy * osc_param.display_aspect1200 osc_param.playresx = osc_param.playresy * osc_param.display_aspect
1202 end1201 end
1203 1202
@@ -1371,8 +1370,8 @@ layouts["slimbox"] = function () · 167 unmodified lines
1371 }1370 }
1372 1371
1373 -- make sure the OSC actually fits into the video1372 -- make sure the OSC actually fits into the video
1374 if (osc_param.playresx < (osc_geo.w)) then1373 if osc_param.playresx < (osc_geo.w) then
1375 osc_param.playresy = (osc_geo.w)/osc_param.display_aspect1374 osc_param.playresy = (osc_geo.w) / osc_param.display_aspect
1376 osc_param.playresx = osc_param.playresy * osc_param.display_aspect1375 osc_param.playresx = osc_param.playresy * osc_param.display_aspect
1377 end1376 end
1378 1377
@@ -1423,7 +1422,7 @@ layouts["slimbox"] = function () · 44 unmodified lines
1423 lo.style = osc_styles.box1422 lo.style = osc_styles.box
1424 lo.alpha[1] = user_opts.boxalpha1423 lo.alpha[1] = user_opts.boxalpha
1425 lo.alpha[3] = 01424 lo.alpha[3] = 0
1426 if not (user_opts["seekbarstyle"] == "bar") then1425 if user_opts["seekbarstyle"] ~= "bar" then
1427 lo.box.radius = osc_geo.r1426 lo.box.radius = osc_geo.r
1428 lo.box.hexagon = user_opts["seekbarstyle"] == "diamond"1427 lo.box.hexagon = user_opts["seekbarstyle"] == "diamond"
1429 end1428 end
@@ -1505,7 +1504,7 @@ function bar_layout(direction) · 75 unmodified lines
1505 padwc_r = window_control_box_width1504 padwc_r = window_control_box_width
1506 end1505 end
1507 1506
1508 if ((osc_param.display_aspect > 0) and (osc_param.playresx < minW)) then1507 if osc_param.display_aspect > 0 and osc_param.playresx < minW then
1509 osc_param.playresy = minW / osc_param.display_aspect1508 osc_param.playresy = minW / osc_param.display_aspect
1510 osc_param.playresx = osc_param.playresy * osc_param.display_aspect1509 osc_param.playresx = osc_param.playresy * osc_param.display_aspect
1511 end1510 end
@@ -1654,7 +1653,7 @@ function bar_layout(direction) · 142 unmodified lines
1654 lo.style = osc_styles.timecodesBar1653 lo.style = osc_styles.timecodesBar
1655 lo.alpha[1] =1654 lo.alpha[1] =
1656 math.min(255, user_opts.boxalpha + (255 - user_opts.boxalpha)*0.8)1655 math.min(255, user_opts.boxalpha + (255 - user_opts.boxalpha)*0.8)
1657 if not (user_opts["seekbarstyle"] == "bar") then1656 if user_opts["seekbarstyle"] ~= "bar" then
1658 lo.box.radius = geo.h / 21657 lo.box.radius = geo.h / 2
1659 lo.box.hexagon = user_opts["seekbarstyle"] == "diamond"1658 lo.box.hexagon = user_opts["seekbarstyle"] == "diamond"
1660 end1659 end
@@ -1749,7 +1748,7 @@ function osc_init() · 88 unmodified lines
1749 local display_w, display_h, display_aspect = mp.get_osd_size()1748 local display_w, display_h, display_aspect = mp.get_osd_size()
1750 local scale = 11749 local scale = 1
1751 1750
1752 if (mp.get_property("video") == "no") then -- dummy/forced window1751 if mp.get_property("video") == "no" then -- dummy/forced window
1753 scale = user_opts.scaleforcedwindow1752 scale = user_opts.scaleforcedwindow
1754 elseif state.fullscreen then1753 elseif state.fullscreen then
1755 scale = user_opts.scalefullscreen1754 scale = user_opts.scalefullscreen
@@ -1763,7 +1762,7 @@ function osc_init() · 7 unmodified lines
1763 osc_param.unscaled_y = display_h1762 osc_param.unscaled_y = display_h
1764 end1763 end
1765 osc_param.playresy = osc_param.unscaled_y / scale1764 osc_param.playresy = osc_param.unscaled_y / scale
1766 if (display_aspect > 0) then1765 if display_aspect > 0 then
1767 osc_param.display_aspect = display_aspect1766 osc_param.display_aspect = display_aspect
1768 end1767 end
1769 osc_param.playresx = osc_param.playresy * osc_param.display_aspect1768 osc_param.playresx = osc_param.playresy * osc_param.display_aspect
@@ -1797,7 +1796,7 @@ function osc_init() · 27 unmodified lines
1797 1796
1798 ne.eventresponder["mbtn_left_up"] = function ()1797 ne.eventresponder["mbtn_left_up"] = function ()
1799 local title = mp.get_property_osd("media-title")1798 local title = mp.get_property_osd("media-title")
1800 if (have_pl) then1799 if have_pl then
1801 title = string.format("[%d/%d] %s", countone(pl_pos - 1),1800 title = string.format("[%d/%d] %s", countone(pl_pos - 1),
1802 pl_count, title)1801 pl_count, title)
1803 end1802 end
@@ -1926,7 +1925,7 @@ function osc_init() · 122 unmodified lines
1926 ne.enabled = (#tracks_osc.audio > 0)1925 ne.enabled = (#tracks_osc.audio > 0)
1927 ne.content = function ()1926 ne.content = function ()
1928 local aid = "–"1927 local aid = "–"
1929 if not (get_track("audio") == 0) then1928 if get_track("audio") ~= 0 then
1930 aid = get_track("audio")1929 aid = get_track("audio")
1931 end1930 end
1932 return ("\238\132\134" .. osc_styles.smallButtonsLlabel1931 return ("\238\132\134" .. osc_styles.smallButtonsLlabel
@@ -1949,7 +1948,7 @@ function osc_init() · 16 unmodified lines
1949 ne.enabled = (#tracks_osc.sub > 0)1948 ne.enabled = (#tracks_osc.sub > 0)
1950 ne.content = function ()1949 ne.content = function ()
1951 local sid = "–"1950 local sid = "–"
1952 if not (get_track("sub") == 0) then1951 if get_track("sub") ~= 0 then
1953 sid = get_track("sub")1952 sid = get_track("sub")
1954 end1953 end
1955 return ("\238\132\135" .. osc_styles.smallButtonsLlabel1954 return ("\238\132\135" .. osc_styles.smallButtonsLlabel
@@ -1969,7 +1968,7 @@ function osc_init() · 13 unmodified lines
1969 --tog_fs1968 --tog_fs
1970 ne = new_element("tog_fs", "button")1969 ne = new_element("tog_fs", "button")
1971 ne.content = function ()1970 ne.content = function ()
1972 if (state.fullscreen) then1971 if state.fullscreen then
1973 return ("\238\132\137")1972 return ("\238\132\137")
1974 else1973 else
1975 return ("\238\132\136")1974 return ("\238\132\136")
@@ -1981,11 +1980,11 @@ function osc_init() · 5 unmodified lines
1981 --seekbar1980 --seekbar
1982 ne = new_element("seekbar", "slider")1981 ne = new_element("seekbar", "slider")
1983 1982
1984 ne.enabled = not (mp.get_property("percent-pos") == nil)1983 ne.enabled = mp.get_property("percent-pos") ~= nil
1985 state.slider_element = ne.enabled and ne or nil -- used for forced_title1984 state.slider_element = ne.enabled and ne or nil -- used for forced_title
1986 ne.slider.markerF = function ()1985 ne.slider.markerF = function ()
1987 local duration = mp.get_property_number("duration", nil)1986 local duration = mp.get_property_number("duration", nil)
1988 if not (duration == nil) then1987 if duration ~= nil then
1989 local chapters = mp.get_property_native("chapter-list", {})1988 local chapters = mp.get_property_native("chapter-list", {})
1990 local markers = {}1989 local markers = {}
1991 for n = 1, #chapters do1990 for n = 1, #chapters do
@@ -2000,7 +1999,7 @@ function osc_init() · 8 unmodified lines
2000 function () return mp.get_property_number("percent-pos", nil) end1999 function () return mp.get_property_number("percent-pos", nil) end
2001 ne.slider.tooltipF = function (pos)2000 ne.slider.tooltipF = function (pos)
2002 local duration = mp.get_property_number("duration", nil)2001 local duration = mp.get_property_number("duration", nil)
2003 if not ((duration == nil) or (pos == nil)) then2002 if duration ~= nil and pos ~= nil then
2004 possec = duration * (pos / 100)2003 possec = duration * (pos / 100)
2005 return mp.format_time(possec)2004 return mp.format_time(possec)
2006 else2005 else
@@ -2016,7 +2015,7 @@ function osc_init() · 9 unmodified lines
2016 return nil2015 return nil
2017 end2016 end
2018 local duration = mp.get_property_number("duration", nil)2017 local duration = mp.get_property_number("duration", nil)
2019 if (duration == nil) or duration <= 0 then2018 if duration == nil or duration <= 0 then
2020 return nil2019 return nil
2021 end2020 end
2022 local ranges = cache_state["seekable-ranges"]2021 local ranges = cache_state["seekable-ranges"]
@@ -2038,8 +2037,8 @@ function osc_init() · 15 unmodified lines
2038 -- sent when the user is done seeking, so we need to throw away2037 -- sent when the user is done seeking, so we need to throw away
2039 -- identical seeks2038 -- identical seeks
2040 local seekto = get_slider_value(element)2039 local seekto = get_slider_value(element)
2041 if (element.state.lastseek == nil) or2040 if element.state.lastseek == nil or
2042 (not (element.state.lastseek == seekto)) then2041 element.state.lastseek ~= seekto then
2043 local flags = "absolute-percent"2042 local flags = "absolute-percent"
2044 if not user_opts.seekbarkeyframes then2043 if not user_opts.seekbarkeyframes then
2045 flags = flags .. "+exact"2044 flags = flags .. "+exact"
@@ -2064,7 +2063,7 @@ function osc_init() · 18 unmodified lines
2064 ne = new_element("tc_left", "button")2063 ne = new_element("tc_left", "button")
2065 2064
2066 ne.content = function ()2065 ne.content = function ()
2067 if (state.tc_ms) then2066 if state.tc_ms then
2068 return (mp.get_property_osd("playback-time/full"))2067 return (mp.get_property_osd("playback-time/full"))
2069 else2068 else
2070 return (mp.get_property_osd("playback-time"))2069 return (mp.get_property_osd("playback-time"))
@@ -2080,7 +2079,7 @@ function osc_init() · 9 unmodified lines
2080 2079
2081 ne.visible = (mp.get_property_number("duration", 0) > 0)2080 ne.visible = (mp.get_property_number("duration", 0) > 0)
2082 ne.content = function ()2081 ne.content = function ()
2083 if (state.rightTC_trem) then2082 if state.rightTC_trem then
2084 local minus = user_opts.unicodeminus and UNICODE_MINUS or "-"2083 local minus = user_opts.unicodeminus and UNICODE_MINUS or "-"
2085 local property = user_opts.remaining_playtime and "playtime-remaining"2084 local property = user_opts.remaining_playtime and "playtime-remaining"
2086 or "time-remaining"2085 or "time-remaining"
@@ -2174,7 +2173,7 @@ function update_margins() · 87 unmodified lines
2174 local margins = osc_param.video_margins2173 local margins = osc_param.video_margins
2175 2174
2176 -- Don't use margins if it's visible only temporarily.2175 -- Don't use margins if it's visible only temporarily.
2177 if (not state.osc_visible) or (get_hidetimeout() >= 0) or2176 if not state.osc_visible or get_hidetimeout() >= 0 or
2178 (state.fullscreen and not user_opts.showfullscreen) or2177 (state.fullscreen and not user_opts.showfullscreen) or
2179 (not state.fullscreen and not user_opts.showwindowed)2178 (not state.fullscreen and not user_opts.showwindowed)
2180 then2179 then
@@ -2196,7 +2195,7 @@ function update_margins() · 15 unmodified lines
2196 if not margins_used then2195 if not margins_used then
2197 for _, opt in ipairs(margins_opts) do2196 for _, opt in ipairs(margins_opts) do
2198 local v = margins[opt[1]]2197 local v = margins[opt[1]]
2199 if (v ~= 0) or state.using_video_margins then2198 if v ~= 0 or state.using_video_margins then
2200 mp.set_property_number(opt[2], v)2199 mp.set_property_number(opt[2], v)
2201 state.using_video_margins = true2200 state.using_video_margins = true
2202 end2201 end
@@ -2229,7 +2228,7 @@ function show_osc() · 26 unmodified lines
2229 2228
2230 osc_visible(true)2229 osc_visible(true)
2231 2230
2232 if (user_opts.fadeduration > 0) then2231 if user_opts.fadeduration > 0 then
2233 state.anitype = nil2232 state.anitype = nil
2234 end2233 end
2235end2234end
@@ -2241,8 +2240,8 @@ function hide_osc() · 5 unmodified lines
2241 -- no-op and won't render again to remove the osc, so do that manually.2240 -- no-op and won't render again to remove the osc, so do that manually.
2242 state.osc_visible = false2241 state.osc_visible = false
2243 render_wipe()2242 render_wipe()
2244 elseif (user_opts.fadeduration > 0) then2243 elseif user_opts.fadeduration > 0 then
2245 if not(state.osc_visible == false) then2244 if state.osc_visible then
2246 state.anitype = "out"2245 state.anitype = "out"
2247 request_tick()2246 request_tick()
2248 end2247 end
@@ -2324,8 +2323,8 @@ function render() · 75 unmodified lines
2324 local now = mp.get_time()2323 local now = mp.get_time()
2325 2324
2326 -- check if display changed, if so request reinit2325 -- check if display changed, if so request reinit
2327 if not (state.mp_screen_sizeX == current_screen_sizeX2326 if state.mp_screen_sizeX ~= current_screen_sizeX
2328 and state.mp_screen_sizeY == current_screen_sizeY) then2327 or state.mp_screen_sizeY ~= current_screen_sizeY then
2329 2328
2330 request_init_resize()2329 request_init_resize()
2331 2330
@@ -2355,27 +2354,27 @@ function render() · 23 unmodified lines
2355 2354
2356 2355
2357 -- fade animation2356 -- fade animation
2358 if not(state.anitype == nil) then2357 if state.anitype ~= nil then
2359 2358
2360 if (state.anistart == nil) then2359 if state.anistart == nil then
2361 state.anistart = now2360 state.anistart = now
2362 end2361 end
2363 2362
2364 if (now < state.anistart + (user_opts.fadeduration/1000)) then2363 if now < state.anistart + (user_opts.fadeduration / 1000) then
2365 2364
2366 if (state.anitype == "in") then --fade in2365 if state.anitype == "in" then --fade in
2367 osc_visible(true)2366 osc_visible(true)
2368 state.animation = scale_value(state.anistart,2367 state.animation = scale_value(state.anistart,
2369 (state.anistart + (user_opts.fadeduration/1000)),2368 (state.anistart + (user_opts.fadeduration / 1000)),
2370 255, 0, now)2369 255, 0, now)
2371 elseif (state.anitype == "out") then --fade out2370 elseif state.anitype == "out" then --fade out
2372 state.animation = scale_value(state.anistart,2371 state.animation = scale_value(state.anistart,
2373 (state.anistart + (user_opts.fadeduration/1000)),2372 (state.anistart + (user_opts.fadeduration / 1000)),
2374 0, 255, now)2373 0, 255, now)
2375 end2374 end
2376 2375
2377 else2376 else
2378 if (state.anitype == "out") then2377 if state.anitype == "out" then
2379 osc_visible(false)2378 osc_visible(false)
2380 end2379 end
2381 kill_animation()2380 kill_animation()
@@ -2413,7 +2412,7 @@ function render() · 31 unmodified lines
2413 state.input_enabled = state.osc_visible2412 state.input_enabled = state.osc_visible
2414 end2413 end
2415 2414
2416 if (mouse_hit_coords(cords.x1, cords.y1, cords.x2, cords.y2)) then2415 if mouse_hit_coords(cords.x1, cords.y1, cords.x2, cords.y2) then
2417 mouse_over_osc = true2416 mouse_over_osc = true
2418 end2417 end
2419 end2418 end
@@ -2432,7 +2431,7 @@ function render() · 12 unmodified lines
2432 state.windowcontrols_buttons = state.osc_visible2431 state.windowcontrols_buttons = state.osc_visible
2433 end2432 end
2434 2433
2435 if (mouse_hit_coords(cords.x1, cords.y1, cords.x2, cords.y2)) then2434 if mouse_hit_coords(cords.x1, cords.y1, cords.x2, cords.y2) then
2436 mouse_over_osc = true2435 mouse_over_osc = true
2437 end2436 end
2438 end2437 end
@@ -2440,17 +2439,17 @@ function render() · 1 unmodified line
2440 2439
2441 if osc_param.areas["window-controls-title"] then2440 if osc_param.areas["window-controls-title"] then
2442 for _,cords in ipairs(osc_param.areas["window-controls-title"]) do2441 for _,cords in ipairs(osc_param.areas["window-controls-title"]) do
2443 if (mouse_hit_coords(cords.x1, cords.y1, cords.x2, cords.y2)) then2442 if mouse_hit_coords(cords.x1, cords.y1, cords.x2, cords.y2) then
2444 mouse_over_osc = true2443 mouse_over_osc = true
2445 end2444 end
2446 end2445 end
2447 end2446 end
2448 2447
2449 -- autohide2448 -- autohide
2450 if not (state.showtime == nil) and (get_hidetimeout() >= 0) then2449 if state.showtime ~= nil and get_hidetimeout() >= 0 then
2451 local timeout = state.showtime + (get_hidetimeout()/1000) - now2450 local timeout = state.showtime + (get_hidetimeout() / 1000) - now
2452 if timeout <= 0 then2451 if timeout <= 0 then
2453 if (state.active_element == nil) and not (mouse_over_osc) then2452 if state.active_element == nil and not mouse_over_osc then
2454 hide_osc()2453 hide_osc()
2455 end2454 end
2456 else2455 else
@@ -2544,8 +2543,8 @@ function process_event(source, what) · 87 unmodified lines
2544 state.mouse_in_window = true2543 state.mouse_in_window = true
2545 2544
2546 local mouseX, mouseY = get_virt_mouse_pos()2545 local mouseX, mouseY = get_virt_mouse_pos()
2547 if (user_opts.minmousemove == 0) or2546 if user_opts.minmousemove == 0 or
2548 (not ((state.last_mouseX == nil) or (state.last_mouseY == nil)) and2547 ((state.last_mouseX ~= nil and state.last_mouseY ~= nil) and
2549 ((math.abs(mouseX - state.last_mouseX) >= user_opts.minmousemove)2548 ((math.abs(mouseX - state.last_mouseX) >= user_opts.minmousemove)
2550 or (math.abs(mouseY - state.last_mouseY) >= user_opts.minmousemove)2549 or (math.abs(mouseY - state.last_mouseY) >= user_opts.minmousemove)
2551 )2550 )
@@ -2597,9 +2596,9 @@ function tick() · 45 unmodified lines
2597 state.marginsREQ = false2596 state.marginsREQ = false
2598 end2597 end
2599 2598
2600 if (not state.enabled) then return end2599 if not state.enabled then return end
2601 2600
2602 if (state.idle) then2601 if state.idle then
2603 2602
2604 -- render idle message2603 -- render idle message
2605 msg.trace("idle message")2604 msg.trace("idle message")
@@ -2645,7 +2644,7 @@ function tick() · 39 unmodified lines
2645 end2644 end
2646 2645
2647 2646
2648 elseif (state.fullscreen and user_opts.showfullscreen)2647 elseif state.fullscreen and user_opts.showfullscreen
2649 or (not state.fullscreen and user_opts.showwindowed) then2648 or (not state.fullscreen and user_opts.showwindowed) then
2650 2649
2651 -- render the OSC2650 -- render the OSC
@@ -2708,7 +2707,7 @@ function update_duration_watch() · 56 unmodified lines
2708 (mp.get_property_number("chapters", 0) or 0) > 0 and2707 (mp.get_property_number("chapters", 0) or 0) > 0 and
2709 true or false -- ensure it's a boolean2708 true or false -- ensure it's a boolean
2710 2709
2711 if (want_watch ~= duration_watched) then2710 if want_watch ~= duration_watched then
2712 if want_watch then2711 if want_watch then
2713 mp.observe_property("duration", nil, on_duration)2712 mp.observe_property("duration", nil, on_duration)
2714 else2713 else
player/lua/stats.lua+3−3
@@ -1092,7 +1092,7 @@ local function cache_stats() · 1091 unmodified lines
1092 append(stats, opt_time(a) .. " - " .. opt_time(b), {prefix = "Packet queue:"})1092 append(stats, opt_time(a) .. " - " .. opt_time(b), {prefix = "Packet queue:"})
1093 1093
1094 local r = nil1094 local r = nil
1095 if (a ~= nil) and (b ~= nil) then1095 if a ~= nil and b ~= nil then
1096 r = b - a1096 r = b - a
1097 end1097 end
1098 1098
@@ -1174,7 +1174,7 @@ local function record_cache_stats() · 75 unmodified lines
1174 1174
1175 local a = info["reader-pts"]1175 local a = info["reader-pts"]
1176 local b = info["cache-end"]1176 local b = info["cache-end"]
1177 if (a ~= nil) and (b ~= nil) then1177 if a ~= nil and b ~= nil then
1178 graph_add_value(cache_ahead_buf, b - a)1178 graph_add_value(cache_ahead_buf, b - a)
1179 end1179 end
1180 1180
@@ -1274,7 +1274,7 @@ local function unbind_scroll() · 93 unmodified lines
1274 end1274 end
1275end1275end
1276local function update_scroll_bindings(k)1276local function update_scroll_bindings(k)
1277 if (pages[k].scroll) then1277 if pages[k].scroll then
1278 bind_scroll()1278 bind_scroll()
1279 else1279 else
1280 unbind_scroll()1280 unbind_scroll()
player/lua/ytdl_hook.lua+40−40
@@ -357,7 +357,7 @@ local function join_url(base_url, fragment) · 356 unmodified lines
357end357end
358 358
359local function edl_track_joined(fragments, protocol, is_live, base)359local function edl_track_joined(fragments, protocol, is_live, base)
360 if not (type(fragments) == "table") or not fragments[1] then360 if type(fragments) ~= "table" or not fragments[1] then
361 msg.debug("No fragments to join into EDL")361 msg.debug("No fragments to join into EDL")
362 return nil362 return nil
363 end363 end
@@ -366,7 +366,7 @@ local function edl_track_joined(fragments, protocol, is_live, base) · 2 unmodified lines
366 local offset = 1366 local offset = 1
367 local parts = {}367 local parts = {}
368 368
369 if (protocol == "http_dash_segments") and not is_live then369 if protocol == "http_dash_segments" and not is_live then
370 msg.debug("Using dash")370 msg.debug("Using dash")
371 local args = ""371 local args = ""
372 372
@@ -674,7 +674,7 @@ local function add_single_video(json) · 301 unmodified lines
674 end674 end
675 end675 end
676 676
677 if (not res) and has_requested_formats then677 if not res and has_requested_formats then
678 format_info = "youtube-dl (separate)"678 format_info = "youtube-dl (separate)"
679 res = formats_to_edl(json, requested_formats, false)679 res = formats_to_edl(json, requested_formats, false)
680 end680 end
@@ -721,7 +721,7 @@ local function add_single_video(json) · 40 unmodified lines
721 end721 end
722 722
723 -- add subtitles723 -- add subtitles
724 if not (json.requested_subtitles == nil) then724 if json.requested_subtitles ~= nil then
725 local subs = {}725 local subs = {}
726 for lang, info in pairs(json.requested_subtitles) do726 for lang, info in pairs(json.requested_subtitles) do
727 subs[#subs + 1] = {lang = lang or "-", info = info}727 subs[#subs + 1] = {lang = lang or "-", info = info}
@@ -733,14 +733,14 @@ local function add_single_video(json) · 5 unmodified lines
733 733
734 local sub = nil734 local sub = nil
735 735
736 if not (sub_info.data == nil) then736 if sub_info.data ~= nil then
737 sub = "memory://"..sub_info.data737 sub = "memory://"..sub_info.data
738 elseif not (sub_info.url == nil) and738 elseif sub_info.url ~= nil and
739 url_is_safe(sub_info.url) then739 url_is_safe(sub_info.url) then
740 sub = sub_info.url740 sub = sub_info.url
741 end741 end
742 742
743 if not (sub == nil) then743 if sub ~= nil then
744 local edl = "edl://!no_clip;!delay_open,media_type=sub"744 local edl = "edl://!no_clip;!delay_open,media_type=sub"
745 local codec = map_codec_to_mpv(sub_info.ext)745 local codec = map_codec_to_mpv(sub_info.ext)
746 if codec then746 if codec then
@@ -756,15 +756,15 @@ local function add_single_video(json) · 9 unmodified lines
756 end756 end
757 757
758 -- add thumbnails758 -- add thumbnails
759 if (o.thumbnails == 'all' or o.thumbnails == 'best') and not (json.thumbnails == nil) then759 if (o.thumbnails == 'all' or o.thumbnails == 'best') and json.thumbnails ~= nil then
760 local thumb = nil760 local thumb = nil
761 local thumb_height = -1761 local thumb_height = -1
762 local thumb_preference = nil762 local thumb_preference = nil
763 763
764 for i = #json.thumbnails, 1, -1 do764 for i = #json.thumbnails, 1, -1 do
765 local thumb_info = json.thumbnails[i]765 local thumb_info = json.thumbnails[i]
766 if not (thumb_info.url == nil) then766 if thumb_info.url ~= nil then
767 if (o.thumbnails == 'all') then767 if o.thumbnails == 'all' then
768 msg.verbose("adding thumbnail")768 msg.verbose("adding thumbnail")
769 mp.commandv("video-add", thumb_info.url, "auto")769 mp.commandv("video-add", thumb_info.url, "auto")
770 thumb_height = 0770 thumb_height = 0
@@ -777,10 +777,10 @@ local function add_single_video(json) · 6 unmodified lines
777 end777 end
778 end778 end
779 779
780 if not (thumb == nil) then780 if thumb ~= nil then
781 msg.verbose("adding thumbnail")781 msg.verbose("adding thumbnail")
782 mp.commandv("video-add", thumb, "auto")782 mp.commandv("video-add", thumb, "auto")
783 elseif (thumb_height == -1) then783 elseif thumb_height == -1 then
784 msg.verbose("No thumbnail url")784 msg.verbose("No thumbnail url")
785 end785 end
786 end786 end
@@ -796,12 +796,12 @@ local function add_single_video(json) · 9 unmodified lines
796 end796 end
797 table.insert(chapter_list, {time=chapter.start_time, title=title})797 table.insert(chapter_list, {time=chapter.start_time, title=title})
798 end798 end
799 elseif not (json.description == nil) and not (json.duration == nil) then799 elseif json.description ~= nil and json.duration ~= nil then
800 chapter_list = extract_chapters(json.description, json.duration)800 chapter_list = extract_chapters(json.description, json.duration)
801 end801 end
802 802
803 -- set start time803 -- set start time
804 if (json.start_time or json.section_start) and804 if json.start_time or json.section_start and
805 not option_was_set("start") and805 not option_was_set("start") and
806 not option_was_set_locally("start") then806 not option_was_set_locally("start") then
807 local start_time = json.start_time or json.section_start807 local start_time = json.start_time or json.section_start
@@ -810,7 +810,7 @@ local function add_single_video(json) · 2 unmodified lines
810 end810 end
811 811
812 -- set end time812 -- set end time
813 if (json.end_time or json.section_end) and813 if json.end_time or json.section_end and
814 not option_was_set("end") and814 not option_was_set("end") and
815 not option_was_set_locally("end") then815 not option_was_set_locally("end") then
816 local end_time = json.end_time or json.section_end816 local end_time = json.end_time or json.section_end
@@ -819,7 +819,7 @@ local function add_single_video(json) · 2 unmodified lines
819 end819 end
820 820
821 -- set aspect ratio for anamorphic video821 -- set aspect ratio for anamorphic video
822 if not (json.stretched_ratio == nil) and822 if json.stretched_ratio ~= nil and
823 not option_was_set("video-aspect-override") then823 not option_was_set("video-aspect-override") then
824 mp.set_property('file-local-options/video-aspect-override', json.stretched_ratio)824 mp.set_property('file-local-options/video-aspect-override', json.stretched_ratio)
825 end825 end
@@ -827,7 +827,7 @@ local function add_single_video(json) · 1 unmodified line
827 local stream_opts = mp.get_property_native("file-local-options/stream-lavf-o", {})827 local stream_opts = mp.get_property_native("file-local-options/stream-lavf-o", {})
828 828
829 -- for rtmp829 -- for rtmp
830 if (json.protocol == "rtmp") then830 if json.protocol == "rtmp" then
831 stream_opts = append_libav_opt(stream_opts,831 stream_opts = append_libav_opt(stream_opts,
832 "rtmp_tcurl", streamurl)832 "rtmp_tcurl", streamurl)
833 stream_opts = append_libav_opt(stream_opts,833 stream_opts = append_libav_opt(stream_opts,
@@ -869,12 +869,12 @@ local function check_version(ytdl_path) · 35 unmodified lines
869 local year, month, day = string.match(version_string, "(%d+).(%d+).(%d+)")869 local year, month, day = string.match(version_string, "(%d+).(%d+).(%d+)")
870 870
871 -- sanity check871 -- sanity check
872 if (tonumber(year) < 2000) or (tonumber(month) > 12) or872 if tonumber(year) < 2000 or tonumber(month) > 12 or
873 (tonumber(day) > 31) then873 tonumber(day) > 31 then
874 return874 return
875 end875 end
876 local version_ts = os.time{year=year, month=month, day=day}876 local version_ts = os.time{year=year, month=month, day=day}
877 if (os.difftime(os.time(), version_ts) > 60*60*24*90) then877 if os.difftime(os.time(), version_ts) > 60*60*24*90 then
878 msg.warn("It appears that your youtube-dl version is severely out of date.")878 msg.warn("It appears that your youtube-dl version is severely out of date.")
879 end879 end
880end880end
@@ -883,7 +883,7 @@ function run_ytdl_hook(url) · 2 unmodified lines
883 local start_time = os.clock()883 local start_time = os.clock()
884 884
885 -- strip ytdl://885 -- strip ytdl://
886 if (url:find("ytdl://") == 1) then886 if url:find("ytdl://") == 1 then
887 url = url:sub(8)887 url = url:sub(8)
888 end888 end
889 889
@@ -900,12 +900,12 @@ function run_ytdl_hook(url) · 10 unmodified lines
900 900
901 -- Checks if video option is "no", change format accordingly,901 -- Checks if video option is "no", change format accordingly,
902 -- but only if user didn't explicitly set one902 -- but only if user didn't explicitly set one
903 if (mp.get_property("options/vid") == "no") and (#format == 0) then903 if mp.get_property("options/vid") == "no" and #format == 0 then
904 format = "bestaudio/best"904 format = "bestaudio/best"
905 msg.verbose("Video disabled. Only using audio")905 msg.verbose("Video disabled. Only using audio")
906 end906 end
907 907
908 if (format == "") then908 if format == "" then
909 format = "bestvideo+bestaudio/best"909 format = "bestvideo+bestaudio/best"
910 end910 end
911 911
@@ -916,19 +916,19 @@ function run_ytdl_hook(url) · 4 unmodified lines
916 916
917 for param, arg in pairs(raw_options) do917 for param, arg in pairs(raw_options) do
918 table.insert(command, "--" .. param)918 table.insert(command, "--" .. param)
919 if (arg ~= "") then919 if arg ~= "" then
920 table.insert(command, arg)920 table.insert(command, arg)
921 end921 end
922 if (param == "sub-lang" or param == "sub-langs" or param == "srt-lang") and (arg ~= "") then922 if (param == "sub-lang" or param == "sub-langs" or param == "srt-lang") and (arg ~= "") then
923 allsubs = false923 allsubs = false
924 elseif (param == "proxy") and (arg ~= "") then924 elseif param == "proxy" and arg ~= "" then
925 proxy = arg925 proxy = arg
926 elseif (param == "yes-playlist") then926 elseif param == "yes-playlist" then
927 use_playlist = true927 use_playlist = true
928 end928 end
929 end929 end
930 930
931 if (allsubs == true) then931 if allsubs == true then
932 table.insert(command, "--all-subs")932 table.insert(command, "--all-subs")
933 end933 end
934 if not use_playlist then934 if not use_playlist then
@@ -989,7 +989,7 @@ function run_ytdl_hook(url) · 54 unmodified lines
989 json, parse_err = utils.parse_json(json)989 json, parse_err = utils.parse_json(json)
990 end990 end
991 991
992 if (json == nil) then992 if json == nil then
993 msg.verbose("status:", result.status)993 msg.verbose("status:", result.status)
994 msg.verbose("reason:", result.error_string)994 msg.verbose("reason:", result.error_string)
995 msg.verbose("stdout:", result.stdout)995 msg.verbose("stdout:", result.stdout)
@@ -1023,11 +1023,11 @@ function run_ytdl_hook(url) · 27 unmodified lines
1023 -- direct URL, nothing to do1023 -- direct URL, nothing to do
1024 msg.verbose("Got direct URL")1024 msg.verbose("Got direct URL")
1025 return1025 return
1026 elseif (json["_type"] == "playlist")1026 elseif json["_type"] == "playlist" or
1027 or (json["_type"] == "multi_video") then1027 json["_type"] == "multi_video" then
1028 -- a playlist1028 -- a playlist
1029 1029
1030 if (#json.entries == 0) then1030 if #json.entries == 0 then
1031 msg.warn("Got empty playlist, nothing to play.")1031 msg.warn("Got empty playlist, nothing to play.")
1032 return1032 return
1033 end1033 end
@@ -1065,19 +1065,19 @@ function run_ytdl_hook(url) · 31 unmodified lines
1065 -- there might not be subs for the first segment1065 -- there might not be subs for the first segment
1066 local entry_wsubs = nil1066 local entry_wsubs = nil
1067 for i, entry in pairs(json.entries) do1067 for i, entry in pairs(json.entries) do
1068 if not (entry.requested_subtitles == nil) then1068 if entry.requested_subtitles ~= nil then
1069 entry_wsubs = i1069 entry_wsubs = i
1070 break1070 break
1071 end1071 end
1072 end1072 end
1073 1073
1074 if not (entry_wsubs == nil) and1074 if entry_wsubs ~= nil and
1075 not (json.entries[entry_wsubs].duration == nil) then1075 json.entries[entry_wsubs].duration ~= nil then
1076 for j, req in pairs(json.entries[entry_wsubs].requested_subtitles) do1076 for j, req in pairs(json.entries[entry_wsubs].requested_subtitles) do
1077 local subfile = "edl://"1077 local subfile = "edl://"
1078 for i, entry in pairs(json.entries) do1078 for i, entry in pairs(json.entries) do
1079 if not (entry.requested_subtitles == nil) and1079 if entry.requested_subtitles ~= nil and
1080 not (entry.requested_subtitles[j] == nil) and1080 entry.requested_subtitles[j] ~= nil and
1081 url_is_safe(entry.requested_subtitles[j].url) then1081 url_is_safe(entry.requested_subtitles[j].url) then
1082 subfile = subfile..edl_escape(entry.requested_subtitles[j].url)1082 subfile = subfile..edl_escape(entry.requested_subtitles[j].url)
1083 else1083 else
@@ -1100,7 +1100,7 @@ function run_ytdl_hook(url) · 16 unmodified lines
1100 local site = entry.url1100 local site = entry.url
1101 local title = entry.title1101 local title = entry.title
1102 1102
1103 if not (title == nil) then1103 if title ~= nil then
1104 title = string.gsub(title, '%s+', ' ')1104 title = string.gsub(title, '%s+', ' ')
1105 table.insert(playlist, "#EXTINF:0," .. title)1105 table.insert(playlist, "#EXTINF:0," .. title)
1106 end1106 end
@@ -1151,11 +1151,11 @@ function run_ytdl_hook(url) · 44 unmodified lines
1151 msg.debug('script running time: '..os.clock()-start_time..' seconds')1151 msg.debug('script running time: '..os.clock()-start_time..' seconds')
1152end1152end
1153 1153
1154if (not o.try_ytdl_first) then1154if not o.try_ytdl_first then
1155 mp.add_hook("on_load", 10, function ()1155 mp.add_hook("on_load", 10, function ()
1156 msg.verbose('ytdl:// hook')1156 msg.verbose('ytdl:// hook')
1157 local url = mp.get_property("stream-open-filename", "")1157 local url = mp.get_property("stream-open-filename", "")
1158 if not (url:find("ytdl://") == 1) then1158 if url:find("ytdl://") ~= 1 then
1159 msg.verbose('not a ytdl:// url')1159 msg.verbose('not a ytdl:// url')
1160 return1160 return
1161 end1161 end
@@ -1174,7 +1174,7 @@ end) · 12 unmodified lines
1174mp.add_hook(o.try_ytdl_first and "on_load" or "on_load_fail", 10, function()1174mp.add_hook(o.try_ytdl_first and "on_load" or "on_load_fail", 10, function()
1175 msg.verbose('full hook')1175 msg.verbose('full hook')
1176 local url = mp.get_property("stream-open-filename", "")1176 local url = mp.get_property("stream-open-filename", "")
1177 if not (url:find("ytdl://") == 1) and1177 if url:find("ytdl://") ~= 1 and
1178 not ((url:find("https?://") == 1) and not is_blacklisted(url)) then1178 not ((url:find("https?://") == 1) and not is_blacklisted(url)) then
1179 return1179 return
1180 end1180 end

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t