Beispiel #1
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;
}
Beispiel #2
0
bool getAudioInfo(const QString& file, qint64* durationMiliSecs, int* bitrate)
{
	TagLib::FileRef ref = Qomp::fileName2TaglibRef(file);
	if(!ref.isNull() && ref.audioProperties()) {
		TagLib::AudioProperties *prop = ref.audioProperties();

		*bitrate = prop->bitrate();
		*durationMiliSecs = prop->length() * 1000;

		return true;
	}

	return false;
}
Beispiel #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]);
}
Beispiel #4
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(),"") ;
            }
        }
    }

}
/*!
* \brief Find the length of the track (in seconds)
*
* \param filename The filename for which we want to find the length.
* \returns An integer (signed!) to represent the length in milliseconds.
*/
int MetaIOTagLib::getTrackLength(const QString &filename)
{
    int milliseconds = 0;
    QByteArray fname = filename.toLocal8Bit();
    TagLib::FileRef *file = new TagLib::FileRef(fname.constData());

    if (file && file->audioProperties())
        milliseconds = file->audioProperties()->length() * 1000;

    // If we didn't get a valid length, add the metadata but show warning.
    if (milliseconds <= 1000)
        LOG(VB_GENERAL, LOG_ERR,
            QString("MetaIOTagLib: Failed to read length "
                    "from '%1'. It may be corrupt.").arg(filename));
    
    return milliseconds;
}
Beispiel #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);
}
Beispiel #7
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 ) );
}
Beispiel #8
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);
    }

}
Beispiel #9
0
void MediaInfo::readInfo(TagLib::FileRef f) {
    bitrate = f.audioProperties() -> bitrate();
    channels = f.audioProperties() -> channels();
    duration = f.audioProperties() -> length();
    sampleRate = f.audioProperties() -> sampleRate();
}