Beispiel #1
0
bool
ITunesTrack::podcast()
{
    VARIANT_BOOL podcast = FALSE;
    IITFileOrCDTrack* fileTrack = 0;
    HRESULT res = m_comTrack->QueryInterface( IID_IITFileOrCDTrack, (void**)&fileTrack );
    if ( res != S_OK || fileTrack == 0 )
    {
        ITunesComWrapper::logComError( res, L"Casting IITrack to IITFileOrCDTrack failed" );
    }
    else
    {
        res = fileTrack->get_Podcast( &podcast );
        if ( res != S_OK )
        {
            BSTR a;
            BSTR n;
            fileTrack->get_Artist( &a );
            fileTrack->get_Name( &n );
            wstring artist = ITunesComWrapper::bstrToWString( a );
            wstring track = ITunesComWrapper::bstrToWString( n );
            wostringstream os;
            os << L"COM couldn't get podcast for " << artist << L" - " << track;
            ITunesComWrapper::logComError( res, os.str() );
        }

        fileTrack->Release();
    }

    return podcast != FALSE;
}
Beispiel #2
0
wstring
ITunesTrack::albumArtist() const
{
    if ( m_comTrack == 0 )
        return L"";  // empty track case

    BSTR bstrAlbumArtist = 0;

    IITFileOrCDTrack* fileTrack = static_cast<IITFileOrCDTrack*>(m_comTrack);
    HRESULT res = m_comTrack->QueryInterface(IID_IITFileOrCDTrack, (void**)&fileTrack);

    if ( res != S_OK || fileTrack == 0 )
    {
        ITunesComWrapper::logComError( res, L"Casting IITrack to IITFileOrCDTrack failed" );
    }
    else
    {
        res = fileTrack->get_AlbumArtist( &bstrAlbumArtist );
        fileTrack->Release();
    }

    ITunesComWrapper::handleComResult( res, L"Failed to read album artist of track" );

    return ITunesComWrapper::bstrToWString( bstrAlbumArtist );
}
Beispiel #3
0
wstring
ITunesTrack::pathForTrack( IITTrack* track )
{
    wstring path;
    IITFileOrCDTrack* fileTrack = 0;
    HRESULT res = track->QueryInterface( IID_IITFileOrCDTrack, (void**)&fileTrack );
    if ( res != S_OK || fileTrack == 0 )
    {
        // Not ideal, but logging this makes the iPodScrobbler log
        // really messy for mostly iTunes Match track libraries
        //ITunesComWrapper::logComError( res, L"Casting IITrack to IITFileOrCDTrack failed" );
    }
    else
    {
        BSTR bstrLocation = 0; // BSTR = WCHAR*
        res = fileTrack->get_Location( &bstrLocation );
        if ( res == S_OK )
        {
            path = ITunesComWrapper::bstrToWString( bstrLocation );
        }
        else
        {
            BSTR a;
            BSTR n;
            fileTrack->get_Artist( &a );
            fileTrack->get_Name( &n );
            wstring artist = ITunesComWrapper::bstrToWString( a );
            wstring track = ITunesComWrapper::bstrToWString( n );
            wostringstream os;
            os << L"COM couldn't get file path for " << artist << L" - " << track;
            ITunesComWrapper::logComError( res, os.str() );
        }

        fileTrack->Release();
    }

    return path;
}
Beispiel #4
0
bool
ITunesTrack::video()
{
    bool video = false;
    IITFileOrCDTrack* fileTrack = 0;
    HRESULT res = m_comTrack->QueryInterface( IID_IITFileOrCDTrack, (void**)&fileTrack );
    if ( res != S_OK || fileTrack == 0 )
    {
        ITunesComWrapper::logComError( res, L"Casting IITrack to IITFileOrCDTrack failed" );
    }
    else
    {
        ITVideoKind videoKind = ITVideoKindNone;
        res = fileTrack->get_VideoKind( &videoKind );
        if ( res == S_OK )
        {
            video = videoKind != ITVideoKindNone && videoKind != ITVideoKindMusicVideo;
        }
        else
        {
            BSTR a;
            BSTR n;
            fileTrack->get_Artist( &a );
            fileTrack->get_Name( &n );
            wstring artist = ITunesComWrapper::bstrToWString( a );
            wstring track = ITunesComWrapper::bstrToWString( n );
            wostringstream os;
            os << L"COM couldn't get video kind for " << artist << L" - " << track;
            ITunesComWrapper::logComError( res, os.str() );
        }

        fileTrack->Release();
    }

    return video;
}
Beispiel #5
0
/*
** Called by iTunes event handler on track change.
**
*/
void PlayerITunes::OnTrackChange()
{
	IITTrack* track;
	HRESULT hr = m_iTunes->get_CurrentTrack(&track);
	if (SUCCEEDED(hr) && track)
	{
		BSTR tmpStr;
		long tmpVal;

		// Get metadata
		track->get_Artist(&tmpStr);
		tmpStr ? (m_Artist = tmpStr) : m_Artist.clear();

		track->get_Name(&tmpStr);
		tmpStr ? (m_Title = tmpStr) : m_Title.clear();

		track->get_Album(&tmpStr);
		tmpStr ? (m_Album = tmpStr) : m_Album.clear();

		track->get_Genre(&tmpStr);;
		tmpStr ? (m_Genre = tmpStr) : m_Genre.clear();

		track->get_Duration(&tmpVal);
		m_Duration = (UINT)tmpVal;

		// Rating is 0 - 100, divide to 0 - 5
		track->get_Rating(&tmpVal);
		tmpVal /= 20L;
		m_Rating = (UINT)tmpVal;

		track->get_TrackNumber(&tmpVal);
		m_Number = (UINT)tmpVal;

		track->get_Year(&tmpVal);
		m_Year = (UINT)tmpVal;

		IITPlaylist* playlist;
		hr = track->get_Playlist(&playlist);
		if (SUCCEEDED(hr))
		{
			ITPlaylistRepeatMode repeat;
			hr = playlist->get_SongRepeat(&repeat);
			if (SUCCEEDED(hr))
			{
				m_Repeat = repeat != ITPlaylistRepeatModeOff;
			}

			playlist->Release();
		}

		IITFileOrCDTrack* file;
		hr = track->QueryInterface(&file);
		if (SUCCEEDED(hr))
		{
			file->get_Location(&tmpStr);
			file->Release();
			if (tmpStr && wcscmp(tmpStr, m_FilePath.c_str()) != 0)
			{
				++m_TrackCount;
				m_FilePath = tmpStr;

				if (m_Measures & MEASURE_COVER)
				{
					m_CoverPath.clear();

					// Check for embedded art through iTunes interface
					IITArtworkCollection* artworkCollection;
					hr = track->get_Artwork(&artworkCollection);

					if (SUCCEEDED(hr))
					{
						long count;
						artworkCollection->get_Count(&count);

						if (count > 0)
						{
							IITArtwork* artwork;
							hr = artworkCollection->get_Item(1, &artwork);

							if (SUCCEEDED(hr))
							{
								_bstr_t coverPath = m_TempCoverPath.c_str();
								hr = artwork->SaveArtworkToFile(coverPath);
								if (SUCCEEDED(hr))
								{
									m_CoverPath = m_TempCoverPath;
								}

								artwork->Release();
							}
						}

						artworkCollection->Release();
					}
				}

				if (m_Measures & MEASURE_LYRICS)
				{
					FindLyrics();
				}
			}
		}

		track->Release();
	}
	else
	{
		ClearData(false);
	}
}