diff --git a/.travis.yml b/.travis.yml index 1a95af741..a310674a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,18 +3,18 @@ language: cpp # # Define the build matrix # -# Travis defaults to building on Ubuntu Precise when building on -# Linux. We need Trusty in order to get up to date versions of +# Travis defaults to building on Ubuntu Precise when building on +# Linux. We need Trusty in order to get up to date versions of # cmake and g++. # matrix: include: - os: linux - dist: trusty + dist: trusty sudo: required compiler: gcc - os: linux - dist: trusty + dist: trusty sudo: required compiler: clang - os: osx @@ -23,7 +23,7 @@ matrix: osx_image: xcode6.1 # -# Some of the OS X images don't have cmake, contrary to what people +# Some of the OS X images don't have cmake, contrary to what people # on the Internet say # before_install: @@ -38,6 +38,6 @@ before_script: - cd $TRAVIS_BUILD_DIR/.. - git clone --depth=1 https://github.com/xbmc/xbmc.git - cd pvr.iptvsimple && mkdir build && cd build - - cmake -DADDONS_TO_BUILD=pvr.iptvsimple -DADDON_SRC_PREFIX=$TRAVIS_BUILD_DIR/.. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=$TRAVIS_BUILD_DIR/../xbmc/addons -DPACKAGE_ZIP=1 $TRAVIS_BUILD_DIR/../xbmc/project/cmake/addons + - cmake -DADDONS_TO_BUILD=pvr.iptvsimple -DADDON_SRC_PREFIX=$TRAVIS_BUILD_DIR/.. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=$TRAVIS_BUILD_DIR/../xbmc/addons -DPACKAGE_ZIP=1 $TRAVIS_BUILD_DIR/../xbmc/cmake/addons script: make diff --git a/src/PVRIptvData.cpp b/src/PVRIptvData.cpp index f813ca8b2..b8ac1586e 100644 --- a/src/PVRIptvData.cpp +++ b/src/PVRIptvData.cpp @@ -103,7 +103,7 @@ PVRIptvData::~PVRIptvData(void) m_genres.clear(); } -bool PVRIptvData::LoadEPG(time_t iStart, time_t iEnd) +bool PVRIptvData::LoadEPG(time_t iStart, time_t iEnd) { if (m_strXMLTVUrl.empty()) { @@ -118,7 +118,7 @@ bool PVRIptvData::LoadEPG(time_t iStart, time_t iEnd) int iCount = 0; while(iCount < 3) // max 3 tries { - if ((iReaded = GetCachedFileContents(TVG_FILE_NAME, m_strXMLTVUrl, data, g_bCacheEPG)) != 0) + if ((iReaded = GetCachedFileContents(TVG_FILE_NAME, m_strXMLTVUrl, data, g_bCacheEPG)) != 0) { break; } @@ -128,7 +128,7 @@ bool PVRIptvData::LoadEPG(time_t iStart, time_t iEnd) usleep(2 * 1000 * 1000); // sleep 2 sec before next try. } } - + if (iReaded == 0) { XBMC->Log(LOG_ERROR, "Unable to load EPG file '%s': file is missing or empty. After %d tries.", m_strXMLTVUrl.c_str(), iCount); @@ -138,7 +138,7 @@ bool PVRIptvData::LoadEPG(time_t iStart, time_t iEnd) char * buffer; // gzip packed - if (data[0] == '\x1F' && data[1] == '\x8B' && data[2] == '\x08') + if (data[0] == '\x1F' && data[1] == '\x8B' && data[2] == '\x08') { if (!GzipInflate(data, decompressed)) { @@ -169,11 +169,11 @@ bool PVRIptvData::LoadEPG(time_t iStart, time_t iEnd) } xml_document<> xmlDoc; - try + try { xmlDoc.parse<0>(buffer); - } - catch(parse_error p) + } + catch(parse_error p) { XBMC->Log(LOG_ERROR, "Unable parse EPG XML: %s", p.what()); return false; @@ -187,7 +187,7 @@ bool PVRIptvData::LoadEPG(time_t iStart, time_t iEnd) } // clear previously loaded epg - if (m_epg.size() > 0) + if (m_epg.size() > 0) m_epg.clear(); int iBroadCastId = 0; @@ -215,12 +215,12 @@ bool PVRIptvData::LoadEPG(time_t iStart, time_t iEnd) m_epg.push_back(epgChannel); } - if (m_epg.size() == 0) + if (m_epg.size() == 0) { XBMC->Log(LOG_ERROR, "EPG channels not found."); return false; } - + int iMinShiftTime = m_iEPGTimeShift; int iMaxShiftTime = m_iEPGTimeShift; if (!m_bTSOverride) @@ -252,14 +252,14 @@ bool PVRIptvData::LoadEPG(time_t iStart, time_t iEnd) } std::string strStart, strStop; - if ( !GetAttributeValue(pChannelNode, "start", strStart) - || !GetAttributeValue(pChannelNode, "stop", strStop)) + if ( !GetAttributeValue(pChannelNode, "start", strStart) + || !GetAttributeValue(pChannelNode, "stop", strStop)) continue; int iTmpStart = ParseDateTime(strStart); int iTmpEnd = ParseDateTime(strStop); - if ( (iTmpEnd + iMaxShiftTime < iStart) + if ( (iTmpEnd + iMaxShiftTime < iStart) || (iTmpStart + iMinShiftTime > iEnd)) continue; @@ -293,7 +293,7 @@ bool PVRIptvData::LoadEPG(time_t iStart, time_t iEnd) return true; } -bool PVRIptvData::LoadPlayList(void) +bool PVRIptvData::LoadPlayList(void) { if (m_strM3uUrl.empty()) { @@ -327,7 +327,7 @@ bool PVRIptvData::LoadPlayList(void) tmpChannel.iTvgShift = 0; char szLine[1024]; - while(stream.getline(szLine, 1024)) + while(stream.getline(szLine, 1024)) { std::string strLine(szLine); strLine = StringUtils::TrimRight(strLine, " \t\r\n"); @@ -340,7 +340,7 @@ bool PVRIptvData::LoadPlayList(void) continue; } - if (bFirst) + if (bFirst) { bFirst = false; if (StringUtils::Left(strLine, 3) == "\xEF\xBB\xBF") @@ -370,13 +370,14 @@ bool PVRIptvData::LoadPlayList(void) std::string strTvgId = ""; std::string strTvgName = ""; std::string strTvgLogo = ""; + std::string strTvgShift = ""; std::string strGroupName = ""; std::string strRadio = ""; // parse line int iColon = (int)strLine.find(':'); int iComma = (int)strLine.rfind(','); - if (iColon >= 0 && iComma >= 0 && iComma > iColon) + if (iColon >= 0 && iComma >= 0 && iComma > iColon) { // parse name iComma++; @@ -392,7 +393,7 @@ bool PVRIptvData::LoadPlayList(void) strTvgLogo = ReadMarkerValue(strInfoLine, TVG_INFO_LOGO_MARKER); strGroupName = ReadMarkerValue(strInfoLine, GROUP_NAME_MARKER); strRadio = ReadMarkerValue(strInfoLine, RADIO_MARKER); - fTvgShift = atof(ReadMarkerValue(strInfoLine, TVG_INFO_SHIFT_MARKER).c_str()); + strTvgShift = ReadMarkerValue(strInfoLine, TVG_INFO_SHIFT_MARKER); if (strTvgId.empty()) { @@ -404,6 +405,7 @@ bool PVRIptvData::LoadPlayList(void) { strTvgLogo = strChnlName; } + fTvgShift = atof(strTvgShift.c_str()); bRadio = !StringUtils::CompareNoCase(strRadio, "true"); tmpChannel.strTvgId = strTvgId; @@ -412,7 +414,7 @@ bool PVRIptvData::LoadPlayList(void) tmpChannel.iTvgShift = (int)(fTvgShift * 3600.0); tmpChannel.bRadio = bRadio; - if (tmpChannel.iTvgShift == 0 && iEPGTimeShift != 0) + if (strTvgShift.empty()) { tmpChannel.iTvgShift = iEPGTimeShift; } @@ -438,7 +440,7 @@ bool PVRIptvData::LoadPlayList(void) } } } - } + } else if (strLine[0] != '#') { XBMC->Log(LOG_DEBUG, @@ -457,7 +459,7 @@ bool PVRIptvData::LoadPlayList(void) channel.strStreamURL = strLine; channel.iEncryptionSystem = 0; - if (iCurrentGroupId > 0) + if (iCurrentGroupId > 0) { channel.bRadio = m_groups.at(iCurrentGroupId - 1).bRadio; m_groups.at(iCurrentGroupId - 1).members.push_back(iChannelIndex); @@ -474,7 +476,7 @@ bool PVRIptvData::LoadPlayList(void) tmpChannel.bRadio = false; } } - + stream.clear(); if (m_channels.size() == 0) @@ -663,7 +665,7 @@ PVR_ERROR PVRIptvData::GetEPGForChannel(ADDON_HANDLE handle, const PVR_CHANNEL & if (myChannel->iUniqueId != (int) channel.iUniqueId) continue; - if (iStart > m_iLastStart || iEnd > m_iLastEnd) + if (iStart > m_iLastStart || iEnd > m_iLastEnd) { // reload EPG for new time interval only LoadEPG(iStart, iEnd); @@ -683,7 +685,7 @@ PVR_ERROR PVRIptvData::GetEPGForChannel(ADDON_HANDLE handle, const PVR_CHANNEL & std::vector::iterator myTag; for (myTag = epg->epg.begin(); myTag < epg->epg.end(); ++myTag) { - if ((myTag->endTime + iShift) < iStart) + if ((myTag->endTime + iShift) < iStart) continue; int iGenreType, iGenreSubType; @@ -778,9 +780,9 @@ int PVRIptvData::ParseDateTime(std::string& strDate, bool iDateFormat) #else _get_timezone(&offset); #endif // TARGET_WINDOWS - + long offset_of_date = (hours * 60 * 60) + (minutes * 60); - if (sign == '-') + if (sign == '-') { offset_of_date = -offset_of_date; } @@ -799,7 +801,7 @@ PVRIptvChannel * PVRIptvData::FindChannel(const std::string &strId, const std::s if (it->strTvgId == strId) return &*it; - if (strTvgName == "") + if (strTvgName == "") continue; if (it->strTvgName == strTvgName) @@ -881,7 +883,7 @@ bool PVRIptvData::FindEpgGenre(const std::string& strGenre, int& iType, int& iSu * Author: Andrew Lim Chong Liang * http://windrealm.org */ -bool PVRIptvData::GzipInflate( const std::string& compressedBytes, std::string& uncompressedBytes ) { +bool PVRIptvData::GzipInflate( const std::string& compressedBytes, std::string& uncompressedBytes ) { #define HANDLE_CALL_ZLIB(status) { \ if(status != Z_OK) { \ @@ -890,68 +892,68 @@ bool PVRIptvData::GzipInflate( const std::string& compressedBytes, std::string& } \ } - if ( compressedBytes.size() == 0 ) - { - uncompressedBytes = compressedBytes ; - return true ; - } - - uncompressedBytes.clear() ; - - unsigned full_length = compressedBytes.size() ; - unsigned half_length = compressedBytes.size() / 2; - - unsigned uncompLength = full_length ; - char* uncomp = (char*) calloc( sizeof(char), uncompLength ); - - z_stream strm; - strm.next_in = (Bytef *) compressedBytes.c_str(); - strm.avail_in = compressedBytes.size() ; - strm.total_out = 0; - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - - bool done = false ; - + if ( compressedBytes.size() == 0 ) + { + uncompressedBytes = compressedBytes ; + return true ; + } + + uncompressedBytes.clear() ; + + unsigned full_length = compressedBytes.size() ; + unsigned half_length = compressedBytes.size() / 2; + + unsigned uncompLength = full_length ; + char* uncomp = (char*) calloc( sizeof(char), uncompLength ); + + z_stream strm; + strm.next_in = (Bytef *) compressedBytes.c_str(); + strm.avail_in = compressedBytes.size() ; + strm.total_out = 0; + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + + bool done = false ; + HANDLE_CALL_ZLIB(inflateInit2(&strm, (16+MAX_WBITS))); - - while (!done) - { - // If our output buffer is too small - if (strm.total_out >= uncompLength ) + + while (!done) + { + // If our output buffer is too small + if (strm.total_out >= uncompLength ) { - // Increase size of output buffer + // Increase size of output buffer uncomp = (char *) realloc(uncomp, uncompLength + half_length); if (uncomp == NULL) return false; - uncompLength += half_length ; - } - - strm.next_out = (Bytef *) (uncomp + strm.total_out); - strm.avail_out = uncompLength - strm.total_out; - - // Inflate another chunk. - int err = inflate (&strm, Z_SYNC_FLUSH); - if (err == Z_STREAM_END) - done = true; - else if (err != Z_OK) - { - break; - } - } - + uncompLength += half_length ; + } + + strm.next_out = (Bytef *) (uncomp + strm.total_out); + strm.avail_out = uncompLength - strm.total_out; + + // Inflate another chunk. + int err = inflate (&strm, Z_SYNC_FLUSH); + if (err == Z_STREAM_END) + done = true; + else if (err != Z_OK) + { + break; + } + } + HANDLE_CALL_ZLIB(inflateEnd (&strm)); - - for ( size_t i=0; iFileExists(strCachedPath.c_str(), false)) + if (bUseCache && XBMC->FileExists(strCachedPath.c_str(), false)) { struct __stat64 statCached; struct __stat64 statOrig; @@ -968,16 +970,16 @@ int PVRIptvData::GetCachedFileContents(const std::string &strCachedName, const s XBMC->StatFile(strFilePath.c_str(), &statOrig); bNeedReload = statCached.st_mtime < statOrig.st_mtime || statOrig.st_mtime == 0; - } - else + } + else bNeedReload = true; - if (bNeedReload) + if (bNeedReload) { GetFileContents(strFilePath, strContents); // write to cache - if (bUseCache && strContents.length() > 0) + if (bUseCache && strContents.length() > 0) { void* fileHandle = XBMC->OpenFileForWrite(strCachedPath.c_str(), true); if (fileHandle) @@ -987,7 +989,7 @@ int PVRIptvData::GetCachedFileContents(const std::string &strCachedName, const s } } return strContents.length(); - } + } return GetFileContents(strCachedPath, strContents); } @@ -999,7 +1001,7 @@ void PVRIptvData::ApplyChannelsLogos() { if (!channel->strTvgLogo.empty()) { - if (!m_strLogoPath.empty() + if (!m_strLogoPath.empty() // special proto && channel->strTvgLogo.find("://") == std::string::npos) channel->strLogoPath = PathCombine(m_strLogoPath, channel->strTvgLogo); @@ -1108,7 +1110,7 @@ std::string PVRIptvData::ReadMarkerValue(std::string &strLine, const char* strMa return std::string(""); } -int PVRIptvData::GetChannelId(const char * strChannelName, const char * strStreamUrl) +int PVRIptvData::GetChannelId(const char * strChannelName, const char * strStreamUrl) { std::string concat(strChannelName); concat.append(strStreamUrl);