diff options
author | chriszero <zerov83@gmail.com> | 2015-12-20 18:43:35 +0100 |
---|---|---|
committer | chriszero <zerov83@gmail.com> | 2015-12-20 18:43:35 +0100 |
commit | 4775c62bf44ba6d757722611313f53d6dd2a0b56 (patch) | |
tree | b948261300ea449823485305b2d980504190b11d | |
parent | 516d7da6bf79c8e48d5348706faeba8ea5061984 (diff) | |
download | vdr-plugin-plex-4775c62bf44ba6d757722611313f53d6dd2a0b56.tar.gz vdr-plugin-plex-4775c62bf44ba6d757722611313f53d6dd2a0b56.tar.bz2 |
completed "secure connections" and "remote server"
support.
-rw-r--r-- | PlexServer.cpp | 8 | ||||
-rw-r--r-- | PlexServer.h | 2 | ||||
-rw-r--r-- | hlsPlayer.cpp | 27 | ||||
-rw-r--r-- | hlsPlayer.h | 4 |
4 files changed, 20 insertions, 21 deletions
diff --git a/PlexServer.cpp b/PlexServer.cpp index 00a41eb..1039b1f 100644 --- a/PlexServer.cpp +++ b/PlexServer.cpp @@ -67,8 +67,8 @@ void PlexServer::ParseData(std::string data, std::string ip) } } } - delete m_httpSession; - m_httpSession = NULL; + + m_bLocal = true; Poco::URI uri; @@ -105,7 +105,7 @@ Poco::Net::HTTPClientSession* PlexServer::GetClientSession() return m_httpSession; } -std::istream& PlexServer::MakeRequest(Poco::Net::HTTPResponse& response, std::string path, std::map<std::string, std::string> queryParameters) +std::istream& PlexServer::MakeRequest(Poco::Net::HTTPResponse& response, std::string path, const std::map<std::string, std::string>& queryParameters) { Poco::URI uri(path); // Create a request with an optional query @@ -115,7 +115,6 @@ std::istream& PlexServer::MakeRequest(Poco::Net::HTTPResponse& response, std::st uri.addQueryParameter(pair.first, pair.second); } } - Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, uri.getPathAndQuery(), Poco::Net::HTTPMessage::HTTP_1_1); request.add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17"); @@ -135,6 +134,7 @@ std::istream& PlexServer::MakeRequest(Poco::Net::HTTPResponse& response, std::st } GetClientSession()->sendRequest(request); + return GetClientSession()->receiveResponse(response); } diff --git a/PlexServer.h b/PlexServer.h index 61031a0..45ef7d6 100644 --- a/PlexServer.h +++ b/PlexServer.h @@ -66,7 +66,7 @@ class PlexServer m_authToken = token; } - std::istream& MakeRequest(Poco::Net::HTTPResponse& response, std::string path, std::map<std::string, std::string> queryParameters = std::map<std::string, std::string>()); + std::istream& MakeRequest(Poco::Net::HTTPResponse& response, std::string path, const std::map<std::string, std::string>& queryParameters = std::map<std::string, std::string>()); std::string GetHost(); int GetPort(); diff --git a/hlsPlayer.cpp b/hlsPlayer.cpp index f23db0c..60bc7aa 100644 --- a/hlsPlayer.cpp +++ b/hlsPlayer.cpp @@ -77,7 +77,7 @@ void cHlsSegmentLoader::Action(void) m_ringBufferSize = MEGABYTE(estSize*m_segmentsToBuffer); isyslog("[plex]%s Create Ringbuffer %d MB", __FUNCTION__, estSize*m_segmentsToBuffer); - + m_pRingbuffer = new cRingBufferLinear(m_ringBufferSize, 2*TS_SIZE); while(Running()) { @@ -238,7 +238,7 @@ bool cHlsSegmentLoader::LoadSegment(std::string segmentUri) } Poco::Net::HTTPResponse segmentResponse; std::istream& segmentFile = m_pClientSession->receiveResponse(segmentResponse); - + if(segmentResponse.getStatus() != 200) { // error esyslog("[plex] %s; %s failed.", __FUNCTION__, segmentUri.c_str()); @@ -246,8 +246,7 @@ bool cHlsSegmentLoader::LoadSegment(std::string segmentUri) } dsyslog("[plex] %s: %s successfully.", __FUNCTION__, segmentUri.c_str()); - // copy response - + // copy response int m = 0; segmentFile.read(reinterpret_cast<char*>(m_pBuffer), sizeof(m_pBuffer)); std::streamsize n = segmentFile.gcount(); @@ -336,10 +335,8 @@ bool cHlsSegmentLoader::DoLoad(void) recover = true; std::string stopUri = "/video/:/transcode/universal/stop?session=" + m_sessionCookie; try { - Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_GET, stopUri); - m_pClientSession->sendRequest(req); Poco::Net::HTTPResponse reqResponse; - m_pClientSession->receiveResponse(reqResponse); + m_pVideo->m_pServer->MakeRequest(reqResponse, stopUri); int tmp = m_lastLoadedSegment; int tmp2 = m_lastSegmentSize; CloseConnection(); @@ -373,10 +370,9 @@ bool cHlsSegmentLoader::StopLoader(void) dsyslog("[plex]%s", __FUNCTION__); try { std::string stopUri = "/video/:/transcode/universal/stop?session=" + m_sessionCookie; - Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_GET, stopUri); - m_pClientSession->sendRequest(req); + Poco::Net::HTTPResponse reqResponse; - m_pClientSession->receiveResponse(reqResponse); + m_pVideo->m_pServer->MakeRequest(reqResponse, stopUri); Cancel(); @@ -398,6 +394,11 @@ void cHlsSegmentLoader::AddHeader(Poco::Net::HTTPRequest& req) req.add("X-Plex-Product", "Plex Home Theater"); req.add("X-Plex-Platform", "Plex Home Theater"); } + + if(Config::GetInstance().UsePlexAccount && !m_pVideo->m_pServer->GetAuthToken().empty()) { + // Add PlexToken to Header + req.add("X-Plex-Token", m_pVideo->m_pServer->GetAuthToken()); + } } bool cHlsSegmentLoader::Active(void) @@ -410,11 +411,9 @@ void cHlsSegmentLoader::Ping(void) dsyslog("[plex]%s", __FUNCTION__); try { std::string uri = "/video/:/transcode/universal/ping?session=" + Config::GetInstance().GetUUID(); - Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_GET, uri); - AddHeader(req); - m_pClientSession->sendRequest(req); + Poco::Net::HTTPResponse reqResponse; - m_pClientSession->receiveResponse(reqResponse); + m_pVideo->m_pServer->MakeRequest(reqResponse, uri); } catch(Poco::Exception& exc) { esyslog("[plex]%s %s ", __FUNCTION__, exc.displayText().c_str()); diff --git a/hlsPlayer.h b/hlsPlayer.h index 774aa07..ed5a80e 100644 --- a/hlsPlayer.h +++ b/hlsPlayer.h @@ -33,12 +33,12 @@ private: uchar* m_pBuffer; Poco::Net::HTTPClientSession* m_pClientSession; - plexclient::Video* m_pVideo + plexclient::Video* m_pVideo; Poco::URI m_startUri; std::string m_sessionUriPart; std::string m_segmentUriPart; std::string m_sessionCookie; - + cM3u8Parser m_startParser; cM3u8Parser m_indexParser; |