IITPlaylist* ITunesComWrapper::iPodLibraryPlaylist() { HRESULT h; #define HANDLE_COM_FAIL( x ) h = ( x ); handleComResult( h, L#x ) IITSourceCollection* sources; HANDLE_COM_FAIL( m_iTunesApp->get_Sources( &sources ) ); long n; try { HANDLE_COM_FAIL( sources->get_Count( &n ) ); } catch ( ITunesException& ) { sources->Release(); throw; } IITPlaylist* playlist = NULL; for( int i = 1; i < n + 1 && !playlist; ++i ) { IITSource* source = NULL; IITPlaylistCollection* playlists = NULL; try { HANDLE_COM_FAIL( sources->get_Item( i, &source ) ); ITSourceKind kind; HANDLE_COM_FAIL( source->get_Kind( &kind ) ); if ( kind == ITSourceKindIPod ) { HANDLE_COM_FAIL( source->get_Playlists( &playlists ) ); HANDLE_COM_FAIL( playlists->get_Item( 1, &playlist ) ); BSTR name; HANDLE_COM_FAIL( playlist->get_Name( &name ) ); LOGW( 3, "Playlist name: " << bstrToWString( name ) ); } } catch ( ITunesException& ) { // We'll just continue to the next source } if ( source != NULL ) source->Release(); if ( playlists != NULL ) playlists->Release(); } sources->Release(); if ( playlist == NULL ) throw ITunesException( "No iPod library found" ); return playlist; }
void CiTunes::GetPlaylist() { Init(); long lSourceID; long lPlaylistID; long lTrackId; long countSource; IITObject * pObject; // IITUserPlaylist * pUserPlaylist; IITSourceCollection * pCollection; USES_CONVERSION; short bIsSmart=0; HRESULT hr=m_iITunes->get_Sources(&pCollection); hr=pCollection->get_Count (&countSource); IITSource * pSource = NULL; IITPlaylistCollection * pPlaylistCollection = NULL; IITPlaylist * pPlaylist = NULL; IITTrackCollection * pTrackCollection = NULL; IITTrack * pTrack = NULL; CComPtr<IITFileOrCDTrack> fileTrack; long countPlaylist; long countTracklist; CComBSTR bstrName; for(long i=1;i<=countSource;i++) { hr=pCollection->get_Item (i,&pSource); // pSource->get_SourceID (&lSourceID); pSource->get_Playlists (&pPlaylistCollection); pPlaylistCollection->get_Count (&countPlaylist); for(long j=7;j<=countPlaylist;j++)//get playlists { hr=pPlaylistCollection->get_Item (j,&pPlaylist); pPlaylist->get_PlaylistID (&lPlaylistID); CLOUD_MEIDA_METADATA_STRUCT* cmd = new CLOUD_MEIDA_METADATA_STRUCT(); InitMetadataStruct(cmd); hr=m_iITunes->GetITObjectByID (lSourceID,lPlaylistID,0,0,&pObject); pObject->get_Name (&bstrName); CComPtr<IITUserPlaylist> spUserPlaylist; hr=pPlaylist->QueryInterface(&spUserPlaylist); if(SUCCEEDED(hr)) { /* spUserPlaylist->get_Smart(&bIsSmart); if(bIsSmart==0)*/ //{ /* ITUserPlaylistSpecialKind plKind; spUserPlaylist->get_SpecialKind (&plKind);*/ //if(plKind==ITUserPlaylistSpecialKindPodcasts) //{ //AfxMessageBox(OLE2T(bstrName)); spUserPlaylist->get_Tracks (&pTrackCollection); pTrackCollection->get_Count (&countTracklist); long _lSourceID,_lPlaylistID,_lTrackId, _lDatabaseID; pPlaylist->get_SourceID (&_lSourceID); pPlaylist->get_PlaylistID(&_lPlaylistID); pPlaylist->get_TrackID(&_lTrackId); pPlaylist->get_TrackDatabaseID(&_lDatabaseID); cmd->UID = cmd->PlaylistID = GetGUID(_lSourceID,_lPlaylistID,_lTrackId,_lDatabaseID); cmd->PlaylistName = OLE2T(bstrName); cmd->Count = (int)countTracklist; cmd->Source = PLAYER_TYPE_iTunes; cmd->MediaType = MEDIA_TYPE_audio; cmd->MetadataType = _Metadata_Playlist; for(long k=1;k<=countTracklist;k++)//get tracks form playlist { hr=pTrackCollection->get_Item (k,&pTrack); CComPtr<IITFileOrCDTrack> spFileTrack; hr=pTrack->QueryInterface (__uuidof(spFileTrack),(void **)&spFileTrack); if(SUCCEEDED(hr)) { spFileTrack->get_SourceID (&_lSourceID); spFileTrack->get_PlaylistID(&_lPlaylistID); spFileTrack->get_TrackID(&_lTrackId); spFileTrack->get_TrackDatabaseID(&_lDatabaseID); cmd->ContentIDs.AddTail(GetGUID(_lSourceID,_lPlaylistID,_lTrackId,_lDatabaseID)); /* GetTrackInfo(spFileTrack );*/ } spFileTrack.Release(); pTrack->Release(); //pTrack->get_TrackID(&lTrackId); //pTrack->get_Name (&bstrName); //AfxMessageBox(OLE2T(bstrName)); //} //} } if(countTracklist >0) m_litem->insert(std::make_pair(cmd->UID,cmd)); } spUserPlaylist.Release(); } if(pSource!= NULL) SAFE_RELEASE(pSource); if(pPlaylistCollection!= NULL) SAFE_RELEASE(pPlaylistCollection); if(pPlaylist!= NULL) SAFE_RELEASE(pPlaylist); if(pTrackCollection!= NULL) SAFE_RELEASE(pTrackCollection); } ReleaseiTunes(); }