diff options
-rw-r--r-- | Makefile | 23 | ||||
-rw-r--r-- | plex.cpp | 295 | ||||
-rw-r--r-- | plex.h | 64 | ||||
-rw-r--r-- | plexOsd.cpp | 288 | ||||
-rw-r--r-- | plexOsd.h | 82 |
5 files changed, 386 insertions, 366 deletions
@@ -16,9 +16,6 @@ LIBS += -lPocoUtil -lPocoNet -lPocoNetSSL -lPocoXML -lPocoFoundation -lpcrecpp CONFIG := #-DDEBUG # uncomment to build DEBUG - -_CFLAGS += $(shell pkg-config --cflags libpcrecpp) - ### The version number of this plugin (taken from the main source file): VERSION = $(shell grep 'static const char \*const VERSION *=' $(PLUGIN).h | awk '{ print $$7 }' | sed -e 's/[";]//g') @@ -42,13 +39,6 @@ export CXXFLAGS = $(call PKGCFG,cxxflags) CXXFLAGS += -std=gnu++0x #CXXFLAGS += -std=c++11 -ifeq ($(CFLAGS),) -$(error CFLAGS not set) -endif -ifeq ($(CXXFLAGS),) -$(error CXXFLAGS not set) -endif - ### The version number of VDR's plugin API: APIVERSION = $(call PKGCFG,apiversion) @@ -73,13 +63,6 @@ INCLUDES += DEFINES += -DPLUGIN_NAME_I18N='"$(PLUGIN)"' -DPLUGIN='"$(PLUGIN)"' -D_GNU_SOURCE $(CONFIG) \ $(if $(GIT_REV), -DGIT_REV='"$(GIT_REV)"') -### Make it standard - -override CXXFLAGS += $(_CFLAGS) $(DEFINES) $(INCLUDES) \ - -g -W -Wall -Wextra -Winit-self -Werror=overloaded-virtual -override CFLAGS += $(_CFLAGS) $(DEFINES) $(INCLUDES) \ - -g -W -Wall -Wextra -Winit-self -Wdeclaration-after-statement - ### The object files (add further files here): OBJS = $(PLUGIN).o \ @@ -103,6 +86,7 @@ OBJS = $(PLUGIN).o \ PVideo.o \ Stream.o \ Media.o \ + plexOsd.o \ SRCS = $(wildcard $(OBJS:.o=.c)) $(PLUGIN).cpp @@ -110,6 +94,11 @@ SRCS = $(wildcard $(OBJS:.o=.c)) $(PLUGIN).cpp all: $(SOFILE) i18n +### Implicit rules: + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) -o $@ $< + ### Dependencies: MAKEDEP = $(CXX) -MM -MG @@ -1,283 +1,7 @@ #include "ControlServer.h" #include "SubscriptionManager.h" #include "plex.h" - -////////////////////////////////////////////////////////////////////////////// -// cOsdMenu -////////////////////////////////////////////////////////////////////////////// -static std::shared_ptr<plexclient::Plexservice> pPlexService; - -std::shared_ptr<plexclient::Plexservice> cPlexBrowser::pLastService; -int cPlexBrowser::lastCurrentItem; - -cPlexBrowser::cPlexBrowser(const char *title, std::shared_ptr<plexclient::Plexservice> Service) :cOsdMenu(title) -{ - dsyslog("[plex]%s:\n", __FUNCTION__); - pService = Service; - pService->Authenticate(); - if(pService == pLastService) { - pCont = pService->GetLastSection(true); - } else { - pCont = pService->GetSection(pService->StartUri); - } - SetMenuCategory(mcRecording); - CreateMenu(); -} - -cPlexBrowser* cPlexBrowser::RecoverLastState() -{ - if (cPlexBrowser::pLastService != NULL) { - cPlexBrowser* pBrowser = new cPlexBrowser("", cPlexBrowser::pLastService); - return pBrowser; - } - return NULL; -} - -void cPlexBrowser::CreateMenu() -{ - // Clear Menu - Clear(); - // Directory or Video? - if(pCont && pCont->m_vDirectories.size() > 0) { - - for(std::vector<plexclient::Directory>::iterator it = pCont->m_vDirectories.begin(); it != pCont->m_vDirectories.end(); ++it) { - plexclient::Directory *pDir = &(*it); - Add(new cPlexOsdItem( tr(pDir->GetTitle().c_str()), pDir) ); - } - } - - if(pCont && pCont->m_vVideos.size() > 0) { - for(std::vector<plexclient::Video>::iterator it = pCont->m_vVideos.begin(); it != pCont->m_vVideos.end(); ++it) { - plexclient::Video *vid = &(*it); // cast raw pointer - Add(new cPlexOsdItem( vid->GetTitle().c_str(), vid) ); - } - } - - if(Count() < 1) { - Add(new cPlexOsdItem("Empty")); - } else if (pService == pLastService) { - // recover last selected item - cOsdItem* item = Get(lastCurrentItem); - SetCurrent(item); - pLastService = NULL; - } - - Display(); -} - -eOSState cPlexBrowser::ProcessKey(eKeys key) -{ - eOSState state; - - // call standard function - state = cOsdMenu::ProcessKey(key); - - int current = Current(); // get current menu item index - cPlexOsdItem *item = static_cast<cPlexOsdItem*>(Get(current)); - - if(item->IsVideo()) { - if(item->GetAttachedVideo()->m_iViewCount > 0) SetHelp(tr("Info"), tr("Unscrobble")); - else SetHelp(tr("Info"), tr("Scrobble")); - } else { - SetHelp(NULL); - } - - switch (state) { - case osUnknown: - switch (key) { - case kOk: - return ProcessSelected(); - case kBack: - return LevelUp(); - case kRed: - std::cout << "RED"; - if(item->IsVideo()) { - std::cout << " Video Info"; - } - std::cout << std::endl; - break; - case kGreen: - if(item->IsVideo()) { - if(item->GetAttachedVideo()->m_iViewCount > 0) { - if(item->GetAttachedVideo()->SetUnwatched()) { - item->GetAttachedVideo()->UpdateFromServer(); - } - } else { - if(item->GetAttachedVideo()->SetWatched()) { - item->GetAttachedVideo()->UpdateFromServer(); - } - } - } - if(item->GetAttachedVideo()->m_iViewCount > 0) SetHelp(tr("Info"), tr("Unscrobble")); - else SetHelp(tr("Info"), tr("Scrobble")); - break; - default: - break; - } - break; - case osBack: - state = LevelUp(); - if (state == osEnd) { // top level reached - return osPlugin; - } - default: - break; - } - return state; -} - -eOSState cPlexBrowser::LevelUp() -{ - pCont = pService->GetLastSection(); - if(!pCont) { - cPlayMenu::eShow = menuShow::MAIN; - return osEnd; - } - cString title = cString::sprintf(tr("Browse Plex - %s"), tr(pCont->m_sTitle1.c_str())); - SetTitle(title); - CreateMenu(); - return osContinue; -} - -eOSState cPlexBrowser::ProcessSelected() -{ - int current = Current(); // get current menu item index - cPlexOsdItem *item = static_cast<cPlexOsdItem*>(Get(current)); - - - if(item->IsVideo()) { - pLastService = pService; - lastCurrentItem = current; - cMyPlugin::PlayFile(*item->GetAttachedVideo()); - return osEnd; - } - - if(item->IsDir()) { - plexclient::Directory* pDir = item->GetAttachedDirectory(); - pCont = pService->GetSection(pDir->m_sKey); - cString title = cString::sprintf(tr("Browse Plex - %s"), tr(pDir->m_sTitle.c_str())); - SetTitle(title); - CreateMenu(); - return osContinue; - } - - //return osEnd; - return osContinue; -} - - -cPlexInfo::cPlexInfo(plexclient::Video* video) : cOsdMenu(video->GetTitle().c_str()) -{ - cOsdMenu::Display(); - - Add(new cOsdItem(video->m_sSummary.c_str())); -} - -eOSState cPlexInfo::ProcessKey(eKeys Key) -{ - switch (int(Key)) { - case kUp|k_Repeat: - case kUp: - case kDown|k_Repeat: - case kDown: - case kLeft|k_Repeat: - case kLeft: - case kRight|k_Repeat: - case kRight: - DisplayMenu()->Scroll(NORMALKEY(Key) == kUp || NORMALKEY(Key) == kLeft, NORMALKEY(Key) == kLeft || NORMALKEY(Key) == kRight); - cStatus::MsgOsdTextItem(NULL, NORMALKEY(Key) == kUp || NORMALKEY(Key) == kLeft); - return osContinue; - case kInfo: - return osBack; - default: - break; - } - - eOSState state = cOsdMenu::ProcessKey(Key); - - if (state == osUnknown) { - switch (Key) { - case kGreen: - cRemote::Put(Key, true); - case kOk: - return osBack; - default: - break; - } - } - return state; -} - -////////////////////////////////////////////////////////////////////////////// -// cOsdMenu -////////////////////////////////////////////////////////////////////////////// - -menuShow cPlayMenu::eShow = MAIN; - -/** -** Play menu constructor. -*/ -cPlayMenu::cPlayMenu(const char *title, int c0, int c1, int c2, int c3, int c4) - :cOsdMenu(title, c0, c1, c2, c3, c4) -{ - SetHasHotkeys(); - - for(std::vector<plexclient::PlexServer>::iterator it = plexclient::plexgdm::GetInstance().GetPlexservers().begin(); it != plexclient::plexgdm::GetInstance().GetPlexservers().end(); ++it) { - //&(*it) - auto s1 = std::make_shared<plexclient::Plexservice>( &(*it) ); - s1->StartUri = "/library/sections"; - Add(new cPlexOsdItem(Poco::format(tr("%s - Library"), it->GetServerName()).c_str(), s1)); - - auto s2 = std::make_shared<plexclient::Plexservice>( &(*it) ); - s2->StartUri = "/video"; - Add(new cPlexOsdItem(Poco::format(tr("%s - Video Channels"), it->GetServerName()).c_str(), s2 )); - } - - if(Count() < 1) { - Add(new cPlexOsdItem(tr("No Plex Media Server found.")), false); - } -} - -/** -** Play menu destructor. -*/ -cPlayMenu::~cPlayMenu() -{ -} - -/** -** Handle play plugin menu key event. -** -** @param key key event -*/ -eOSState cPlayMenu::ProcessKey(eKeys key) -{ - eOSState state; - - //if (key != kNone) { - // dsyslog("[plex]%s: key=%d\n", __FUNCTION__, key); - //} - // call standard function - state = cOsdMenu::ProcessKey(key); - - int current = Current(); // get current menu item index - cPlexOsdItem *item = static_cast<cPlexOsdItem*>(Get(current)); - - switch (state) { - case osUnknown: - switch (key) { - case kOk: - pPlexService = item->GetAttachedService(); - cPlayMenu::eShow = menuShow::BROWSER; - return osPlugin; // restart with OSD browser - default: - break; - } - default: - break; - } - return state; -} +#include "plexOsd.h" ////////////////////////////////////////////////////////////////////////////// // cPlugin @@ -324,6 +48,12 @@ const char *cMyPlugin::Description(void) return DESCRIPTION; } + +bool cMyPlugin::Start(void) +{ + return true; +} + /** ** Start any background activities the plugin shall perform. */ @@ -353,16 +83,7 @@ const char *cMyPlugin::MainMenuEntry(void) cOsdObject *cMyPlugin::MainMenuAction(void) { //dsyslog("[plex]%s:\n", __FUNCTION__); - - if(CalledFromCode) { - CalledFromCode = false; - return cPlexBrowser::RecoverLastState(); - } - - if (cPlayMenu::eShow == menuShow::BROWSER) { - return new cPlexBrowser(tr("Browse Plex"), pPlexService); - } - return new cPlayMenu("Plex"); + return cPlexMenu::ProcessMenu(); } /** @@ -24,11 +24,10 @@ #include <algorithm> #include <memory> - /// vdr-plugin version number. /// Makefile extracts the version number for generating the file name /// for the distribution archive. -static const char *const VERSION = "0.1.0" +static const char *const VERSION = "0.1.4" #ifdef GIT_REV "-GIT" GIT_REV #endif @@ -36,66 +35,6 @@ static const char *const VERSION = "0.1.0" static const char *const DESCRIPTION = "Plex for VDR Plugin"; static const char *const MAINMENUENTRY = "Plex for VDR"; -/* - * Plex Browser - */ - -class cPlexBrowser :public cOsdMenu -{ -private: - std::shared_ptr<plexclient::Plexservice> pService; - std::shared_ptr<plexclient::MediaContainer> pCont; - std::vector<plexclient::Video> *v_Vid; - std::vector<plexclient::Directory> *v_Dir; - std::vector<std::string> m_vStack; - std::string m_sSection; - std::string m_sActualPos; - /// Create a browser menu for current directory - void CreateMenu(); - /// Handle menu level up - eOSState LevelUp(void); - /// Handle menu item selection - eOSState ProcessSelected(); - - static std::shared_ptr<plexclient::Plexservice> pLastService; - static int lastCurrentItem; - -public: - cPlexBrowser(const char *title, std::shared_ptr<plexclient::Plexservice> Service); - virtual eOSState ProcessKey(eKeys); - - static cPlexBrowser* RecoverLastState(); - -}; - -class cPlexInfo : public cOsdMenu -{ - -public: - cPlexInfo(plexclient::Video* video); - virtual eOSState ProcessKey(eKeys Keys); -}; - -enum menuShow { - MAIN, - BROWSER, - INFO -}; - -/** -** Play plugin menu class. -*/ -class cPlayMenu:public cOsdMenu -{ - -private: -public: - cPlayMenu(const char *, int = 0, int = 0, int = 0, int = 0, int = 0); - virtual ~ cPlayMenu(); - virtual eOSState ProcessKey(eKeys); - - static menuShow eShow; -}; class cMyPlugin:public cPlugin { @@ -105,6 +44,7 @@ public: virtual const char *Version(void); virtual const char *Description(void); virtual bool Initialize(void); + virtual bool Start(void); virtual void MainThreadHook(void); virtual const char *MainMenuEntry(void); virtual cOsdObject *MainMenuAction(void); diff --git a/plexOsd.cpp b/plexOsd.cpp new file mode 100644 index 0000000..55f26b3 --- /dev/null +++ b/plexOsd.cpp @@ -0,0 +1,288 @@ +#include "plexOsd.h" +#include "plex.h" + +////////////////////////////////////////////////////////////////////////////// +// cOsdMenu +////////////////////////////////////////////////////////////////////////////// +static std::shared_ptr<plexclient::Plexservice> pPlexService; + +std::shared_ptr<plexclient::Plexservice> cPlexBrowser::pLastService; +int cPlexBrowser::lastCurrentItem; + +cPlexBrowser::cPlexBrowser(const char *title, std::shared_ptr<plexclient::Plexservice> Service) :cOsdMenu(title) +{ + dsyslog("[plex]%s:\n", __FUNCTION__); + pService = Service; + pService->Authenticate(); + if(pService == pLastService) { + pCont = pService->GetLastSection(true); + } else { + pCont = pService->GetSection(pService->StartUri); + } + SetMenuCategory(mcRecording); + CreateMenu(); +} + +cPlexBrowser* cPlexBrowser::RecoverLastState() +{ + if (cPlexBrowser::pLastService != NULL) { + cPlexBrowser* pBrowser = new cPlexBrowser("", cPlexBrowser::pLastService); + return pBrowser; + } + return NULL; +} + +void cPlexBrowser::CreateMenu() +{ + // Clear Menu + Clear(); + // Directory or Video? + if(pCont && pCont->m_vDirectories.size() > 0) { + + for(std::vector<plexclient::Directory>::iterator it = pCont->m_vDirectories.begin(); it != pCont->m_vDirectories.end(); ++it) { + plexclient::Directory *pDir = &(*it); + Add(new cPlexOsdItem( tr(pDir->GetTitle().c_str()), pDir) ); + } + } + + if(pCont && pCont->m_vVideos.size() > 0) { + for(std::vector<plexclient::Video>::iterator it = pCont->m_vVideos.begin(); it != pCont->m_vVideos.end(); ++it) { + plexclient::Video *vid = &(*it); // cast raw pointer + Add(new cPlexOsdItem( vid->GetTitle().c_str(), vid) ); + } + } + + if(Count() < 1) { + Add(new cPlexOsdItem("Empty")); + } else if (pService == pLastService) { + // recover last selected item + cOsdItem* item = Get(lastCurrentItem); + SetCurrent(item); + pLastService = NULL; + } + + Display(); +} + +eOSState cPlexBrowser::ProcessKey(eKeys key) +{ + eOSState state; + + // call standard function + state = cOsdMenu::ProcessKey(key); + + int current = Current(); // get current menu item index + cPlexOsdItem *item = static_cast<cPlexOsdItem*>(Get(current)); + + if(item->IsVideo()) { + if(item->GetAttachedVideo()->m_iViewCount > 0) SetHelp(tr("Info"), tr("Unscrobble")); + else SetHelp(tr("Info"), tr("Scrobble")); + } else { + SetHelp(NULL); + } + + switch (state) { + case osUnknown: + switch (key) { + case kOk: + return ProcessSelected(); + case kBack: + return LevelUp(); + case kRed: + std::cout << "RED"; + if(item->IsVideo()) { + std::cout << " Video Info"; + } + std::cout << std::endl; + break; + case kGreen: + if(item->IsVideo()) { + if(item->GetAttachedVideo()->m_iViewCount > 0) { + if(item->GetAttachedVideo()->SetUnwatched()) { + item->GetAttachedVideo()->UpdateFromServer(); + } + } else { + if(item->GetAttachedVideo()->SetWatched()) { + item->GetAttachedVideo()->UpdateFromServer(); + } + } + } + if(item->GetAttachedVideo()->m_iViewCount > 0) SetHelp(tr("Info"), tr("Unscrobble")); + else SetHelp(tr("Info"), tr("Scrobble")); + break; + default: + break; + } + break; + case osBack: + state = LevelUp(); + if (state == osEnd) { // top level reached + return osPlugin; + } + default: + break; + } + return state; +} + +eOSState cPlexBrowser::LevelUp() +{ + pCont = pService->GetLastSection(); + if(!pCont) { + cPlexMenu::eShow = menuShow::MAIN; + return osEnd; + } + cString title = cString::sprintf(tr("Browse Plex - %s"), tr(pCont->m_sTitle1.c_str())); + SetTitle(title); + CreateMenu(); + return osContinue; +} + +eOSState cPlexBrowser::ProcessSelected() +{ + int current = Current(); // get current menu item index + cPlexOsdItem *item = static_cast<cPlexOsdItem*>(Get(current)); + + + if(item->IsVideo()) { + pLastService = pService; + lastCurrentItem = current; + cMyPlugin::PlayFile(*item->GetAttachedVideo()); + return osEnd; + } + + if(item->IsDir()) { + plexclient::Directory* pDir = item->GetAttachedDirectory(); + pCont = pService->GetSection(pDir->m_sKey); + cString title = cString::sprintf(tr("Browse Plex - %s"), tr(pDir->m_sTitle.c_str())); + SetTitle(title); + CreateMenu(); + return osContinue; + } + + //return osEnd; + return osContinue; +} + + +cPlexInfo::cPlexInfo(plexclient::Video* video) : cOsdMenu(video->GetTitle().c_str()) +{ + cOsdMenu::Display(); + + Add(new cOsdItem(video->m_sSummary.c_str())); +} + +eOSState cPlexInfo::ProcessKey(eKeys Key) +{ + switch (int(Key)) { + case kUp|k_Repeat: + case kUp: + case kDown|k_Repeat: + case kDown: + case kLeft|k_Repeat: + case kLeft: + case kRight|k_Repeat: + case kRight: + DisplayMenu()->Scroll(NORMALKEY(Key) == kUp || NORMALKEY(Key) == kLeft, NORMALKEY(Key) == kLeft || NORMALKEY(Key) == kRight); + cStatus::MsgOsdTextItem(NULL, NORMALKEY(Key) == kUp || NORMALKEY(Key) == kLeft); + return osContinue; + case kInfo: + return osBack; + default: + break; + } + + eOSState state = cOsdMenu::ProcessKey(Key); + + if (state == osUnknown) { + switch (Key) { + case kGreen: + cRemote::Put(Key, true); + case kOk: + return osBack; + default: + break; + } + } + return state; +} + +////////////////////////////////////////////////////////////////////////////// +// cOsdMenu +////////////////////////////////////////////////////////////////////////////// + +menuShow cPlexMenu::eShow = MAIN; + +/** +** Play menu constructor. +*/ +cPlexMenu::cPlexMenu(const char *title, int c0, int c1, int c2, int c3, int c4) + :cOsdMenu(title, c0, c1, c2, c3, c4) +{ + SetHasHotkeys(); + + for(std::vector<plexclient::PlexServer>::iterator it = plexclient::plexgdm::GetInstance().GetPlexservers().begin(); it != plexclient::plexgdm::GetInstance().GetPlexservers().end(); ++it) { + //&(*it) + auto s1 = std::make_shared<plexclient::Plexservice>( &(*it) ); + s1->StartUri = "/library/sections"; + Add(new cPlexOsdItem(Poco::format(tr("%s - Library"), it->GetServerName()).c_str(), s1)); + + auto s2 = std::make_shared<plexclient::Plexservice>( &(*it) ); + s2->StartUri = "/video"; + Add(new cPlexOsdItem(Poco::format(tr("%s - Video Channels"), it->GetServerName()).c_str(), s2 )); + } + + if(Count() < 1) { + Add(new cPlexOsdItem(tr("No Plex Media Server found.")), false); + } +} + +cOsdMenu* cPlexMenu::ProcessMenu() +{ + if(cMyPlugin::CalledFromCode) { + cMyPlugin::CalledFromCode = false; + return cPlexBrowser::RecoverLastState(); + } + + if (cPlexMenu::eShow == menuShow::BROWSER) { + return new cPlexBrowser(tr("Browse Plex"), pPlexService); + } + return new cPlexMenu("Plex"); +} + + +/** +** Handle play plugin menu key event. +** +** @param key key event +*/ +eOSState cPlexMenu::ProcessKey(eKeys key) +{ + eOSState state; + + //if (key != kNone) { + // dsyslog("[plex]%s: key=%d\n", __FUNCTION__, key); + //} + // call standard function + state = cOsdMenu::ProcessKey(key); + + int current = Current(); // get current menu item index + cPlexOsdItem *item = static_cast<cPlexOsdItem*>(Get(current)); + + switch (state) { + case osUnknown: + switch (key) { + case kOk: + pPlexService = item->GetAttachedService(); + cPlexMenu::eShow = menuShow::BROWSER; + return osPlugin; // restart with OSD browser + default: + break; + } + default: + break; + } + return state; +} + + diff --git a/plexOsd.h b/plexOsd.h new file mode 100644 index 0000000..d6a14f4 --- /dev/null +++ b/plexOsd.h @@ -0,0 +1,82 @@ +#ifndef CPLEXOSD_H +#define CPLEXOSD_H + +#include <vdr/osdbase.h> + +#include <iostream> +#include <string> +#include <vector> +#include <iterator> +#include <algorithm> +#include <memory> + +#include "Config.h" +#include "Plexservice.h" + +#include "plexgdm.h" +#include "cPlexOsdItem.h" +#include "hlsPlayerControl.h" + +enum menuShow { + MAIN, + BROWSER, + INFO +}; + + +/* + * Plex Browser + */ + +class cPlexBrowser :public cOsdMenu +{ +private: + std::shared_ptr<plexclient::Plexservice> pService; + std::shared_ptr<plexclient::MediaContainer> pCont; + std::vector<plexclient::Video> *v_Vid; + std::vector<plexclient::Directory> *v_Dir; + std::vector<std::string> m_vStack; + std::string m_sSection; + std::string m_sActualPos; + /// Create a browser menu for current directory + void CreateMenu(); + /// Handle menu level up + eOSState LevelUp(void); + /// Handle menu item selection + eOSState ProcessSelected(); + + static std::shared_ptr<plexclient::Plexservice> pLastService; + static int lastCurrentItem; + +public: + cPlexBrowser(const char *title, std::shared_ptr<plexclient::Plexservice> Service); + virtual eOSState ProcessKey(eKeys); + + static cPlexBrowser* RecoverLastState(); + +}; + +class cPlexInfo : public cOsdMenu +{ + +public: + cPlexInfo(plexclient::Video* video); + virtual eOSState ProcessKey(eKeys Keys); +}; + +/** +** Play plugin menu class. +*/ +class cPlexMenu:public cOsdMenu +{ + +private: +public: + cPlexMenu(const char *, int = 0, int = 0, int = 0, int = 0, int = 0); + virtual eOSState ProcessKey(eKeys); + + static cOsdMenu* ProcessMenu(); + static menuShow eShow; +}; + +#endif // CPLEXOSD_H |