Skip to content

Commit

Permalink
Support selective recall and restart
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuehlma committed Nov 10, 2017
1 parent d5db140 commit 23d9993
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pvr.zattoo/addon.xml.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon id="pvr.zattoo"
version="18.0.28"
version="18.0.29"
name="Zattoo PVR Client"
provider-name="trummerjo,rbuehlma">
<requires>@ADDON_DEPENDS@</requires>
Expand Down
2 changes: 2 additions & 0 deletions pvr.zattoo/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
v18.0.29
- Support selective recall and restart
v18.0.28
- Revert "Allow playing current program from start without recall"
v18.0.27
Expand Down
64 changes: 53 additions & 11 deletions src/ZatData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ bool ZatData::InitSession()

countryCode = session["aliased_country_code"].GetString();
recallEnabled = streamType == "dash" && session["recall_eligible"].GetBool();
selectiveRecallEnabled = session.HasMember("selective_recall_eligible") ? session["selective_recall_eligible"].GetBool() : false;
recordingEnabled = session["recording_eligible"].GetBool();
XBMC->Log(LOG_NOTICE, "Country code: %s", countryCode.c_str());
XBMC->Log(LOG_NOTICE, "Stream type: %s", streamType.c_str());
Expand All @@ -359,6 +360,7 @@ bool ZatData::InitSession()
{
XBMC->Log(LOG_NOTICE, "Recall is disabled");
}
XBMC->Log(LOG_NOTICE, "Selective recall is %s", selectiveRecallEnabled ? "enabled" : "disabled");
XBMC->Log(LOG_NOTICE, "Recordings are %s", recordingEnabled ? "enabled" : "disabled");
powerHash = session["power_guide_hash"].GetString();
return true;
Expand Down Expand Up @@ -421,6 +423,8 @@ bool ZatData::LoadChannels()
channel.iChannelNumber = ++channelNumber;
channel.strLogoPath = "http://logos.zattic.com";
channel.strLogoPath.append(qualityItem["logo_white_84"].GetString());
channel.selectiveRecallSeconds = channelItem.HasMember("selective_recall_seconds") ? channelItem["selective_recall_seconds"].GetInt() : 0;
channel.recordingEnabled = channelItem.HasMember("recording") ? channelItem["recording"].GetBool() : false;
group.channels.insert(group.channels.end(), channel);
allChannels[cid] = channel;
channelsByCid[channel.cid] = channel;
Expand Down Expand Up @@ -1181,14 +1185,34 @@ bool ZatData::DeleteRecording(string recordingId)

bool ZatData::IsPlayable(const EPG_TAG *tag)
{
if (!recallEnabled)
time_t current_time;
time(&current_time);
if (tag->startTime > current_time) {
return false;
}
int recallSeconds = GetRecallSeconds(tag);
if (recallSeconds == 0)
{
return false;
}
time_t current_time;
time(&current_time);
return ((current_time - tag->endTime) < maxRecallSeconds)
&& (tag->startTime < current_time);
if (current_time < tag->endTime)
{
return true;
}
return (current_time - tag->endTime) < recallSeconds;
}

int ZatData::GetRecallSeconds(const EPG_TAG *tag) {
if (recallEnabled)
{
return maxRecallSeconds;
}
if (selectiveRecallEnabled)
{
ZatChannel channel = channelsByUid[tag->iUniqueChannelId];
return channel.selectiveRecallSeconds;
}
return 0;
}

bool ZatData::IsRecordable(const EPG_TAG *tag)
Expand All @@ -1197,13 +1221,18 @@ bool ZatData::IsRecordable(const EPG_TAG *tag)
{
return false;
}
ZatChannel channel = channelsByUid[tag->iUniqueChannelId];
if (!channel.recordingEnabled) {
return false;
}
int recallSeconds = GetRecallSeconds(tag);
time_t current_time;
time(&current_time);
if (!recallEnabled)
if (recallSeconds == 0)
{
return current_time < tag->startTime;
}
return ((current_time - tag->endTime) < maxRecallSeconds);
return ((current_time - tag->endTime) < recallSeconds);
}

string ZatData::GetEpgTagUrl(const EPG_TAG *tag)
Expand All @@ -1217,11 +1246,24 @@ string ZatData::GetEpgTagUrl(const EPG_TAG *tag)
char timeEnd[sizeof "2011-10-08T07:07:09Z"];
gmtime_r(&tag->endTime, &tm);
strftime(timeEnd, sizeof timeEnd, "%FT%TZ", &tm);

dataStream << "cid=" << channel.cid << "&start=" << timeStart << "&end="

string jsonString;

if (recallEnabled)
{
dataStream << "cid=" << channel.cid << "&start=" << timeStart << "&end="
<< timeEnd << "&stream_type=" << streamType;

string jsonString = HttpPost(providerUrl + "/zapi/watch", dataStream.str());
jsonString = HttpPost(providerUrl + "/zapi/watch", dataStream.str());
}
else if (selectiveRecallEnabled)
{
dataStream << "https_watch_urls=True" << "&stream_type=" << streamType;
jsonString = HttpPost(providerUrl + "/zapi/watch/selective_recall/" + channel.cid + "/" + to_string(tag->iUniqueBroadcastId), dataStream.str());
}
else
{
return "";
}

Document doc;
doc.Parse(jsonString.c_str());
Expand Down
4 changes: 4 additions & 0 deletions src/ZatData.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ struct ZatChannel
int iChannelNumber;
int iEncryptionSystem;
int iTvgShift;
int selectiveRecallSeconds;
bool recordingEnabled;
string name;
string strLogoPath;
string strStreamURL;
Expand Down Expand Up @@ -101,6 +103,7 @@ class ZatData
int lastplayedposition);
virtual int GetRecordingLastPlayedPosition(const PVR_RECORDING &recording);
virtual bool IsPlayable(const EPG_TAG *tag);
virtual int GetRecallSeconds(const EPG_TAG *tag);
virtual bool IsRecordable(const EPG_TAG *tag);
virtual string GetEpgTagUrl(const EPG_TAG *tag);
virtual bool RecordingEnabled()
Expand All @@ -113,6 +116,7 @@ class ZatData
string powerHash;
string countryCode = "";
bool recallEnabled = false;
bool selectiveRecallEnabled = false;
bool recordingEnabled = false;
string streamType;
string username;
Expand Down

0 comments on commit 23d9993

Please sign in to comment.