Skip to content

Commit

Permalink
Use single quote throughout
Browse files Browse the repository at this point in the history
  • Loading branch information
CrendKing committed Dec 7, 2022
1 parent 9781453 commit e78c9d0
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ local o = {
local options = require 'mp.options'
options.read_options(o)

local utils = require "mp.utils"
local utils = require 'mp.utils'

-- sid to be operated on
local chat_sid
Expand All @@ -54,12 +54,12 @@ local seq_counter
-- timer to fetch new segments of the chat data
local timer
-- delimiters to specify where to allow lines to add graceful line breaks at
local delimiter_pattern = " %.,%-!%?"
local delimiter_pattern = ' %.,%-!%?'

local function split_string(input)
local splits = {}

for input in string.gmatch(input, "[^" .. delimiter_pattern .. "]+[" .. delimiter_pattern .. "]*") do
for input in string.gmatch(input, '[^' .. delimiter_pattern .. ']+[' .. delimiter_pattern .. ']*') do
table.insert(splits, input)
end

Expand All @@ -72,14 +72,14 @@ local function break_message_body(message_body)
end

local length_sofar = 0
local ret = ""
local ret = ''

for _, v in ipairs(split_string(message_body)) do
length_sofar = length_sofar + #v

if length_sofar > o.max_message_length then
-- assume #v is always < o.max_message_length for simplicity
ret = ret .. "\n" .. v
ret = ret .. '\n' .. v
length_sofar = #v
else
ret = ret .. v
Expand Down Expand Up @@ -108,38 +108,38 @@ local function load_twitch_chat(is_new_session)
}

if is_new_session then
local time_pos = mp.get_property_native("time-pos")
local time_pos = mp.get_property_native('time-pos')
if not time_pos then
return
end

request_body.variables.contentOffsetSeconds = math.max(math.floor(time_pos), 0)
next_segment = ""
next_segment = ''
seq_counter = 0
else
request_body.variables.cursor = twitch_cursor
end

local sp_ret = mp.command_native({
name = "subprocess",
name = 'subprocess',
capture_stdout = true,
args = {"curl", '--request', 'POST', "--header", "Client-ID: " .. o.twitch_client_id, '--data', utils.format_json(request_body), "--silent", TWITCH_GRAPHQL_URL},
args = {'curl', '--request', 'POST', '--header', 'Client-ID: ' .. o.twitch_client_id, '--data', utils.format_json(request_body), '--silent', TWITCH_GRAPHQL_URL},
})
if sp_ret.status ~= 0 then
mp.msg.error("Error curl exit code: " .. sp_ret.status)
mp.msg.error('Error curl exit code: ' .. sp_ret.status)
return
end

local resp_json = utils.parse_json(sp_ret.stdout)
local comments = resp_json.data.video.comments.edges
if not comments then
mp.msg.error("Failed to download comments JSON: " .. sp_ret.stdout)
mp.msg.error('Failed to download comments JSON: ' .. sp_ret.stdout)
return
end

twitch_cursor = comments[1].cursor
curr_segment = next_segment
next_segment = ""
next_segment = ''

local last_msg_offset = comments[#comments].node.contentOffsetSeconds
local segment_duration = last_msg_offset - comments[1].node.contentOffsetSeconds
Expand Down Expand Up @@ -169,20 +169,20 @@ local function load_twitch_chat(is_new_session)
if o.show_name then
msg_part_1 = curr_comment_node.commenter.displayName
msg_part_2 = break_message_body(msg_text)
msg_separator = ": "
msg_separator = ': '
else
msg_part_1 = break_message_body(msg_text)
msg_part_2 = ""
msg_separator = ""
msg_part_2 = ''
msg_separator = ''
end

if o.color then
if curr_comment_node.message.userColor then
msg_color = curr_comment_node.message.userColor
else
msg_color = string.format("#%06x", curr_comment_node.commenter.id % 16777216)
msg_color = string.format('#%06x', curr_comment_node.commenter.id % 16777216)
end
msg_part_1 = string.format("<font color=\"%s\">%s</font>", msg_color, msg_part_1)
msg_part_1 = string.format('<font color="%s">%s</font>', msg_color, msg_part_1)
end

local msg_line = msg_part_1 .. msg_separator .. msg_part_2
Expand All @@ -203,11 +203,11 @@ local function load_twitch_chat(is_new_session)
end

mp.command_native({
name = "sub-add",
url = "memory://" .. curr_segment .. next_segment,
title = "Twitch Chat"
name = 'sub-add',
url = 'memory://' .. curr_segment .. next_segment,
title = 'Twitch Chat'
})
chat_sid = mp.get_property_native("sid")
chat_sid = mp.get_property_native('sid')

return last_msg_offset
end
Expand All @@ -219,7 +219,7 @@ end
local function timer_callback(is_new_session)
local last_msg_offset = load_twitch_chat(is_new_session)
if last_msg_offset then
local fetch_delay = last_msg_offset - mp.get_property_native("time-pos") - o.fetch_aot
local fetch_delay = last_msg_offset - mp.get_property_native('time-pos') - o.fetch_aot
timer = mp.add_timeout(fetch_delay, function()
timer_callback(false)
end)
Expand All @@ -232,9 +232,9 @@ local function handle_track_change(name, sid)
timer = nil
elseif sid and not timer then
if not twitch_video_id then
local sub_filename = mp.get_property_native("current-tracks/sub/external-filename")
local sub_filename = mp.get_property_native('current-tracks/sub/external-filename')
if sub_filename then
twitch_video_id, twitch_client_id_from_track = sub_filename:match("https://api%.twitch%.tv/v5/videos/(%d+)/comments%?client_id=(%w+)")
twitch_video_id, twitch_client_id_from_track = sub_filename:match('https://api%.twitch%.tv/v5/videos/(%d+)/comments%?client_id=(%w+)')

if twitch_client_id_from_track and not o.twitch_client_id then
o.twitch_client_id = twitch_client_id_from_track
Expand All @@ -244,14 +244,14 @@ local function handle_track_change(name, sid)

if twitch_video_id then
chat_sid = sid
mp.command_native({"sub-remove", chat_sid})
mp.command_native({'sub-remove', chat_sid})
timer_callback(true)
end
end
end

local function handle_seek()
if mp.get_property_native("sid") then
if mp.get_property_native('sid') then
load_twitch_chat(true)
end
end
Expand All @@ -266,7 +266,7 @@ local function handle_pause(name, paused)
end
end

mp.register_event("start-file", init)
mp.observe_property("current-tracks/sub/id", "native", handle_track_change)
mp.register_event("seek", handle_seek)
mp.observe_property("pause", "native", handle_pause)
mp.register_event('start-file', init)
mp.observe_property('current-tracks/sub/id', 'native', handle_track_change)
mp.register_event('seek', handle_seek)
mp.observe_property('pause', 'native', handle_pause)

0 comments on commit e78c9d0

Please sign in to comment.