예제 #1
0
파일: taglib_ext.cpp 프로젝트: pft/taggit
/**
 * Change tag type informmation in a struct taggit_list
 *
 * A string is created for the tagtypes entry. It will be a comma seperated
 * list of tags found within the given mp3 file. This string is dynamically
 * allocated and needs to be freed if it is not in use anymore (which will be
 * taken care of when taglist_destroy() is called).
 *
 * Secondly, the readmap is checked for which of the existing tag types should
 * be read. This information is then stored in the tagtype entry of the struct.
 *
 * @param   f       TagLib_File pointer to check
 * @param   lst     A pointer to the taggit_list structure to change
 *
 * @return      void (see description)
 * @sideeffects none
 */
void
mp3_tagtypes(TagLib_File *f, struct taggit_list *lst)
{
    TagLib::MPEG::File::File *file;
    TagLib::ID3v1::Tag *v1;
    TagLib::ID3v2::Tag *v2;
    TagLib::APE::Tag *ape;
    std::string tmp;
    int types;
    char *rc;

    file = reinterpret_cast<TagLib::MPEG::File::File *>(f);
    types = MP3_NO_TAGS;
    tmp = "";
    ape = file->APETag();
    if (ape != NULL &&
        !(ape->isEmpty() && ape->itemListMap()["ALBUMARTIST"].isEmpty()))
    {
        tmp += "apetag";
        types |= MP3_APE;
    }

    v1 = file->ID3v1Tag();
    if (v1 != NULL && !v1->isEmpty()) {
        if (tmp != "")
            tmp += ",";
        tmp = "id3v1";
        types |= MP3_ID3V1;
    }

    v2 = file->ID3v2Tag();
    if (v2 != NULL && !v2->isEmpty()) {
        if (tmp != "")
            tmp += ",";
        tmp += "id3v2";
        types |= MP3_ID3V2;
    }

    if (tmp == "")
        tmp = "(no tags)";

    rc = xstrdup(tmp.c_str());
    if (errno == ENOMEM) {
        fprintf(stderr, "Out of memory. Aborting.\n");
        exit(EXIT_FAILURE);
    }
    lst->tagtypes = rc;
    lst->tagtype = setup_please_read((char*)"mp3", types);
}
예제 #2
0
QList<FileInfo *> DecoderMPCFactory::createPlayList(const QString &fileName, bool useMetaData, QStringList *)
{
    FileInfo *info = new FileInfo(fileName);

#if (TAGLIB_MAJOR_VERSION > 1) || ((TAGLIB_MAJOR_VERSION == 1) && (TAGLIB_MINOR_VERSION >= 8))
    TagLib::FileStream stream(fileName.toLocal8Bit().constData(), true);
    TagLib::MPC::File fileRef(&stream);
#else
    TagLib::MPC::File fileRef(fileName.toLocal8Bit().constData());
#endif

    TagLib::APE::Tag *tag = useMetaData ? fileRef.APETag() : 0;
    if (tag && !tag->isEmpty())
    {
        info->setMetaData(Qmmp::ALBUM,
                       QString::fromUtf8(tag->album().toCString(true)).trimmed());
        info->setMetaData(Qmmp::ARTIST,
                       QString::fromUtf8(tag->artist().toCString(true)).trimmed());
        info->setMetaData(Qmmp::COMMENT,
                       QString::fromUtf8(tag->comment().toCString(true)).trimmed());
        info->setMetaData(Qmmp::GENRE,
                       QString::fromUtf8(tag->genre().toCString(true)).trimmed());
        info->setMetaData(Qmmp::TITLE,
                       QString::fromUtf8(tag->title().toCString(true)).trimmed());
        info->setMetaData(Qmmp::YEAR, tag->year());
        info->setMetaData(Qmmp::TRACK, tag->track());
    }
    if (fileRef.audioProperties())
        info->setLength(fileRef.audioProperties()->length());
    //additional metadata
    if(tag)
    {
        TagLib::APE::Item fld;
        if(!(fld = tag->itemListMap()["ALBUM ARTIST"]).isEmpty())
            info->setMetaData(Qmmp::ALBUMARTIST,
                              QString::fromUtf8(fld.toString().toCString(true)).trimmed());
        if(!(fld = tag->itemListMap()["COMPOSER"]).isEmpty())
            info->setMetaData(Qmmp::COMPOSER,
                              QString::fromUtf8(fld.toString().toCString(true)).trimmed());
    }

    QList <FileInfo*> list;
    list << info;
    return list;
}