Basically, I am trying to edit the vlcrc
file(%APPDATA%vlcvlcrc
) from within the VLC > View > Edit the path for saving recordings menu item by running the below extension code file:
function descriptor()
return {
title = "VLC Edit Record Dir";
version = "0.0.1";
author = "vicky-dev";
shortdesc = "&Edit the path for saving recordings";
}
end
function main_fn()
local id = vlc.playlist.current()
local item = (vlc.player or vlc.input).item()
local uri = item:uri()
vlc.msg.dbg("[VLC Playing] Write File!")
local fname_tmp = item:uri():match("([^/\]*)$")
local file_name = vlc.strings.decode_uri(fname_tmp)
write_file(vlc.config.userdatadir().."n")
edit_vlcrc_file(file_name)
end
function activate()
main_fn()
end
function deactivate()
vlc.deactivate()
end
function close()
deactivate()
end
function write_file(data)
local file = vlc.config.userdatadir() .. "/VLC_Current_Playing.txt"
assert(os.remove(file))
vlc.msg.dbg("[VLC Playing] Write File!")
local VLCPlayingFile = vlc.config.userdatadir() .. "/VLC_Current_Playing.txt"
local file = io.open(VLCPlayingFile, "a+")
file:write('Current Media File: '..data)
file:close()
end
function edit_vlcrc_file(videoName)
local vlcRc = vlc.config.userdatadir() .. "\vlcrc"
write_file(vlcRc)
local file = io.open(vlcRc, "w+")
for line in io.lines(file) do
line:gsub("input-record-path*", "input-record-path=C:Users<Username>Videos<CustomFolder>".."\"..videoName)
end
-- file:write('Current Media File: '..data)
file:close()
end
Notice that I am getting the path of vlcrc file correctly, as you can see in the text file that I have made for debug purpose using write_file()
method.
But the code when trying to open vlcrc file for write mode (w+), it throws this error:
<codefile>.lua:47: bad argument #1 to 'lines' (string expected, got userdata)
Can anyone help out in understanding why it’s throwing that error on for line in io.lines(file) do
and fixing it therein ?