Example #1
0
TrackInfo
ITunesLibrary::Track::trackInfo() const
{
    // NOTE we only what data we require for scrobbling, though we could fill in
    // more of the TrackInfo object
    TrackInfo t;
    t.setSource( TrackInfo::MediaDevice );

    QString source;
    if (!m_sourcePersistentId.isEmpty())
        source = "tell first source whose persistent ID is '" + m_sourcePersistentId + "' to ";

    // TODO compile once and pass pid as argument
    // NOTE trust me, the code is ugly, but doesn't work any other way, don't clean it up!
    AppleScript script;
    script << "tell application 'iTunes'"
        <<     source + "set lib to library playlist 1"
        <<     "set t to first track of lib whose persistent ID is '" + persistentId() + "'"
		<<     "if (get class of t) is list then set t to item 1 of t"
        <<     "set d to played date of t"
        << "end tell"

        << "try"
        <<     "set d to (year of d) & ':' & "
        "((month of d) as integer) & ':' & "
        "(day of d) & ':' & "
        "(time of d)"
        << "end try"

        << "tell application 'iTunes' to tell t"
        <<     "set l to location"
        <<     "try" << "set l to POSIX path of l" << "end try"
        <<     "return artist & '\n' & name & '\n' & (duration as integer)  & '\n' & album & '\n' & played count  & '\n' & d & '\n' & l"
        << "end tell";

    QString out = script.exec();
    QTextStream s( &out, QIODevice::ReadOnly );

    t.setArtist( s.readLine() );
    t.setTrack( s.readLine() );
    t.setDuration( (uint) s.readLine().toFloat() );
    t.setAlbum( s.readLine() );
    t.setPlayCount( s.readLine().toInt() );
    t.setTimeStamp( qDateTimeFromScriptString( s.readLine() ).toTime_t() );

    QFileInfo fileinfo( s.readLine() );
    t.setFileName( fileinfo.fileName() );
    t.setPath( fileinfo.absolutePath() );

    return t;
}
Example #2
0
void
ITunesDictionaryHelper::determineTrackInformation()
{
    duration = token<int>( CFSTR("Total Time") ) / 1000;
    artist = token<QString>( CFSTR("Artist") );
    album = token<QString>( CFSTR("Album") );
    name = token<QString>( CFSTR("Name") );
    
    // Get path decoded - iTunes encodes the file location as URL
    CFStringRef location = token<CFStringRef>( CFSTR("Location") );
    QUrl url = QUrl::fromEncoded( UnicornUtils::CFStringToUtf8( location ) );
    path = url.toString().remove( "file://localhost" );
    
    static AppleScript script( "tell application \"iTunes\" to return persistent ID of current track & player position" );
    QString const out = script.exec();
    pid = out.left( 16 );
    position = out.mid( 16 ).toInt();
}
Example #3
0
void
Growl::notify()
{
    if (!CoreProcess::isRunning( "GrowlHelperApp" ))
        return;

    AppleScript script;
    script << "tell application 'GrowlHelperApp'"
           <<     "register as application '" + qApp->applicationName() + "'"
                          " all notifications {'" + m_name + "'}"
                          " default notifications {'" + m_name + "'}"
                          " icon of application 'Last.fm.app'"
           <<     "notify with name '" + m_name + "'"
                          " title " + AppleScript::asUnicodeText( m_title ) +
                          " description " + AppleScript::asUnicodeText( m_description ) + 
                          " application name '" + qApp->applicationName() + "'"
           << "end tell";
    script.exec();
}
Example #4
0
void
GrowlNotifyExtension::onAppEvent( int e, const QVariant& data )
{
    switch (e) 
    {
        case Event::PlaybackStarted:
        case Event::TrackChanged:
            break;
        default:
            return;
    }

    // conveniently, this determines if Growl is installed for us
    if (UnicornUtils::isGrowlInstalled() == false)
        return;

    TrackInfo metaData = data.value<TrackInfo>();

    #define APPEND_IF_NOT_EMPTY( x ) if (!x.isEmpty()) description += x + '\n';
    QString description;
    APPEND_IF_NOT_EMPTY( metaData.artist() );
    APPEND_IF_NOT_EMPTY( metaData.album() );
    description += metaData.durationString();

    QString title = metaData.track();
    if (title.isEmpty())
        title = QFileInfo( metaData.path() ).fileName();

    AppleScript script;
    script << "tell application 'GrowlHelperApp'"
           <<     "register as application 'Last.fm'"
                          " all notifications {'Track Notification'}"
                          " default notifications {'Track Notification'}"
                          " icon of application 'Last.fm.app'"
           <<     "notify with name 'Track Notification'"
                          " title " + AppleScript::asUnicodeText( title ) +
                          " description " + AppleScript::asUnicodeText( description ) + 
                          " application name 'Last.fm'"
           << "end tell";
    script.exec();
}