JSONRPC_STATUS CPlaylistOperations::GetItems(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { CFileItemList list; int playlist = GetPlaylist(parameterObject["playlistid"]); CGUIWindowSlideShow *slideshow = NULL; switch (playlist) { case PLAYLIST_VIDEO: case PLAYLIST_MUSIC: CApplicationMessenger::Get().PlayListPlayerGetItems(playlist, list); break; case PLAYLIST_PICTURE: slideshow = (CGUIWindowSlideShow*)g_windowManager.GetWindow(WINDOW_SLIDESHOW); if (slideshow) slideshow->GetSlideShowContents(list); break; } HandleFileItemList("id", true, "items", list, parameterObject, result); return OK; }
JSONRPC_STATUS CPlayerOperations::GetItem(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { PlayerType player = GetPlayer(parameterObject["playerid"]); CFileItemPtr fileItem; switch (player) { case Video: case Audio: { fileItem = CFileItemPtr(new CFileItem(g_application.CurrentFileItem())); if (fileItem->GetLabel().empty()) { if (IsPVRChannel()) { CPVRChannelPtr currentChannel; if (g_PVRManager.GetCurrentChannel(currentChannel) && currentChannel.get() != NULL) fileItem = CFileItemPtr(new CFileItem(*currentChannel.get())); } else if (player == Video) { if (!CVideoLibrary::FillFileItem(g_application.CurrentFile(), fileItem, parameterObject)) { const CVideoInfoTag *currentVideoTag = g_infoManager.GetCurrentMovieTag(); if (currentVideoTag != NULL) fileItem = CFileItemPtr(new CFileItem(*currentVideoTag)); fileItem->SetPath(g_application.CurrentFileItem().GetPath()); } } else { if (!CAudioLibrary::FillFileItem(g_application.CurrentFile(), fileItem, parameterObject)) { const MUSIC_INFO::CMusicInfoTag *currentMusicTag = g_infoManager.GetCurrentSongTag(); if (currentMusicTag != NULL) fileItem = CFileItemPtr(new CFileItem(*currentMusicTag)); fileItem->SetPath(g_application.CurrentFileItem().GetPath()); } } } if (IsPVRChannel()) break; if (player == Video) { bool additionalInfo = false; bool streamdetails = false; for (CVariant::const_iterator_array itr = parameterObject["properties"].begin_array(); itr != parameterObject["properties"].end_array(); itr++) { CStdString fieldValue = itr->asString(); if (fieldValue == "cast" || fieldValue == "set" || fieldValue == "setid" || fieldValue == "showlink" || fieldValue == "resume" || (fieldValue == "streamdetails" && !fileItem->GetVideoInfoTag()->m_streamDetails.HasItems())) additionalInfo = true; } CVideoDatabase videodatabase; if ((additionalInfo) && videodatabase.Open()) { if (additionalInfo) { switch (fileItem->GetVideoContentType()) { case VIDEODB_CONTENT_MOVIES: videodatabase.GetMovieInfo("", *(fileItem->GetVideoInfoTag()), fileItem->GetVideoInfoTag()->m_iDbId); break; case VIDEODB_CONTENT_MUSICVIDEOS: videodatabase.GetMusicVideoInfo("", *(fileItem->GetVideoInfoTag()), fileItem->GetVideoInfoTag()->m_iDbId); break; case VIDEODB_CONTENT_EPISODES: videodatabase.GetEpisodeInfo("", *(fileItem->GetVideoInfoTag()), fileItem->GetVideoInfoTag()->m_iDbId); break; case VIDEODB_CONTENT_TVSHOWS: case VIDEODB_CONTENT_MOVIE_SETS: default: break; } } videodatabase.Close(); } } else if (player == Audio) { if (fileItem->IsMusicDb()) { CMusicDatabase musicdb; CFileItemList items; items.Add(fileItem); CAudioLibrary::GetAdditionalSongDetails(parameterObject, items, musicdb); } } break; } case Picture: { CGUIWindowSlideShow *slideshow = (CGUIWindowSlideShow*)g_windowManager.GetWindow(WINDOW_SLIDESHOW); if (!slideshow) return FailedToExecute; CFileItemList slides; slideshow->GetSlideShowContents(slides); fileItem = slides[slideshow->CurrentSlide() - 1]; break; } case None: default: return FailedToExecute; } HandleFileItem("id", !IsPVRChannel(), "item", fileItem, parameterObject, parameterObject["properties"], result, false); return OK; }
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; }
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; }
JSON_STATUS CPlayerOperations::GetItem(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { PlayerType player = GetPlayer(parameterObject["playerid"]); CFileItemPtr fileItem; switch (player) { case Video: case Audio: { if (g_application.CurrentFileItem().GetLabel().empty()) { CFileItem tmpItem; if (player == Video) CVideoLibrary::FillFileItem(g_application.CurrentFile(), tmpItem); else CAudioLibrary::FillFileItem(g_application.CurrentFile(), tmpItem); fileItem = CFileItemPtr(new CFileItem(tmpItem)); } else fileItem = CFileItemPtr(new CFileItem(g_application.CurrentFileItem())); if (player == Video) { bool additionalInfo = false; for (CVariant::const_iterator_array itr = parameterObject["properties"].begin_array(); itr != parameterObject["properties"].end_array(); itr++) { CStdString fieldValue = itr->asString(); if (fieldValue == "cast" || fieldValue == "set" || fieldValue == "setid" || fieldValue == "showlink" || fieldValue == "resume") additionalInfo = true; } if (additionalInfo) { CVideoDatabase videodatabase; if (videodatabase.Open()) { switch (fileItem->GetVideoContentType()) { case VIDEODB_CONTENT_MOVIES: videodatabase.GetMovieInfo("", *(fileItem->GetVideoInfoTag()), fileItem->GetVideoInfoTag()->m_iDbId); break; case VIDEODB_CONTENT_MUSICVIDEOS: videodatabase.GetMusicVideoInfo("", *(fileItem->GetVideoInfoTag()), fileItem->GetVideoInfoTag()->m_iDbId); break; case VIDEODB_CONTENT_EPISODES: videodatabase.GetEpisodeInfo("", *(fileItem->GetVideoInfoTag()), fileItem->GetVideoInfoTag()->m_iDbId); break; case VIDEODB_CONTENT_TVSHOWS: case VIDEODB_CONTENT_MOVIE_SETS: default: break; } videodatabase.Close(); } } } break; } case Picture: { CGUIWindowSlideShow *slideshow = (CGUIWindowSlideShow*)g_windowManager.GetWindow(WINDOW_SLIDESHOW); if (!slideshow) return FailedToExecute; CFileItemList slides; slideshow->GetSlideShowContents(slides); fileItem = slides[slideshow->CurrentSlide() - 1]; break; } case None: default: return FailedToExecute; } HandleFileItem("id", true, "item", fileItem, parameterObject, parameterObject["properties"], result, false); return OK; }