summaryrefslogtreecommitdiff
path: root/PVideo.cpp
diff options
context:
space:
mode:
authorchriszero <zerov83@gmail.com>2015-02-22 16:26:29 +0100
committerchriszero <zerov83@gmail.com>2015-02-22 16:26:29 +0100
commita4567e4d33727c941a8abe14c8165f212835f064 (patch)
treec2437e167edbb9d353981242810755f53be88860 /PVideo.cpp
parent3f4e427c519aebc2e918443bc03dbec6c5344416 (diff)
downloadvdr-plugin-plex-a4567e4d33727c941a8abe14c8165f212835f064.tar.gz
vdr-plugin-plex-a4567e4d33727c941a8abe14c8165f212835f064.tar.bz2
Video is now able to update itself
Diffstat (limited to 'PVideo.cpp')
-rw-r--r--PVideo.cpp83
1 files changed, 79 insertions, 4 deletions
diff --git a/PVideo.cpp b/PVideo.cpp
index 22f36e7..0518afb 100644
--- a/PVideo.cpp
+++ b/PVideo.cpp
@@ -1,5 +1,10 @@
#include "PVideo.h"
#include <Poco/Format.h>
+#include <Poco/Net/HTTPRequest.h>
+#include <Poco/Net/HTTPResponse.h>
+
+#include <vdr/tools.h>
+#include "PlexHelper.h"
namespace plexclient
{
@@ -9,6 +14,57 @@ Video::Video(Poco::XML::Node* pNode, PlexServer Server, MediaContainer* parent)
m_iMyPlayOffset = 0;
m_lViewoffset = 0;
m_Server = Server;
+ Parse(pNode);
+
+ if (m_iParentIndex < 0) {
+ m_iParentIndex = parent->m_iParentIndex;
+ }
+}
+
+bool Video::UpdateFromServer()
+{
+ try {
+ Poco::URI fileuri(Poco::format("%s/library/metadata/%d", m_Server.GetUri(), m_iRatingKey));
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, fileuri.getPathAndQuery(), Poco::Net::HTTPMessage::HTTP_1_1);
+ PlexHelper::AddHttpHeader(request);
+
+ Poco::Net::HTTPClientSession session(fileuri.getHost(), fileuri.getPort());
+
+ session.sendRequest(request);
+ Poco::Net::HTTPResponse response;
+ std::istream &rs = session.receiveResponse(response);
+
+ if(response.getStatus() == 200) {
+ // clear vectors
+ m_vCountry.clear();
+ m_vDirector.clear();
+ m_vGenre.clear();
+ m_vRole.clear();
+ m_vWriter.clear();
+
+ InputSource src(rs);
+ DOMParser parser;
+ Poco::XML::AutoPtr<Document> pDoc = parser.parse(&src);
+
+ NodeIterator it(pDoc, Poco::XML::NodeFilter::SHOW_ALL);
+ Poco::XML::Node* pNode = it.nextNode();
+ while(pNode) {
+ if(Poco::icompare(pNode->nodeName(), "Video") == 0) {
+ Parse(pNode);
+ }
+
+ pNode = it.nextNode();
+ }
+ return true;
+ }
+ } catch (Poco::Exception &exc) {
+ esyslog("[plex]: %s: %s", __FUNCTION__, exc.displayText().c_str());
+ }
+ return false;
+}
+
+void Video::Parse(Poco::XML::Node* pNode)
+{
NodeIterator it(pNode, Poco::XML::NodeFilter::SHOW_ALL);
Poco::XML::Node* pChildNode = it.nextNode();
@@ -18,7 +74,6 @@ Video::Video(Poco::XML::Node* pNode, PlexServer Server, MediaContainer* parent)
Poco::XML::AutoPtr<Poco::XML::NamedNodeMap> pAttribs = pNode->attributes();
m_iRatingKey = GetNodeValueAsInt(pAttribs->getNamedItem("ratingKey"));
- m_iIndex = GetNodeValueAsInt(pAttribs->getNamedItem("index"));
m_iParentIndex = GetNodeValueAsInt(pAttribs->getNamedItem("parentIndex"));
m_sKey = GetNodeValue(pAttribs->getNamedItem("key"));
m_sStudio = GetNodeValue(pAttribs->getNamedItem("studio"));
@@ -55,9 +110,6 @@ Video::Video(Poco::XML::Node* pNode, PlexServer Server, MediaContainer* parent)
}
pChildNode = it.nextNode();
}
- if (m_iParentIndex < 0) {
- m_iParentIndex = parent->m_iParentIndex;
- }
}
std::string Video::GetTitle()
@@ -76,4 +128,27 @@ std::string Video::GetTitle()
return res;
}
+bool Video::SetStream(Stream* stream)
+{
+ try {
+ Poco::Net::HTTPClientSession session(m_Server.GetIpAdress(), m_Server.GetPort());
+
+ std::string uri = Poco::format("/library/parts/%d?%s", m_Media.m_iPartId, stream->GetSetStreamQuery());
+ Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_PUT, uri);
+ session.sendRequest(req);
+
+ Poco::Net::HTTPResponse resp;
+ session.receiveResponse(resp);
+
+ if(resp.getStatus() == 200) {
+ dsyslog("[plex]: Set Stream: %s", uri.c_str());
+ return true;
+ }
+ return false;
+ } catch (Poco::Exception &exc) {
+ esyslog("[plex]: %s: %s", __FUNCTION__, exc.displayText().c_str());
+ return false;
+ }
+}
+
} // Namespace