summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchriszero <zerov83@gmail.com>2015-01-31 17:55:07 +0100
committerchriszero <zerov83@gmail.com>2015-01-31 17:55:07 +0100
commit1ecdb2a5d9e05e0d30dae89e3d675218ca4c255e (patch)
tree1047246d4c34fa39134aa6b1b868fcf4712e68fa
parent7eaaba1d58d1baeb35288e66ee5e9703ec10cdbe (diff)
downloadvdr-plugin-plex-1ecdb2a5d9e05e0d30dae89e3d675218ca4c255e.tar.gz
vdr-plugin-plex-1ecdb2a5d9e05e0d30dae89e3d675218ca4c255e.tar.bz2
- If watched +90%, the media will be marked as watched
- current play state is syncronized with the pms - remaing time is now displayed according to the VDR setup
-rw-r--r--hlsPlayer.cpp83
-rw-r--r--hlsPlayer.h7
-rw-r--r--hlsPlayerControl.cpp7
3 files changed, 88 insertions, 9 deletions
diff --git a/hlsPlayer.cpp b/hlsPlayer.cpp
index d53c025..92ce5c6 100644
--- a/hlsPlayer.cpp
+++ b/hlsPlayer.cpp
@@ -179,7 +179,7 @@ int cHlsSegmentLoader::EstimateSegmentSize()
int len = m_indexParser.TargetDuration;
double estSize = (bandw) * len;
estSize = max(estSize, 1.0);
- // default
+ // default
if(estSize <= 1) {
estSize = 32;
}
@@ -323,6 +323,22 @@ bool cHlsSegmentLoader::Active(void)
return Running();
}
+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);
+
+ } catch(Poco::Exception& exc) {
+ esyslog("[plex]%s %s ", __FUNCTION__, exc.displayText().c_str());
+ }
+}
+
//--- cHlsPlayer
cHlsPlayer::cHlsPlayer(std::string startm3u8, plexclient::Video* Video)
@@ -335,6 +351,7 @@ cHlsPlayer::cHlsPlayer(std::string startm3u8, plexclient::Video* Video)
m_doJump = false;
m_isBuffering = false;
AudioIndexOffset = 1000; // Just a magic number
+ m_tTimer.Set(1);
}
cHlsPlayer::~cHlsPlayer()
@@ -364,7 +381,7 @@ void cHlsPlayer::Action(void)
{
// Start SegmentLoader
m_pSegmentLoader->Start();
-
+
m_bFirstPlay = true;
while (Running()) {
@@ -393,8 +410,20 @@ void cHlsPlayer::Action(void)
// Pause
cCondWait::SleepMs(3);
}
+ // statusupdates to pms every 60s
+ if(m_pSegmentLoader && m_tTimer.TimedOut()) {
+ if(playMode == pmPause) {
+ m_pSegmentLoader->Ping();
+ }
+ ReportProgress();
+ m_tTimer.Set(60000);
+ }
+ }
+ // set as watched if >= 90%
+ int t = m_pVideo->m_Media.m_lDuration / 1000 * 0.9;
+ if( GetPlayedSeconds() >= t) {
+ SetWatched();
}
-
DeviceClear();
}
@@ -480,9 +509,10 @@ void cHlsPlayer::Stop(void)
{
LOCK_THREAD;
dsyslog("[plex]%s", __FUNCTION__);
+ ReportProgress(true);
if (m_pSegmentLoader)
m_pSegmentLoader->StopLoader();
- Cancel(0);
+ Cancel(1);
}
double cHlsPlayer::FramesPerSecond(void)
@@ -551,8 +581,7 @@ void cHlsPlayer::CountPlayedSeconds(void)
unsigned long long tTmp = cTimeMs::Now();
m_tTimeSum += (tTmp - m_tLastTime);
m_tLastTime = tTmp;
- }
- else {
+ } else {
m_tLastTime = cTimeMs::Now();
}
}
@@ -562,3 +591,45 @@ void cHlsPlayer::ResetPlayedSeconds(void)
m_tTimeSum = 0;
m_tLastTime = cTimeMs::Now();
}
+
+void cHlsPlayer::ReportProgress(bool stopped)
+{
+ std::string state;
+ if(stopped) {
+ state = "stopped";
+ }
+ else if (playMode == pmPlay) {
+ state = "playing";
+ }
+ else {
+ state = "paused";
+ }
+
+ Poco::Net::HTTPClientSession session(m_pVideo->m_pServer->GetIpAdress(), m_pVideo->m_pServer->GetPort());
+ std::string uri = "/:/progress?key=" + std::string(itoa(m_pVideo->m_iRatingKey)) + "&identifier=com.plexapp.plugins.library&time=" + std::string(itoa(GetPlayedSeconds()*1000)) + "&state=" + state;
+ 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] %s", __FUNCTION__);
+ }
+
+}
+
+void cHlsPlayer::SetWatched(void)
+{
+ Poco::Net::HTTPClientSession session(m_pVideo->m_pServer->GetIpAdress(), m_pVideo->m_pServer->GetPort());
+ std::string uri = "/:/scrobble?key=" + std::string(itoa(m_pVideo->m_iRatingKey)) + "&identifier=com.plexapp.plugins.library";
+ 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] %s", __FUNCTION__);
+ }
+}
diff --git a/hlsPlayer.h b/hlsPlayer.h
index 4144659..c188fc2 100644
--- a/hlsPlayer.h
+++ b/hlsPlayer.h
@@ -48,11 +48,11 @@ private:
bool LoadSegment(std::string uri);
int EstimateSegmentSize();
bool LoadLists(void);
+
protected:
void Action(void);
bool DoLoad(void);
- void AddHeader(Poco::Net::HTTPRequest& req);
public:
cHlsSegmentLoader(std::string startm3u8);
@@ -63,6 +63,8 @@ public:
bool Active(void);
bool StopLoader(void);
bool LoadM3u8(std::string uri);
+ void AddHeader(Poco::Net::HTTPRequest& req);
+ void Ping(void);
};
class cHlsPlayer : public cPlayer, cThread
@@ -85,6 +87,7 @@ private:
unsigned long long m_tLastTime;
unsigned long long m_tTimeSum;
bool m_bFirstPlay;
+ cTimeMs m_tTimer;
enum ePlayModes { pmPlay, pmPause };
ePlayModes playMode;
@@ -93,6 +96,8 @@ private:
int GetPlayedSeconds(void);
void CountPlayedSeconds(void);
void ResetPlayedSeconds(void);
+ void ReportProgress(bool stopped = false);
+ void SetWatched(void);
protected:
void Action(void);
diff --git a/hlsPlayerControl.cpp b/hlsPlayerControl.cpp
index 8d65310..168c60e 100644
--- a/hlsPlayerControl.cpp
+++ b/hlsPlayerControl.cpp
@@ -43,8 +43,9 @@ cHlsPlayerControl::cHlsPlayerControl(cHlsPlayer* Player, plexclient::MediaContai
cHlsPlayerControl::~cHlsPlayerControl()
{
dsyslog("[plex]: '%s'", __FUNCTION__);
- delete player;
Hide();
+ delete player;
+ player = NULL;
cStatus::MsgReplaying(this, NULL, NULL, false);
}
@@ -232,8 +233,10 @@ bool cHlsPlayerControl::ShowProgress(bool Initial)
lastCurrent = lastTotal = -1;
}
if (Current != lastCurrent || Total != lastTotal) {
- if (Total != lastTotal) {
+ if (Setup.ShowRemainingTime || Total != lastTotal) {
int Index = Total;
+ if (Setup.ShowRemainingTime)
+ Index = Current - Index;
displayReplay->SetTotal(IndexToHMSF(Index, false, FramesPerSecond()));
if (!Initial)
displayReplay->Flush();