コード例 #1
0
QVector<bool> TagsManager::writeTags(const QVector<SongFile>& songs)
{
    QVector<bool> result;

    for (SongFile const& song : songs)
    {
        bool success = false;

        if (!song.getAuthors().isEmpty() || !song.getTitle().isEmpty())
        {
            const QString songFilePath = song.getFilepath();
            TagLib::FileRef file(songFilePath.toStdString().c_str());

            if (!file.isNull() && file.tag())
            {
                TagLib::Tag *tag = file.tag();

                tag->setArtist(song.getAuthors().join(";").toStdString());
                tag->setTitle(song.getTitle().toStdString());

                success = file.save();
            }
        }

        result.append(success);
    }

    return result;
}
コード例 #2
0
bool WriteTag(const musik::Core::SongInfo& info)
{
    bool ret = true;

    try
    {
#if defined (WIN32)
        TagLib::FileRef tag_file(info.GetFilename().c_str());
#else
        TagLib::FileRef tag_file(utf16to8(info.GetFilename(), true).c_str());
#endif
        if (!tag_file.isNull())
        {
            TagLib::Tag *tag = tag_file.tag();

            tag->setArtist(info.GetArtist().c_str());
            tag->setAlbum(info.GetAlbum().c_str());
            tag->setTitle(info.GetTitle().c_str());
            tag->setGenre(info.GetGenre().c_str());
            tag->setYear(musik::Core::StringToInt(info.GetYear()));
            tag->setTrack(musik::Core::StringToInt(info.GetTrackNum()));
            tag->setComment(info.GetNotes().c_str());

            tag_file.save();
        }
    }
    catch (...)
    {
        ret = false;
        cout << "taglib crashed trying to write: " << info.GetFilename().c_str() << endl;
    }

    return ret;
}
コード例 #3
0
ファイル: media.cpp プロジェクト: Valodim/eqbeats
void Media::updateTags(Format format){
    if(format == MP3){
        TagLib::MPEG::File mp3(filePath(MP3).c_str());
        TagLib::Tag *t = mp3.tag();
        if(!t) return;
        t->setTitle(TagLib::String(title(), TagLib::String::UTF8));
        t->setArtist(TagLib::String(artist().name(), TagLib::String::UTF8));
        mp3.save(TagLib::MPEG::File::ID3v1 | TagLib::MPEG::File::ID3v2);
    } else if(format == Vorbis) {
        TagLib::Ogg::Vorbis::File vorbis(filePath(Vorbis).c_str());
        TagLib::Tag *t = vorbis.tag();
        if(!t) return;
        t->setTitle(TagLib::String(title(), TagLib::String::UTF8));
        t->setArtist(TagLib::String(artist().name(), TagLib::String::UTF8));
        vorbis.save();
    }
}
コード例 #4
0
void mttFile::removeTag( void )
{
	fileref = new TagLib::FileRef( QFile::encodeName( fname ).constData() );

    if ( ismpeg ) {
        TagLib::MPEG::File *f = dynamic_cast<TagLib::MPEG::File *>(fileref->file());
        f->strip();
    }
    else {
        TagLib::Tag *intag = fileref->tag();

        intag->setTitle( TagLib::String::null );
        intag->setArtist( TagLib::String::null );
        intag->setAlbum( TagLib::String::null );
        intag->setComment( TagLib::String::null );
        intag->setGenre( TagLib::String::null );
        intag->setYear( 0 );
        intag->setTrack( 0 );
        fileref->save();
    }

    delete fileref;
    fileref = NULL;
}
コード例 #5
0
ファイル: audiotagger.cpp プロジェクト: AlbanBedel/mixxx
bool AudioTagger::save () {
    TagLib::File* file = NULL;

    if (m_file.endsWith(".mp3", Qt::CaseInsensitive)) {
        file =  new TagLib::MPEG::File(m_file.toUtf8().constData());
        //process special ID3 fields, APEv2 fiels, etc

        //If the mp3 has no ID3v2 tag, we create a new one and add the TBPM and TKEY frame
        addID3v2Tag( ((TagLib::MPEG::File*) file)->ID3v2Tag(true)  );
        //If the mp3 has an APE tag, we update
        addAPETag( ((TagLib::MPEG::File*) file)->APETag(false)  );

    }
    if (m_file.endsWith(".m4a", Qt::CaseInsensitive)) {
        file =  new TagLib::MP4::File(m_file.toUtf8().constData());
        //process special ID3 fields, APEv2 fiels, etc
        processMP4Tag(((TagLib::MP4::File*) file)->tag());

    }
    if (m_file.endsWith(".ogg", Qt::CaseInsensitive)) {
        file =  new TagLib::Ogg::Vorbis::File(m_file.toUtf8().constData());
        //process special ID3 fields, APEv2 fiels, etc
        addXiphComment( ((TagLib::Ogg::Vorbis::File*) file)->tag()   );

    }
    if (m_file.endsWith(".wav", Qt::CaseInsensitive)) {
        file =  new TagLib::RIFF::WAV::File(m_file.toUtf8().constData());
        //If the flac has no ID3v2 tag, we create a new one and add the TBPM and TKEY frame
        addID3v2Tag( ((TagLib::RIFF::WAV::File*) file)->tag()  );

    }
    if (m_file.endsWith(".flac", Qt::CaseInsensitive)) {
        file =  new TagLib::FLAC::File(m_file.toUtf8().constData());

        //If the flac has no ID3v2 tag, we create a new one and add the TBPM and TKEY frame
        addID3v2Tag( ((TagLib::FLAC::File*) file)->ID3v2Tag(true)  );
        //If the flac has no APE tag, we create a new one and add the TBPM and TKEY frame
        addXiphComment( ((TagLib::FLAC::File*) file)->xiphComment (true)   );

    }
    if (m_file.endsWith(".aif", Qt::CaseInsensitive) || m_file.endsWith(".aiff", Qt::CaseInsensitive)) {
        file =  new TagLib::RIFF::AIFF::File(m_file.toUtf8().constData());
        //If the flac has no ID3v2 tag, we create a new one and add the TBPM and TKEY frame
        addID3v2Tag( ((TagLib::RIFF::AIFF::File*) file)->tag()  );

    }

    //process standard tags
    if (file) {
        TagLib::Tag *tag = file->tag();
        if (tag) {
            tag->setArtist(m_artist.toStdString());
            tag->setTitle(m_title.toStdString());
            tag->setAlbum(m_album.toStdString());
            tag->setGenre(m_genre.toStdString());
            tag->setComment(m_comment.toStdString());
            uint year =  m_year.toUInt();
            if (year >  0)
                tag->setYear(year);
            uint tracknumber = m_tracknumber.toUInt();
            if (tracknumber > 0)
                tag->setTrack(tracknumber);

        }
        //write audio tags to file
        int success = file->save();
        if (success) {
            qDebug() << "Successfully updated metadata of track " << m_file;
        } else {
             qDebug() << "Could not update metadata of track " << m_file;
        }
        //delete file and return
        delete file;
        return success;
    } else {
        return false;
    }
}