Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/Leia' into Matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuehlma committed May 21, 2019
2 parents cc6a997 + 45785fc commit 004e9a7
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pvr.zattoo/addon.xml.in
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon id="pvr.zattoo"
version="19.0.1"
version="19.0.2"
name="Zattoo PVR Client"
provider-name="trummerjo,rbuehlma">
<requires>@ADDON_DEPENDS@</requires>
Expand Down
6 changes: 6 additions & 0 deletions pvr.zattoo/changelog.txt
@@ -1,7 +1,13 @@
v19.0.2
- Improve loading xmltv file
v19.0.1
- Load description from xmltv file
v19.0.0
- Update to PVR addon API v6.0.0
v18.1.2
- Improve loading xmltv file
v18.1.1
- Load description from xmltv file
v18.1.0
- Support DASH widevine streams
v18.0.68
Expand Down
2 changes: 1 addition & 1 deletion pvr.zattoo/resources/settings.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<settings version="1">
<section id="pvr.dvbviewer">
<section id="pvr.zattoo">
<!-- general -->
<category id="general" label="37110">
<group id="1" label="37114">
Expand Down
65 changes: 63 additions & 2 deletions src/XmlTV.cpp
@@ -1,3 +1,5 @@
#include <sstream>
#include <algorithm>
#include "XmlTV.h"
#include <tinyxml2.h>
#include <time.h>
Expand All @@ -7,8 +9,10 @@
using namespace tinyxml2;
using namespace ADDON;

const time_t minimumUpdateDelay = 600;

XmlTV::XmlTV(std::string xmlFile) :
m_xmlFile(xmlFile)
m_xmlFile(xmlFile), m_lastUpdate(0)
{
if (!XBMC->FileExists(m_xmlFile.c_str(), true))
{
Expand All @@ -21,15 +25,23 @@ XmlTV::XmlTV(std::string xmlFile) :
XBMC->Log(LOG_DEBUG, "XMLTV: Using xml file for additional guide data: %s",
m_xmlFile.c_str());
}
}

XmlTV::~XmlTV()
{
m_xmlFile = "";
}

bool XmlTV::GetEPGForChannel(const std::string &cid, unsigned int uniqueChannelId)
{
if (!XBMC->FileExists(m_xmlFile.c_str(), true))
if (!m_xmlFile.empty() && !XBMC->FileExists(m_xmlFile.c_str(), true))
{
return false;
}

if (!isUpdateDue()) {
return false;
}

XMLDocument doc;
if (doc.LoadFile(m_xmlFile.c_str()) != XML_SUCCESS)
Expand Down Expand Up @@ -86,6 +98,45 @@ bool XmlTV::GetEPGForChannel(const std::string &cid, unsigned int uniqueChannelI
tag.iGenreType = EPG_GENRE_USE_STRING;
tag.strGenreDescription = genre;
}

// episode is deliverd in format "1 . 2 .". Try to parse that format
XMLElement* episodeItem = programme->FirstChildElement("episode-num");
if (episodeItem != nullptr) {
std::string episode = episodeItem->GetText();
episode.erase (std::remove(episode.begin(), episode.end(), ' '), episode.end());
std::replace(episode.begin(), episode.end(), '.', ' ');
std::stringstream ss(episode);
int number;
if (ss >> number) {
tag.iSeriesNumber = number + 1;
if (ss >> number) {
tag.iEpisodeNumber = number + 1;
}
}
}

XMLElement* ratingItem = programme->FirstChildElement("rating");
if (ratingItem != nullptr) {
XMLElement* valuteItem = ratingItem->FirstChildElement("value");
if (valuteItem != nullptr) {
std::string ratingString = valuteItem->GetText();
tag.iParentalRating = std::stoi(ratingString);
}
}

XMLElement* iconItem = programme->FirstChildElement("icon");
if (iconItem != nullptr) {
tag.strIconPath = iconItem->Attribute("src", 0);
}

XMLElement* starRatingItem = programme->FirstChildElement("star-rating");
if (starRatingItem != nullptr) {
XMLElement* valuteItem = starRatingItem->FirstChildElement("value");
if (valuteItem != nullptr) {
std::string ratingString = valuteItem->GetText();
tag.iStarRating = std::stoi(ratingString);
}
}

result = true;
PVR->EpgEventStateChange(&tag, EPG_EVENT_CREATED);
Expand All @@ -97,6 +148,16 @@ bool XmlTV::GetEPGForChannel(const std::string &cid, unsigned int uniqueChannelI

}

bool XmlTV::isUpdateDue() {
time_t currentTime;
time(&currentTime);
if (m_lastUpdate + minimumUpdateDelay > currentTime) {
return false;
}
m_lastUpdate = currentTime;
return true;
}

time_t XmlTV::StringToTime(const std::string &timeString)
{
struct tm tm
Expand Down
3 changes: 3 additions & 0 deletions src/XmlTV.h
Expand Up @@ -5,9 +5,12 @@ class XmlTV
{
public:
XmlTV(std::string xmlFile);
~XmlTV();
bool GetEPGForChannel(const std::string &cid, unsigned int uniqueChannelId);

private:
std::string m_xmlFile;
time_t m_lastUpdate;
time_t StringToTime(const std::string &timeString);
bool isUpdateDue();
};

0 comments on commit 004e9a7

Please sign in to comment.