Skip to content

Instantly share code, notes, and snippets.

@MaxEtMoritz
Created November 8, 2023 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaxEtMoritz/dd0725c4ff293b7564107e2e1962ae50 to your computer and use it in GitHub Desktop.
Save MaxEtMoritz/dd0725c4ff293b7564107e2e1962ae50 to your computer and use it in GitHub Desktop.
VLC Lua script to extract artist and title metadata from the filename
--[[
Tries to extract artist and title from the filename.
Expected file name format: <artist> - <title>.ext
Usage: put this script inside <vlc-dir>/lua/meta/fetcher folder (create if not present).
If a music file is opened without meta tags, the script analyzes the filename and, if the pattern applies, sets the extracted artist and title info as metadata.
--]]
function descriptor()
return { scope="local" }
end
function fetch_meta()
local metas = vlc.item:metas()
-- Don't do anything if there is already a title or artist
if metas["title"] or metas["artist"] then
return
end
local name = metas["filename"];
if not name then
return
end
-- Find "artist - title.ext"
_, _, artist, title = string.find(name, "^(.+) %- (.+)%..+$")
if not artist or not title then
return
end
vlc.item:set_meta("title", title)
vlc.item:set_meta("artist", artist)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment