示例#1
0
void TrackInfoObject::parseFilename() {
    // If the file name has the following form: "Artist - Title.type", extract
    // Artist, Title and type fields
    parseArtist();
    parseTitle();

    // Add no comment
    m_sComment.clear();

    // Find the type
    QString filename = m_fileInfo.fileName();
    m_sType = filename.section(".",-1).toLower().trimmed();
    setDirty(true);
}
示例#2
0
void TrackInfoObject::parse() {
    // Log parsing of header information in developer mode. This is useful for
    // tracking down corrupt files.
    const QString& canonicalLocation = m_fileInfo.canonicalFilePath();
    if (CmdlineArgs::Instance().getDeveloper()) {
        qDebug() << "TrackInfoObject::parse()" << canonicalLocation;
    }

    // Parse the information stored in the sound file.
    SoundSourceProxy proxy(canonicalLocation, m_pSecurityToken);
    Mixxx::SoundSource* pProxiedSoundSource = proxy.getProxiedSoundSource();
    if (pProxiedSoundSource != NULL && proxy.parseHeader() == OK) {

        // Dump the metadata extracted from the file into the track.

        // TODO(XXX): This involves locking the mutex for every setXXX
        // method. We should figure out an optimization where there are private
        // setters that don't lock the mutex.

        // If Artist, Title and Type fields are not blank, modify them.
        // Otherwise, keep their current values.
        // TODO(rryan): Should we re-visit this decision?
        if (!(pProxiedSoundSource->getArtist().isEmpty())) {
            setArtist(pProxiedSoundSource->getArtist());
        } else {
            parseArtist();
        }

        if (!(pProxiedSoundSource->getTitle().isEmpty())) {
            setTitle(pProxiedSoundSource->getTitle());
        } else {
            parseTitle();
        }

        if (!(pProxiedSoundSource->getType().isEmpty())) {
            setType(pProxiedSoundSource->getType());
        }

        setAlbum(pProxiedSoundSource->getAlbum());
        setAlbumArtist(pProxiedSoundSource->getAlbumArtist());
        setYear(pProxiedSoundSource->getYear());
        setGenre(pProxiedSoundSource->getGenre());
        setComposer(pProxiedSoundSource->getComposer());
        setGrouping(pProxiedSoundSource->getGrouping());
        setComment(pProxiedSoundSource->getComment());
        setTrackNumber(pProxiedSoundSource->getTrackNumber());
        float replayGain = pProxiedSoundSource->getReplayGain();
        if (replayGain != 0) {
            setReplayGain(replayGain);
        }
        float bpm = pProxiedSoundSource->getBPM();
        if (bpm > 0) {
            // do not delete beat grid if bpm is not set in file
            setBpm(bpm);
        }
        setDuration(pProxiedSoundSource->getDuration());
        setBitrate(pProxiedSoundSource->getBitrate());
        setSampleRate(pProxiedSoundSource->getSampleRate());
        setChannels(pProxiedSoundSource->getChannels());
        QString key = pProxiedSoundSource->getKey();
        if (!key.isEmpty()) {
            setKeyText(key, mixxx::track::io::key::FILE_METADATA);
        }
        setHeaderParsed(true);
    } else {
        qDebug() << "TrackInfoObject::parse() error at file"
                 << canonicalLocation;
        setHeaderParsed(false);

        // Add basic information derived from the filename:
        parseFilename();
    }
}
示例#3
0
QString
MusicBrainzXmlParser::parseRecording( const QDomElement &e )
{
    QString id;
    QVariantMap track;

    if( e.hasAttribute( "id" ) )
        id = e.attribute( "id" );
    if( id.isEmpty() )
        return id;

    if( tracks.contains( id ) )
        track = tracks.value( id );
    else
        track.insert( MusicBrainz::TRACKID, id );
    if( track.isEmpty() )
        return id;

    if( e.hasAttribute( "ext:score" ) )
        track.insert( Meta::Field::SCORE, e.attribute( "ext:score" ).toInt() );

    QDomNode dNode = e.firstChild();
    QDomElement dElement;
    QString elementName;

    while( !dNode.isNull() )
    {
        if( dNode.isElement() )
        {
            dElement = dNode.toElement();
            elementName = dElement.tagName();

            if( elementName == "title" )
                track.insert( Meta::Field::TITLE, dElement.text() );
            else if( elementName == "length" )
            {
                int length = dElement.text().toInt();
                if( length > 0 )
                    track.insert( Meta::Field::LENGTH, length );
            }
            else if( elementName == "artist-credit" )
            {
                QStringList idList = parseArtist( dElement );
                if( !idList.isEmpty() )
                {
                    QString artist;
                    QVariantMap artistInfo;
                    foreach( const QString &id, idList )
                    {
                        if( artists.contains( id ) )
                        {
                            artistInfo.insert( id, artists.value( id ) );
                            artist += artists.value( id );
                        }
                        else
                            // If it's not among IDs, it's a joinphrase attribute.
                            artist += id;
                    }
                    if( !artistInfo.isEmpty() )
                    {
                        track.insert( MusicBrainz::ARTISTID, artistInfo );
                        track.insert( Meta::Field::ARTIST, artist );
                    }
                }
            }