Example #1
0
void Track::readTags()
{
    QByteArray fileName = QFile::encodeName( p->url.toLocalFile() );
    const char * encodedName = fileName.constData();
    TagLib::FileRef fileref = TagLib::FileRef( encodedName, true, TagLib::AudioProperties::Fast);

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

            p->title   = !tag->title().isNull() ? TStringToQString( tag->title() ).trimmed() : QObject::tr("Unknown");
            p->artist  = !tag->artist().isNull() ? TStringToQString( tag->artist() ).trimmed() : QObject::tr("Unknown");
            p->album   = !tag->album().isNull() ? TStringToQString( tag->album() ).trimmed() : QObject::tr("Unknown");
            p->comment = TStringToQString( tag->comment() ).trimmed();
            p->genre   = !tag->genre().isNull() ? TStringToQString( tag->genre() ).trimmed() : QObject::tr("Unknown");
            p->year    = tag->year() ? QString::number( tag->year() ) : QString::null;
            p->tracknumber   = tag->track() ? QString::number( tag->track() ) : QString::null;
            p->length     = fileref.audioProperties()->length();
            p->counter = 0;
            p->rate = 0;

            //polish up empty tags
            if( p->title == QObject::tr("Unknown") ) {
                QFileInfo fileInfo(p->url.toLocalFile());
                p->title = fileInfo.fileName().replace( '_', ' ' ).replace('.' + fileInfo.suffix(),"") ;
            }
        }
    }

}
Example #2
0
Tune* tuneFromFile(const QString& file)
{
	Tune* tune = new Tune(false);
	tune->file = file;

	TagLib::FileRef ref = fileName2TaglibRef(file);
	if(!ref.isNull()) {
		if(ref.tag()) {
			TagLib::Tag* tag = ref.tag();
			tune->artist = safeTagLibString2QString( tag->artist() );
			tune->album = safeTagLibString2QString( tag->album() );
			tune->title = safeTagLibString2QString( tag->title() );
			tune->trackNumber = QString::number( tag->track() );
			tune->genre = safeTagLibString2QString( tag->genre() );
		}

		Qomp::loadCover(tune, ref.file());

		if(ref.audioProperties()) {
			TagLib::AudioProperties *prop = ref.audioProperties();
			tune->duration = Qomp::durationSecondsToString( prop->length() );
			tune->bitRate = QString::number( prop->bitrate() );
		}

		tune->setMetadataResolved(true);
	}

	return tune;
}
Example #3
0
/**
 * MPEG-4:
 * Video Codecs:
 *    H.264 Baseline: avc1.42E0xx, where xx is the AVC level
 *    H.264 Main: avc1.4D40xx, where xx is the AVC level
 *    H.264 High: avc1.6400xx, where xx is the AVC level
 *    MPEG-4 Visual Simple Profile Level 0: mp4v.20.9
 *    MPEG-4 Visual Advanced Simple Profile Level 0: mp4v.20.240
 * Audio Codecs:
 *    Low-Complexity AAC: mp4a.40.2
 */
void p_mp4_header(TagLib::FileRef f)
{
    TagLib::String title = f.tag()->title();
    TagLib::String artist = f.tag()->artist();
    TagLib::String album = f.tag()->album();
    TagLib::String comment = f.tag()->comment();
    TagLib::String genre = f.tag()->genre();
    TagLib::uint year = f.tag()->year();
    TagLib::uint track = f.tag()->track();
    TagLib::MP4::Properties *prop = (TagLib::MP4::Properties*) f.audioProperties();
    TagLib::MP4::Properties::Codec codec = prop->codec();

    printf("Metadata\n");
    printf("Artist    :  %s\nTitle     :  %s\nAlbum     :  %s\nGenre     :  %s\n",
            artist.toCString(true),
            title.toCString(true),
            album.toCString(true),
            genre.toCString(true));
    printf("Comment   :  %s\nYear      :  %d\nTrack     :  %d\n",
            comment.toCString(true),
            year, track);
    printf("Length    :  %d\nBitrate   :  %d\nS' Rate   :  %d\nChannels  :  %d\n",
            prop->length(),
            prop->bitrate(),
            prop->sampleRate(),
            prop->channels());
    printf("BPS       :  %d\nEncrypted :  %d\nAudio Codec  :  %s\n",
            prop->bitsPerSample(),
            prop->isEncrypted(),
            mp4_codec_str[codec]);
}
Example #4
0
void
MetaBundle::readTags( TagLib::AudioProperties::ReadStyle readStyle )
{
    if( m_url.protocol() != "file" )
        return;

    const QString path = m_url.path();
    TagLib::FileRef fileref;
    TagLib::Tag *tag = 0;

    if( AmarokConfig::recodeID3v1Tags() && path.endsWith( ".mp3", false ) )
    {
        TagLib::MPEG::File *mpeg = new TagLib::MPEG::File( QFile::encodeName( path ), true, readStyle );
        fileref = TagLib::FileRef( mpeg );

        if( mpeg->isValid() )
            // we prefer ID3v1 over ID3v2 if recoding tags because
            // apparently this is what people who ignore ID3 standards want
            tag = mpeg->ID3v1Tag() ? (TagLib::Tag*)mpeg->ID3v1Tag() : (TagLib::Tag*)mpeg->ID3v2Tag();
    }

    else {
        fileref = TagLib::FileRef( QFile::encodeName( path ), true, readStyle );

        if( !fileref.isNull() )
            tag = fileref.tag();
    }

    if( !fileref.isNull() ) {
        if ( tag ) {
            #define strip( x ) TStringToQString( x ).stripWhiteSpace()
            m_title   = strip( tag->title() );
            m_artist  = strip( tag->artist() );
            m_album   = strip( tag->album() );
            m_comment = strip( tag->comment() );
            m_genre   = strip( tag->genre() );
            m_year    = tag->year() ? QString::number( tag->year() ) : QString();
            m_track   = tag->track() ? QString::number( tag->track() ) : QString();
            #undef strip

            m_isValidMedia = true;
        }

        init( fileref.audioProperties() );
    }

    //FIXME disabled for beta4 as it's simpler to not got 100 bug reports
    //else if( KMimeType::findByUrl( m_url )->is( "audio" ) )
    //    init( KFileMetaInfo( m_url, QString::null, KFileMetaInfo::Everything ) );
}
Example #5
0
// Use Taglib to parse tags from file and add entried to wxListCtrl
void AddFromFile_Taglib(wxListCtrl *listctrl, const std::map< wxString, long > &mapping, const wxString &filename)
{
    TagLib::FileRef f = TagLib::FileRef(filename.c_str(), TagLib::String::UTF8 ); //TODO: is c_str() safe?

    if ( f.isNull() )
    {
        wxLogError(wxT("Error: TagLib could not read ") + filename + wxT("."));
        return;
    }

    if ( ! f.tag() )
    {
        wxLogError(wxT("Error: TagLib could not read the tags of file ") + filename + wxT("."));
        return;
    }

    TagLib::Tag *tag = f.tag();
    auto idx = listctrl->GetItemCount();
    auto row_idx = listctrl->InsertItem(idx, wxString::Format(wxT("%d"), idx) );

    // TODO: check return values
    listctrl->SetItem(row_idx, mapping.find("Artist")->second, wxString(tag->artist().to8Bit(true)) );
    listctrl->SetItem(row_idx, mapping.find("Trackname")->second, wxString(tag->title().to8Bit(true)));
    listctrl->SetItem(row_idx, mapping.find("Album")->second, wxString(tag->album().to8Bit(true)));

    if ( f.audioProperties() )
    {
      TagLib::AudioProperties *properties = f.audioProperties();
      int seconds = properties->length() % 60;
      int minutes = (properties->length() - seconds) / 60;

      wxString timestr = wxString::Format("%d:%02d", minutes, seconds);

      listctrl->SetItem(row_idx, mapping.find("Time")->second, timestr);
    }

}
Example #6
0
BlockResult Block::eval(const TagLib::FileRef& file)
{
    TagLib::PropertyMap metadata = file.tag()->properties();
    TagLib::StringList list;
    std::stringstream ss;
    // TODO: Needs to be refactored
    // TODO: Add more
    ss << file.audioProperties()->length();
    list.append(ss.str());
    metadata.insert("length", list);
    list.clear();
    ss.clear();

    ss << file.audioProperties()->bitrate();
    list.append(ss.str());
    metadata.insert("bitrate", list);
    list.clear();
    ss.clear();

    if (file.audioProperties()->channels() == 1) {
        list.append("mono");
    } else if (file.audioProperties()->channels() == 2) {
        list.append("stereo");
    } //TODO: Add more channels names

    metadata.insert("channels", list);
    list.clear();
    ss.clear();

    ss << file.audioProperties()->sampleRate();
    list.append(ss.str());
    metadata.insert("samplerate", list);
    list.clear();
    ss.clear();

    list.append(file.file()->name());
    metadata.insert("filename", list);
    list.clear();
    ss.clear();

    return this->eval(metadata);
}
Example #7
0
void TagWalker::handleMusicFile(const TagLib::FileRef &fr, std::string path) {
    // check whether the file is already in the right place
    // to do that, expand the pattern first and make it a complete filename
    std::string expandedPattern;

    if (this->expandPattern(fr.tag(), expandedPattern)) {

        // put the pieces together - depending what opmode we have
        switch (this->config.getOpMode()) {
            case Configuration::M_REORDER:
                expandedPattern = this->config.getWalkRoot() + expandedPattern;
                expandedPattern.append(this->getBasename(path));
                break;

            case Configuration::M_RENAME:
                expandedPattern = this->getPathname(path) + std::string("/") + expandedPattern;
                expandedPattern.append(this->getSuffix(path));
                break;
        }

        // only act if the two directories differ
        if ( path != expandedPattern ) {

            // now decide which opmode we have and what we should do
            // in rename mode only the file itself is altered,
            // so creating a directory is unnecessary
            switch (this->config.getOpMode()) {
            case Configuration::M_REORDER:
                this->RecursivelyMkdir(expandedPattern);
                this->forkAndMove(path, expandedPattern);
                break;

            case Configuration::M_RENAME:
                this->forkAndMove(path, expandedPattern);
                break;
            }
        }
    } else {
        ++this->unableToHandleCount;
    }
}
Example #8
0
    {
        TagLib::FileRef f(reinterpret_cast<filestr*>(filepath.constData()));
        TagLib::AudioProperties* props = f.audioProperties();
        duration += props->lengthInSeconds();

        QString filename = filepath.split("/").last();
        filename.remove(QRegExp("\\.(mp3|flac|m4a)"));
        filenames += filename + "\n";
    }
    ui->lengthLine->setText(QTime(duration / 3600, (duration % 3600) / 60, ((duration % 3600) % 60)).toString("hh:mm:ss"));
    filenames.remove(QRegExp("\n$"));
    ui->tracklistText->setPlainText(filenames);

    QString tagfile = files.first();
    TagLib::FileRef f(reinterpret_cast<filestr*>(tagfile.constData()));
    QString artist = f.tag()->artist().toCString(true);
    QString album  = f.tag()->album() .toCString(true);
    uint    year   = f.tag()->year();
    QString genre  = f.tag()->genre() .toCString(true);

    ui->artistLine ->setText(artist);
    ui->albumLine  ->setText(album);
    ui->yearSpinBox->setValue(year);

    QStringList genres = genre.split(" / ");
    if(genres.count() > 1)
    {
        int num = genres.count();
        for (int i = 1; i <= num; i++)
        {
            addGenre();
Example #9
0
int main(int argc,char *argv[])
{
	/*g_Indexer.BuildIndex();

	g_Indexer.SetCallback(FinishIndex);

	while (1)
	{
		WormSleep(300);
	}*/

	if (Init()) return 0;

	g_Indexer.SetCallback(FinishIndex, AddToIndex);

	if(REGISTER_WITH_DEVICE) return 0;

	ReportError("In Build Index");

	ReportError("Past Build Index");

	// Inits the music part of the program.
	g_MusController.Init(StartSong, FinishSeek);

	ReportError("About to start the music controller");

	g_MusController.Start();

	ReportError("Made it past the init stuff");

	WormIndexer::READY = 1;

#ifndef ON_DEVICE

	g_MusController.PassMessage(MUS_MESSAGE_ATTRIB_SET,
								ATTRIB_MUSCON_PAUSED,
								MUS_PLAY_CONST,
								0);

	ReportError("Made it past open");

	g_MusController.PassMessage(MUS_MESSAGE_OPEN_SONG, "c:/aobdt.mp3", 0);

	TagLib::FileRef *f =
					new TagLib::FileRef("c:/Users/Katiebird/amazing_grace.ogg");

	fprintf(stderr, "Please Work!!!!! - %s\n", f->tag()->artist().toCString());
	fprintf(stderr, "Please Work!!!!! - %s\n", f->tag()->album().toCString());
	fprintf(stderr, "Please Work!!!!! - %s\n", f->tag()->title().toCString());
	fprintf(stderr, "Please Work!!!!! - %u\n", f->tag()->year());
	fprintf(stderr, "Please Work!!!!! - %s\n", f->tag()->comment().toCString());
	fprintf(stderr, "Please Work!!!!! - %u\n", f->tag()->track());
	fprintf(stderr, "Please Work!!!!! - %s\n", f->tag()->genre().toCString());

	delete f;

	//g_MusController.PassMessage(MUS_MESSAGE_OPEN_SONG, "c:/amazing_grace.ogg", 0);
	//g_MusController.PassMessage(MUS_MESSAGE_OPEN_SONG, "c:/test1.mp3", 0);

	g_MusController.PassMessage(MUS_MESSAGE_SET_NEXT, "c:/amazing_grace.ogg", -10.0, 0);

	//g_MusController.PassMessage(MUS_MESSAGE_SET_NEXT, "c:/test2.mp3", -10.0, 0);

	ReportError("Made it past SetNext");

	// this keeps track of how long the user has waited for
	//	the buffering
	uint32_t uiCurWaitTime;

	uiCurWaitTime = 0;

	// routine to stop for a set time
	/*WormMarkStartTime();
	while (uiCurWaitTime < 10) // check wait time
	{
		uiCurWaitTime = WormCheckTimeSinceMark();
		WormSleep(100);
	}

	g_MusController.PassMessage(MUS_MESSAGE_SEEK,
									100.0);*/


	while (g_iContinue)
	{
		WormSleep(1800);
		//ReportError1("BPM:%s", g_MusController.PassMessage(MUS_MESSAGE_GET_BPM, 0));
		//ReportError1("CurTime:%s", g_MusController.PassMessage(MUS_MESSAGE_GET_SONG_CUR, 0));
		/*const char *cstrRet = g_MusController.PassMessage(MUS_MESSAGE_GET_MAG_STR, 0);
		for (int i=0; i<256; i++)
		{
			fprintf(ERROUT,"%i|", cstrRet[i]);
		}
		fprintf(ERROUT, "\n");*/
	}

#else
	while (1)
	{
		WormSleep(10000);
	}
#endif


	Quit();
	return 0;
}
Example #10
0
void ReplaceDialog::replace(){

    QProgressDialog p("Replacing tags...", "Cancel", 0, items_.size(), 0);
    p.setWindowModality(Qt::WindowModal);
    Qt::CaseSensitivity case_sens = Qt::CaseInsensitive;
    if(CaseSensitive->isChecked()){
        case_sens = Qt::CaseSensitive;
    }
    QString log; int nReplaced=0;
    TagLib::FileRef f; QString before;
    for(int i=0;i<items_.size();i++){

        p.setValue(i);
        if( p.wasCanceled() ){
            break;
        }

        f = TagLib::FileRef( items_[i]->fileInfo().absoluteFilePath().toStdString().c_str() );
        if( f.tag() ){
            QString field = TagComboBox->currentText().toLower();
            QString tagtxt;
            if( field=="artist" ){
                tagtxt = f.tag()->artist().toCString(); before=tagtxt;
                tagtxt.replace( Before->text(), After->text(), case_sens );
                if(before!=tagtxt){
                    nReplaced++;
                }
                f.tag()->setArtist( tagtxt.toStdString().c_str() );
            }else if(field=="album"){
                tagtxt = f.tag()->album().toCString(); before=tagtxt;
                tagtxt.replace( Before->text(), After->text(), case_sens );
                if(before!=tagtxt){
                    nReplaced++;
                }
                f.tag()->setAlbum( tagtxt.toStdString().c_str() );
            }else if(field=="title"){
                tagtxt = f.tag()->title().toCString(); before=tagtxt;
                tagtxt.replace( Before->text(), After->text(), case_sens );
                if(before!=tagtxt){
                    nReplaced++;
                }
                f.tag()->setTitle( tagtxt.toStdString().c_str() );
            }else if(field=="genre"){
                tagtxt = f.tag()->genre().toCString(); before=tagtxt;
                tagtxt.replace( Before->text(), After->text(), case_sens );
                if(before!=tagtxt){
                    nReplaced++;
                }
                f.tag()->setGenre( tagtxt.toStdString().c_str() );
            }else if(field=="comment"){
                tagtxt = f.tag()->comment().toCString(); before=tagtxt;
                tagtxt.replace( Before->text(), After->text(), case_sens );
                if(before!=tagtxt){
                    nReplaced++;
                }
                f.tag()->setComment( tagtxt.toStdString().c_str() );
            }else if(field=="track"){
                tagtxt = QString::number(f.tag()->track()); before=tagtxt;
                tagtxt.replace( Before->text(), After->text(), case_sens );
                bool ok; int tmp=tagtxt.toInt(&ok);
                if(ok){
                    if(before!=tagtxt){
                        nReplaced++;
                    }
                    f.tag()->setTrack( tmp );
                }else{
                    log.append("\nInvalid value for "+field+": "+tagtxt+". "+field+" must be uint");
                }
            }else if(field=="year"){
                tagtxt = QString::number(f.tag()->year()); before=tagtxt;
                tagtxt.replace( Before->text(), After->text(), case_sens );
                bool ok; int tmp=tagtxt.toInt(&ok);
                if(ok){
                    if(before!=tagtxt){
                        nReplaced++;
                    }
                    f.tag()->setYear( tmp );
                }else{
                    log.append("\nInvalid value for "+field+": "+tagtxt+". "+field+" must be uint");
                }
            }
            f.save();
            items_[i]->clearTags();
            items_[i]->readTags();
        }else{
            log.append("\n Could not get tag for "+items_[i]->fileInfo().absoluteFilePath());
        }

    }
    log.append("\n\nReplaced "+Before->text()+" with "+After->text()+" in "+QString::number(nReplaced)+" tags");
    p.setValue(items_.size());
    TextViewer t(log);
    t.exec();

    accept();
}