Created
November 8, 2023 11:34
-
-
Save MaxEtMoritz/dd0725c4ff293b7564107e2e1962ae50 to your computer and use it in GitHub Desktop.
VLC Lua script to extract artist and title metadata from the filename
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
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