void CShoutcastRipFile::SetFilename( const char* filePath, const char* fileName ) { //first look if we need to create the directory XFILE::CDirectory::Create(filePath); CFileItemList items; XFILE::CDirectory::GetDirectory(filePath, items, ".mp3", false); items.SetFastLookup(true); CStdString file; for (int i = m_iTrackCount; i <= MAX_RECORDED_TRACKS; i++ ) { if ( m_recState.bHasMetaData ) file.Format("%i - %s.mp3", i, fileName); // will be "TRACKNUMBER - FILENAME.mp3" else file.Format("%s - %i.mp3", fileName, i); // will be "FILENAME - TRACKNUMBER.mp3" file = CUtil::AddFileToFolder(filePath, CUtil::MakeLegalFileName(file)); if (!items.Get(file)) { strcpy( m_szFilteredFileName, file.c_str() ); //set the appropriate trackNumber m_Tag.SetTrackNumber(i); if ( !m_recState.bHasMetaData ) m_iTrackCount = i; return; } } //if its the MAX_RECORDED_TRACKS. file, we overwrite it strcpy( m_szFilteredFileName, file.c_str() ); return; }
void CMusicInfoLoader::LoadCache(const std::string& strFileName, CFileItemList& items) { CFile file; if (file.Open(strFileName)) { CArchive ar(&file, CArchive::load); int iSize = 0; ar >> iSize; for (int i = 0; i < iSize; i++) { CFileItemPtr pItem(new CFileItem()); ar >> *pItem; items.Add(pItem); } ar.Close(); file.Close(); items.SetFastLookup(true); }
/// \brief Add unique file and folders and its subfolders to playlist /// \param pItem The file item to add void CGUIWindowMusicBase::AddItemToPlayList(const CFileItemPtr &pItem, CFileItemList &queuedItems) { if (!pItem->CanQueue() || pItem->IsRAR() || pItem->IsZIP() || pItem->IsParentFolder()) // no zip/rar enques thank you! return; // fast lookup is needed here queuedItems.SetFastLookup(true); if (pItem->IsMusicDb() && pItem->m_bIsFolder && !pItem->IsParentFolder()) { // we have a music database folder, just grab the "all" item underneath it CMusicDatabaseDirectory dir; if (!dir.ContainsSongs(pItem->GetPath())) { // grab the ALL item in this category // Genres will still require 2 lookups, and queuing the entire Genre folder // will require 3 lookups (genre, artist, album) CMusicDbUrl musicUrl; musicUrl.FromString(pItem->GetPath()); musicUrl.AppendPath("-1/"); CFileItemPtr item(new CFileItem(musicUrl.ToString(), true)); item->SetCanQueue(true); // workaround for CanQueue() check above AddItemToPlayList(item, queuedItems); return; } } if (pItem->m_bIsFolder || (g_windowManager.GetActiveWindow() == WINDOW_MUSIC_NAV && pItem->IsPlayList())) { // Check if we add a locked share if ( pItem->m_bIsShareOrDrive ) { CFileItem item = *pItem; if ( !g_passwordManager.IsItemUnlocked( &item, "music" ) ) return ; } // recursive CFileItemList items; GetDirectory(pItem->GetPath(), items); //OnRetrieveMusicInfo(items); FormatAndSort(items); for (int i = 0; i < items.Size(); ++i) AddItemToPlayList(items[i], queuedItems); } else { if (pItem->IsPlayList()) { auto_ptr<CPlayList> pPlayList (CPlayListFactory::Create(*pItem)); if (pPlayList.get()) { // load it if (!pPlayList->Load(pItem->GetPath())) { CGUIDialogOK::ShowAndGetInput(6, 0, 477, 0); return; //hmmm unable to load playlist? } CPlayList playlist = *pPlayList; for (int i = 0; i < (int)playlist.size(); ++i) { AddItemToPlayList(playlist[i], queuedItems); } return; } } else if(pItem->IsInternetStream()) { // just queue the internet stream, it will be expanded on play queuedItems.Add(pItem); } else if (pItem->IsPlugin() && pItem->GetProperty("isplayable") == "true") { // python files can be played queuedItems.Add(pItem); } else if (!pItem->IsNFO() && pItem->IsAudio()) { CFileItemPtr itemCheck = queuedItems.Get(pItem->GetPath()); if (!itemCheck || itemCheck->m_lStartOffset != pItem->m_lStartOffset) { // add item CFileItemPtr item(new CFileItem(*pItem)); m_musicdatabase.SetPropertiesForFileItem(*item); queuedItems.Add(item); } } } }
void CGUIWindowVideoNav::LoadVideoInfo(CFileItemList &items, CVideoDatabase &database, bool allowReplaceLabels) { //! @todo this could possibly be threaded as per the music info loading, //! we could also cache the info if (!items.GetContent().empty() && !items.IsPlugin()) return; // don't load for listings that have content set and weren't created from plugins std::string content = items.GetContent(); // determine content only if it isn't set if (content.empty()) { content = database.GetContentForPath(items.GetPath()); items.SetContent((content.empty() && !items.IsPlugin()) ? "files" : content); } /* If we have a matching item in the library, so we can assign the metadata to it. In addition, we can choose * whether the item is stacked down (eg in the case of folders representing a single item) * whether or not we assign the library's labels to the item, or leave the item as is. As certain users (read: certain developers) don't want either of these to occur, we compromise by stacking items down only if stacking is available and enabled. Similarly, we assign the "clean" library labels to the item only if the "Replace filenames with library titles" setting is enabled. */ const bool stackItems = items.GetProperty("isstacked").asBoolean() || (StackingAvailable(items) && CServiceBroker::GetSettings().GetBool(CSettings::SETTING_MYVIDEOS_STACKVIDEOS)); const bool replaceLabels = allowReplaceLabels && CServiceBroker::GetSettings().GetBool(CSettings::SETTING_MYVIDEOS_REPLACELABELS); CFileItemList dbItems; /* NOTE: In the future when GetItemsForPath returns all items regardless of whether they're "in the library" we won't need the fetchedPlayCounts code, and can "simply" do this directly on absence of content. */ bool fetchedPlayCounts = false; if (!content.empty()) { database.GetItemsForPath(content, items.GetPath(), dbItems); dbItems.SetFastLookup(true); } for (int i = 0; i < items.Size(); i++) { CFileItemPtr pItem = items[i]; CFileItemPtr match; if (!content.empty()) /* optical media will be stacked down, so it's path won't match the base path */ { std::string pathToMatch = pItem->IsOpticalMediaFile() ? pItem->GetLocalMetadataPath() : pItem->GetPath(); if (URIUtils::IsMultiPath(pathToMatch)) pathToMatch = CMultiPathDirectory::GetFirstPath(pathToMatch); match = dbItems.Get(pathToMatch); } if (match) { pItem->UpdateInfo(*match, replaceLabels); if (stackItems) { if (match->m_bIsFolder) pItem->SetPath(match->GetVideoInfoTag()->m_strPath); else pItem->SetPath(match->GetVideoInfoTag()->m_strFileNameAndPath); // if we switch from a file to a folder item it means we really shouldn't be sorting files and // folders separately if (pItem->m_bIsFolder != match->m_bIsFolder) { items.SetSortIgnoreFolders(true); pItem->m_bIsFolder = match->m_bIsFolder; } } } else { /* NOTE: Currently we GetPlayCounts on our items regardless of whether content is set as if content is set, GetItemsForPaths doesn't return anything not in the content tables. This code can be removed once the content tables are always filled */ if (!pItem->m_bIsFolder && !fetchedPlayCounts) { database.GetPlayCounts(items.GetPath(), items); fetchedPlayCounts = true; } // set the watched overlay if (pItem->IsVideo()) pItem->SetOverlayImage(CGUIListItem::ICON_OVERLAY_UNWATCHED, pItem->HasVideoInfoTag() && pItem->GetVideoInfoTag()->GetPlayCount() > 0); } } }
bool CZipDirectory::GetDirectory(const CStdString& strPathOrig, CFileItemList& items) { CStdString strPath; /* if this isn't a proper archive path, assume it's the path to a archive file */ if( !strPathOrig.Left(6).Equals("zip://") ) URIUtils::CreateArchivePath(strPath, "zip", strPathOrig, ""); else strPath = strPathOrig; CURL url(strPath); CStdString strArchive = url.GetHostName(); CStdString strOptions = url.GetOptions(); CStdString strPathInZip = url.GetFileName(); url.SetOptions(""); // delete options to have a clean path to add stuff too url.SetFileName(""); // delete filename too as our names later will contain it CStdString strSlashPath = url.Get(); CStdString strBuffer; // the RAR code depends on things having a "/" at the end of the path URIUtils::AddSlashAtEnd(strSlashPath); vector<SZipEntry> entries; // turn on fast lookups bool bWasFast(items.GetFastLookup()); items.SetFastLookup(true); if (!g_ZipManager.GetZipList(strPath,entries)) return false; vector<CStdString> baseTokens; if (!strPathInZip.IsEmpty()) CUtil::Tokenize(strPathInZip,baseTokens,"/"); for (vector<SZipEntry>::iterator ze=entries.begin(); ze!=entries.end(); ++ze) { CStdString strEntryName(ze->name); strEntryName.Replace('\\','/'); if (strEntryName == strPathInZip) // skip the listed dir continue; vector<CStdString> pathTokens; CUtil::Tokenize(strEntryName,pathTokens,"/"); if (pathTokens.size() < baseTokens.size()+1) continue; bool bAdd=true; strEntryName = ""; for ( unsigned int i=0; i<baseTokens.size(); ++i ) { if (pathTokens[i] != baseTokens[i]) { bAdd = false; break; } strEntryName += pathTokens[i] + "/"; } if (!bAdd) continue; strEntryName += pathTokens[baseTokens.size()]; char c=ze->name[strEntryName.size()]; if (c == '/' || c == '\\') strEntryName += '/'; bool bIsFolder = false; if (strEntryName[strEntryName.size()-1] != '/') // this is a file { strBuffer = strSlashPath + strEntryName + strOptions; } else { // this is new folder. add if not already added bIsFolder = true; strBuffer = strSlashPath + strEntryName + strOptions; if (items.Contains(strBuffer)) // already added continue; } CFileItemPtr pFileItem(new CFileItem); if (g_charsetConverter.isValidUtf8(pathTokens[baseTokens.size()])) g_charsetConverter.utf8ToStringCharset(pathTokens[baseTokens.size()]); pFileItem->SetLabel(pathTokens[baseTokens.size()]); if (bIsFolder) { pFileItem->m_dwSize = 0; URIUtils::AddSlashAtEnd(strBuffer); } else pFileItem->m_dwSize = ze->usize; pFileItem->SetPath(strBuffer); pFileItem->m_bIsFolder = bIsFolder; pFileItem->m_idepth = ze->method; items.Add(pFileItem); } items.SetFastLookup(bWasFast); return true; }