Saving last played file

Discuss your Lua playlist, album art and interface scripts.
Spider8411
New Cone
New Cone
Posts: 2
Joined: 23 Apr 2021 01:43

Saving last played file

Postby Spider8411 » 23 Apr 2021 01:56

Hello.

I am newbie at scripting vlc and I want to create the extension that do the following.

For minimum requirements I want that the extension every time when playing starts will write to file the name and path to file that started playing.
For full requirements I want store last played file name for every folder separately, save this info to file or database and output this in dialog box.

Is it possible with Lua?
Thanks.

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: Saving last played file

Postby mederi » 24 Apr 2021 14:11

Yes, it is. Have you already checked available extensions? Perhaps you can find something similar: https://addons.videolan.org

Legitosity
New Cone
New Cone
Posts: 1
Joined: 17 Apr 2021 23:15

Re: Saving last played file

Postby Legitosity » 30 Apr 2021 10:59

EDIT: wow I freaking figured it out minutes after posting when trying to save another lua file into the same folder. Running VLC as an administrator fixed the problem... I guess I could save the txt file somewhere in my documents folder since it will have to read/write every time a file is played.

I'm trying something similar, however io.output is throwing me an error.

Code: Select all

extfile = io.open(vlc.config.datadir().."\\lua\\extensions\\basic_history.txt", "r") if extfile == nil then extfile = io.output (vlc.config.datadir().."\\lua\\extensions\\basic_history.txt") extfile = io.open(vlc.config.datadir().."\\lua\\extensions\\basic_history.txt", "r") end

Specifically, VLC messages is throwing this error

Code: Select all

lua warning: Error while running script C:\Program Files\VideoLAN\VLC\lua\extensions\basic_history.lua, function activate(): ... Files\VideoLAN\VLC\lua\extensions\basic_history.lua:29: bad argument #1 to 'output' (C:\Program Files\VideoLAN\VLC\lua\extensions\basic_history.txt: Permission denied) lua error: Could not activate extension!
I'd like to just create a text file, and every time VLC opens a new file it appends the file name to the text file. Essentially creating a history.

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: Saving last played file

Postby mederi » 30 Apr 2021 13:27

You could use "vlc.io" instead of Lua's standard "io". It is available since VLC 3.0.2 and it solves a problem with non-ASCII characters.
Input/Output
------------
All path for this namespace are expected to be passed as UTF8 strings.

io.mkdir("path", "mode"): Similar to mkdir(2). The mode is passed as a string
to allow for octal representations. This returns a success code (non 0 in
case of failure), and a more specific error code as its 2nd returned value
in case of failure. The error code is to be used with vlc.errno
io.readdir("path"): Lists all files & directories in the provided folder.
io.open("path"[, "mode"]): Similar to lua's io.open. Mode is optional and
defaults to "r". It returns a file object with the following member functions:
.read
.write
.seek
.flush
.close
all of which are used exactly like the lua object returned by io.open
io.unlink("path"): Similar to os.remove. First return value is 0 in case
of success. In case of failure, the 2nd return parameter is an error
code to be compared against vlc.errno values.
Example:

Code: Select all

f = vlc.io.open(vlc.config.userdatadir().."/text_file.txt", "a+") if f then f:write("string".."\r\n") f:close() end


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 9 guests