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
175175 end
176176
177177 local function add_binding(attrs, key, name, fn, rp)
178− if (type(name) ~= "string") and (name ~= nil) then
178+ if type(name) ~= "string" and name ~= nil then
179179 rp = fn
180180 fn = name
181181 name = nil
@@ -226,7 +226,7 @@ local function add_binding(attrs, key, name, fn, rp) · 44 unmodified lines
226226 end
227227 if is_mouse and (event == "u" or event == "p") then
228228 fn()
229− elseif (not is_mouse) and (event == "d" or event == "r" or event == "p") then
229+ elseif not is_mouse and (event == "d" or event == "r" or event == "p") then
230230 fn()
231231 end
232232 end
@@ -316,7 +316,7 @@ end · 83 unmodified lines
316316 local function get_next_timer()
317317 local best = nil
318318 for t, _ in pairs(timers) do
319− if (best == nil) or (t.next_deadline < best.next_deadline) then
319+ if best == nil or t.next_deadline < best.next_deadline then
320320 best = t
321321 end
322322 end
@@ -598,7 +598,7 @@ mp.register_event("hook", function(ev) · 275 unmodified lines
598598 if fn then
599599 fn(hookobj)
600600 end
601− if (not hookobj._defer) and hookobj._id ~= nil then
601+ if not hookobj._defer and hookobj._id ~= nil then
602602 hookobj:cont()
603603 end
604604 end)
player/lua/options.lua+1−1
@@ -12,7 +12,7 @@ local function typeconv(desttypeval, val) · 11 unmodified lines
1212 val = nil
1313 end
1414 elseif type(desttypeval) == "number" then
15− if not (tonumber(val) == nil) then
15+ if tonumber(val) ~= nil then
1616 val = tonumber(val)
1717 else
1818 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
280280 end
281281
282282 function countone(val)
283− if not (user_opts.iamaprogrammer) then
283+ if not user_opts.iamaprogrammer then
284284 val = val + 1
285285 end
286286 return val
@@ -301,7 +301,7 @@ end · 14 unmodified lines
301301
302302 function add_area(name, x1, y1, x2, y2)
303303 -- create area if needed
304− if (osc_param.areas[name] == nil) then
304+ if osc_param.areas[name] == nil then
305305 osc_param.areas[name] = {}
306306 end
307307 table.insert(osc_param.areas[name], {x1=x1, y1=y1, x2=x2, y2=y2})
@@ -356,7 +356,7 @@ function update_tracklist() · 48 unmodified lines
356356 tracks_mpv = {}
357357 tracks_mpv.video, tracks_mpv.audio, tracks_mpv.sub = {}, {}, {}
358358 for n = 1, #tracktable do
359− if not (tracktable[n].type == "unknown") then
359+ if tracktable[n].type ~= "unknown" then
360360 local type = tracktable[n].type
361361 local mpv_id = tonumber(tracktable[n].id)
362362
@@ -379,9 +379,9 @@ function get_tracklist(type) · 16 unmodified lines
379379 for n = 1, #tracks_osc[type] do
380380 local track = tracks_osc[type][n]
381381 local lang, title, selected = "unknown", "", "○"
382− if not(track.lang == nil) then lang = track.lang end
383− if not(track.title == nil) then title = track.title end
384− if (track.id == tonumber(mp.get_property(type))) then
382+ if track.lang ~= nil then lang = track.lang end
383+ if track.title ~= nil then title = track.title end
384+ if track.id == tonumber(mp.get_property(type)) then
385385 selected = "●"
386386 end
387387 msg = msg.."\n"..selected.." "..n..": ["..lang.."] "..title
@@ -394,7 +394,7 @@ end · 6 unmodified lines
394394 --(+1 -> next, -1 -> previous)
395395 function set_track(type, next)
396396 local current_track_mpv, current_track_osc
397− if (mp.get_property(type) == "no") then
397+ if mp.get_property(type) == "no" then
398398 current_track_osc = 0
399399 else
400400 current_track_mpv = tonumber(mp.get_property(type))
@@ -410,7 +410,7 @@ function set_track(type, next) · 9 unmodified lines
410410
411411 mp.commandv("set", type, new_track_mpv)
412412
413− if (new_track_osc == 0) then
413+ if new_track_osc == 0 then
414414 show_message(nicetypes[type] .. " Track: none")
415415 else
416416 show_message(nicetypes[type] .. " Track: "
@@ -457,7 +457,7 @@ function prepare_elements() · 40 unmodified lines
457457 -- remove elements without layout or invisible
458458 local elements2 = {}
459459 for n, element in pairs(elements) do
460− if not (element.layout == nil) and (element.visible) then
460+ if element.layout ~= nil and element.visible then
461461 table.insert(elements2, element)
462462 end
463463 end
@@ -492,14 +492,14 @@ function prepare_elements() · 28 unmodified lines
492492 local static_ass = assdraw.ass_new()
493493
494494
495− if (element.type == "box") then
495+ if element.type == "box" then
496496 --draw box
497497 static_ass:draw_start()
498498 ass_draw_rr_h_cw(static_ass, 0, 0, elem_geo.w, elem_geo.h,
499499 element.layout.box.radius, element.layout.box.hexagon)
500500 static_ass:draw_stop()
501501
502− elseif (element.type == "slider") then
502+ elseif element.type == "slider" then
503503 --draw static slider parts
504504
505505 local r1 = 0
@@ -509,13 +509,13 @@ function prepare_elements() · 3 unmodified lines
509509 local foV = slider_lo.border + slider_lo.gap
510510
511511 -- calculate positions of min and max points
512− if (slider_lo.stype ~= "bar") then
512+ if slider_lo.stype ~= "bar" then
513513 r1 = elem_geo.h / 2
514514 element.slider.min.ele_pos = elem_geo.h / 2
515515 element.slider.max.ele_pos = elem_geo.w - (elem_geo.h / 2)
516− if (slider_lo.stype == "diamond") then
516+ if slider_lo.stype == "diamond" then
517517 r2 = (elem_geo.h - 2 * slider_lo.border) / 2
518− elseif (slider_lo.stype == "knob") then
518+ elseif slider_lo.stype == "knob" then
519519 r2 = r1
520520 end
521521 else
@@ -543,45 +543,45 @@ function prepare_elements() · 21 unmodified lines
543543 r2, slider_lo.stype == "diamond")
544544
545545 -- marker nibbles
546− if not (element.slider.markerF == nil) and (slider_lo.gap > 0) then
546+ if element.slider.markerF ~= nil and slider_lo.gap > 0 then
547547 local markers = element.slider.markerF()
548548 for _,marker in pairs(markers) do
549− if (marker > element.slider.min.value) and
550− (marker < element.slider.max.value) then
549+ if marker > element.slider.min.value and
550+ marker < element.slider.max.value then
551551
552552 local s = get_slider_ele_pos_for(element, marker)
553553
554− if (slider_lo.gap > 1) then -- draw triangles
554+ if slider_lo.gap > 1 then -- draw triangles
555555
556556 local a = slider_lo.gap / 0.5 --0.866
557557
558558 --top
559− if (slider_lo.nibbles_top) then
560− static_ass:move_to(s - (a/2), slider_lo.border)
561− static_ass:line_to(s + (a/2), slider_lo.border)
559+ if slider_lo.nibbles_top then
560+ static_ass:move_to(s - (a / 2), slider_lo.border)
561+ static_ass:line_to(s + (a / 2), slider_lo.border)
562562 static_ass:line_to(s, foV)
563563 end
564564
565565 --bottom
566− if (slider_lo.nibbles_bottom) then
567− static_ass:move_to(s - (a/2),
566+ if slider_lo.nibbles_bottom then
567+ static_ass:move_to(s - (a / 2),
568568 elem_geo.h - slider_lo.border)
569569 static_ass:line_to(s,
570570 elem_geo.h - foV)
571− static_ass:line_to(s + (a/2),
571+ static_ass:line_to(s + (a / 2),
572572 elem_geo.h - slider_lo.border)
573573 end
574574
575575 else -- draw 2x1px nibbles
576576
577577 --top
578− if (slider_lo.nibbles_top) then
578+ if slider_lo.nibbles_top then
579579 static_ass:rect_cw(s - 1, slider_lo.border,
580580 s + 1, slider_lo.border + slider_lo.gap);
581581 end
582582
583583 --bottom
584− if (slider_lo.nibbles_bottom) then
584+ if slider_lo.nibbles_bottom then
585585 static_ass:rect_cw(s - 1,
586586 elem_geo.h -slider_lo.border -slider_lo.gap,
587587 s + 1, elem_geo.h - slider_lo.border);
@@ -597,7 +597,7 @@ function prepare_elements() · 9 unmodified lines
597597
598598 -- if the element is supposed to be disabled,
599599 -- style it accordingly and kill the eventresponders
600− if not (element.enabled) then
600+ if not element.enabled then
601601 element.layout.alpha[1] = 136
602602 element.eventresponder = nil
603603 end
@@ -648,18 +648,18 @@ function render_elements(master_ass) · 44 unmodified lines
648648 if element.eventresponder and (state.active_element == n) then
649649
650650 -- run render event functions
651− if not (element.eventresponder.render == nil) then
651+ if element.eventresponder.render ~= nil then
652652 element.eventresponder.render(element)
653653 end
654654
655655 if mouse_hit(element) then
656656 -- mouse down styling
657− if (element.styledown) then
657+ if element.styledown then
658658 style_ass:append(osc_styles.elementDown)
659659 end
660660
661− if (element.softrepeat) and (state.mouse_down_counter >= 15
662− and state.mouse_down_counter % 5 == 0) then
661+ if element.softrepeat and state.mouse_down_counter >= 15
662+ and state.mouse_down_counter % 5 == 0 then
663663
664664 element.eventresponder[state.active_event_source.."_down"](element)
665665 end
@@ -672,11 +672,11 @@ function render_elements(master_ass) · 6 unmodified lines
672672
673673 elem_ass:merge(style_ass)
674674
675− if not (element.type == "button") then
675+ if element.type ~= "button" then
676676 elem_ass:merge(element.static_ass)
677677 end
678678
679− if (element.type == "slider") then
679+ if element.type == "slider" then
680680
681681 local slider_lo = element.layout.slider
682682 local elem_geo = element.layout.geometry
@@ -794,8 +794,7 @@ function render_elements(master_ass) · 111 unmodified lines
794794 elem_ass:draw_stop()
795795
796796 -- add tooltip
797− if not (element.slider.tooltipF == nil) then
798−
797+ if element.slider.tooltipF ~= nil then
799798 if mouse_hit(element) then
800799 local sliderpos = get_slider_value(element)
801800 local tooltiplabel = element.slider.tooltipF(sliderpos)
@@ -804,21 +803,21 @@ function render_elements(master_ass) · 2 unmodified lines
804803
805804 local ty
806805
807− if (an == 2) then
806+ if an == 2 then
808807 ty = element.hitbox.y1 - slider_lo.border
809808 else
810− ty = element.hitbox.y1 + elem_geo.h/2
809+ ty = element.hitbox.y1 + elem_geo.h / 2
811810 end
812811
813812 local tx = get_virt_mouse_pos()
814− if (slider_lo.adjust_tooltip) then
815− if (an == 2) then
816− if (sliderpos < (s_min + 3)) then
813+ if slider_lo.adjust_tooltip then
814+ if an == 2 then
815+ if sliderpos < (s_min + 3) then
817816 an = an - 1
818− elseif (sliderpos > (s_max - 3)) then
817+ elseif sliderpos > (s_max - 3) then
819818 an = an + 1
820819 end
821− elseif (sliderpos > (s_max+s_min)/2) then
820+ elseif sliderpos > (s_max+s_min) / 2 then
822821 an = an + 1
823822 tx = tx - 5
824823 else
@@ -838,20 +837,20 @@ function render_elements(master_ass) · 13 unmodified lines
838837 end
839838 end
840839
841− elseif (element.type == "button") then
840+ elseif element.type == "button" then
842841
843842 local buttontext
844843 if type(element.content) == "function" then
845844 buttontext = element.content() -- function objects
846− elseif not (element.content == nil) then
845+ elseif element.content ~= nil then
847846 buttontext = element.content -- text objects
848847 end
849848
850849 local maxchars = element.layout.button.maxchars
851− if not (maxchars == nil) and (#buttontext > maxchars) then
850+ if maxchars ~= nil and #buttontext > maxchars then
852851 local max_ratio = 1.25 -- up to 25% more chars while shrinking
853852 local limit = math.max(0, math.floor(maxchars * max_ratio) - 3)
854− if (#buttontext > limit) then
853+ if #buttontext > limit then
855854 while (#buttontext > limit) do
856855 buttontext = buttontext:gsub(".[\128-\191]*$", "")
857856 end
@@ -1007,7 +1006,7 @@ function new_element(name, type) · 149 unmodified lines
10071006 elements[name].styledown = (type == "button")
10081007 elements[name].state = {}
10091008
1010− if (type == "slider") then
1009+ if type == "slider" then
10111010 elements[name].slider = {min = {value = 0}, max = {value = 100}}
10121011 end
10131012
@@ -1016,7 +1015,7 @@ function new_element(name, type) · 2 unmodified lines
10161015 end
10171016
10181017 function add_layout(name)
1019− if not (elements[name] == nil) then
1018+ if elements[name] ~= nil then
10201019 -- new layout
10211020 elements[name].layout = {}
10221021
@@ -1024,11 +1023,11 @@ function add_layout(name) · 1 unmodified line
10241023 elements[name].layout.layer = 50
10251024 elements[name].layout.alpha = {[1] = 0, [2] = 255, [3] = 255, [4] = 255}
10261025
1027− if (elements[name].type == "button") then
1026+ if elements[name].type == "button" then
10281027 elements[name].layout.button = {
10291028 maxchars = nil,
10301029 }
1031− elseif (elements[name].type == "slider") then
1030+ elseif elements[name].type == "slider" then
10321031 -- slider defaults
10331032 elements[name].layout.slider = {
10341033 border = 1,
@@ -1041,7 +1040,7 @@ function add_layout(name) · 6 unmodified lines
10411040 tooltip_an = 2,
10421041 alpha = {[1] = 0, [2] = 255, [3] = 88, [4] = 255},
10431042 }
1044− elseif (elements[name].type == "box") then
1043+ elseif elements[name].type == "box" then
10451044 elements[name].layout.box = {radius = 0, hexagon = false}
10461045 end
10471046
@@ -1196,8 +1195,8 @@ layouts["box"] = function () · 148 unmodified lines
11961195 }
11971196
11981197 -- make sure the OSC actually fits into the video
1199− 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_aspect
1198+ if osc_param.playresx < (osc_geo.w + (2 * osc_geo.p)) then
1199+ osc_param.playresy = (osc_geo.w + (2 * osc_geo.p)) / osc_param.display_aspect
12011200 osc_param.playresx = osc_param.playresy * osc_param.display_aspect
12021201 end
12031202
@@ -1371,8 +1370,8 @@ layouts["slimbox"] = function () · 167 unmodified lines
13711370 }
13721371
13731372 -- make sure the OSC actually fits into the video
1374− if (osc_param.playresx < (osc_geo.w)) then
1375− osc_param.playresy = (osc_geo.w)/osc_param.display_aspect
1373+ if osc_param.playresx < (osc_geo.w) then
1374+ osc_param.playresy = (osc_geo.w) / osc_param.display_aspect
13761375 osc_param.playresx = osc_param.playresy * osc_param.display_aspect
13771376 end
13781377
@@ -1423,7 +1422,7 @@ layouts["slimbox"] = function () · 44 unmodified lines
14231422 lo.style = osc_styles.box
14241423 lo.alpha[1] = user_opts.boxalpha
14251424 lo.alpha[3] = 0
1426− if not (user_opts["seekbarstyle"] == "bar") then
1425+ if user_opts["seekbarstyle"] ~= "bar" then
14271426 lo.box.radius = osc_geo.r
14281427 lo.box.hexagon = user_opts["seekbarstyle"] == "diamond"
14291428 end
@@ -1505,7 +1504,7 @@ function bar_layout(direction) · 75 unmodified lines
15051504 padwc_r = window_control_box_width
15061505 end
15071506
1508− if ((osc_param.display_aspect > 0) and (osc_param.playresx < minW)) then
1507+ if osc_param.display_aspect > 0 and osc_param.playresx < minW then
15091508 osc_param.playresy = minW / osc_param.display_aspect
15101509 osc_param.playresx = osc_param.playresy * osc_param.display_aspect
15111510 end
@@ -1654,7 +1653,7 @@ function bar_layout(direction) · 142 unmodified lines
16541653 lo.style = osc_styles.timecodesBar
16551654 lo.alpha[1] =
16561655 math.min(255, user_opts.boxalpha + (255 - user_opts.boxalpha)*0.8)
1657− if not (user_opts["seekbarstyle"] == "bar") then
1656+ if user_opts["seekbarstyle"] ~= "bar" then
16581657 lo.box.radius = geo.h / 2
16591658 lo.box.hexagon = user_opts["seekbarstyle"] == "diamond"
16601659 end
@@ -1749,7 +1748,7 @@ function osc_init() · 88 unmodified lines
17491748 local display_w, display_h, display_aspect = mp.get_osd_size()
17501749 local scale = 1
17511750
1752− if (mp.get_property("video") == "no") then -- dummy/forced window
1751+ if mp.get_property("video") == "no" then -- dummy/forced window
17531752 scale = user_opts.scaleforcedwindow
17541753 elseif state.fullscreen then
17551754 scale = user_opts.scalefullscreen
@@ -1763,7 +1762,7 @@ function osc_init() · 7 unmodified lines
17631762 osc_param.unscaled_y = display_h
17641763 end
17651764 osc_param.playresy = osc_param.unscaled_y / scale
1766− if (display_aspect > 0) then
1765+ if display_aspect > 0 then
17671766 osc_param.display_aspect = display_aspect
17681767 end
17691768 osc_param.playresx = osc_param.playresy * osc_param.display_aspect
@@ -1797,7 +1796,7 @@ function osc_init() · 27 unmodified lines
17971796
17981797 ne.eventresponder["mbtn_left_up"] = function ()
17991798 local title = mp.get_property_osd("media-title")
1800− if (have_pl) then
1799+ if have_pl then
18011800 title = string.format("[%d/%d] %s", countone(pl_pos - 1),
18021801 pl_count, title)
18031802 end
@@ -1926,7 +1925,7 @@ function osc_init() · 122 unmodified lines
19261925 ne.enabled = (#tracks_osc.audio > 0)
19271926 ne.content = function ()
19281927 local aid = "–"
1929− if not (get_track("audio") == 0) then
1928+ if get_track("audio") ~= 0 then
19301929 aid = get_track("audio")
19311930 end
19321931 return ("\238\132\134" .. osc_styles.smallButtonsLlabel
@@ -1949,7 +1948,7 @@ function osc_init() · 16 unmodified lines
19491948 ne.enabled = (#tracks_osc.sub > 0)
19501949 ne.content = function ()
19511950 local sid = "–"
1952− if not (get_track("sub") == 0) then
1951+ if get_track("sub") ~= 0 then
19531952 sid = get_track("sub")
19541953 end
19551954 return ("\238\132\135" .. osc_styles.smallButtonsLlabel
@@ -1969,7 +1968,7 @@ function osc_init() · 13 unmodified lines
19691968 --tog_fs
19701969 ne = new_element("tog_fs", "button")
19711970 ne.content = function ()
1972− if (state.fullscreen) then
1971+ if state.fullscreen then
19731972 return ("\238\132\137")
19741973 else
19751974 return ("\238\132\136")
@@ -1981,11 +1980,11 @@ function osc_init() · 5 unmodified lines
19811980 --seekbar
19821981 ne = new_element("seekbar", "slider")
19831982
1984− ne.enabled = not (mp.get_property("percent-pos") == nil)
1983+ ne.enabled = mp.get_property("percent-pos") ~= nil
19851984 state.slider_element = ne.enabled and ne or nil -- used for forced_title
19861985 ne.slider.markerF = function ()
19871986 local duration = mp.get_property_number("duration", nil)
1988− if not (duration == nil) then
1987+ if duration ~= nil then
19891988 local chapters = mp.get_property_native("chapter-list", {})
19901989 local markers = {}
19911990 for n = 1, #chapters do
@@ -2000,7 +1999,7 @@ function osc_init() · 8 unmodified lines
20001999 function () return mp.get_property_number("percent-pos", nil) end
20012000 ne.slider.tooltipF = function (pos)
20022001 local duration = mp.get_property_number("duration", nil)
2003− if not ((duration == nil) or (pos == nil)) then
2002+ if duration ~= nil and pos ~= nil then
20042003 possec = duration * (pos / 100)
20052004 return mp.format_time(possec)
20062005 else
@@ -2016,7 +2015,7 @@ function osc_init() · 9 unmodified lines
20162015 return nil
20172016 end
20182017 local duration = mp.get_property_number("duration", nil)
2019− if (duration == nil) or duration <= 0 then
2018+ if duration == nil or duration <= 0 then
20202019 return nil
20212020 end
20222021 local ranges = cache_state["seekable-ranges"]
@@ -2038,8 +2037,8 @@ function osc_init() · 15 unmodified lines
20382037 -- sent when the user is done seeking, so we need to throw away
20392038 -- identical seeks
20402039 local seekto = get_slider_value(element)
2041− if (element.state.lastseek == nil) or
2042− (not (element.state.lastseek == seekto)) then
2040+ if element.state.lastseek == nil or
2041+ element.state.lastseek ~= seekto then
20432042 local flags = "absolute-percent"
20442043 if not user_opts.seekbarkeyframes then
20452044 flags = flags .. "+exact"
@@ -2064,7 +2063,7 @@ function osc_init() · 18 unmodified lines
20642063 ne = new_element("tc_left", "button")
20652064
20662065 ne.content = function ()
2067− if (state.tc_ms) then
2066+ if state.tc_ms then
20682067 return (mp.get_property_osd("playback-time/full"))
20692068 else
20702069 return (mp.get_property_osd("playback-time"))
@@ -2080,7 +2079,7 @@ function osc_init() · 9 unmodified lines
20802079
20812080 ne.visible = (mp.get_property_number("duration", 0) > 0)
20822081 ne.content = function ()
2083− if (state.rightTC_trem) then
2082+ if state.rightTC_trem then
20842083 local minus = user_opts.unicodeminus and UNICODE_MINUS or "-"
20852084 local property = user_opts.remaining_playtime and "playtime-remaining"
20862085 or "time-remaining"
@@ -2174,7 +2173,7 @@ function update_margins() · 87 unmodified lines
21742173 local margins = osc_param.video_margins
21752174
21762175 -- Don't use margins if it's visible only temporarily.
2177− if (not state.osc_visible) or (get_hidetimeout() >= 0) or
2176+ if not state.osc_visible or get_hidetimeout() >= 0 or
21782177 (state.fullscreen and not user_opts.showfullscreen) or
21792178 (not state.fullscreen and not user_opts.showwindowed)
21802179 then
@@ -2196,7 +2195,7 @@ function update_margins() · 15 unmodified lines
21962195 if not margins_used then
21972196 for _, opt in ipairs(margins_opts) do
21982197 local v = margins[opt[1]]
2199− if (v ~= 0) or state.using_video_margins then
2198+ if v ~= 0 or state.using_video_margins then
22002199 mp.set_property_number(opt[2], v)
22012200 state.using_video_margins = true
22022201 end
@@ -2229,7 +2228,7 @@ function show_osc() · 26 unmodified lines
22292228
22302229 osc_visible(true)
22312230
2232− if (user_opts.fadeduration > 0) then
2231+ if user_opts.fadeduration > 0 then
22332232 state.anitype = nil
22342233 end
22352234 end
@@ -2241,8 +2240,8 @@ function hide_osc() · 5 unmodified lines
22412240 -- no-op and won't render again to remove the osc, so do that manually.
22422241 state.osc_visible = false
22432242 render_wipe()
2244− elseif (user_opts.fadeduration > 0) then
2245− if not(state.osc_visible == false) then
2243+ elseif user_opts.fadeduration > 0 then
2244+ if state.osc_visible then
22462245 state.anitype = "out"
22472246 request_tick()
22482247 end
@@ -2324,8 +2323,8 @@ function render() · 75 unmodified lines
23242323 local now = mp.get_time()
23252324
23262325 -- check if display changed, if so request reinit
2327− if not (state.mp_screen_sizeX == current_screen_sizeX
2328− and state.mp_screen_sizeY == current_screen_sizeY) then
2326+ if state.mp_screen_sizeX ~= current_screen_sizeX
2327+ or state.mp_screen_sizeY ~= current_screen_sizeY then
23292328
23302329 request_init_resize()
23312330
@@ -2355,27 +2354,27 @@ function render() · 23 unmodified lines
23552354
23562355
23572356 -- fade animation
2358− if not(state.anitype == nil) then
2357+ if state.anitype ~= nil then
23592358
2360− if (state.anistart == nil) then
2359+ if state.anistart == nil then
23612360 state.anistart = now
23622361 end
23632362
2364− if (now < state.anistart + (user_opts.fadeduration/1000)) then
2363+ if now < state.anistart + (user_opts.fadeduration / 1000) then
23652364
2366− if (state.anitype == "in") then --fade in
2365+ if state.anitype == "in" then --fade in
23672366 osc_visible(true)
23682367 state.animation = scale_value(state.anistart,
2369− (state.anistart + (user_opts.fadeduration/1000)),
2368+ (state.anistart + (user_opts.fadeduration / 1000)),
23702369 255, 0, now)
2371− elseif (state.anitype == "out") then --fade out
2370+ elseif state.anitype == "out" then --fade out
23722371 state.animation = scale_value(state.anistart,
2373− (state.anistart + (user_opts.fadeduration/1000)),
2372+ (state.anistart + (user_opts.fadeduration / 1000)),
23742373 0, 255, now)
23752374 end
23762375
23772376 else
2378− if (state.anitype == "out") then
2377+ if state.anitype == "out" then
23792378 osc_visible(false)
23802379 end
23812380 kill_animation()
@@ -2413,7 +2412,7 @@ function render() · 31 unmodified lines
24132412 state.input_enabled = state.osc_visible
24142413 end
24152414
2416− if (mouse_hit_coords(cords.x1, cords.y1, cords.x2, cords.y2)) then
2415+ if mouse_hit_coords(cords.x1, cords.y1, cords.x2, cords.y2) then
24172416 mouse_over_osc = true
24182417 end
24192418 end
@@ -2432,7 +2431,7 @@ function render() · 12 unmodified lines
24322431 state.windowcontrols_buttons = state.osc_visible
24332432 end
24342433
2435− if (mouse_hit_coords(cords.x1, cords.y1, cords.x2, cords.y2)) then
2434+ if mouse_hit_coords(cords.x1, cords.y1, cords.x2, cords.y2) then
24362435 mouse_over_osc = true
24372436 end
24382437 end
@@ -2440,17 +2439,17 @@ function render() · 1 unmodified line
24402439
24412440 if osc_param.areas["window-controls-title"] then
24422441 for _,cords in ipairs(osc_param.areas["window-controls-title"]) do
2443− if (mouse_hit_coords(cords.x1, cords.y1, cords.x2, cords.y2)) then
2442+ if mouse_hit_coords(cords.x1, cords.y1, cords.x2, cords.y2) then
24442443 mouse_over_osc = true
24452444 end
24462445 end
24472446 end
24482447
24492448 -- autohide
2450− if not (state.showtime == nil) and (get_hidetimeout() >= 0) then
2451− local timeout = state.showtime + (get_hidetimeout()/1000) - now
2449+ if state.showtime ~= nil and get_hidetimeout() >= 0 then
2450+ local timeout = state.showtime + (get_hidetimeout() / 1000) - now
24522451 if timeout <= 0 then
2453− if (state.active_element == nil) and not (mouse_over_osc) then
2452+ if state.active_element == nil and not mouse_over_osc then
24542453 hide_osc()
24552454 end
24562455 else
@@ -2544,8 +2543,8 @@ function process_event(source, what) · 87 unmodified lines
25442543 state.mouse_in_window = true
25452544
25462545 local mouseX, mouseY = get_virt_mouse_pos()
2547− if (user_opts.minmousemove == 0) or
2548− (not ((state.last_mouseX == nil) or (state.last_mouseY == nil)) and
2546+ if user_opts.minmousemove == 0 or
2547+ ((state.last_mouseX ~= nil and state.last_mouseY ~= nil) and
25492548 ((math.abs(mouseX - state.last_mouseX) >= user_opts.minmousemove)
25502549 or (math.abs(mouseY - state.last_mouseY) >= user_opts.minmousemove)
25512550 )
@@ -2597,9 +2596,9 @@ function tick() · 45 unmodified lines
25972596 state.marginsREQ = false
25982597 end
25992598
2600− if (not state.enabled) then return end
2599+ if not state.enabled then return end
26012600
2602− if (state.idle) then
2601+ if state.idle then
26032602
26042603 -- render idle message
26052604 msg.trace("idle message")
@@ -2645,7 +2644,7 @@ function tick() · 39 unmodified lines
26452644 end
26462645
26472646
2648− elseif (state.fullscreen and user_opts.showfullscreen)
2647+ elseif state.fullscreen and user_opts.showfullscreen
26492648 or (not state.fullscreen and user_opts.showwindowed) then
26502649
26512650 -- render the OSC
@@ -2708,7 +2707,7 @@ function update_duration_watch() · 56 unmodified lines
27082707 (mp.get_property_number("chapters", 0) or 0) > 0 and
27092708 true or false -- ensure it's a boolean
27102709
2711− if (want_watch ~= duration_watched) then
2710+ if want_watch ~= duration_watched then
27122711 if want_watch then
27132712 mp.observe_property("duration", nil, on_duration)
27142713 else
player/lua/stats.lua+3−3
@@ -1092,7 +1092,7 @@ local function cache_stats() · 1091 unmodified lines
10921092 append(stats, opt_time(a) .. " - " .. opt_time(b), {prefix = "Packet queue:"})
10931093
10941094 local r = nil
1095− if (a ~= nil) and (b ~= nil) then
1095+ if a ~= nil and b ~= nil then
10961096 r = b - a
10971097 end
10981098
@@ -1174,7 +1174,7 @@ local function record_cache_stats() · 75 unmodified lines
11741174
11751175 local a = info["reader-pts"]
11761176 local b = info["cache-end"]
1177− if (a ~= nil) and (b ~= nil) then
1177+ if a ~= nil and b ~= nil then
11781178 graph_add_value(cache_ahead_buf, b - a)
11791179 end
11801180
@@ -1274,7 +1274,7 @@ local function unbind_scroll() · 93 unmodified lines
12741274 end
12751275 end
12761276 local function update_scroll_bindings(k)
1277− if (pages[k].scroll) then
1277+ if pages[k].scroll then
12781278 bind_scroll()
12791279 else
12801280 unbind_scroll()
player/lua/ytdl_hook.lua+40−40
@@ -357,7 +357,7 @@ local function join_url(base_url, fragment) · 356 unmodified lines
357357 end
358358
359359 local function edl_track_joined(fragments, protocol, is_live, base)
360− if not (type(fragments) == "table") or not fragments[1] then
360+ if type(fragments) ~= "table" or not fragments[1] then
361361 msg.debug("No fragments to join into EDL")
362362 return nil
363363 end
@@ -366,7 +366,7 @@ local function edl_track_joined(fragments, protocol, is_live, base) · 2 unmodified lines
366366 local offset = 1
367367 local parts = {}
368368
369− if (protocol == "http_dash_segments") and not is_live then
369+ if protocol == "http_dash_segments" and not is_live then
370370 msg.debug("Using dash")
371371 local args = ""
372372
@@ -674,7 +674,7 @@ local function add_single_video(json) · 301 unmodified lines
674674 end
675675 end
676676
677− if (not res) and has_requested_formats then
677+ if not res and has_requested_formats then
678678 format_info = "youtube-dl (separate)"
679679 res = formats_to_edl(json, requested_formats, false)
680680 end
@@ -721,7 +721,7 @@ local function add_single_video(json) · 40 unmodified lines
721721 end
722722
723723 -- add subtitles
724− if not (json.requested_subtitles == nil) then
724+ if json.requested_subtitles ~= nil then
725725 local subs = {}
726726 for lang, info in pairs(json.requested_subtitles) do
727727 subs[#subs + 1] = {lang = lang or "-", info = info}
@@ -733,14 +733,14 @@ local function add_single_video(json) · 5 unmodified lines
733733
734734 local sub = nil
735735
736− if not (sub_info.data == nil) then
736+ if sub_info.data ~= nil then
737737 sub = "memory://"..sub_info.data
738− elseif not (sub_info.url == nil) and
738+ elseif sub_info.url ~= nil and
739739 url_is_safe(sub_info.url) then
740740 sub = sub_info.url
741741 end
742742
743− if not (sub == nil) then
743+ if sub ~= nil then
744744 local edl = "edl://!no_clip;!delay_open,media_type=sub"
745745 local codec = map_codec_to_mpv(sub_info.ext)
746746 if codec then
@@ -756,15 +756,15 @@ local function add_single_video(json) · 9 unmodified lines
756756 end
757757
758758 -- add thumbnails
759− if (o.thumbnails == 'all' or o.thumbnails == 'best') and not (json.thumbnails == nil) then
759+ if (o.thumbnails == 'all' or o.thumbnails == 'best') and json.thumbnails ~= nil then
760760 local thumb = nil
761761 local thumb_height = -1
762762 local thumb_preference = nil
763763
764764 for i = #json.thumbnails, 1, -1 do
765765 local thumb_info = json.thumbnails[i]
766− if not (thumb_info.url == nil) then
767− if (o.thumbnails == 'all') then
766+ if thumb_info.url ~= nil then
767+ if o.thumbnails == 'all' then
768768 msg.verbose("adding thumbnail")
769769 mp.commandv("video-add", thumb_info.url, "auto")
770770 thumb_height = 0
@@ -777,10 +777,10 @@ local function add_single_video(json) · 6 unmodified lines
777777 end
778778 end
779779
780− if not (thumb == nil) then
780+ if thumb ~= nil then
781781 msg.verbose("adding thumbnail")
782782 mp.commandv("video-add", thumb, "auto")
783− elseif (thumb_height == -1) then
783+ elseif thumb_height == -1 then
784784 msg.verbose("No thumbnail url")
785785 end
786786 end
@@ -796,12 +796,12 @@ local function add_single_video(json) · 9 unmodified lines
796796 end
797797 table.insert(chapter_list, {time=chapter.start_time, title=title})
798798 end
799− elseif not (json.description == nil) and not (json.duration == nil) then
799+ elseif json.description ~= nil and json.duration ~= nil then
800800 chapter_list = extract_chapters(json.description, json.duration)
801801 end
802802
803803 -- set start time
804− if (json.start_time or json.section_start) and
804+ if json.start_time or json.section_start and
805805 not option_was_set("start") and
806806 not option_was_set_locally("start") then
807807 local start_time = json.start_time or json.section_start
@@ -810,7 +810,7 @@ local function add_single_video(json) · 2 unmodified lines
810810 end
811811
812812 -- set end time
813− if (json.end_time or json.section_end) and
813+ if json.end_time or json.section_end and
814814 not option_was_set("end") and
815815 not option_was_set_locally("end") then
816816 local end_time = json.end_time or json.section_end
@@ -819,7 +819,7 @@ local function add_single_video(json) · 2 unmodified lines
819819 end
820820
821821 -- set aspect ratio for anamorphic video
822− if not (json.stretched_ratio == nil) and
822+ if json.stretched_ratio ~= nil and
823823 not option_was_set("video-aspect-override") then
824824 mp.set_property('file-local-options/video-aspect-override', json.stretched_ratio)
825825 end
@@ -827,7 +827,7 @@ local function add_single_video(json) · 1 unmodified line
827827 local stream_opts = mp.get_property_native("file-local-options/stream-lavf-o", {})
828828
829829 -- for rtmp
830− if (json.protocol == "rtmp") then
830+ if json.protocol == "rtmp" then
831831 stream_opts = append_libav_opt(stream_opts,
832832 "rtmp_tcurl", streamurl)
833833 stream_opts = append_libav_opt(stream_opts,
@@ -869,12 +869,12 @@ local function check_version(ytdl_path) · 35 unmodified lines
869869 local year, month, day = string.match(version_string, "(%d+).(%d+).(%d+)")
870870
871871 -- sanity check
872− if (tonumber(year) < 2000) or (tonumber(month) > 12) or
873− (tonumber(day) > 31) then
872+ if tonumber(year) < 2000 or tonumber(month) > 12 or
873+ tonumber(day) > 31 then
874874 return
875875 end
876876 local version_ts = os.time{year=year, month=month, day=day}
877− if (os.difftime(os.time(), version_ts) > 60*60*24*90) then
877+ if os.difftime(os.time(), version_ts) > 60*60*24*90 then
878878 msg.warn("It appears that your youtube-dl version is severely out of date.")
879879 end
880880 end
@@ -883,7 +883,7 @@ function run_ytdl_hook(url) · 2 unmodified lines
883883 local start_time = os.clock()
884884
885885 -- strip ytdl://
886− if (url:find("ytdl://") == 1) then
886+ if url:find("ytdl://") == 1 then
887887 url = url:sub(8)
888888 end
889889
@@ -900,12 +900,12 @@ function run_ytdl_hook(url) · 10 unmodified lines
900900
901901 -- Checks if video option is "no", change format accordingly,
902902 -- but only if user didn't explicitly set one
903− if (mp.get_property("options/vid") == "no") and (#format == 0) then
903+ if mp.get_property("options/vid") == "no" and #format == 0 then
904904 format = "bestaudio/best"
905905 msg.verbose("Video disabled. Only using audio")
906906 end
907907
908− if (format == "") then
908+ if format == "" then
909909 format = "bestvideo+bestaudio/best"
910910 end
911911
@@ -916,19 +916,19 @@ function run_ytdl_hook(url) · 4 unmodified lines
916916
917917 for param, arg in pairs(raw_options) do
918918 table.insert(command, "--" .. param)
919− if (arg ~= "") then
919+ if arg ~= "" then
920920 table.insert(command, arg)
921921 end
922922 if (param == "sub-lang" or param == "sub-langs" or param == "srt-lang") and (arg ~= "") then
923923 allsubs = false
924− elseif (param == "proxy") and (arg ~= "") then
924+ elseif param == "proxy" and arg ~= "" then
925925 proxy = arg
926− elseif (param == "yes-playlist") then
926+ elseif param == "yes-playlist" then
927927 use_playlist = true
928928 end
929929 end
930930
931− if (allsubs == true) then
931+ if allsubs == true then
932932 table.insert(command, "--all-subs")
933933 end
934934 if not use_playlist then
@@ -989,7 +989,7 @@ function run_ytdl_hook(url) · 54 unmodified lines
989989 json, parse_err = utils.parse_json(json)
990990 end
991991
992− if (json == nil) then
992+ if json == nil then
993993 msg.verbose("status:", result.status)
994994 msg.verbose("reason:", result.error_string)
995995 msg.verbose("stdout:", result.stdout)
@@ -1023,11 +1023,11 @@ function run_ytdl_hook(url) · 27 unmodified lines
10231023 -- direct URL, nothing to do
10241024 msg.verbose("Got direct URL")
10251025 return
1026− elseif (json["_type"] == "playlist")
1027− or (json["_type"] == "multi_video") then
1026+ elseif json["_type"] == "playlist" or
1027+ json["_type"] == "multi_video" then
10281028 -- a playlist
10291029
1030− if (#json.entries == 0) then
1030+ if #json.entries == 0 then
10311031 msg.warn("Got empty playlist, nothing to play.")
10321032 return
10331033 end
@@ -1065,19 +1065,19 @@ function run_ytdl_hook(url) · 31 unmodified lines
10651065 -- there might not be subs for the first segment
10661066 local entry_wsubs = nil
10671067 for i, entry in pairs(json.entries) do
1068− if not (entry.requested_subtitles == nil) then
1068+ if entry.requested_subtitles ~= nil then
10691069 entry_wsubs = i
10701070 break
10711071 end
10721072 end
10731073
1074− if not (entry_wsubs == nil) and
1075− not (json.entries[entry_wsubs].duration == nil) then
1074+ if entry_wsubs ~= nil and
1075+ json.entries[entry_wsubs].duration ~= nil then
10761076 for j, req in pairs(json.entries[entry_wsubs].requested_subtitles) do
10771077 local subfile = "edl://"
10781078 for i, entry in pairs(json.entries) do
1079− if not (entry.requested_subtitles == nil) and
1080− not (entry.requested_subtitles[j] == nil) and
1079+ if entry.requested_subtitles ~= nil and
1080+ entry.requested_subtitles[j] ~= nil and
10811081 url_is_safe(entry.requested_subtitles[j].url) then
10821082 subfile = subfile..edl_escape(entry.requested_subtitles[j].url)
10831083 else
@@ -1100,7 +1100,7 @@ function run_ytdl_hook(url) · 16 unmodified lines
11001100 local site = entry.url
11011101 local title = entry.title
11021102
1103− if not (title == nil) then
1103+ if title ~= nil then
11041104 title = string.gsub(title, '%s+', ' ')
11051105 table.insert(playlist, "#EXTINF:0," .. title)
11061106 end
@@ -1151,11 +1151,11 @@ function run_ytdl_hook(url) · 44 unmodified lines
11511151 msg.debug('script running time: '..os.clock()-start_time..' seconds')
11521152 end
11531153
1154−if (not o.try_ytdl_first) then
1154+if not o.try_ytdl_first then
11551155 mp.add_hook("on_load", 10, function ()
11561156 msg.verbose('ytdl:// hook')
11571157 local url = mp.get_property("stream-open-filename", "")
1158− if not (url:find("ytdl://") == 1) then
1158+ if url:find("ytdl://") ~= 1 then
11591159 msg.verbose('not a ytdl:// url')
11601160 return
11611161 end
@@ -1174,7 +1174,7 @@ end) · 12 unmodified lines
11741174 mp.add_hook(o.try_ytdl_first and "on_load" or "on_load_fail", 10, function()
11751175 msg.verbose('full hook')
11761176 local url = mp.get_property("stream-open-filename", "")
1177− if not (url:find("ytdl://") == 1) and
1177+ if url:find("ytdl://") ~= 1 and
11781178 not ((url:find("https?://") == 1) and not is_blacklisted(url)) then
11791179 return
11801180 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