[Interface/Extension] Filename Forcer

Discuss your Lua playlist, album art and interface scripts.
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

[Interface/Extension] Filename Forcer

Postby mederi » 07 Jan 2017 22:07

The idea: forum topic Option to display FILE NAMES instead of META TAGS

Code: Select all

-- "looper_filename.lua" >> copy the script file into \lua\intf\ folder -- activate it in VLC preferences or use CLI options: -- vlc.exe --extraintf=luaintf{intf="looper_filename"} function Looper() local curi=nil local loops=0 -- counter of loops while true do if vlc.volume.get() == -256 then break end -- inspired by syncplay.lua; kills vlc.exe process in Task Manager if vlc.playlist.status()=="stopped" then -- no input or stopped input if curi then -- input stopped Log("stopped") curi=nil end loops=loops+1 Log(loops) Sleep(1) else -- playing, paused local uri=nil if vlc.input.item() then uri=vlc.input.item():uri() end if not uri then --- WTF (VLC 2.1+): status playing with nil input? Stopping? O.K. in VLC 2.0.x Log("WTF? " .. vlc.playlist.status()) Sleep(0.1) elseif not curi or curi~=uri then -- new input (first input or changed input) curi=uri Log(curi) else -- current input if vlc.playlist.status()=="playing" then FF(curi) --Log("playing") elseif vlc.playlist.status()=="paused" then --Log("paused") Sleep(0.3) else -- ? Log("unknown") Sleep(1) end Sleep(0.1) end end end end function Log(lm) vlc.msg.info("[looper_intf] " .. lm) end function Sleep(st) -- seconds vlc.misc.mwait(vlc.misc.mdate() + st*1000000) end --- FILENAME_FORCER --- function FF(curi) if string.sub(curi,1,8)=="file:///" then vlc.input.item():set_meta("title", vlc.strings.decode_uri(string.gsub(tostring(curi), "^.*/(.-)$","%1"))) Sleep(1) --Log("FF") end end --- XXX --- FILENAME_FORCER --- Looper()
More installation instructions: Time (looper_intf.lua)

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: [Interface] Filename Forcer

Postby mederi » 31 Jan 2017 23:01

[Extension]:

Code: Select all

-- "Filename_Forcer.lua" -- VLC Extension. -- Copy this script file into \lua\extensions\ folder. -- Then activate the extension in VLC menu "View > Filename Forcer" -- or "VLC > Extensions > Filename Forcer" on Mac OS X. function descriptor() return { title = "Filename Forcer", capabilities = {}, } end function activate() Create_dialog() end function deactivate() end function meta_changed() -- click_Filename_Forcer() collectgarbage() end function close() vlc.deactivate() end --------------------------- function Create_dialog() d = vlc.dialog(descriptor().title) d:add_button("Set title", click_Filename_Forcer, 1,1,1,1) end function click_Filename_Forcer() if vlc.input.item() then curi=vlc.input.item():uri() if curi and string.sub(curi,1,8)=="file:///" then filename=vlc.strings.decode_uri(string.gsub(tostring(curi), "^.*/(.-)$","%1")) vlc.input.item():set_meta("title", filename) end end end

ogilvierothchild
New Cone
New Cone
Posts: 6
Joined: 15 Apr 2020 16:28

Re: [Interface] Filename Forcer

Postby ogilvierothchild » 15 Apr 2020 16:38

Since the previous post wasn't working, despite most of the needed code being present, I've updated it to function properly. Tested on VLC 3.0.8 on Linux.

For context, this is a VLC extension that forces the 'title' field in the VLC Playlist and Media Library to be the filename of the media file, instead of being whatever is parsed out of the media fie metadata. This is written for local files and SMB files, though it's easy to update for other protocols also.

Paste the code below into a file called "filename_forcer_extn.lua" and move it to the VLC lua extensions folder; details in the 2-step procedure given in the comments at the top of the file.

Code: Select all

-- File: "filename_forcer_extn.lua" -- -- VLC Extension -- --[[ STEP 1/2: Copy this script file into VLC lua extensions folder. VLC folder path: Windows: *C:\Program Files\VideoLAN\VLC\lua\extensions* macOS: ~/Library/Application\ Support/org.videolan.vlc/lua/extensions/ Linux user path: /home/$USER/.local/share/vlc/lua/extensions Linux system path: /usr/share/vlc/lua/extensions On Linux, do mkdir -p ~/.local/share/vlc/lua/extensions and copy this file there, or to /usr/share/vlc/lua/extensions See also: https://www.vlchelp.com/install-vlc-media-player-addon/ STEP 2/2: Restart VLC Activate the extension in VLC menu "View > Filename Forcer" or "VLC > Extensions > Filename Forcer" on Mac OS X. If you dont see it, run vlc --verbose=2 to verify the extension is being loaded -- Modified from Filename_Forcer.lua by user mederi See: https://forum.videolan.org/viewtopic.php?f=29&t=136996 Tested on VLC 3.0.8 Changes: - removed useless dialog - removed recursive meta updates - added shortdesc so it shows in view menu - added support for smb:// - removed test for leading '/' in file uri's - re-enabled call to update function ]]-- -- levels : 0:no msgs, 1:on change, 2:debug local verbosity = 1 function descriptor() return { title = "Filename Forcer", version = "1.0", author = "maali", shortdesc = "Filename Forcer", capabilities = {"meta-listener", "input-listener"} -- capabilities = {} } end function activate() debug("activate") end function deactivate() debug("deactivate") end function input_changed() debug("input_changed") end function meta_changed() debug("meta_changed") filename_forcer() collectgarbage() end function close() debug("close") vlc.deactivate() end --------------------------- function filename_forcer() debug("checking") if vlc.input.item() then local curi = vlc.input.item():uri() debug("uri = '" .. curi .. "'") if curi and (string.sub(curi,1,7)=="file://" or string.sub(curi,1,6)=="smb://") then local filename = vlc.strings.decode_uri(string.gsub(tostring(curi), "^.*/(.-)$","%1")) debug("filename = '" .. filename .. "'") local s = vlc.input.item():metas()["title"] local original = s and s or "" debug("original = '" .. original .. "'") if original~=filename then vlc.input.item():set_meta("title", filename) report("*** update: set title to filename ***") end end end end --------------------------- function report(s) if verbosity > 0 then vlc.msg.info("filename_forcer: " .. s) end end function debug(s) if verbosity > 1 then vlc.msg.info("filename_forcer: " .. s) end end

jsn
New Cone
New Cone
Posts: 2
Joined: 08 Jul 2020 13:38

Re: [Interface] Filename Forcer

Postby jsn » 08 Jul 2020 14:31

Hi !

Thanks for your work here ! :D

I modified your code to fit my use, so I also added a feature to extract the files extensions from the files titles in the "genre" or "rating" column and extracted files titles in the "comment" column.



In the first code the files extensions are in the column "genre/style" and you can sort it alphabetically :

Code: Select all

-- File: "filename_forcer_extn.lua" -- -- VLC Extension -- --[[ STEP 1/2: Copy this script file into VLC lua extensions folder. VLC folder path: Windows: *C:\Program Files\VideoLAN\VLC\lua\extensions* macOS: ~/Library/Application\ Support/org.videolan.vlc/lua/extensions/ Linux user path: /home/$USER/.local/share/vlc/lua/extensions Linux system path: /usr/share/vlc/lua/extensions On Linux, do mkdir -p ~/.local/share/vlc/lua/extensions and copy this file there, or to /usr/share/vlc/lua/extensions See also: https://www.vlchelp.com/install-vlc-media-player-addon/ STEP 2/2: Restart VLC Activate the extension in VLC menu "View > Filename Forcer" or "VLC > Extensions > Filename Forcer" on Mac OS X. If you dont see it, run vlc --verbose=2 to verify the extension is being loaded -- Modified from Filename_Forcer.lua by user mederi See: https://forum.videolan.org/viewtopic.php?f=29&t=136996 Tested on VLC 3.0.8 Changes: - removed useless dialog - removed recursive meta updates - added shortdesc so it shows in view menu - added support for smb:// - removed test for leading '/' in file uri's - re-enabled call to update function ]]-- -- levels : 0:no msgs, 1:on change, 2:debug local verbosity = 1 function descriptor() return { file = "Filename Forcer", version = "1.0", author = "maali", shortdesc = "Filename Forcer", capabilities = {"meta-listener", "input-listener"} -- capabilities = {} } end function activate() debug("activate") end function deactivate() debug("deactivate") end function input_changed() debug("input_changed") end function meta_changed() debug("meta_changed") filename_forcer() collectgarbage() end function close() debug("close") vlc.deactivate() end --------------------------- function filename_forcer() debug("checking") if vlc.input.item() then local curi = vlc.input.item():uri() debug("uri = '" .. curi .. "'") if curi and (string.sub(curi,1,7)=="file://" or string.sub(curi,1,6)=="smb://") then local filename = vlc.strings.decode_uri(string.gsub(tostring(curi), "^.*/(.-)$","%1")) debug("filename = '" .. filename .. "'") local s = vlc.input.item():metas()["description"] local original = s and s or "" debug("original = '" .. original .. "'") if original~=filename then vlc.input.item():set_meta("description", filename) report("*** update: set description to filename ***") end local filename = string.sub(filename,-4) local filename = string.gsub(filename, "%W","") debug("filename = '" .. filename .. "'") local s = vlc.input.item():metas()["genre"] local original = s and s or "" debug("original = '" .. original .. "'") if original~=filename then vlc.input.item():set_meta("genre", filename) report("*** update: set genre to file extension ***") end end end end --------------------------- function report(s) if verbosity > 0 then vlc.msg.info("filename_forcer: " .. s) end end function debug(s) if verbosity > 1 then vlc.msg.info("filename_forcer: " .. s) end end

jsn
New Cone
New Cone
Posts: 2
Joined: 08 Jul 2020 13:38

Re: [Interface] Filename Forcer

Postby jsn » 08 Jul 2020 14:31

In the second code the files extensions are in the column "rating" and you can't sort it alphabetically !

Code: Select all

-- File: "filename_forcer_extn.lua" -- -- VLC Extension -- --[[ STEP 1/2: Copy this script file into VLC lua extensions folder. VLC folder path: Windows: *C:\Program Files\VideoLAN\VLC\lua\extensions* macOS: ~/Library/Application\ Support/org.videolan.vlc/lua/extensions/ Linux user path: /home/$USER/.local/share/vlc/lua/extensions Linux system path: /usr/share/vlc/lua/extensions On Linux, do mkdir -p ~/.local/share/vlc/lua/extensions and copy this file there, or to /usr/share/vlc/lua/extensions See also: https://www.vlchelp.com/install-vlc-media-player-addon/ STEP 2/2: Restart VLC Activate the extension in VLC menu "View > Filename Forcer" or "VLC > Extensions > Filename Forcer" on Mac OS X. If you dont see it, run vlc --verbose=2 to verify the extension is being loaded -- Modified from Filename_Forcer.lua by user mederi See: https://forum.videolan.org/viewtopic.php?f=29&t=136996 Tested on VLC 3.0.8 Changes: - removed useless dialog - removed recursive meta updates - added shortdesc so it shows in view menu - added support for smb:// - removed test for leading '/' in file uri's - re-enabled call to update function ]]-- -- levels : 0:no msgs, 1:on change, 2:debug local verbosity = 1 function descriptor() return { file = "Filename Forcer", version = "1.0", author = "maali", shortdesc = "Filename Forcer", capabilities = {"meta-listener", "input-listener"} -- capabilities = {} } end function activate() debug("activate") end function deactivate() debug("deactivate") end function input_changed() debug("input_changed") end function meta_changed() debug("meta_changed") filename_forcer() collectgarbage() end function close() debug("close") vlc.deactivate() end --------------------------- function filename_forcer() debug("checking") if vlc.input.item() then local curi = vlc.input.item():uri() debug("uri = '" .. curi .. "'") if curi and (string.sub(curi,1,7)=="file://" or string.sub(curi,1,6)=="smb://") then local filename = vlc.strings.decode_uri(string.gsub(tostring(curi), "^.*/(.-)$","%1")) debug("filename = '" .. filename .. "'") local s = vlc.input.item():metas()["description"] local original = s and s or "" debug("original = '" .. original .. "'") if original~=filename then vlc.input.item():set_meta("description", filename) report("*** update: set description to filename ***") end local filename = string.sub(filename,-4) local filename = string.gsub(filename, "%W","" ) debug("filename = '" .. filename .. "'") local s = vlc.input.item():metas()["rating"] local original = s and s or "" debug("original = '" .. original .. "'") if original~=filename then vlc.input.item():set_meta("rating", filename) report("*** update: set rating to file extension ***") end end end end --------------------------- function report(s) if verbosity > 0 then vlc.msg.info("filename_forcer: " .. s) end end function debug(s) if verbosity > 1 then vlc.msg.info("filename_forcer: " .. s) end end

MickeyKnox
New Cone
New Cone
Posts: 2
Joined: 01 Nov 2020 19:50

Re: [Interface] Filename Forcer

Postby MickeyKnox » 01 Nov 2020 20:01

I've copied the script from ogilvierothchild to Library/Application Support/org.videolan.vlc/lua/extensions/filename_forcer_extn.lua

After that I've clicked on VLC > Extensions > Filename Forcer

... and nothing happens. Absolutely nothing. Nothing changes.

I'm on MacOS Mojave and am running vlc 3.0.11.1

Some output from vlc --verbose=2:

[00007ff708e8b770] lua generic debug: Trying Lua scripts in /Users/ingmar/Library/Application Support/org.videolan.vlc/lua/extensions
[00007ff708e8b770] lua generic debug: Trying Lua playlist script /Users/ingmar/Library/Application Support/org.videolan.vlc/lua/extensions/filename_forcer_extn.lua
[00007ff708e8b770] lua generic debug: Scanning Lua script /Users/ingmar/Library/Application Support/org.videolan.vlc/lua/extensions/filename_forcer_extn.lua
[00007ff708e8b770] lua generic debug: Script /Users/ingmar/Library/Application Support/org.videolan.vlc/lua/extensions/filename_forcer_extn.lua has the following capability flags: 0xc

ogilvierothchild
New Cone
New Cone
Posts: 6
Joined: 15 Apr 2020 16:28

Re: [Interface] Filename Forcer

Postby ogilvierothchild » 02 Nov 2020 11:07

Unfortunately my only Mac is in my office, which has been closed for months. Could you retry with VLC 3.0.8 ? Also, change the line

Code: Select all

local verbosity = 1
to say

Code: Select all

local verbosity = 2
then paste in the log here. If the menu item showed up, at least we know it found the script.

Thanks!

MickeyKnox
New Cone
New Cone
Posts: 2
Joined: 01 Nov 2020 19:50

Re: [Interface] Filename Forcer

Postby MickeyKnox » 02 Nov 2020 23:04

Ok, I've changed local verbosity to 2 and ran vlc with --verbose=2. This is the output:

Well, not all of it, there was an error on the forum:
Your message contains 72480 characters.
The maximum number of allowed characters is 5998.
This is the output after clicking VLC > Extensions > Filename Forcer:

Code: Select all

[00007fab2bca8400] macosx interface debug: activating or triggering extension 'Filename Forcer', id 0 [00007fab2bf18db0] lua generic debug: Activating extension 'Filename Forcer' [00007fab2bf18db0] lua generic: filename_forcer: activate

ogilvierothchild
New Cone
New Cone
Posts: 6
Joined: 15 Apr 2020 16:28

Re: [Interface] Filename Forcer

Postby ogilvierothchild » 08 Nov 2020 17:41

You could use a pastebin and link to the log. There isn't enough there to determine anything.

I will retry next week when I get access to my Mac, but we'll see how it goes.

Thanks for the feedback!

ogilvierothchild
New Cone
New Cone
Posts: 6
Joined: 15 Apr 2020 16:28

Re: [Interface/Extension] Filename Forcer

Postby ogilvierothchild » 06 May 2021 04:45

I have tested the script I posted in VLC version 3.0.11.1 on all supported platforms.

Once the script is installed, it appears in the menu and must be manually activated on each VLC launch.

Please post the full log using pastebin and copy a link here if you're still having problems.


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 11 guests