示例#1
0
void
Scrobbler::trackStarted( const Tomahawk::result_ptr& track )
{
    Q_ASSERT( QThread::currentThread() == thread() );

    if ( m_reachedScrobblePoint )
    {
        m_reachedScrobblePoint = false;
        scrobble();
    }

    Tomahawk::InfoSystem::InfoStringHash trackInfo;
    trackInfo["title"] = track->track();
    trackInfo["artist"] = track->artist()->name();
    trackInfo["album"] = track->album()->name();
    trackInfo["duration"] = QString::number( track->duration() );
    trackInfo["albumpos"] = QString::number( track->albumpos() );

    QVariantMap playInfo;
    playInfo["trackinfo"] = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo );
    playInfo["private"] = TomahawkSettings::instance()->privateListeningMode();

    Tomahawk::InfoSystem::InfoPushData pushData (
        s_scInfoIdentifier, Tomahawk::InfoSystem::InfoSubmitNowPlaying,
        playInfo,
        Tomahawk::InfoSystem::PushNoFlag );

    Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( pushData );

    // liblastfm forces 0-length tracks to scrobble after 4 minutes, stupid.
    if ( track->duration() == 0 )
        m_scrobblePoint = ScrobblePoint( 30 );
    else
        m_scrobblePoint = ScrobblePoint( track->duration() / 2 );
}
示例#2
0
void
Scrobbler::trackStarted( const Tomahawk::result_ptr& track )
{
    Q_ASSERT( QThread::currentThread() == thread() );
//    qDebug() << Q_FUNC_INFO;

    if( m_reachedScrobblePoint )
    {
        m_reachedScrobblePoint = false;
        scrobble();
    }

    Tomahawk::InfoSystem::InfoCriteriaHash trackInfo;

    trackInfo["title"] = track->track();
    trackInfo["artist"] = track->artist()->name();
    trackInfo["album"] = track->album()->name();
    trackInfo["duration"] = QString::number( track->duration() );

    Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo(
        s_scInfoIdentifier, Tomahawk::InfoSystem::InfoSubmitNowPlaying,
        QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo ) );

    m_scrobblePoint = ScrobblePoint( track->duration() / 2 );
}
示例#3
0
void
AudioControls::onPlaybackStarted( const Tomahawk::result_ptr& result )
{
    qDebug() << Q_FUNC_INFO;

    onPlaybackLoading( result );

    QString artistName = result->artist()->name();
    QString albumName = result->album()->name();
    
    Tomahawk::InfoSystem::InfoCustomDataHash trackInfo;
    
    trackInfo["artist"] = QVariant::fromValue< QString >( result->artist()->name() );
    trackInfo["album"] = QVariant::fromValue< QString >( result->album()->name() );
    TomahawkApp::instance()->infoSystem()->getInfo(
        s_infoIdentifier, Tomahawk::InfoSystem::InfoAlbumCoverArt,
        QVariant::fromValue< Tomahawk::InfoSystem::InfoCustomDataHash >( trackInfo ), Tomahawk::InfoSystem::InfoCustomDataHash() );
}
示例#4
0
QVariantMap
MprisPlugin::metadata() const
{
    QVariantMap metadataMap;
    Tomahawk::result_ptr track = AudioEngine::instance()->currentTrack();
    if( track )
    {
        metadataMap.insert( "mpris:trackid", QString( "/track/" ) + track->id().replace( "-", "" ) );
        metadataMap.insert( "mpris:length", track->duration() );
        metadataMap.insert( "xesam:album", track->album()->name() );
        metadataMap.insert( "xesam:artist", track->artist()->name() );
        metadataMap.insert( "xesam:title", track->track() );
    }

    return metadataMap;
}
示例#5
0
bool
TrackProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const
{
    TrackModelItem* pi = itemFromIndex( sourceModel()->index( sourceRow, 0, sourceParent ) );
    if ( !pi )
        return false;

    const Tomahawk::query_ptr& q = pi->query();
    if( q.isNull() ) // uh oh? filter out invalid queries i guess
        return false;

    Tomahawk::result_ptr r;
    if ( q->numResults() )
        r = q->results().first();

    if ( !m_showOfflineResults && !r.isNull() && !r->collection()->source()->isOnline() )
        return false;

    if ( filterRegExp().isEmpty() )
        return true;

    QStringList sl = filterRegExp().pattern().split( " ", QString::SkipEmptyParts );
    foreach( QString s, sl )
    {
        s = s.toLower();
        if ( !r.isNull() )
        {
            if ( !r->artist()->name().toLower().contains( s ) &&
                 !r->album()->name().toLower().contains( s ) &&
                 !r->track().toLower().contains( s ) )
            {
                return false;
            }
        }
        else
        {
            if ( !q->artist().toLower().contains( s ) &&
                 !q->album().toLower().contains( s ) &&
                 !q->track().toLower().contains( s ) )
            {
                return false;
            }
        }
    }
示例#6
0
void
AudioControls::onPlaybackStarted( const Tomahawk::result_ptr& result )
{
    tDebug( LOGEXTRA ) << Q_FUNC_INFO;

    if ( result.isNull() )
        return;

    if ( m_currentTrack.isNull() || ( !m_currentTrack.isNull() && m_currentTrack.data()->id() != result.data()->id() ) )
        onPlaybackLoading( result );

    qint64 duration = AudioEngine::instance()->currentTrackTotalTime();

    if ( duration == -1 )
        duration = result.data()->duration() * 1000;

    ui->seekSlider->setRange( 0, duration );
    ui->seekSlider->setValue( 0 );

    m_phononTickCheckTimer.stop();

    m_sliderTimeLine.stop();
    m_sliderTimeLine.setDuration( duration );
    m_sliderTimeLine.setFrameRange( 0, duration );
    m_sliderTimeLine.setCurrentTime( 0 );
    m_seekMsecs = -1;

    ui->seekSlider->setVisible( true );

    m_noTimeChange = false;
    m_lastSliderCheck = 0;

    Tomahawk::InfoSystem::InfoStringHash trackInfo;
    trackInfo["artist"] = result->artist()->name();
    trackInfo["album"] = result->album()->name();

    Tomahawk::InfoSystem::InfoRequestData requestData;
    requestData.caller = s_acInfoIdentifier;
    requestData.type = Tomahawk::InfoSystem::InfoAlbumCoverArt;
    requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo );
    requestData.customData = QVariantMap();

    Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
}
// TODO make clever (ft. featuring live (stuff) etc)
float
DatabaseCommand_Resolve::how_similar( const Tomahawk::query_ptr& q, const Tomahawk::result_ptr& r )
{
    // query values
    const QString qArtistname = DatabaseImpl::sortname( q->artist() );
    const QString qAlbumname  = DatabaseImpl::sortname( q->album() );
    const QString qTrackname  = DatabaseImpl::sortname( q->track() );

    // result values
    const QString rArtistname = DatabaseImpl::sortname( r->artist()->name() );
    const QString rAlbumname  = DatabaseImpl::sortname( r->album()->name() );
    const QString rTrackname  = DatabaseImpl::sortname( r->track() );

    // normal edit distance
    int artdist = levenshtein( qArtistname, rArtistname );
    int albdist = levenshtein( qAlbumname, rAlbumname );
    int trkdist = levenshtein( qTrackname, rTrackname );

    // max length of name
    int mlart = qMax( qArtistname.length(), rArtistname.length() );
    int mlalb = qMax( qAlbumname.length(), rAlbumname.length() );
    int mltrk = qMax( qTrackname.length(), rTrackname.length() );

    // distance scores
    float dcart = (float)( mlart - artdist ) / mlart;
    float dcalb = (float)( mlalb - albdist ) / mlalb;
    float dctrk = (float)( mltrk - trkdist ) / mltrk;

    // don't penalize for missing album name
    if( qAlbumname.length() == 0 )
        dcalb = 1.0;

    // weighted, so album match is worth less than track title
    float combined = ( dcart*4 + dcalb + dctrk*5 ) / 10;
    return combined;
}
示例#8
0
QVariantMap
MprisPlugin::metadata() const
{
    QVariantMap metadataMap;
    Tomahawk::result_ptr track = AudioEngine::instance()->currentTrack();
    if ( track )
    {
        metadataMap.insert( "mpris:trackid", QVariant::fromValue(QDBusObjectPath(QString( "/track/" ) + track->id().replace( "-", "" ))) );
        metadataMap.insert( "mpris:length", static_cast<qlonglong>(track->duration()) * 1000000 );
        metadataMap.insert( "xesam:album", track->album()->name() );
        metadataMap.insert( "xesam:artist", QStringList( track->artist()->name() ) );
        metadataMap.insert( "xesam:title", track->track() );

        // Only return art if tempfile exists, and if its name contains the same "artist_album_tomahawk_cover.png"
        if ( !m_coverTempFile.isEmpty() )
        {
            QFile coverFile( m_coverTempFile );
            if ( coverFile.exists() && coverFile.fileName().contains( track->artist()->name() + "_" + track->album()->name() + "_tomahawk_cover.png" ) )
                metadataMap.insert( "mpris:artUrl", QString( QUrl::fromLocalFile( m_coverTempFile ).toEncoded() ) );
        }
    }

    return metadataMap;
}