Пример #1
0
void
ScrobbleCache::add( const QList<lastfm::Track>& tracks )
{
    foreach (const Track& track, tracks)
    {
        Invalidity invalidity;
        
        if ( !isValid( track, &invalidity ) )
        {
            qWarning() << invalidity;
            MutableTrack mt = MutableTrack( track );
            mt.setScrobbleStatus( Track::Error );
            mt.setScrobbleErrorText( QObject::tr( "Invalid" ) );
        }
        else if (track.isNull()) 
            qDebug() << "Will not cache an empty track";
        else 
        {
            bool ok;
            int plays = track.extra( "playCount" ).toInt( &ok );
            if ( !ok ) plays = 1;

            for ( int i = 0 ; i < plays ; ++i )
                d->m_tracks += track;

            MutableTrack( track ).setScrobbleStatus( Track::Cached );
        }
    }
Пример #2
0
Track
DragMimeData::track() const
{
    MutableTrack track;
    track.setArtist( QString::fromUtf8( data( "item/artist" ) ) );
    track.setTitle( QString::fromUtf8( data( "item/track" ) ) );
    track.setAlbum( QString::fromUtf8( data( "item/album" ) ) );
    return track;
}
Пример #3
0
FirehoseItem::FirehoseItem( const WsDomElement& e )
            : m_user( e["user"]["name"].text() )
{
    static WsAccessManager* nam = 0;
    if (!nam) nam = new WsAccessManager;
    
    MutableTrack t;
    t.setArtist( e["track"]["artist"]["name"].text() );
    t.setTitle( e["track"]["name"].text() );
    m_track = t;
    
    QNetworkReply* r = nam->get( QNetworkRequest( e["user"]["image"].text() ) );
    
    connect( r, SIGNAL(finished()), SLOT(onAvatarDownloaded()) );
}
Пример #4
0
Track
PlayerCommandParser::extractTrack( const QMap<QChar, QString>& args )
{
    MutableTrack track;
    track.setArtist( args['a'] );
    track.setTitle( args['t'] );
    track.setAlbum( args['b'] );
    track.setMbid( Mbid( args['m'] ) );
    track.setDuration( args['l'].toInt() );
    track.setUrl( QUrl::fromLocalFile( QUrl::fromPercentEncoding( args['p'].toUtf8() ) ) );
    track.setSource( Track::Player );
    track.setExtra( "playerId", args['c'] );

    //TODO should be done earlier, NOTE don't get the plugin to send a stamp 
    // time as this is prolly unecessary, and I bet you get new bugs!
    track.stamp();
    
    return track;
}
Пример #5
0
int main(int argc, char *argv[])
{
    int exitCode = -1;

    QtSingleCoreApplication::setApplicationName( "Last.fm Fingerprinter" );
    QtSingleCoreApplication::setOrganizationName( "Last.fm" );

    unicorn::CoreApplication a(argc, argv);

    qDebug() << a.arguments();

    int usernameIndex = a.arguments().indexOf( "--username" );
    int filenameIndex = a.arguments().indexOf( "--filename" );

    if ( usernameIndex != -1 && filenameIndex != -1 )
    {
        // username and filename are required fields
        lastfm::ws::Username = a.arguments().at( usernameIndex + 1 );

        // create the track from the command line arguments
        MutableTrack track;
        track.setUrl( QUrl::fromLocalFile( a.arguments().at( filenameIndex + 1 ) ) );

        int titleIndex = a.arguments().indexOf( "--title" );
        int albumIndex = a.arguments().indexOf( "--album" );
        int artistIndex = a.arguments().indexOf( "--artist" );

        if ( titleIndex != -1 ) track.setTitle( a.arguments().at( titleIndex + 1 ) );
        if ( albumIndex != -1 ) track.setAlbum( a.arguments().at( albumIndex + 1 ) );
        if ( artistIndex != -1 ) track.setTitle( a.arguments().at( artistIndex + 1 ) );

        Fingerprinter* fingerprinter = new Fingerprinter( track );
        exitCode = a.exec();
        delete fingerprinter;
    }
    else
    {
        qWarning() << "Usage: fingerprinter --username <username> --filename <filename> --title <title> --album <album> --artist <artist>";
    }

    return exitCode;
}
Пример #6
0
void
LocalRqlTrackCallback::trackOk(const char* title, const char* album, const char* artist, const char* url, unsigned duration)
{
    MutableTrack mt;
    mt.setTitle( QString::fromUtf8( title ) );
    mt.setAlbum( QString::fromUtf8( album ) );
    mt.setArtist( QString::fromUtf8( artist ) );
    mt.setUrl( QString::fromUtf8( url ) );
    mt.setDuration( duration );
    emit track( mt );
    delete this;
}
void
UnitTestsFingerprintIdRequest::testValidMp3()
{
    MutableTrack t;
    t.setUrl( QUrl::fromLocalFile( "../lib/fingerprint/tests/data/05 - You Lot.mp3" ) );
    t.setAlbum( "Blue Album" );
    t.setArtist( "Orbital" );
    t.setTitle( "You Lot" );      
    t.setDuration( 427 );
    t.setTrackNumber( 5 );
    
    FingerprintIdRequest f( t );
    QSignalSpy spy( &f, SIGNAL(FpIDFound( QString )) );
    
    QTest::qWait( 5000 );
    
    QVERIFY2( spy.count() == 1, "Did not receive FpIdFound signal" );
    QVERIFY( spy.takeFirst().takeFirst().toString() != "0" );
}
void
SpotifyListenerWin::loop()
{
    m_windowTitle.clear();

    EnumWindows( SpotifyListenerWin::callback, reinterpret_cast<LPARAM>(this) );

    // stopped =
    // paused = Spotify
    // playing = Spotify - Allo, Darlin' – Kiss Your Lips

    State playerState = Stopped;

    if ( m_windowTitle.startsWith( "Spotify" ) )
    {
        if ( !m_connection )
            emit newConnection( m_connection = new SpotifyConnection );

        QRegExp re( QString( "^Spotify - (.+) %1 (.+)").arg( QChar( 0x2013 )  ), Qt::CaseSensitive, QRegExp::RegExp2 );

        playerState = re.indexIn( m_windowTitle ) == 0 ? Playing : Paused;

        if ( m_lastPlayerState != playerState )
        {
            if ( playerState == Stopped )
            {
                m_connection->stop();
                m_lastTrack = Track();
            }
            else if ( playerState == Paused )
            {
                if ( m_lastPlayerState == Playing )
                    m_connection->pause();
            }
            else if ( playerState == Playing )
            {
                MutableTrack t;
                t.setTitle( re.capturedTexts().at( 2 ) );
                t.setArtist( re.capturedTexts().at( 1 ) );
                // we don't know the duration, but we don't display it so just guess
                t.setDuration( 320 );

                if ( m_lastPlayerState == Paused && t == m_lastTrack )
                    m_connection->resume();
                else
                    m_connection->start( t );

                m_lastTrack = t;
            }
        }
        else if ( playerState == Playing )
        {
            // when going from one song to the next we stay in the play state
            MutableTrack t;
            t.setTitle( re.capturedTexts().at( 2 ) );
            t.setArtist( re.capturedTexts().at( 1 ) );
            // we don't know the duration, but we don't display it so just guess
            t.setDuration( 320 );

            if ( t != m_lastTrack )
                m_connection->start( t );

            m_lastTrack = t;
        }
    }
    else
    {
        if ( m_lastPlayerState == Playing || m_lastPlayerState == Paused )
            m_connection->stop();

        delete m_connection;
    }

    m_lastPlayerState = playerState;
}