Auto-select flac or mp3 script for VLC Player (.lua)

52 views Asked by At

I have my music collection organized like ...\Artist\Album\ folder hierarchies. The albums contain the songs as .mp3 files plus cover.jpg. Now I want to add the same songs as .flac files to these folders, like

track01.flac track01.mp3 track02.flac track02.mp3

I mainly use VLC Player to play the files and start the playback by right-clicking artist or album folders in Windows Explorer. I want to add a .lua script to VLC that then checks the folder for flac and mp3 files and if there are flac and mp3 of the same song only add the flac of that song to the playlist.

Now comes the hard part: I don't have a clue about lua scripting. So I asked ChatGPT for the code and it came up with the following:

function descriptor()
    return { title = "Auto Select (MP3/FLAC)", version = "1.0", author = "Your Name" }
end

function activate()
    local items = vlc.playlist.items()
    
    for _, item in ipairs(items) do
        local file_path = item.path

        if file_path:match("%.mp3$") then
            local flac_path = file_path:gsub("%.mp3$", ".flac")

            if vlc.io.exists(flac_path) then
                vlc.playlist.add({{path = flac_path}})
                vlc.playlist.play()
                break
            end
        end
    end
end

function close()
end

VLC does load that script (you can see it as a menu entry in VLC's View right below VLsub as well as in VLC's Tools > Plugins and Extensions > Active Extensions) but ...

  1. neither adds an entry to the folder's right click menu for selection to play flac or mp3 (ChatGPT claims it would do so, but from that code I wouldn't see how this is supposed to work ... there is no mention/implication of that function at all)

  2. nor does it add select flac over mp3. It still adds all files to the playlist.

ChatGPT suggested to activate Lua Scripts in VLC by replacing "dummy" by "LUA SD" (Service Discovery) in VLC's Tools > Preferences (ALL Settings) > Interface > Main Interface > LUA > Lua Interface, but that didn't change anything.

Anyone got a clue how I get the auto selection to work? The right-click menu entry would be nice, too, but I'd be totally fine without it either.

Additional Info:

  1. I do not want to solve the problem using playlists.
  2. The reason to have flac and mp3 of the same song in the same folder ... I use a Synology to store that archive and to make it available to several client hosts. The PCs in my network are supposed to playback the flac files. I further sync that collection to my notebook, which I'm using as mp3 player in my car as well as to my mobile phone to have music available over the day. Both the notebook and the phone are limited in available space, so there I want to limit the sync to mp3 only.
  3. I do not want mp3 and flac in different folder structures. That would become impossible to maintain.
0

There are 0 answers