summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchriszero <zerov83@gmail.com>2015-12-22 20:29:57 +0100
committerchriszero <zerov83@gmail.com>2015-12-22 20:29:57 +0100
commit78eff7c58f9913bdc7dcad71370160261614aeaa (patch)
treea923453f6af5f94e008328763cf9d0301a9faab8
parent2a112bcf6f15603d46ab904eabb13bd8ee062a91 (diff)
downloadvdr-plugin-plex-78eff7c58f9913bdc7dcad71370160261614aeaa.tar.gz
vdr-plugin-plex-78eff7c58f9913bdc7dcad71370160261614aeaa.tar.bz2
Some fixes
-rw-r--r--PlexServer.cpp19
-rw-r--r--PlexServer.h2
-rw-r--r--Plexservice.cpp40
-rw-r--r--SubscriptionManager.cpp6
-rw-r--r--browserGrid.cpp10
-rw-r--r--hlsPlayer.cpp24
-rw-r--r--plexOsd.cpp2
-rw-r--r--plexgdm.cpp33
-rw-r--r--plexgdm.h2
-rw-r--r--po/de_DE.po2
-rw-r--r--viewGridNavigator.cpp4
11 files changed, 78 insertions, 66 deletions
diff --git a/PlexServer.cpp b/PlexServer.cpp
index 1039b1f..5fe3f49 100644
--- a/PlexServer.cpp
+++ b/PlexServer.cpp
@@ -15,6 +15,7 @@ PlexServer::PlexServer(std::string ip, int port)
uri.setPort(port);
uri.setScheme("http");
m_uri = uri.toString();
+ Offline = false;
}
PlexServer::PlexServer(std::string data, std::string ip)
@@ -31,7 +32,7 @@ PlexServer::PlexServer(std::string uri, std::string name, std::string uuid, std:
m_nOwned = owned;
m_bLocal = local;
m_authToken = accessToken;
-
+ Offline = false;
m_uri = uri;
}
@@ -102,10 +103,11 @@ Poco::Net::HTTPClientSession* PlexServer::GetClientSession()
m_httpSession = new Poco::Net::HTTPClientSession(uri.getHost(), uri.getPort());
}
}
+ m_httpSession->setTimeout(Poco::Timespan(5, 0)); // set 5 seconds Timeout
return m_httpSession;
}
-std::istream& PlexServer::MakeRequest(Poco::Net::HTTPResponse& response, std::string path, const std::map<std::string, std::string>& queryParameters)
+std::istream& PlexServer::MakeRequest(Poco::Net::HTTPResponse& response, bool& ok, std::string path, const std::map<std::string, std::string>& queryParameters)
{
Poco::URI uri(path);
// Create a request with an optional query
@@ -132,10 +134,15 @@ std::istream& PlexServer::MakeRequest(Poco::Net::HTTPResponse& response, std::st
// Add PlexToken to Header
request.add("X-Plex-Token", GetAuthToken());
}
-
- GetClientSession()->sendRequest(request);
-
- return GetClientSession()->receiveResponse(response);
+ try {
+ GetClientSession()->sendRequest(request);
+ } catch (Poco::TimeoutException &exc) {
+ esyslog("[plex] Timeout: %s", path);
+ ok = false;
+ }
+ std::istream& stream = GetClientSession()->receiveResponse(response);
+ ok = response.getStatus() == 200;
+ return stream;
}
diff --git a/PlexServer.h b/PlexServer.h
index 45ef7d6..0363343 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, const std::map<std::string, std::string>& queryParameters = std::map<std::string, std::string>());
+ std::istream& MakeRequest(Poco::Net::HTTPResponse& response, bool& ok, 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/Plexservice.cpp b/Plexservice.cpp
index 1177c70..caa6489 100644
--- a/Plexservice.cpp
+++ b/Plexservice.cpp
@@ -128,7 +128,7 @@ void Plexservice::UpdateResources()
// pick remote connection
for(std::vector<Connection>::iterator c_it = d_it->m_vConnections.begin(); c_it != d_it->m_vConnections.end(); ++c_it) {
if(c_it->m_bLocal == false) {
- dsyslog("[plex] Found remote server: %s", d_it->m_sName.c_str());
+ dsyslog("[plex] Found server via plex.tv: %s", d_it->m_sName.c_str());
// a remote Server
plexgdm::GetInstance().AddServer(PlexServer(c_it->m_sUri, d_it->m_sName, d_it->m_sClientIdentifier, d_it->m_sAccessToken, d_it->m_bOwned, c_it->m_bLocal));
}
@@ -153,7 +153,6 @@ std::shared_ptr<MediaContainer> Plexservice::GetSection(std::string section, boo
uri = Poco::format("%s/%s", m_vUriStack.top(), section);
}
- auto pRequest = CreateRequest(uri);
if(putOnStack) {
m_vUriStack.push(uri);
}
@@ -161,11 +160,17 @@ std::shared_ptr<MediaContainer> Plexservice::GetSection(std::string section, boo
dsyslog("[plex] URI: %s%s", pServer->GetUri().c_str(), uri.c_str());
Poco::Net::HTTPResponse response;
- std::istream &rs = pServer->MakeRequest(response, uri);;
-
- std::shared_ptr<MediaContainer> pAllsections(new MediaContainer(&rs, pServer));
-
- return pAllsections;
+ bool ok;
+ std::istream &rs = pServer->MakeRequest(response, ok, uri);
+ if(ok) {
+ std::shared_ptr<MediaContainer> pAllsections(new MediaContainer(&rs, pServer));
+ return pAllsections;
+ }
+ else {
+ dsyslog("[plex] URI: %s%s Response bad: s%", pServer->GetUri().c_str(), uri.c_str(), response.getReasonForStatus(response.getStatus()).c_str() );
+ return 0;
+ }
+
} catch (Poco::Net::NetException &exc) {
pServer->Offline = true;
@@ -223,25 +228,20 @@ std::shared_ptr<MediaContainer> Plexservice::GetMediaContainer(std::string fullU
pServer = plexgdm::GetInstance().GetServer(fileuri.getHost(), fileuri.getPort());
Poco::Net::HTTPResponse response;
- std::istream &rs = pServer->MakeRequest(response, fileuri.getPathAndQuery());
-
+ bool ok;
+ std::istream &rs = pServer->MakeRequest(response, ok, fileuri.getPathAndQuery());
+ if(ok) {
+ std::shared_ptr<MediaContainer> pAllsections = std::shared_ptr<MediaContainer>(new MediaContainer(&rs, pServer));
+ return pAllsections;
+ }
+ return 0;
//Poco::StreamCopier::copyStream(rs, std::cout);
-
- std::shared_ptr<MediaContainer> pAllsections = std::shared_ptr<MediaContainer>(new MediaContainer(&rs, pServer));
- return pAllsections;
} catch (Poco::Net::NetException &exc) {
std::cout << exc.displayText() << std::endl;
return 0;
}
}
-/*
-std::string Plexservice::encode(std::string message)
-{
- std::string temp;
- Poco::URI::encode(message, " !\"#$%&'()*+,/:;=?@[]", temp);
- return temp;
-}
-*/
+
std::string Plexservice::GetUniversalTranscodeUrl(Video* video, int offset, PlexServer* server, bool http)
{
PlexServer* pSrv = server ? server : video->m_pServer;
diff --git a/SubscriptionManager.cpp b/SubscriptionManager.cpp
index 061f823..d287c2e 100644
--- a/SubscriptionManager.cpp
+++ b/SubscriptionManager.cpp
@@ -67,7 +67,8 @@ void SubscriptionManager::ReportProgress()
queryMap["state"] = state;
Poco::Net::HTTPResponse resp;
- m_pStatus->pVideo->m_pServer->MakeRequest(resp, "/:/progress", queryMap);
+ bool ok;
+ m_pStatus->pVideo->m_pServer->MakeRequest(resp, ok, "/:/progress", queryMap);
} catch (Poco::Exception&) {}
}
@@ -114,7 +115,8 @@ void SubscriptionManager::NotifyServer()
Poco::Net::HTTPResponse response;
- pServer->MakeRequest(response, "/:/timeline", queryMap);
+ bool ok;
+ pServer->MakeRequest(response, ok, "/:/timeline", queryMap);
if(m_pStatus->PlayerStopped) {
diff --git a/browserGrid.cpp b/browserGrid.cpp
index 8504ced..5242a13 100644
--- a/browserGrid.cpp
+++ b/browserGrid.cpp
@@ -124,7 +124,7 @@ void cBrowserGrid::SwitchGrid(int index)
m_pHeader->AddIntToken("totalcount", m_vElements.size());
if(plexclient::plexgdm::GetInstance().GetFirstServer()) {
- if(m_viewEntryIndex < Config::GetInstance().m_viewentries.size()) {
+ if(m_viewEntryIndex < (int)Config::GetInstance().m_viewentries.size()) {
ViewEntry entry = Config::GetInstance().m_viewentries[index];
m_pHeader->AddStringToken("tabname", tr(entry.Name.c_str()));
m_pService = std::shared_ptr<plexclient::Plexservice>(new plexclient::Plexservice( plexclient::plexgdm::GetInstance().GetFirstServer(), entry.PlexPath ) );
@@ -224,7 +224,7 @@ eOSState cBrowserGrid::NavigateSelect()
m_vServerElements.clear();
ProcessData();
return eOSState::osContinue;
- } else if(plexclient::Video* vid = dynamic_cast<plexclient::Video*>(SelectedObject())) {
+ } else if(dynamic_cast<plexclient::Video*>(SelectedObject())) {
return eOSState::osUser1;
} else return eOSState::osEnd;
}
@@ -295,9 +295,9 @@ void cBrowserGrid::DrawFooter()
//if (!active)
// return;
cString nextTab = "Library";
- if(m_viewEntryIndex + 1 < Config::GetInstance().m_viewentries.size()) {
+ if(m_viewEntryIndex + 1 < (int)Config::GetInstance().m_viewentries.size()) {
nextTab = Config::GetInstance().m_viewentries[m_viewEntryIndex + 1].Name.c_str();
- } else if(m_viewEntryIndex + 1 == Config::GetInstance().m_viewentries.size() + 1) {
+ } else if(m_viewEntryIndex + 1 == (int)Config::GetInstance().m_viewentries.size() + 1) {
nextTab = Config::GetInstance().m_viewentries[0].Name.c_str();
}
cString prevTab = "Library";
@@ -386,7 +386,7 @@ void cBrowserGrid::DrawScrollbar()
void cBrowserGrid::NextTab()
{
m_viewEntryIndex++;
- if(m_viewEntryIndex > Config::GetInstance().m_viewentries.size()) {
+ if(m_viewEntryIndex > (int)Config::GetInstance().m_viewentries.size()) {
m_viewEntryIndex = 0;
}
SwitchGrid(m_viewEntryIndex);
diff --git a/hlsPlayer.cpp b/hlsPlayer.cpp
index 60bc7aa..a4b1aaf 100644
--- a/hlsPlayer.cpp
+++ b/hlsPlayer.cpp
@@ -336,7 +336,8 @@ bool cHlsSegmentLoader::DoLoad(void)
std::string stopUri = "/video/:/transcode/universal/stop?session=" + m_sessionCookie;
try {
Poco::Net::HTTPResponse reqResponse;
- m_pVideo->m_pServer->MakeRequest(reqResponse, stopUri);
+ bool ok;
+ m_pVideo->m_pServer->MakeRequest(reqResponse, ok, stopUri);
int tmp = m_lastLoadedSegment;
int tmp2 = m_lastSegmentSize;
CloseConnection();
@@ -372,7 +373,8 @@ bool cHlsSegmentLoader::StopLoader(void)
std::string stopUri = "/video/:/transcode/universal/stop?session=" + m_sessionCookie;
Poco::Net::HTTPResponse reqResponse;
- m_pVideo->m_pServer->MakeRequest(reqResponse, stopUri);
+ bool ok;
+ m_pVideo->m_pServer->MakeRequest(reqResponse, ok, stopUri);
Cancel();
@@ -413,7 +415,8 @@ void cHlsSegmentLoader::Ping(void)
std::string uri = "/video/:/transcode/universal/ping?session=" + Config::GetInstance().GetUUID();
Poco::Net::HTTPResponse reqResponse;
- m_pVideo->m_pServer->MakeRequest(reqResponse, uri);
+ bool ok;
+ m_pVideo->m_pServer->MakeRequest(reqResponse, ok, uri);
} catch(Poco::Exception& exc) {
esyslog("[plex]%s %s ", __FUNCTION__, exc.displayText().c_str());
@@ -680,8 +683,9 @@ void cHlsPlayer::SetAudioTrack(eTrackType Type __attribute__((unused)), const tT
std::string uri = "/library/parts/" + std::string(itoa(m_Video.m_Media.m_iPartId)) + "?audioStreamID=" + std::string(itoa(streamId));
Poco::Net::HTTPResponse resp;
- m_Video.m_pServer->MakeRequest(resp, uri);
- if(resp.getStatus() == 200) {
+ bool ok;
+ m_Video.m_pServer->MakeRequest(resp, ok, uri);
+ if(ok) {
DeviceSetCurrentAudioTrack(eTrackType(ttDolby + 0)); // hacky
DeviceSetAvailableTrack(ttDolby, 0, 0, TrackId->language);
JumpRelative(0); // Reload Stream to get new Audio
@@ -727,9 +731,10 @@ void cHlsPlayer::ReportProgress(bool stopped)
std::string uri = "/:/progress?key=" + std::string(itoa(m_Video.m_iRatingKey)) + "&identifier=com.plexapp.plugins.library&time=" + std::string(itoa(GetPlayedSeconds()*1000)) + "&state=" + state;
Poco::Net::HTTPResponse resp;
- m_Video.m_pServer->MakeRequest(resp, uri);
+ bool ok;
+ m_Video.m_pServer->MakeRequest(resp, ok, uri);
- if(resp.getStatus() == 200) {
+ if(ok) {
dsyslog("[plex] %s", __FUNCTION__);
}
} catch (Poco::Exception&) {}
@@ -741,9 +746,10 @@ void cHlsPlayer::SetWatched(void)
std::string uri = "/:/scrobble?key=" + std::string(itoa(m_Video.m_iRatingKey)) + "&identifier=com.plexapp.plugins.library";
Poco::Net::HTTPResponse resp;
- m_Video.m_pServer->MakeRequest(resp, uri);
+ bool ok;
+ m_Video.m_pServer->MakeRequest(resp, ok, uri);
- if(resp.getStatus() == 200) {
+ if(ok) {
dsyslog("[plex] %s", __FUNCTION__);
}
}
diff --git a/plexOsd.cpp b/plexOsd.cpp
index 8a54cc8..ba498d5 100644
--- a/plexOsd.cpp
+++ b/plexOsd.cpp
@@ -13,7 +13,7 @@ cPlexBrowser::cPlexBrowser(const char *title, std::shared_ptr<plexclient::Plexse
{
dsyslog("[plex]%s:\n", __FUNCTION__);
pService = Service;
- pService->Authenticate();
+ //pService->Authenticate();
if(pService == pLastService) {
pCont = pService->GetLastSection(true);
} else {
diff --git a/plexgdm.cpp b/plexgdm.cpp
index e76279d..b63363e 100644
--- a/plexgdm.cpp
+++ b/plexgdm.cpp
@@ -169,22 +169,19 @@ void plexgdm::discover()
for(std::map<std::string, std::string>::iterator it = vBuffer.begin(); it != vBuffer.end(); ++it) {
std::string host = it->first;
std::string data = it->second;
- bool flag = true;
- // Check for duplicates
- for(std::vector<PlexServer>::iterator s_it = m_vServers.begin(); s_it != m_vServers.end(); ++s_it) {
- if(s_it->GetHost() == host) {
- flag = false;
- s_it->ParseData(data, host);
- dsyslog("[plex] Server Updated: %s", host.c_str());
- }
+
+ PlexServer newServ(data, host);
+ // Set token for local servers
+ if(Config::GetInstance().UsePlexAccount) {
+ newServ.SetAuthToken(Plexservice::GetMyPlexToken());
}
- if(flag) {
- m_vServers.push_back(PlexServer(data, host));
- // Set token for local servers
- if(Config::GetInstance().UsePlexAccount) {
- m_vServers[m_vServers.size()-1].SetAuthToken(Plexservice::GetMyPlexToken());
- }
- isyslog("[plex] New Server Discovered: %s", host.c_str());
+
+ if(AddServer(newServ)) {
+ isyslog("[plex] New server found via GDM: %s", host.c_str());
+ }
+ else if(GetServer(newServ.m_sUuid)) {
+ GetServer(newServ.m_sUuid)->ParseData(data, host);
+ dsyslog("[plex] Server updated via GDM: %s", host.c_str());
}
}
} catch (Poco::IOException&) {
@@ -230,16 +227,16 @@ PlexServer* plexgdm::GetServer(std::string uuid)
return NULL;
}
-void plexgdm::AddServer(PlexServer server)
+bool plexgdm::AddServer(PlexServer server)
{
for(std::vector<PlexServer>::iterator s_it = m_vServers.begin(); s_it != m_vServers.end(); ++s_it) {
if(s_it->GetUuid() == server.GetUuid() ){
- dsyslog("[plex] Server already in list: %s", server.GetUri().c_str());
- return;
+ return false;
}
}
m_vServers.push_back(server);
isyslog("[plex] New Server Added: %s", server.GetUri().c_str());
+ return true;
}
} // namespace
diff --git a/plexgdm.h b/plexgdm.h
index 41e7dd7..ab472cb 100644
--- a/plexgdm.h
+++ b/plexgdm.h
@@ -35,7 +35,7 @@ public:
PlexServer* getServerList();
PlexServer* GetServer(std::string ip, int port);
PlexServer* GetServer(std::string uuid);
- void AddServer(PlexServer server);
+ bool AddServer(PlexServer server);
PlexServer* GetFirstServer();
void discover();
void checkClientRegistration();
diff --git a/po/de_DE.po b/po/de_DE.po
index 265d9b6..f08f70a 100644
--- a/po/de_DE.po
+++ b/po/de_DE.po
@@ -10,7 +10,7 @@ msgstr ""
"POT-Creation-Date: 2015-12-15 20:56+0100\n"
"PO-Revision-Date: 2015-11-07 16:38+0200\n"
"Last-Translator: Chris <zerov83@gmail.com>\n"
-"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language-Team: German\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
diff --git a/viewGridNavigator.cpp b/viewGridNavigator.cpp
index b79b7c7..b0159f3 100644
--- a/viewGridNavigator.cpp
+++ b/viewGridNavigator.cpp
@@ -61,7 +61,7 @@ void cViewGridNavigator::FilterElements(int scrollOffset)
if(m_startIndex < 0) m_startIndex = 0;
m_endIndex = m_startIndex + (m_rows * m_columns);
- if(m_endIndex > m_vElements.size()) m_endIndex = m_vElements.size();
+ if(m_endIndex > (int)m_vElements.size()) m_endIndex = m_vElements.size();
if(scrollOffset > 0 && m_startIndex >= m_endIndex) {
// allign elements
@@ -70,7 +70,7 @@ void cViewGridNavigator::FilterElements(int scrollOffset)
m_startIndex = m_endIndex - delta;
}
- unsigned int i = 0;
+ int i = 0;
int pos = 0;
for(auto it = m_vElements.begin(); it != m_vElements.end(); ++it) {