Score:2

Problem with metaflac

jp flag

I can't seem to get the --with-filename tag to work in metaflac. It enumerates tags into a file just fine with this command:

metaflac --with-filename --export-tags-to=audio_tags.csv '/media/marcel/Archives2/Albums/Locatelli; Concerti Grossi, Op. 1, Nos. 1-6/Track 21.flac'

but I get no filename, just the tags:

title=2. Allegro
work=Concerto Grosso in D major, Op. 1, No. 5
ALBUM=Locatelli: Concerti Grossi, Op. 1, Nos. 1-6
ALBUMARTIST=Jaroslav Kreček, Capella Istropolitana
ARTIST=Jaroslav Kreček, Capella Istropolitana
BAND=Jaroslav Kreček, Capella Istropolitana
CATALOGUE=730099444521, 8.553445
COMPOSER=Pietro Antonio Locatelli
DISCNUMBER=1
TOTALDISCS=1
TOTALTRACKS=27
DATE=1996
ORGANIZATION=Naxos
TRACKNUMBER=21

Any help is much appreciated. Using Xubuntu 22.04

andrew.46 avatar
in flag
Indeed there seems to be an issue. I have placed a bug report with a similar case presentation here: https://github.com/xiph/flac/issues/537
OldFart avatar
jp flag
Great, thanks. (Thought it was me.) Meanwhile, I've managed a work-around by writing the filename out first, followed by the tags and a delimiter, then re-parsing.
andrew.46 avatar
in flag
You could incorporate the bug report and your work-around into a self accepted answer?
OldFart avatar
jp flag
Initially, I just wanted to load the result into a database table. The work-around involved coding, which I'm perfectly willing to post, but may not be suitable for some readers?
andrew.46 avatar
in flag
Sounds like it should be a great answer!
Score:1
jp flag

I've managed a work around, albeit via a PHP script, since the end goal was to bring the tags into a database served up by a web server. First, list all flac files to a text file:

find /media/marcel/Archives2/Albums -type f -name '*flac' > flac_files.txt

Using PHP, open the file for read, then get a database handle and prepare a PDO statement to write each filename:

$dbh = new PDO(<database_details>, <user>, <pw>, <persistent>);
$qry = "INSERT INTO temp (filename) VALUES (?)";
$stmt = $dbh->prepare($qry);
$flac = fopen('/media/marcel/Archives2/Albums/flac_files.txt', "r");

Now parse through each line in flac_files.txt, write the filename to the database using the prepared query, get the tag values into an array from a metaflac shell and write each in turn to the database:

    while (!feof($flac))    {
        $filename = rtrim(fgets($flac));
        $stmt = $dbh->bindParam(1, $filename);
        $stmt->execute();
        $tag_list = explode("\n", shell_exec('metaflac --export-tags-to=- "' . $filename . '"')) //explode on linefeed character;
        $c = count($tag_list);
        for ($i = 0 ; $i < $c ; $i++)   {
            $tag = explode('=', $tag_list[$i]);
            if ($tag[0])    { // no empty tags!
                $rec = "UPDATE albums.temp SET " . $tag[0] . " = '" . str_replace("'", "’", $tag[1]) . "' WHERE filename = '" . $filename . "'"; //no quotes, just real apostrophes
                $data = $dbh->query($rec);
            }
        }
    }

Quick & dirty, but works. Of course you will need to set up the temp table with the appropriate tags as column names in advance. Alternatively, you could write each filename out to a second file, followed by the tags retrieved from a metaflac command, then finish up each one with a delimiter, say "@" on its own line. Also tedious, but also works.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.