bool CSmartPlaylistFileItemListModifier::Modify(CFileItemList &items) const { if (items.HasProperty(PROPERTY_SORT_ORDER)) return false; std::string xspOption = GetUrlOption(items.GetPath(), URL_OPTION_XSP); if (xspOption.empty()) return false; // check for smartplaylist-specific sorting information CSmartPlaylist xsp; if (!xsp.LoadFromJson(xspOption)) return false; items.SetProperty(PROPERTY_SORT_ORDER, (int)xsp.GetOrder()); items.SetProperty(PROPERTY_SORT_ASCENDING, xsp.GetOrderDirection() == SortOrderAscending); return true; }
bool CSmartPlaylistDirectory::GetDirectory(const CURL& url, CFileItemList& items) { // Load in the SmartPlaylist and get the WHERE query CSmartPlaylist playlist; if (!playlist.Load(url)) return false; bool result = GetDirectory(playlist, items); if (result) items.SetProperty("library.smartplaylist", true); return result; }
bool CGUIWindowAddonBrowser::GetDirectory(const CStdString& strDirectory, CFileItemList& items) { bool result; if (strDirectory.Equals("addons://downloading/")) { VECADDONS addons; CAddonInstaller::Get().GetInstallList(addons); CURL url(strDirectory); CAddonsDirectory::GenerateListing(url,addons,items); result = true; items.SetProperty("reponame",g_localizeStrings.Get(24067)); items.SetPath(strDirectory); if (m_guiState.get() && !m_guiState->HideParentDirItems()) { CFileItemPtr pItem(new CFileItem("..")); pItem->SetPath(m_history.GetParentPath()); pItem->m_bIsFolder = true; pItem->m_bIsShareOrDrive = false; items.AddFront(pItem, 0); } } else result = CGUIMediaWindow::GetDirectory(strDirectory,items); if (strDirectory.IsEmpty() && CAddonInstaller::Get().IsDownloading()) { CFileItemPtr item(new CFileItem("addons://downloading/",true)); item->SetLabel(g_localizeStrings.Get(24067)); item->SetLabelPreformated(true); item->SetIconImage("DefaultNetwork.png"); items.Add(item); } items.SetContent("addons"); for (int i=0;i<items.Size();++i) SetItemLabel2(items[i]); return result; }
bool CHTTPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { CFileCurl http; CURL url(strPath); CStdString strName, strLink; CStdString strBasePath = url.GetFileName(); if(!http.Open(url)) { CLog::Log(LOGERROR, "%s - Unable to get http directory", __FUNCTION__); return false; } CRegExp reItem(true); // HTML is case-insensitive reItem.RegComp("<a href=\"(.*)\">(.*)</a>"); /* read response from server into string buffer */ char buffer[MAX_PATH + 1024]; while(http.ReadString(buffer, sizeof(buffer)-1)) { CStdString strBuffer = buffer; StringUtils::RemoveCRLF(strBuffer); if (reItem.RegFind(strBuffer.c_str()) >= 0) { strLink = reItem.GetReplaceString("\\1"); strName = reItem.GetReplaceString("\\2"); if(strLink[0] == '/') strLink = strLink.Mid(1); CStdString strNameTemp = strName.Trim(); CStdString strLinkTemp = strLink; URIUtils::RemoveSlashAtEnd(strLinkTemp); URIUtils::RemoveSlashAtEnd(strNameTemp); CURL::Decode(strLinkTemp); if (strNameTemp == strLinkTemp && strLinkTemp != "..") { CStdStringW wName, wLink, wConverted; g_charsetConverter.unknownToUTF8(strName); g_charsetConverter.utf8ToW(strName, wName, false); HTML::CHTMLUtil::ConvertHTMLToW(wName, wConverted); g_charsetConverter.wToUTF8(wConverted, strName); URIUtils::RemoveSlashAtEnd(strName); g_charsetConverter.unknownToUTF8(strLink); g_charsetConverter.utf8ToW(strLink, wLink, false); HTML::CHTMLUtil::ConvertHTMLToW(wLink, wConverted); g_charsetConverter.wToUTF8(wConverted, strLink); CFileItemPtr pItem(new CFileItem(strName)); pItem->SetProperty("IsHTTPDirectory", true); url.SetFileName(strBasePath + strLink); pItem->SetPath(url.Get()); if(URIUtils::HasSlashAtEnd(pItem->GetPath())) pItem->m_bIsFolder = true; if (!pItem->m_bIsFolder && g_advancedSettings.m_bHTTPDirectoryStatFilesize) { CFileCurl file; file.Open(url); pItem->m_dwSize= file.GetLength(); file.Close(); } if (!pItem->m_bIsFolder && pItem->m_dwSize == 0) { CRegExp reSize(true); reSize.RegComp(">*([0-9.]+)(B|K|M|G| )</td>"); if (reSize.RegFind(strBuffer.c_str()) >= 0) { double Size = atof(reSize.GetReplaceString("\\1")); CStdString strUnit = reSize.GetReplaceString("\\2"); if (strUnit == "K") Size = Size * 1024; else if (strUnit == "M") Size = Size * 1024 * 1024; else if (strUnit == "G") Size = Size * 1000 * 1024 * 1024; pItem->m_dwSize = (int64_t)Size; } } items.Add(pItem); } } } http.Close(); items.SetProperty("IsHTTPDirectory", true); return true; }
JSONRPC_STATUS CPlayerOperations::Open(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { CVariant options = parameterObject["options"]; CVariant optionShuffled = options["shuffled"]; CVariant optionRepeat = options["repeat"]; CVariant optionResume = options["resume"]; CVariant optionPlayer = options["playername"]; if (parameterObject["item"].isObject() && parameterObject["item"].isMember("playlistid")) { int playlistid = (int)parameterObject["item"]["playlistid"].asInteger(); if (playlistid < PLAYLIST_PICTURE) { // Apply the "shuffled" option if available if (optionShuffled.isBoolean()) g_playlistPlayer.SetShuffle(playlistid, optionShuffled.asBoolean(), false); // Apply the "repeat" option if available if (!optionRepeat.isNull()) g_playlistPlayer.SetRepeat(playlistid, (REPEAT_STATE)ParseRepeatState(optionRepeat), false); } int playlistStartPosition = (int)parameterObject["item"]["position"].asInteger(); switch (playlistid) { case PLAYLIST_MUSIC: case PLAYLIST_VIDEO: CApplicationMessenger::GetInstance().SendMsg(TMSG_MEDIA_PLAY, playlistid, playlistStartPosition); OnPlaylistChanged(); break; case PLAYLIST_PICTURE: { std::string firstPicturePath; if (playlistStartPosition > 0) { CGUIWindowSlideShow *slideshow = (CGUIWindowSlideShow*)g_windowManager.GetWindow(WINDOW_SLIDESHOW); if (slideshow != NULL) { CFileItemList list; slideshow->GetSlideShowContents(list); if (playlistStartPosition < list.Size()) firstPicturePath = list.Get(playlistStartPosition)->GetPath(); } } return StartSlideshow("", false, optionShuffled.isBoolean() && optionShuffled.asBoolean(), firstPicturePath); break; } } return ACK; } else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("path")) { bool random = (optionShuffled.isBoolean() && optionShuffled.asBoolean()) || (!optionShuffled.isBoolean() && parameterObject["item"]["random"].asBoolean()); return StartSlideshow(parameterObject["item"]["path"].asString(), parameterObject["item"]["recursive"].asBoolean(), random); } else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("partymode")) { if (g_partyModeManager.IsEnabled()) g_partyModeManager.Disable(); CApplicationMessenger::GetInstance().SendMsg(TMSG_EXECUTE_BUILT_IN, -1, -1, nullptr, "playercontrol(partymode(" + parameterObject["item"]["partymode"].asString() + "))"); return ACK; } else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("channelid")) { if (!g_PVRManager.IsStarted()) return FailedToExecute; CPVRChannelGroupsContainer *channelGroupContainer = g_PVRChannelGroups; if (channelGroupContainer == NULL) return FailedToExecute; CPVRChannelPtr channel = channelGroupContainer->GetChannelById((int)parameterObject["item"]["channelid"].asInteger()); if (channel == NULL) return InvalidParams; if ((g_PVRManager.IsPlayingRadio() && channel->IsRadio()) || (g_PVRManager.IsPlayingTV() && !channel->IsRadio())) g_application.m_pPlayer->SwitchChannel(channel); else { CFileItemList *l = new CFileItemList; //don't delete, l->Add(std::make_shared<CFileItem>(channel)); CApplicationMessenger::GetInstance().PostMsg(TMSG_MEDIA_PLAY, -1, -1, static_cast<void*>(l)); } return ACK; } else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("recordingid")) { if (!g_PVRManager.IsStarted()) return FailedToExecute; CPVRRecordings *recordingsContainer = g_PVRRecordings; if (recordingsContainer == NULL) return FailedToExecute; CFileItemPtr fileItem = recordingsContainer->GetById((int)parameterObject["item"]["recordingid"].asInteger()); if (fileItem == NULL) return InvalidParams; CFileItemList *l = new CFileItemList; //don't delete, l->Add(std::make_shared<CFileItem>(*fileItem)); CApplicationMessenger::GetInstance().PostMsg(TMSG_MEDIA_PLAY, -1, -1, static_cast<void*>(l)); return ACK; } else { CFileItemList list; if (FillFileItemList(parameterObject["item"], list) && list.Size() > 0) { bool slideshow = true; for (int index = 0; index < list.Size(); index++) { if (!list[index]->IsPicture()) { slideshow = false; break; } } if (slideshow) { CGUIWindowSlideShow *slideshow = (CGUIWindowSlideShow*)g_windowManager.GetWindow(WINDOW_SLIDESHOW); if (!slideshow) return FailedToExecute; SendSlideshowAction(ACTION_STOP); slideshow->Reset(); for (int index = 0; index < list.Size(); index++) slideshow->Add(list[index].get()); return StartSlideshow("", false, optionShuffled.isBoolean() && optionShuffled.asBoolean()); } else { std::string playername; // Handle the "playerid" option if (!optionPlayer.isNull()) { if (optionPlayer.isString()) { playername = optionPlayer.asString(); if (playername != "default") { // check if the there's actually a player with the given name if (CPlayerCoreFactory::GetInstance().GetPlayerType(playername).empty()) return InvalidParams; // check if the player can handle at least the first item in the list std::vector<std::string> possiblePlayers; CPlayerCoreFactory::GetInstance().GetPlayers(*list.Get(0).get(), possiblePlayers); bool match = false; for (auto entry : possiblePlayers) { if (StringUtils::CompareNoCase(entry, playername)) { match = true; break; } } if (!match) return InvalidParams; } } else return InvalidParams; } // Handle "shuffled" option if (optionShuffled.isBoolean()) list.SetProperty("shuffled", optionShuffled); // Handle "repeat" option if (!optionRepeat.isNull()) list.SetProperty("repeat", ParseRepeatState(optionRepeat)); // Handle "resume" option if (list.Size() == 1) { if (optionResume.isBoolean() && optionResume.asBoolean()) list[0]->m_lStartOffset = STARTOFFSET_RESUME; else if (optionResume.isDouble()) list[0]->SetProperty("StartPercent", optionResume); else if (optionResume.isObject()) list[0]->m_lStartOffset = (int)(ParseTimeInSeconds(optionResume) * 75.0); } auto l = new CFileItemList(); //don't delete l->Copy(list); CApplicationMessenger::GetInstance().SendMsg(TMSG_MEDIA_PLAY, -1, -1, static_cast<void*>(l), playername); } return ACK; } else return InvalidParams; } return InvalidParams; }
bool CLibraryDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { std::string libNode = GetNode(strPath); if (libNode.empty()) return false; if (URIUtils::HasExtension(libNode, ".xml")) { // a filter or folder node TiXmlElement *node = LoadXML(libNode); if (node) { CStdString type = node->Attribute("type"); if (type == "filter") { CSmartPlaylist playlist; CStdString type, label; XMLUtils::GetString(node, "content", type); if (type.IsEmpty()) { CLog::Log(LOGERROR, "<content> tag must not be empty for type=\"filter\" node '%s'", libNode.c_str()); return false; } if (XMLUtils::GetString(node, "label", label)) label = CGUIControlFactory::FilterLabel(label); playlist.SetType(type); playlist.SetName(label); if (playlist.LoadFromXML(node) && CSmartPlaylistDirectory::GetDirectory(playlist, items)) { items.SetProperty("library.filter", "true"); items.SetPath(items.GetProperty("path.db").asString()); return true; } } else if (type == "folder") { CStdString path; XMLUtils::GetPath(node, "path", path); if (!path.IsEmpty()) { URIUtils::AddSlashAtEnd(path); return CDirectory::GetDirectory(path, items, m_strFileMask, m_flags); } } } return false; } // just a plain node - read the folder for XML nodes and other folders CFileItemList nodes; if (!CDirectory::GetDirectory(libNode, nodes, ".xml", DIR_FLAG_NO_FILE_DIRS)) return false; // iterate over our nodes for (int i = 0; i < nodes.Size(); i++) { const TiXmlElement *node = NULL; CStdString xml = nodes[i]->GetPath(); if (nodes[i]->m_bIsFolder) node = LoadXML(URIUtils::AddFileToFolder(xml, "index.xml")); else { node = LoadXML(xml); if (node && URIUtils::GetFileName(xml).Equals("index.xml")) { // set the label on our items CStdString label; if (XMLUtils::GetString(node, "label", label)) label = CGUIControlFactory::FilterLabel(label); items.SetLabel(label); continue; } } if (node) { CStdString label, icon; if (XMLUtils::GetString(node, "label", label)) label = CGUIControlFactory::FilterLabel(label); XMLUtils::GetString(node, "icon", icon); int order = 0; node->Attribute("order", &order); // create item URIUtils::RemoveSlashAtEnd(xml); CStdString folder = URIUtils::GetFileName(xml); CFileItemPtr item(new CFileItem(URIUtils::AddFileToFolder(strPath, folder), true)); item->SetLabel(label); if (!icon.IsEmpty() && g_TextureManager.HasTexture(icon)) item->SetIconImage(icon); item->m_iprogramCount = order; items.Add(item); } } items.Sort(SortByPlaylistOrder, SortOrderAscending); return true; }
bool CSmartPlaylistDirectory::GetDirectory(const CSmartPlaylist &playlist, CFileItemList& items, const std::string &strBaseDir /* = "" */, bool filter /* = false */) { bool success = false, success2 = false; std::vector<std::string> virtualFolders; SortDescription sorting; sorting.limitEnd = playlist.GetLimit(); sorting.sortBy = playlist.GetOrder(); sorting.sortOrder = playlist.GetOrderAscending() ? SortOrderAscending : SortOrderDescending; sorting.sortAttributes = playlist.GetOrderAttributes(); if (CSettings::Get().GetBool("filelists.ignorethewhensorting")) sorting.sortAttributes = (SortAttribute)(sorting.sortAttributes | SortAttributeIgnoreArticle); items.SetSortIgnoreFolders((sorting.sortAttributes & SortAttributeIgnoreFolders) == SortAttributeIgnoreFolders); std::string option = !filter ? "xsp" : "filter"; const std::string& group = playlist.GetGroup(); bool isGrouped = !group.empty() && !StringUtils::EqualsNoCase(group, "none") && !playlist.IsGroupMixed(); // get all virtual folders and add them to the item list playlist.GetVirtualFolders(virtualFolders); for (std::vector<std::string>::const_iterator virtualFolder = virtualFolders.begin(); virtualFolder != virtualFolders.end(); virtualFolder++) { CFileItemPtr pItem = CFileItemPtr(new CFileItem(*virtualFolder, true)); IFileDirectory *dir = CFileDirectoryFactory::Create(pItem->GetURL(), pItem.get()); if (dir != NULL) { pItem->SetSpecialSort(SortSpecialOnTop); items.Add(pItem); delete dir; } } if (playlist.GetType() == "movies" || playlist.GetType() == "tvshows" || playlist.GetType() == "episodes") { CVideoDatabase db; if (db.Open()) { MediaType mediaType = MediaTypes::FromString(playlist.GetType()); std::string baseDir = strBaseDir; if (strBaseDir.empty()) { if (mediaType == MediaTypeTvShow || mediaType == MediaTypeEpisode) baseDir = "videodb://tvshows/"; else if (mediaType == MediaTypeMovie) baseDir = "videodb://movies/"; else return false; if (!isGrouped) baseDir += "titles"; else baseDir += group; URIUtils::AddSlashAtEnd(baseDir); if (mediaType == MediaTypeEpisode) baseDir += "-1/-1/"; } CVideoDbUrl videoUrl; if (!videoUrl.FromString(baseDir)) return false; // store the smartplaylist as JSON in the URL as well std::string xsp; if (!playlist.IsEmpty(filter)) { if (!playlist.SaveAsJson(xsp, !filter)) return false; } if (!xsp.empty()) videoUrl.AddOption(option, xsp); else videoUrl.RemoveOption(option); CDatabase::Filter dbfilter; success = db.GetItems(videoUrl.ToString(), items, dbfilter, sorting); db.Close(); // if we retrieve a list of episodes and we didn't receive // a pre-defined base path, we need to fix it if (strBaseDir.empty() && mediaType == MediaTypeEpisode && !isGrouped) videoUrl.AppendPath("-1/-1/"); items.SetProperty(PROPERTY_PATH_DB, videoUrl.ToString()); } } else if (playlist.IsMusicType() || playlist.GetType().empty()) { CMusicDatabase db; if (db.Open()) { CSmartPlaylist plist(playlist); if (playlist.GetType() == "mixed" || playlist.GetType().empty()) plist.SetType("songs"); MediaType mediaType = MediaTypes::FromString(plist.GetType()); std::string baseDir = strBaseDir; if (strBaseDir.empty()) { baseDir = "musicdb://"; if (!isGrouped) { if (mediaType == MediaTypeArtist) baseDir += "artists"; else if (mediaType == MediaTypeAlbum) baseDir += "albums"; else if (mediaType == MediaTypeSong) baseDir += "songs"; else return false; } else baseDir += group; URIUtils::AddSlashAtEnd(baseDir); } CMusicDbUrl musicUrl; if (!musicUrl.FromString(baseDir)) return false; // store the smartplaylist as JSON in the URL as well std::string xsp; if (!plist.IsEmpty(filter)) { if (!plist.SaveAsJson(xsp, !filter)) return false; } if (!xsp.empty()) musicUrl.AddOption(option, xsp); else musicUrl.RemoveOption(option); CDatabase::Filter dbfilter; success = db.GetItems(musicUrl.ToString(), items, dbfilter, sorting); db.Close(); items.SetProperty(PROPERTY_PATH_DB, musicUrl.ToString()); } } if (playlist.GetType() == "musicvideos" || playlist.GetType() == "mixed") { CVideoDatabase db; if (db.Open()) { CSmartPlaylist mvidPlaylist(playlist); if (playlist.GetType() == "mixed") mvidPlaylist.SetType("musicvideos"); std::string baseDir = strBaseDir; if (baseDir.empty()) { baseDir = "videodb://musicvideos/"; if (!isGrouped) baseDir += "titles"; else baseDir += group; URIUtils::AddSlashAtEnd(baseDir); } CVideoDbUrl videoUrl; if (!videoUrl.FromString(baseDir)) return false; // store the smartplaylist as JSON in the URL as well std::string xsp; if (!mvidPlaylist.IsEmpty(filter)) { if (!mvidPlaylist.SaveAsJson(xsp, !filter)) return false; } if (!xsp.empty()) videoUrl.AddOption(option, xsp); else videoUrl.RemoveOption(option); CFileItemList items2; CDatabase::Filter dbfilter; success2 = db.GetItems(videoUrl.ToString(), items2, dbfilter, sorting); db.Close(); if (items.Size() <= 0) items.SetPath(videoUrl.ToString()); items.Append(items2); if (items2.Size()) { if (items.Size() > items2.Size()) items.SetContent("mixed"); else items.SetContent("musicvideos"); } items.SetProperty(PROPERTY_PATH_DB, videoUrl.ToString()); } } items.SetLabel(playlist.GetName()); if (isGrouped) items.SetContent(group); else items.SetContent(playlist.GetType()); items.SetProperty(PROPERTY_SORT_ORDER, (int)playlist.GetOrder()); items.SetProperty(PROPERTY_SORT_ASCENDING, playlist.GetOrderDirection() == SortOrderAscending); if (!group.empty()) { items.SetProperty(PROPERTY_GROUP_BY, group); items.SetProperty(PROPERTY_GROUP_MIXED, playlist.IsGroupMixed()); } // sort grouped list by label if (items.Size() > 1 && !group.empty()) items.Sort(SortByLabel, SortOrderAscending, SortAttributeIgnoreArticle); // go through and set the playlist order for (int i = 0; i < items.Size(); i++) { CFileItemPtr item = items[i]; item->m_iprogramCount = i; // hack for playlist order } if (playlist.GetType() == "mixed") return success || success2; else if (playlist.GetType() == "musicvideos") return success2; else return success; }
bool CGUIWindowAddonBrowser::GetDirectory(const std::string& strDirectory, CFileItemList& items) { bool result; if (URIUtils::PathEquals(strDirectory, "addons://downloading/")) { VECADDONS addons; CAddonInstaller::Get().GetInstallList(addons); CURL url(strDirectory); CAddonsDirectory::GenerateListing(url,addons,items); result = true; items.SetProperty("reponame",g_localizeStrings.Get(24067)); items.SetPath(strDirectory); if (m_guiState.get() && !m_guiState->HideParentDirItems()) { CFileItemPtr pItem(new CFileItem("..")); pItem->SetPath(m_history.GetParentPath()); pItem->m_bIsFolder = true; pItem->m_bIsShareOrDrive = false; items.AddFront(pItem, 0); } } else { result = CGUIMediaWindow::GetDirectory(strDirectory,items); if (CSettings::Get().GetBool("general.addonforeignfilter")) { int i=0; while (i < items.Size()) { if (!FilterVar(CSettings::Get().GetBool("general.addonforeignfilter"), items[i]->GetProperty("Addon.Language"), "en") || !FilterVar(CSettings::Get().GetBool("general.addonforeignfilter"), items[i]->GetProperty("Addon.Language"), g_langInfo.GetLanguageLocale())) { i++; } else items.Remove(i); } } } if (strDirectory.empty() && CAddonInstaller::Get().IsDownloading()) { CFileItemPtr item(new CFileItem("addons://downloading/",true)); item->SetLabel(g_localizeStrings.Get(24067)); item->SetLabelPreformated(true); item->SetIconImage("DefaultNetwork.png"); items.Add(item); } items.SetContent("addons"); for (int i=0;i<items.Size();++i) SetItemLabel2(items[i]); return result; }
bool CAddonsDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { CStdString path1(strPath); URIUtils::RemoveSlashAtEnd(path1); CURL path(path1); items.ClearProperties(); items.SetContent("addons"); VECADDONS addons; // get info from repository bool reposAsFolders = true; if (path.GetHostName().Equals("enabled")) { CAddonMgr::Get().GetAllAddons(addons, true); items.SetProperty("reponame",g_localizeStrings.Get(24062)); items.SetLabel(g_localizeStrings.Get(24062)); } else if (path.GetHostName().Equals("disabled")) { // grab all disabled addons, including disabled repositories reposAsFolders = false; CAddonMgr::Get().GetAllAddons(addons, false, true); items.SetProperty("reponame",g_localizeStrings.Get(24039)); items.SetLabel(g_localizeStrings.Get(24039)); } else if (path.GetHostName().Equals("outdated")) { reposAsFolders = false; CAddonMgr::Get().GetAllOutdatedAddons(addons); items.SetProperty("reponame",g_localizeStrings.Get(24043)); items.SetLabel(g_localizeStrings.Get(24043)); } else if (path.GetHostName().Equals("repos")) { CAddonMgr::Get().GetAddons(ADDON_REPOSITORY,addons,true); items.SetLabel(g_localizeStrings.Get(24033)); // Get Add-ons } else if (path.GetHostName().Equals("sources")) { return GetScriptsAndPlugins(path.GetFileName(), items); } else if (path.GetHostName().Equals("all")) { CAddonDatabase database; database.Open(); database.GetAddons(addons); items.SetProperty("reponame",g_localizeStrings.Get(24032)); items.SetLabel(g_localizeStrings.Get(24032)); } else if (path.GetHostName().Equals("search")) { CStdString search(path.GetFileName()); if (search.IsEmpty() && !GetKeyboardInput(16017, search)) return false; items.SetProperty("reponame",g_localizeStrings.Get(283)); items.SetLabel(g_localizeStrings.Get(283)); CAddonDatabase database; database.Open(); database.Search(search, addons); GenerateListing(path, addons, items, true); path.SetFileName(search); items.SetPath(path.Get()); return true; } else { reposAsFolders = false; AddonPtr addon; CAddonMgr::Get().GetAddon(path.GetHostName(),addon); if (!addon) return false; // ensure our repos are up to date CAddonInstaller::Get().UpdateRepos(false, true); CAddonDatabase database; database.Open(); database.GetRepository(addon->ID(),addons); items.SetProperty("reponame",addon->Name()); items.SetLabel(addon->Name()); } if (path.GetFileName().IsEmpty()) { if (!path.GetHostName().Equals("repos")) { for (int i=ADDON_UNKNOWN+1;i<ADDON_VIZ_LIBRARY;++i) { for (unsigned int j=0;j<addons.size();++j) { if (addons[j]->IsType((TYPE)i)) { CFileItemPtr item(new CFileItem(TranslateType((TYPE)i,true))); item->SetPath(URIUtils::AddFileToFolder(strPath,TranslateType((TYPE)i,false))); item->m_bIsFolder = true; CStdString thumb = GetIcon((TYPE)i); if (!thumb.IsEmpty() && g_TextureManager.HasTexture(thumb)) item->SetArt("thumb", thumb); items.Add(item); break; } } } items.SetPath(strPath); return true; } } else { TYPE type = TranslateType(path.GetFileName()); items.SetProperty("addoncategory",TranslateType(type, true)); items.SetLabel(TranslateType(type, true)); items.SetPath(strPath); // FIXME: Categorisation of addons needs adding here for (unsigned int j=0;j<addons.size();++j) { if (!addons[j]->IsType(type)) addons.erase(addons.begin()+j--); } } items.SetPath(strPath); GenerateListing(path, addons, items, reposAsFolders); // check for available updates if (path.GetHostName().Equals("enabled")) { CAddonDatabase database; database.Open(); for (int i=0;i<items.Size();++i) { AddonPtr addon2; database.GetAddon(items[i]->GetProperty("Addon.ID").asString(),addon2); if (addon2 && addon2->Version() > AddonVersion(items[i]->GetProperty("Addon.Version").asString()) && !database.IsAddonBlacklisted(addon2->ID(),addon2->Version().c_str())) { items[i]->SetProperty("Addon.Status",g_localizeStrings.Get(24068)); items[i]->SetProperty("Addon.UpdateAvail", true); } } } if (path.GetHostName().Equals("repos") && items.Size() > 1) { CFileItemPtr item(new CFileItem("addons://all/",true)); item->SetLabel(g_localizeStrings.Get(24032)); items.Add(item); } return true; }
bool CGUIWindowVideoNav::GetDirectory(const CStdString &strDirectory, CFileItemList &items) { if (m_bDisplayEmptyDatabaseMessage) return true; CFileItem directory(strDirectory, true); if (m_thumbLoader.IsLoading()) m_thumbLoader.StopThread(); m_rootDir.SetCacheDirectory(DIR_CACHE_NEVER); items.ClearProperties(); bool bResult = CGUIWindowVideoBase::GetDirectory(strDirectory, items); if (bResult) { if (items.IsVideoDb()) { XFILE::CVideoDatabaseDirectory dir; CQueryParams params; dir.GetQueryParams(items.m_strPath,params); VIDEODATABASEDIRECTORY::NODE_TYPE node = dir.GetDirectoryChildType(items.m_strPath); items.SetThumbnailImage(""); if (node == VIDEODATABASEDIRECTORY::NODE_TYPE_EPISODES || node == NODE_TYPE_SEASONS || node == NODE_TYPE_RECENTLY_ADDED_EPISODES) { CLog::Log(LOGDEBUG, "WindowVideoNav::GetDirectory"); // grab the show thumb CFileItem showItem; m_database.GetFilePathById(params.GetTvShowId(),showItem.m_strPath,VIDEODB_CONTENT_TVSHOWS); showItem.SetVideoThumb(); items.SetProperty("tvshowthumb", showItem.GetThumbnailImage()); // Grab fanart data CVideoInfoTag details; m_database.GetTvShowInfo(showItem.m_strPath, details, params.GetTvShowId()); items.SetProperty("fanart_color1", details.m_fanart.GetColor(0)); items.SetProperty("fanart_color2", details.m_fanart.GetColor(1)); items.SetProperty("fanart_color3", details.m_fanart.GetColor(2)); if (showItem.CacheLocalFanart()) items.SetProperty("fanart_image", showItem.GetCachedFanart()); // save the show description (showplot) items.SetProperty("showplot", details.m_strPlot); // set the season thumb CStdString strLabel; if (params.GetSeason() == 0) strLabel = g_localizeStrings.Get(20381); else strLabel.Format(g_localizeStrings.Get(20358), params.GetSeason()); CFileItem item(strLabel); CUtil::GetParentPath(items.m_strPath,item.m_strPath); item.m_bIsFolder = true; item.SetCachedSeasonThumb(); if (item.HasThumbnail()) items.SetProperty("seasonthumb",item.GetThumbnailImage()); // the container folder thumb is the parent (i.e. season or show) if (node == NODE_TYPE_EPISODES || node == NODE_TYPE_RECENTLY_ADDED_EPISODES) { items.SetContent("episodes"); // grab the season thumb as the folder thumb CStdString strLabel; CStdString strPath; if (params.GetSeason() == -1 && items.Size() > 0) { CQueryParams params2; dir.GetQueryParams(items[0]->m_strPath,params2); strLabel.Format(g_localizeStrings.Get(20358), params2.GetSeason()); CUtil::GetParentPath(items.m_strPath,strPath); } else { if (params.GetSeason() == 0) strLabel = g_localizeStrings.Get(20381); else strLabel.Format(g_localizeStrings.Get(20358), params.GetSeason()); strPath = items.m_strPath; } CFileItem item(strLabel); item.m_strPath = strPath; item.m_bIsFolder = true; item.GetVideoInfoTag()->m_strPath = showItem.m_strPath; item.SetCachedSeasonThumb(); items.SetThumbnailImage(item.GetThumbnailImage()); items.SetProperty("seasonthumb",item.GetThumbnailImage()); } else { items.SetContent("seasons"); items.SetThumbnailImage(showItem.GetThumbnailImage()); } } else if (node == NODE_TYPE_TITLE_MOVIES || node == NODE_TYPE_RECENTLY_ADDED_MOVIES) items.SetContent("movies"); else if (node == NODE_TYPE_TITLE_TVSHOWS) items.SetContent("tvshows"); else if (node == NODE_TYPE_TITLE_MUSICVIDEOS || node == NODE_TYPE_RECENTLY_ADDED_MUSICVIDEOS) items.SetContent("musicvideos"); else if (node == NODE_TYPE_GENRE) items.SetContent("genres"); else if (node == NODE_TYPE_COUNTRY) items.SetContent("countries"); else if (node == NODE_TYPE_ACTOR) { if (params.GetContentType() == VIDEODB_CONTENT_MUSICVIDEOS) items.SetContent("artists"); else items.SetContent("actors"); } else if (node == NODE_TYPE_DIRECTOR) items.SetContent("directors"); else if (node == NODE_TYPE_STUDIO) items.SetContent("studios"); else if (node == NODE_TYPE_YEAR) items.SetContent("years"); else if (node == NODE_TYPE_MUSICVIDEOS_ALBUM) items.SetContent("albums"); else items.SetContent(""); } } return bResult; }
bool CSmartPlaylistDirectory::GetDirectory(const CSmartPlaylist &playlist, CFileItemList& items, const CStdString &strBaseDir /* = "" */, bool filter /* = false */) { bool success = false, success2 = false; std::set<CStdString> playlists; SortDescription sorting; sorting.limitEnd = playlist.GetLimit(); sorting.sortBy = playlist.GetOrder(); sorting.sortOrder = playlist.GetOrderAscending() ? SortOrderAscending : SortOrderDescending; if (g_guiSettings.GetBool("filelists.ignorethewhensorting")) sorting.sortAttributes = SortAttributeIgnoreArticle; std::string option = !filter ? "xsp" : "filter"; if (playlist.GetType().Equals("movies") || playlist.GetType().Equals("tvshows") || playlist.GetType().Equals("episodes")) { CVideoDatabase db; if (db.Open()) { MediaType mediaType = DatabaseUtils::MediaTypeFromString(playlist.GetType()); CStdString baseDir = strBaseDir; if (strBaseDir.empty()) { switch (mediaType) { case MediaTypeTvShow: case MediaTypeEpisode: baseDir = "videodb://2/2/"; break; case MediaTypeMovie: baseDir = "videodb://1/2/"; break; default: return false; } } CVideoDbUrl videoUrl; if (!videoUrl.FromString(baseDir)) return false; // store the smartplaylist as JSON in the URL as well CStdString xsp; if (!playlist.IsEmpty(filter)) { if (!playlist.SaveAsJson(xsp, !filter)) return false; } videoUrl.AddOption(option, xsp); CDatabase::Filter dbfilter; success = db.GetSortedVideos(mediaType, videoUrl.ToString(), sorting, items, dbfilter, true); db.Close(); // if we retrieve a list of episodes and we didn't receive // a pre-defined base path, we need to fix it if (strBaseDir.empty() && mediaType == MediaTypeEpisode) videoUrl.AppendPath("-1/-1/"); items.SetProperty(PROPERTY_PATH_DB, videoUrl.ToString()); } } else if (playlist.GetType().Equals("albums")) { CMusicDatabase db; if (db.Open()) { CMusicDbUrl musicUrl; if (!musicUrl.FromString(!strBaseDir.empty() ? strBaseDir : "musicdb://3/")) return false; // store the smartplaylist as JSON in the URL as well CStdString xsp; if (!playlist.IsEmpty(filter)) { if (!playlist.SaveAsJson(xsp, !filter)) return false; } musicUrl.AddOption(option, xsp); CDatabase::Filter dbfilter; success = db.GetAlbumsByWhere(musicUrl.ToString(), dbfilter, items, sorting); db.Close(); items.SetContent("albums"); items.SetProperty(PROPERTY_PATH_DB, musicUrl.ToString()); } } else if (playlist.GetType().Equals("artists")) { CMusicDatabase db; if (db.Open()) { CMusicDbUrl musicUrl; if (!musicUrl.FromString("musicdb://2/")) return false; // store the smartplaylist as JSON in the URL as well CStdString xsp; if (!playlist.IsEmpty(filter)) { if (!playlist.SaveAsJson(xsp, !filter)) return false; } musicUrl.AddOption(option, xsp); CDatabase::Filter dbfilter; success = db.GetArtistsNav(musicUrl.ToString(), items, !g_guiSettings.GetBool("musiclibrary.showcompilationartists"), -1, -1, -1, dbfilter, sorting); db.Close(); items.SetContent("artists"); items.SetProperty(PROPERTY_PATH_DB, musicUrl.ToString()); } } if (playlist.GetType().Equals("songs") || playlist.GetType().Equals("mixed") || playlist.GetType().IsEmpty()) { CMusicDatabase db; if (db.Open()) { CSmartPlaylist songPlaylist(playlist); if (playlist.GetType().IsEmpty() || playlist.GetType().Equals("mixed")) songPlaylist.SetType("songs"); CMusicDbUrl musicUrl; if (!musicUrl.FromString(!strBaseDir.empty() ? strBaseDir : "musicdb://4/")) return false; // store the smartplaylist as JSON in the URL as well CStdString xsp; if (!songPlaylist.IsEmpty(filter)) { if (!songPlaylist.SaveAsJson(xsp, !filter)) return false; } musicUrl.AddOption(option, xsp); CDatabase::Filter dbfilter; success = db.GetSongsByWhere(musicUrl.ToString(), dbfilter, items, sorting); db.Close(); items.SetContent("songs"); items.SetProperty(PROPERTY_PATH_DB, musicUrl.ToString()); } } if (playlist.GetType().Equals("musicvideos") || playlist.GetType().Equals("mixed")) { CVideoDatabase db; if (db.Open()) { CSmartPlaylist mvidPlaylist(playlist); if (playlist.GetType().Equals("mixed")) mvidPlaylist.SetType("musicvideos"); CVideoDbUrl videoUrl; if (!videoUrl.FromString(!strBaseDir.empty() ? strBaseDir : "videodb://3/2/")) return false; // store the smartplaylist as JSON in the URL as well CStdString xsp; if (!mvidPlaylist.IsEmpty(filter)) { if (!mvidPlaylist.SaveAsJson(xsp, !filter)) return false; } videoUrl.AddOption(option, xsp); CFileItemList items2; success2 = db.GetSortedVideos(MediaTypeMusicVideo, videoUrl.ToString(), sorting, items2); db.Close(); items.Append(items2); if (items2.Size()) { if (items.Size() > items2.Size()) items.SetContent("mixed"); else items.SetContent("musicvideos"); } items.SetProperty(PROPERTY_PATH_DB, videoUrl.ToString()); } } items.SetLabel(playlist.GetName()); // go through and set the playlist order for (int i = 0; i < items.Size(); i++) { CFileItemPtr item = items[i]; item->m_iprogramCount = i; // hack for playlist order } if (playlist.GetType().Equals("mixed")) return success || success2; else if (playlist.GetType().Equals("musicvideos")) return success2; else return success; }
bool CAddonsDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { CStdString path1(strPath); CUtil::RemoveSlashAtEnd(path1); CURL path(path1); items.ClearProperties(); items.SetContent("addons"); VECADDONS addons; // get info from repository bool reposAsFolders = true; if (path.GetHostName().Equals("enabled")) { CAddonMgr::Get().GetAllAddons(addons, true); items.SetProperty("reponame",g_localizeStrings.Get(24062)); } else if (path.GetHostName().Equals("disabled")) { // grab all disabled addons, including disabled repositories reposAsFolders = false; CAddonMgr::Get().GetAllAddons(addons, false, true); items.SetProperty("reponame",g_localizeStrings.Get(24039)); } else if (path.GetHostName().Equals("outdated")) { reposAsFolders = false; CAddonMgr::Get().GetAllOutdatedAddons(addons); items.SetProperty("reponame",g_localizeStrings.Get(24043)); } else if (path.GetHostName().Equals("repos")) { CAddonMgr::Get().GetAddons(ADDON_REPOSITORY,addons,true); } else if (path.GetHostName().Equals("sources")) { return GetScriptsAndPlugins(path.GetFileName(), items); } else if (path.GetHostName().Equals("all")) { CAddonDatabase database; database.Open(); database.GetAddons(addons); items.SetProperty("reponame",g_localizeStrings.Get(24032)); } else { AddonPtr addon; CAddonMgr::Get().GetAddon(path.GetHostName(),addon); if (!addon) return false; CAddonDatabase database; database.Open(); if (!database.GetRepository(addon->ID(),addons)) { RepositoryPtr repo = boost::dynamic_pointer_cast<CRepository>(addon); addons = CRepositoryUpdateJob::GrabAddons(repo,false); } items.SetProperty("reponame",addon->Name()); } if (path.GetFileName().IsEmpty()) { if (!path.GetHostName().Equals("repos")) { for (int i=ADDON_UNKNOWN+1;i<ADDON_VIZ_LIBRARY;++i) { for (unsigned int j=0;j<addons.size();++j) { if (addons[j]->IsType((TYPE)i)) { CFileItemPtr item(new CFileItem(TranslateType((TYPE)i,true))); item->m_strPath = CUtil::AddFileToFolder(strPath,TranslateType((TYPE)i,false)); item->m_bIsFolder = true; CStdString thumb = GetIcon((TYPE)i); if (!thumb.IsEmpty() && g_TextureManager.HasTexture(thumb)) item->SetThumbnailImage(thumb); items.Add(item); break; } } } items.m_strPath = strPath; return true; } } else { TYPE type = TranslateType(path.GetFileName()); items.SetProperty("addoncategory",TranslateType(type, true)); items.m_strPath = strPath; // FIXME: Categorisation of addons needs adding here for (unsigned int j=0;j<addons.size();++j) { if (!addons[j]->IsType(type)) addons.erase(addons.begin()+j--); } } items.m_strPath = strPath; GenerateListing(path, addons, items, reposAsFolders); // check for available updates if (path.GetHostName().Equals("enabled")) { CAddonDatabase database; database.Open(); for (int i=0;i<items.Size();++i) { AddonPtr addon2; database.GetAddon(items[i]->GetProperty("Addon.ID"),addon2); if (addon2 && addon2->Version() > AddonVersion(items[i]->GetProperty("Addon.Version"))) { items[i]->SetProperty("Addon.Status",g_localizeStrings.Get(24068)); items[i]->SetProperty("Addon.UpdateAvail","true"); } } } if (path.GetHostName().Equals("repos") && items.Size() > 1) { CFileItemPtr item(new CFileItem("addons://all/",true)); item->SetLabel(g_localizeStrings.Get(24032)); items.Add(item); } return true; }
bool CHTTPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { CCurlFile http; CURL url(strPath); CStdString strName, strLink; CStdString strBasePath = url.GetFileName(); if(!http.Open(url)) { CLog::Log(LOGERROR, "%s - Unable to get http directory", __FUNCTION__); return false; } CRegExp reItem(true); // HTML is case-insensitive reItem.RegComp("<a href=\"(.*)\">(.*)</a>"); CRegExp reDateTime(true); reDateTime.RegComp("<td align=\"right\">([0-9]{2})-([A-Z]{3})-([0-9]{4}) ([0-9]{2}):([0-9]{2}) +</td>"); CRegExp reDateTimeNginx(true); reDateTimeNginx.RegComp("</a> +([0-9]{2})-([A-Z]{3})-([0-9]{4}) ([0-9]{2}):([0-9]{2}) "); CRegExp reSize(true); reSize.RegComp(">*([0-9.]+)(B|K|M|G| )</td>"); CRegExp reSizeNginx; reSizeNginx.RegComp("([0-9]+)$"); /* read response from server into string buffer */ char buffer[MAX_PATH + 1024]; while(http.ReadString(buffer, sizeof(buffer)-1)) { CStdString strBuffer = buffer; StringUtils::RemoveCRLF(strBuffer); if (reItem.RegFind(strBuffer.c_str()) >= 0) { strLink = reItem.GetReplaceString("\\1"); strName = reItem.GetReplaceString("\\2"); if(strLink[0] == '/') strLink = strLink.Mid(1); CStdString strNameTemp = strName.Trim(); CStdString strLinkTemp = strLink; URIUtils::RemoveSlashAtEnd(strLinkTemp); URIUtils::RemoveSlashAtEnd(strNameTemp); CURL::Decode(strLinkTemp); if (strNameTemp == strLinkTemp && strLinkTemp != "..") { CStdStringW wName, wLink, wConverted; g_charsetConverter.unknownToUTF8(strName); g_charsetConverter.utf8ToW(strName, wName, false); HTML::CHTMLUtil::ConvertHTMLToW(wName, wConverted); g_charsetConverter.wToUTF8(wConverted, strName); URIUtils::RemoveSlashAtEnd(strName); g_charsetConverter.unknownToUTF8(strLink); g_charsetConverter.utf8ToW(strLink, wLink, false); HTML::CHTMLUtil::ConvertHTMLToW(wLink, wConverted); g_charsetConverter.wToUTF8(wConverted, strLink); CFileItemPtr pItem(new CFileItem(strName)); pItem->SetProperty("IsHTTPDirectory", true); url.SetFileName(strBasePath + strLink); pItem->SetPath(url.Get()); if(URIUtils::HasSlashAtEnd(pItem->GetPath())) pItem->m_bIsFolder = true; CStdString day, month, year, hour, minute; if (reDateTime.RegFind(strBuffer.c_str()) >= 0) { day = reDateTime.GetReplaceString("\\1"); month = reDateTime.GetReplaceString("\\2"); year = reDateTime.GetReplaceString("\\3"); hour = reDateTime.GetReplaceString("\\4"); minute = reDateTime.GetReplaceString("\\5"); } else if (reDateTimeNginx.RegFind(strBuffer.c_str()) >= 0) { day = reDateTimeNginx.GetReplaceString("\\1"); month = reDateTimeNginx.GetReplaceString("\\2"); year = reDateTimeNginx.GetReplaceString("\\3"); hour = reDateTimeNginx.GetReplaceString("\\4"); minute = reDateTimeNginx.GetReplaceString("\\5"); } if (day.length() > 0 && month.length() > 0 && year.length() > 0) { pItem->m_dateTime = CDateTime(atoi(year.c_str()), CDateTime::MonthStringToMonthNum(month), atoi(day.c_str()), atoi(hour.c_str()), atoi(minute.c_str()), 0); } if (!pItem->m_bIsFolder) { if (reSize.RegFind(strBuffer.c_str()) >= 0) { double Size = atof(reSize.GetReplaceString("\\1")); CStdString strUnit = reSize.GetReplaceString("\\2"); if (strUnit == "K") Size = Size * 1024; else if (strUnit == "M") Size = Size * 1024 * 1024; else if (strUnit == "G") Size = Size * 1000 * 1024 * 1024; pItem->m_dwSize = (int64_t)Size; } else if (reSizeNginx.RegFind(strBuffer.c_str()) >= 0) { double Size = atof(reSizeNginx.GetReplaceString("\\1")); pItem->m_dwSize = (int64_t)Size; } else if (g_advancedSettings.m_bHTTPDirectoryStatFilesize) // As a fallback get the size by stat-ing the file (slow) { CCurlFile file; file.Open(url); pItem->m_dwSize=file.GetLength(); file.Close(); } } items.Add(pItem); } } } http.Close(); items.SetProperty("IsHTTPDirectory", true); return true; }
bool CRSSDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { CLog::Log(LOGDEBUG,"CRSSDirectory::GetDirectory - path [%s]", strPath.c_str()); m_cacheDirectory = DIR_CACHE_ALWAYS; CStdString strURL = strPath; CStdString newURL; CStdString strRoot = strPath; if (CUtil::HasSlashAtEnd(strRoot)) strRoot.Delete(strRoot.size() - 1); // If we have the items in the cache, return them if (g_directoryCache.GetDirectory(strRoot, items)) { return true; } // Remove the rss:// prefix and replace it with http:// if (strURL.Left(7) == "http://") { newURL = strURL; } else { strURL.Delete(0,6); // if first symbol is '/', we have local file if (strURL.Left(1) == "/") { newURL = "file://"; } else { newURL = "http://"; } newURL = newURL + strURL; } // Remove the last slash if (CUtil::HasSlashAtEnd(newURL)) { CUtil::RemoveSlashAtEnd(newURL); } // Create new thread and run the feed retreival from it // In order to allow progress dialog and cancel operation m_strUrl = newURL; Crc32 crc; crc.ComputeFromLowerCase(newURL); CStdString strLocalFile; strLocalFile.Format("special://temp/rss-%08x-%lu.xml", (unsigned __int32)crc, CTimeUtils::GetTimeMS()); CLog::Log(LOGDEBUG,"CRSSDirectory::GetDirectory - going to load url [%s] to file [%s]", newURL.c_str(), strLocalFile.c_str()); if (!BOXEE::Boxee::GetInstance().AsyncLoadUrl(newURL, _P(strLocalFile), "rss-load", NULL)) { CGUIDialogOK::ShowAndGetInput(51014,0,0,0); return false; } SDL_LockMutex(m_pOpFinishedMutex); int result = SDL_CondWaitTimeout(m_pOpFinishedCond,m_pOpFinishedMutex,REQUEST_WAIT_PERIOD); SDL_UnlockMutex(m_pOpFinishedMutex); m_feed.GetItemList(items); if (result != 0) { m_cacheDirectory = DIR_CACHE_NEVER; // set this property so that the UI will handle the timeout CLog::Log(LOGDEBUG,"CRSSDirectory::GetDirectory, loading timed out, path [%s] loaded:%d out of %d", strPath.c_str(), items.Size(),items.GetPageContext().m_itemsPerPage); items.SetProperty("isRequestTimedOut",true); } CLog::Log(LOGDEBUG,"CRSSDirectory::GetDirectory - done loading url, got [%d] items (result=[%d])",items.Size(),result); if (items.Size() == 0) { m_cacheDirectory = DIR_CACHE_NEVER; return true; } else { CLog::Log(LOGDEBUG,"CRSSDirectory::GetDirectory - Going to add [DefaultSortLabel] property to each item. [path=%s][NumOfItems=%d] (vns)",strPath.c_str(),items.Size()); for(int i=0; i<items.Size(); i++) { CFileItemPtr item = items[i]; char pos[5]; sprintf(pos,"%d",i+1); item->SetProperty("DefaultSortLabel",pos); //CLog::Log(LOGDEBUG,"CRSSDirectory::GetDirectory - For item [path=%s] set property [DefaultSortLabel=%s] (vns)", (item->m_strPath).c_str(),(item->GetProperty("DefaultSortLabel")).c_str()); } items.SetProperty("preferredsortmethod", SORT_METHOD_DEFAULT); items.SetProperty("preferredsortorder", SORT_ORDER_ASC); } return true; }
JSONRPC_STATUS CPlayerOperations::Open(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { CVariant optionShuffled = parameterObject["options"]["shuffled"]; CVariant optionRepeat = parameterObject["options"]["repeat"]; CVariant optionResume = parameterObject["options"]["resume"]; if (parameterObject["item"].isObject() && parameterObject["item"].isMember("playlistid")) { int playlistid = (int)parameterObject["item"]["playlistid"].asInteger(); if (playlistid < PLAYLIST_PICTURE) { // Apply the "shuffled" option if available if (optionShuffled.isBoolean()) g_playlistPlayer.SetShuffle(playlistid, optionShuffled.asBoolean(), false); // Apply the "repeat" option if available if (!optionRepeat.isNull()) g_playlistPlayer.SetRepeat(playlistid, (REPEAT_STATE)ParseRepeatState(optionRepeat), false); } switch (playlistid) { case PLAYLIST_MUSIC: case PLAYLIST_VIDEO: CApplicationMessenger::Get().MediaPlay(playlistid, (int)parameterObject["item"]["position"].asInteger()); OnPlaylistChanged(); break; case PLAYLIST_PICTURE: return StartSlideshow("", false, optionShuffled.isBoolean() && optionShuffled.asBoolean()); break; } return ACK; } else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("path")) { bool random = (optionShuffled.isBoolean() && optionShuffled.asBoolean()) || (!optionShuffled.isBoolean() && parameterObject["item"]["random"].asBoolean()); return StartSlideshow(parameterObject["item"]["path"].asString(), parameterObject["item"]["recursive"].asBoolean(), random); } else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("partymode")) { if (g_partyModeManager.IsEnabled()) g_partyModeManager.Disable(); CApplicationMessenger::Get().ExecBuiltIn("playercontrol(partymode(" + parameterObject["item"]["partymode"].asString() + "))"); return ACK; } else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("channelid")) { if (!g_PVRManager.IsStarted()) return FailedToExecute; CPVRChannelGroupsContainer *channelGroupContainer = g_PVRChannelGroups; if (channelGroupContainer == NULL) return FailedToExecute; CPVRChannelPtr channel = channelGroupContainer->GetChannelById((int)parameterObject["item"]["channelid"].asInteger()); if (channel == NULL) return InvalidParams; CApplicationMessenger::Get().MediaPlay(CFileItem(*channel.get())); return ACK; } else { CFileItemList list; if (FillFileItemList(parameterObject["item"], list) && list.Size() > 0) { bool slideshow = true; for (int index = 0; index < list.Size(); index++) { if (!list[index]->IsPicture()) { slideshow = false; break; } } if (slideshow) { CGUIWindowSlideShow *slideshow = (CGUIWindowSlideShow*)g_windowManager.GetWindow(WINDOW_SLIDESHOW); if (!slideshow) return FailedToExecute; SendSlideshowAction(ACTION_STOP); slideshow->Reset(); for (int index = 0; index < list.Size(); index++) slideshow->Add(list[index].get()); return StartSlideshow("", false, optionShuffled.isBoolean() && optionShuffled.asBoolean()); } else { // Handle "shuffled" option if (optionShuffled.isBoolean()) list.SetProperty("shuffled", optionShuffled); // Handle "repeat" option if (!optionRepeat.isNull()) list.SetProperty("repeat", ParseRepeatState(optionRepeat)); // Handle "resume" option if (list.Size() == 1) { if (optionResume.isBoolean() && optionResume.asBoolean()) list[0]->m_lStartOffset = STARTOFFSET_RESUME; else if (optionResume.isDouble()) list[0]->SetProperty("StartPercent", optionResume); else if (optionResume.isObject()) list[0]->m_lStartOffset = (int)(ParseTimeInSeconds(optionResume) * 75.0); } CApplicationMessenger::Get().MediaPlay(list); } return ACK; } else return InvalidParams; } return InvalidParams; }
JSONRPC_STATUS CPlayerOperations::Open(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { CVariant options = parameterObject["options"]; CVariant optionShuffled = options["shuffled"]; CVariant optionRepeat = options["repeat"]; CVariant optionResume = options["resume"]; CVariant optionPlayer = options["playercoreid"]; if (parameterObject["item"].isObject() && parameterObject["item"].isMember("playlistid")) { int playlistid = (int)parameterObject["item"]["playlistid"].asInteger(); if (playlistid < PLAYLIST_PICTURE) { // Apply the "shuffled" option if available if (optionShuffled.isBoolean()) g_playlistPlayer.SetShuffle(playlistid, optionShuffled.asBoolean(), false); // Apply the "repeat" option if available if (!optionRepeat.isNull()) g_playlistPlayer.SetRepeat(playlistid, (REPEAT_STATE)ParseRepeatState(optionRepeat), false); } int playlistStartPosition = (int)parameterObject["item"]["position"].asInteger(); switch (playlistid) { case PLAYLIST_MUSIC: case PLAYLIST_VIDEO: CApplicationMessenger::Get().MediaPlay(playlistid, playlistStartPosition); OnPlaylistChanged(); break; case PLAYLIST_PICTURE: { std::string firstPicturePath; if (playlistStartPosition > 0) { CGUIWindowSlideShow *slideshow = (CGUIWindowSlideShow*)g_windowManager.GetWindow(WINDOW_SLIDESHOW); if (slideshow != NULL) { CFileItemList list; slideshow->GetSlideShowContents(list); if (playlistStartPosition < list.Size()) firstPicturePath = list.Get(playlistStartPosition)->GetPath(); } } return StartSlideshow("", false, optionShuffled.isBoolean() && optionShuffled.asBoolean(), firstPicturePath); break; } } return ACK; } else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("path")) { bool random = (optionShuffled.isBoolean() && optionShuffled.asBoolean()) || (!optionShuffled.isBoolean() && parameterObject["item"]["random"].asBoolean()); return StartSlideshow(parameterObject["item"]["path"].asString(), parameterObject["item"]["recursive"].asBoolean(), random); } else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("partymode")) { if (g_partyModeManager.IsEnabled()) g_partyModeManager.Disable(); CApplicationMessenger::Get().ExecBuiltIn("playercontrol(partymode(" + parameterObject["item"]["partymode"].asString() + "))"); return ACK; } else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("channelid")) { if (!g_PVRManager.IsStarted()) return FailedToExecute; CPVRChannelGroupsContainer *channelGroupContainer = g_PVRChannelGroups; if (channelGroupContainer == NULL) return FailedToExecute; CPVRChannelPtr channel = channelGroupContainer->GetChannelById((int)parameterObject["item"]["channelid"].asInteger()); if (channel == NULL) return InvalidParams; if ((g_PVRManager.IsPlayingRadio() && channel->IsRadio()) || (g_PVRManager.IsPlayingTV() && !channel->IsRadio())) g_application.m_pPlayer->SwitchChannel(channel); else CApplicationMessenger::Get().MediaPlay(CFileItem(channel)); return ACK; } else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("recordingid")) { if (!g_PVRManager.IsStarted()) return FailedToExecute; CPVRRecordings *recordingsContainer = g_PVRRecordings; if (recordingsContainer == NULL) return FailedToExecute; CFileItemPtr fileItem = recordingsContainer->GetById((int)parameterObject["item"]["recordingid"].asInteger()); if (fileItem == NULL) return InvalidParams; CApplicationMessenger::Get().MediaPlay(*fileItem); return ACK; } else { CFileItemList list; if (FillFileItemList(parameterObject["item"], list) && list.Size() > 0) { bool slideshow = true; for (int index = 0; index < list.Size(); index++) { if (!list[index]->IsPicture()) { slideshow = false; break; } } if (slideshow) { CGUIWindowSlideShow *slideshow = (CGUIWindowSlideShow*)g_windowManager.GetWindow(WINDOW_SLIDESHOW); if (!slideshow) return FailedToExecute; SendSlideshowAction(ACTION_STOP); slideshow->Reset(); for (int index = 0; index < list.Size(); index++) slideshow->Add(list[index].get()); return StartSlideshow("", false, optionShuffled.isBoolean() && optionShuffled.asBoolean()); } else { // Handle the "playerid" option if (!optionPlayer.isNull()) { PLAYERCOREID playerId = EPC_NONE; if (optionPlayer.isInteger()) { playerId = (PLAYERCOREID)optionPlayer.asInteger(); // check if the there's actually a player with the given player ID if (CPlayerCoreFactory::Get().GetPlayerConfig(playerId) == NULL) return InvalidParams; // check if the player can handle at least the first item in the list VECPLAYERCORES possiblePlayers; CPlayerCoreFactory::Get().GetPlayers(*list.Get(0).get(), possiblePlayers); VECPLAYERCORES::const_iterator matchingPlayer = std::find(possiblePlayers.begin(), possiblePlayers.end(), playerId); if (matchingPlayer == possiblePlayers.end()) return InvalidParams; } else if (!optionPlayer.isString() || optionPlayer.asString().compare("default") != 0) return InvalidParams; // set the next player to be used g_application.m_eForcedNextPlayer = playerId; } // Handle "shuffled" option if (optionShuffled.isBoolean()) list.SetProperty("shuffled", optionShuffled); // Handle "repeat" option if (!optionRepeat.isNull()) list.SetProperty("repeat", ParseRepeatState(optionRepeat)); // Handle "resume" option if (list.Size() == 1) { if (optionResume.isBoolean() && optionResume.asBoolean()) list[0]->m_lStartOffset = STARTOFFSET_RESUME; else if (optionResume.isDouble()) list[0]->SetProperty("StartPercent", optionResume); else if (optionResume.isObject()) list[0]->m_lStartOffset = (int)(ParseTimeInSeconds(optionResume) * 75.0); } CApplicationMessenger::Get().MediaPlay(list); } return ACK; } else return InvalidParams; } return InvalidParams; }
bool CGUIWindowVideoNav::GetDirectory(const std::string &strDirectory, CFileItemList &items) { if (m_thumbLoader.IsLoading()) m_thumbLoader.StopThread(); items.ClearArt(); items.ClearProperties(); bool bResult = CGUIWindowVideoBase::GetDirectory(strDirectory, items); if (bResult) { if (items.IsVideoDb()) { XFILE::CVideoDatabaseDirectory dir; CQueryParams params; dir.GetQueryParams(items.GetPath(),params); VIDEODATABASEDIRECTORY::NODE_TYPE node = dir.GetDirectoryChildType(items.GetPath()); int iFlatten = CServiceBroker::GetSettings().GetInt(CSettings::SETTING_VIDEOLIBRARY_FLATTENTVSHOWS); int itemsSize = items.GetObjectCount(); int firstIndex = items.Size() - itemsSize; // perform the flattening logic for tvshows with a single (unwatched) season (+ optional special season) if (node == NODE_TYPE_SEASONS && !items.IsEmpty()) { // check if the last item is the "All seasons" item which should be ignored for flattening if (!items[items.Size() - 1]->HasVideoInfoTag() || items[items.Size() - 1]->GetVideoInfoTag()->m_iSeason < 0) itemsSize -= 1; bool bFlatten = (itemsSize == 1 && iFlatten == 1) || iFlatten == 2 || // flatten if one one season or if always flatten is enabled (itemsSize == 2 && iFlatten == 1 && // flatten if one season + specials (items[firstIndex]->GetVideoInfoTag()->m_iSeason == 0 || items[firstIndex + 1]->GetVideoInfoTag()->m_iSeason == 0)); if (iFlatten > 0 && !bFlatten && (WatchedMode)CMediaSettings::GetInstance().GetWatchedMode("tvshows") == WatchedModeUnwatched) { int count = 0; for(int i = 0; i < items.Size(); i++) { const CFileItemPtr item = items.Get(i); if (item->GetProperty("unwatchedepisodes").asInteger() != 0 && item->GetVideoInfoTag()->m_iSeason > 0) count++; } bFlatten = (count < 2); // flatten if there is only 1 unwatched season (not counting specials) } if (bFlatten) { // flatten if one season or flatten always items.Clear(); CVideoDbUrl videoUrl; if (!videoUrl.FromString(items.GetPath())) return false; videoUrl.AppendPath("-2/"); return GetDirectory(videoUrl.ToString(), items); } } if (node == VIDEODATABASEDIRECTORY::NODE_TYPE_EPISODES || node == NODE_TYPE_SEASONS || node == NODE_TYPE_RECENTLY_ADDED_EPISODES) { CLog::Log(LOGDEBUG, "WindowVideoNav::GetDirectory"); // grab the show thumb CVideoInfoTag details; m_database.GetTvShowInfo("", details, params.GetTvShowId()); std::map<std::string, std::string> art; if (m_database.GetArtForItem(details.m_iDbId, details.m_type, art)) { items.AppendArt(art, details.m_type); items.SetArtFallback("fanart", "tvshow.fanart"); if (node == NODE_TYPE_SEASONS) { // set an art fallback for "thumb" if (items.HasArt("tvshow.poster")) items.SetArtFallback("thumb", "tvshow.poster"); else if (items.HasArt("tvshow.banner")) items.SetArtFallback("thumb", "tvshow.banner"); } } // Grab fanart data items.SetProperty("fanart_color1", details.m_fanart.GetColor(0)); items.SetProperty("fanart_color2", details.m_fanart.GetColor(1)); items.SetProperty("fanart_color3", details.m_fanart.GetColor(2)); // save the show description (showplot) items.SetProperty("showplot", details.m_strPlot); items.SetProperty("showtitle", details.m_strShowTitle); // the container folder thumb is the parent (i.e. season or show) if (itemsSize && (node == NODE_TYPE_EPISODES || node == NODE_TYPE_RECENTLY_ADDED_EPISODES)) { items.SetContent("episodes"); int seasonID = -1; int seasonParam = params.GetSeason(); // grab all season art when flatten always if (seasonParam == -2 && iFlatten == 2) seasonParam = -1; if (seasonParam >= -1) seasonID = m_database.GetSeasonId(details.m_iDbId, seasonParam); else seasonID = items[firstIndex]->GetVideoInfoTag()->m_iIdSeason; CGUIListItem::ArtMap seasonArt; if (seasonID > -1 && m_database.GetArtForItem(seasonID, MediaTypeSeason, seasonArt)) { items.AppendArt(seasonArt, MediaTypeSeason); // set an art fallback for "thumb" if (items.HasArt("season.poster")) items.SetArtFallback("thumb", "season.poster"); else if (items.HasArt("season.banner")) items.SetArtFallback("thumb", "season.banner"); } } else items.SetContent("seasons"); } else if (node == NODE_TYPE_TITLE_MOVIES || node == NODE_TYPE_RECENTLY_ADDED_MOVIES) { if (params.GetSetId() > 0) { CGUIListItem::ArtMap setArt; if (m_database.GetArtForItem(params.GetSetId(), MediaTypeVideoCollection, setArt)) { items.AppendArt(setArt, MediaTypeVideoCollection); items.SetArtFallback("fanart", "set.fanart"); if (items.HasArt("set.poster")) items.SetArtFallback("thumb", "set.poster"); } } items.SetContent("movies"); } else if (node == NODE_TYPE_TITLE_TVSHOWS || node == NODE_TYPE_INPROGRESS_TVSHOWS) items.SetContent("tvshows"); else if (node == NODE_TYPE_TITLE_MUSICVIDEOS || node == NODE_TYPE_RECENTLY_ADDED_MUSICVIDEOS) items.SetContent("musicvideos"); else if (node == NODE_TYPE_GENRE) items.SetContent("genres"); else if (node == NODE_TYPE_COUNTRY) items.SetContent("countries"); else if (node == NODE_TYPE_ACTOR) { if (params.GetContentType() == VIDEODB_CONTENT_MUSICVIDEOS) items.SetContent("artists"); else items.SetContent("actors"); } else if (node == NODE_TYPE_DIRECTOR) items.SetContent("directors"); else if (node == NODE_TYPE_STUDIO) items.SetContent("studios"); else if (node == NODE_TYPE_YEAR) items.SetContent("years"); else if (node == NODE_TYPE_MUSICVIDEOS_ALBUM) items.SetContent("albums"); else if (node == NODE_TYPE_SETS) items.SetContent("sets"); else if (node == NODE_TYPE_TAGS) items.SetContent("tags"); else items.SetContent(""); } else if (URIUtils::PathEquals(items.GetPath(), "special://videoplaylists/")) items.SetContent("playlists"); else if (!items.IsVirtualDirectoryRoot()) { // load info from the database std::string label; if (items.GetLabel().empty() && m_rootDir.IsSource(items.GetPath(), CMediaSourceSettings::GetInstance().GetSources("video"), &label)) items.SetLabel(label); if (!items.IsSourcesPath() && !items.IsLibraryFolder()) LoadVideoInfo(items); } CVideoDbUrl videoUrl; if (videoUrl.FromString(items.GetPath()) && items.GetContent() == "tags" && !items.Contains("newtag://" + videoUrl.GetType())) { CFileItemPtr newTag(new CFileItem("newtag://" + videoUrl.GetType(), false)); newTag->SetLabel(g_localizeStrings.Get(20462)); newTag->SetLabelPreformated(true); newTag->SetSpecialSort(SortSpecialOnTop); items.Add(newTag); } } return bResult; }
JSONRPC_STATUS CPlayerOperations::Open(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { CVariant optionShuffled = parameterObject["options"]["shuffled"]; CVariant optionRepeat = parameterObject["options"]["repeat"]; CVariant optionResume = parameterObject["options"]["resume"]; if (parameterObject["item"].isObject() && parameterObject["item"].isMember("playlistid")) { int playlistid = (int)parameterObject["item"]["playlistid"].asInteger(); if (playlistid < PLAYLIST_PICTURE) { // Apply the "shuffled" option if available if (optionShuffled.isBoolean()) g_playlistPlayer.SetShuffle(playlistid, optionShuffled.asBoolean(), false); // Apply the "repeat" option if available if (!optionRepeat.isNull()) g_playlistPlayer.SetRepeat(playlistid, (REPEAT_STATE)ParseRepeatState(optionRepeat), false); } switch (playlistid) { case PLAYLIST_MUSIC: case PLAYLIST_VIDEO: g_application.getApplicationMessenger().MediaPlay(playlistid, (int)parameterObject["item"]["position"].asInteger()); OnPlaylistChanged(); break; case PLAYLIST_PICTURE: return StartSlideshow(); break; } return ACK; } else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("path")) { CStdString exec = "slideShow("; exec += parameterObject["item"]["path"].asString(); if ((optionShuffled.isBoolean() && optionShuffled.asBoolean()) || (!optionShuffled.isBoolean() && parameterObject["item"]["random"].asBoolean())) exec += ", random"; else exec += ", notrandom"; if (parameterObject["item"]["recursive"].asBoolean()) exec += ", recursive"; exec += ")"; ThreadMessage msg = { TMSG_EXECUTE_BUILT_IN, (DWORD)0, (DWORD)0, exec }; g_application.getApplicationMessenger().SendMessage(msg); return ACK; } else { CFileItemList list; if (FillFileItemList(parameterObject["item"], list) && list.Size() > 0) { bool slideshow = true; for (int index = 0; index < list.Size(); index++) { if (!list[index]->IsPicture()) { slideshow = false; break; } } if (slideshow) { CGUIWindowSlideShow *slideshow = (CGUIWindowSlideShow*)g_windowManager.GetWindow(WINDOW_SLIDESHOW); if (!slideshow) return FailedToExecute; SendSlideshowAction(ACTION_STOP); slideshow->Reset(); for (int index = 0; index < list.Size(); index++) slideshow->Add(list[index].get()); if (optionShuffled.isBoolean() && optionShuffled.asBoolean()) slideshow->Shuffle(); return StartSlideshow(); } else { // Handle "shuffled" option if (optionShuffled.isBoolean()) list.SetProperty("shuffled", optionShuffled); // Handle "repeat" option if (!optionRepeat.isNull()) list.SetProperty("repeat", ParseRepeatState(optionRepeat)); // Handle "resume" option if (list.Size() == 1) { if (optionResume.isBoolean() && optionResume.asBoolean()) list[0]->m_lStartOffset = STARTOFFSET_RESUME; else if (optionResume.isDouble()) list[0]->SetProperty("StartPercent", optionResume); else if (optionResume.isObject()) list[0]->m_lStartOffset = (int)(ParseTimeInSeconds(optionResume) * 75.0); } g_application.getApplicationMessenger().MediaPlay(list); } return ACK; } else return InvalidParams; } return InvalidParams; }