[mythtv] Re: [PATCH] Fix MythMusic metadata extracting from filename

Paul mythtv at dsl.pipex.com
Tue Mar 15 15:45:35 UTC 2005


>Slightly off topic, spent ages trying to work out why the tag edits
>weren't being written to some of my mp3s...

>Am I right in thinking that if a file contains no tags, then any
>changes made in MythMusic Tag editor are not written to the file?

>Thanks

>Paul


>On Sun, 13 Mar 2005 22:49:32 -0000, Paul <mythtv at dsl.pipex.com> wrote:
>> Small patch that should fix the problem reported on the user list of not
>> being able to extract the metadata from the filename properly when
"Ignore
>> ID3 Tags"
>> is turned on.
>>
>> Paul

Hi Paul

I wrote the original metadata editor code but Colin Guthrie wrote the metaio
classes
that does the reading/writing of the metadata to the file. He's knows more
about the
tag writing code than I do.

There does seem to be many problems with the libid3tag library that is used
to read/write
the mp3 tag stuff in MythMusic. I believe one of the problems is that it
cannot increase the
size of the tag at all. The problems you are having could be related to
that.

There was some discussion about dropping the libid3tag for another library
but Isaac wasn't
happy about adding another dependency.

The big problem I have is that it can only create v2.4 tags that are
incompatible with many
players. Including one that I use so I have been forced to replace the tag
writing code
with some custom code that simply calls the command line utility 'id3v2' to
do the tag writing.

If you want to give it a try here's the code I use, just comment out the
original
bool MetaIOID3v2::write(..) function in metaioid3v2.cpp and add the
following

QString quotedString(QString s)
{
  QString sRes = s;
  sRes.replace(QRegExp("\""), QString("\\\""));
//  sRes.replace(QRegExp("'"), QString("\\\'"));
//  sRes.replace(QRegExp("\\\\"), QString("\\\\"));

  sRes = "\"" + sRes + "\"";
  return(sRes);
}

bool MetaIOID3v2::write(Metadata* mdata, bool exclusive)
{
    QString sCommand, sYear, sTrack, sFilename;

    cout << "MetaIOID3v2::write()" << mdata->Filename() << endl;

    sFilename = mdata->Filename();
    sYear.setNum(mdata->Year());
    sTrack.setNum(mdata->Track());

    sCommand = QString("id3v2 --id3v2-only"
                       " --%1 %2 --%3 %4 --%5 %6 --%7 %8")

.arg(ID3_FRAME_ARTIST).arg(quotedString(mdata->Artist()).ascii())
                       .arg(ID3_FRAME_ALBUM)
.arg(quotedString(mdata->Album()).ascii())
                       .arg(ID3_FRAME_TITLE)
.arg(quotedString(mdata->Title()).ascii())
                       .arg(ID3_FRAME_GENRE)
.arg(quotedString(mdata->Genre()).ascii());

    sCommand += QString(" --%1 %2 --%3 %4 %5")
                       .arg("TYER").arg(sYear.ascii())
                       .arg(ID3_FRAME_TRACK) .arg(sTrack.ascii())
                       .arg(quotedString(sFilename));

    cout << sCommand << endl;
    system(sCommand);
}

You will need to install id3v2 if you don't already have it and make sure it
is in your path.

I have to warn you that the code hasn't been tested very much but does seem
to
work for me. I just tried it out on a file with no tag in it and it did
write the tag OK
although it did take about 30 seconds to do it with a lot of network traffic
going on. My
music collection is stored on a windows 2000 machine running an NFS server
across
my network. I thought MythMusic had crashed at first! Its not pretty but it
does work :-).
Writing to a file that already has a tag is instantaneous.

Paul




More information about the mythtv-dev mailing list