From a37e5ffb71a36ed841ec7f53ae24cca5b441c6d2 Mon Sep 17 00:00:00 2001 From: chriszero Date: Thu, 5 Mar 2015 20:11:09 +0100 Subject: Scobble / Unscrobble function --- PVideo.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ PVideo.h | 3 +++ 2 files changed, 51 insertions(+) diff --git a/PVideo.cpp b/PVideo.cpp index a0da43f..8949666 100644 --- a/PVideo.cpp +++ b/PVideo.cpp @@ -74,6 +74,7 @@ void Video::Parse(Poco::XML::Node* pNode) Poco::XML::AutoPtr pAttribs = pNode->attributes(); m_iRatingKey = GetNodeValueAsInt(pAttribs->getNamedItem("ratingKey")); + m_iViewCount = GetNodeValueAsInt(pAttribs->getNamedItem("viewCount")); m_iIndex = GetNodeValueAsInt(pAttribs->getNamedItem("index")); m_iParentIndex = GetNodeValueAsInt(pAttribs->getNamedItem("parentIndex")); m_sKey = GetNodeValue(pAttribs->getNamedItem("key")); @@ -157,4 +158,51 @@ bool Video::SetStream(Stream* stream) } } +bool Video::SetUnwatched() +{ + try { + Poco::Net::HTTPClientSession session(m_Server.GetIpAdress(), m_Server.GetPort()); + + std::string uri = Poco::format("/:/unscrobble?key=%d&identifier=com.plexapp.plugins.library", m_iRatingKey); + Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_GET, uri); + session.sendRequest(req); + + Poco::Net::HTTPResponse resp; + session.receiveResponse(resp); + + if(resp.getStatus() == 200) { + dsyslog("[plex]: Set Unwatched: %s", uri.c_str()); + return true; + } + return false; + } catch (Poco::Exception &exc) { + esyslog("[plex]: %s: %s", __FUNCTION__, exc.displayText().c_str()); + return false; + } +} + +bool Video::SetWatched() +{ + try { + Poco::Net::HTTPClientSession session(m_Server.GetIpAdress(), m_Server.GetPort()); + + std::string uri = Poco::format("/:/scrobble?key=%d&identifier=com.plexapp.plugins.library", m_iRatingKey); + Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_GET, uri); + session.sendRequest(req); + + Poco::Net::HTTPResponse resp; + session.receiveResponse(resp); + + if(resp.getStatus() == 200) { + dsyslog("[plex]: Set Watched: %s", uri.c_str()); + return true; + } + return false; + } catch (Poco::Exception &exc) { + esyslog("[plex]: %s: %s", __FUNCTION__, exc.displayText().c_str()); + return false; + } +} + + } // Namespace diff --git a/PVideo.h b/PVideo.h index c8f7c82..c419fff 100644 --- a/PVideo.h +++ b/PVideo.h @@ -56,6 +56,7 @@ public: std::string m_sThumb; std::string m_sArt; long m_iDuration; + int m_iViewCount; Poco::Timestamp m_tAddedAt; Poco::Timestamp m_tUpdatedAt; @@ -74,6 +75,8 @@ public: std::string GetTitle(); bool SetStream(Stream* stream); bool UpdateFromServer(); + bool SetWatched(); + bool SetUnwatched(); }; } -- cgit v1.2.3