| 1 |
/* |
| 2 |
* Copyright (c) 2018~now Palo Kisa <[email protected]> |
| 3 |
* |
| 4 |
* Copyright (C) 2014 Josef Rokos |
| 5 |
* http://github.com/PepaRokos/xbmc-pvr-addons/ |
| 6 |
* |
| 7 |
* Copyright (C) 2011 Pulse-Eight |
| 8 |
* http://www.pulse-eight.com/ |
| 9 |
* |
| 10 |
* This Program is free software; you can redistribute it and/or modify |
| 11 |
* it under the terms of the GNU General Public License as published by |
| 12 |
* the Free Software Foundation; either version 2, or (at your option) |
| 13 |
* any later version. |
| 14 |
* |
| 15 |
* This Program is distributed in the hope that it will be useful, |
| 16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
* GNU General Public License for more details. |
| 19 |
* |
| 20 |
* You should have received a copy of the GNU General Public License |
| 21 |
* along with this addon; see the file COPYING. If not, write to |
| 22 |
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 |
* http://www.gnu.org/copyleft/gpl.html |
| 24 |
* |
| 25 |
*/ |
| 26 |
|
| 27 |
#ifndef sledovanitcz_ApiManager_h |
| 28 |
#define sledovanitcz_ApiManager_h |
| 29 |
|
| 30 |
#include <string> |
| 31 |
#include <vector> |
| 32 |
#include <memory> |
| 33 |
|
| 34 |
namespace Json |
| 35 |
{ |
| 36 |
class Value; |
| 37 |
} |
| 38 |
|
| 39 |
namespace sledovanitvcz |
| 40 |
{ |
| 41 |
|
| 42 |
typedef std::vector<std::tuple<std::string, std::string> > ApiParams_t; |
| 43 |
|
| 44 |
class ApiManager |
| 45 |
{ |
| 46 |
public: |
| 47 |
enum StreamQuality_t |
| 48 |
{ |
| 49 |
SQ_DEFAULT = 0 |
| 50 |
, SQ_SD = 20 |
| 51 |
, SQ_HD = 40 |
| 52 |
}; |
| 53 |
enum ServiceProvider_t |
| 54 |
{ |
| 55 |
SP_DEFAULT = 0 |
| 56 |
, SP_SLEDOVANITV_CZ = SP_DEFAULT |
| 57 |
, SP_MODERNITV_CZ = 1 |
| 58 |
, SP_END |
| 59 |
}; |
| 60 |
public: |
| 61 |
static std::string formatTime(time_t t); |
| 62 |
static std::string urlEncode(const std::string &str); |
| 63 |
static std::string generateUserAgent(); |
| 64 |
|
| 65 |
public: |
| 66 |
ApiManager(ServiceProvider_t serviceProvider |
| 67 |
, const std::string & userName |
| 68 |
, const std::string & userPassword |
| 69 |
, const std::string & overridenMac //!< device identifier (value for overriding the MAC address detection) |
| 70 |
, const std::string & product //!< product identifier (value for overriding the hostname detection) |
| 71 |
, const std::string & userAgent //!< HTTP header User-Agent (value for overriding the predefined) |
| 72 |
, uint64_t instanceNo |
| 73 |
); |
| 74 |
|
| 75 |
bool login(); |
| 76 |
bool pinUnlock(const std::string & pin); |
| 77 |
bool getPlaylist(StreamQuality_t quality, bool useH265, bool useAdaptive, Json::Value & root); |
| 78 |
bool getStreamQualities(Json::Value & root); |
| 79 |
bool getEpg(time_t start, bool smallDuration, const std::string & channels, Json::Value & root); |
| 80 |
bool getPvr(Json::Value & root); |
| 81 |
std::string getRecordingUrl(const std::string &recId, std::string & channel, bool & isDrm); |
| 82 |
bool getTimeShiftInfo(const std::string &eventId |
| 83 |
, std::string & streamUrl |
| 84 |
, std::string & channel |
| 85 |
, int & duration) const; |
| 86 |
bool addTimer(const std::string & eventId, std::string & recordId); |
| 87 |
bool deleteRecord(const std::string &recId); |
| 88 |
bool keepAlive(); |
| 89 |
bool loggedIn() const; |
| 90 |
bool pinUnlocked() const; |
| 91 |
bool registerDrm(std::string & licenseUrl, std::string & certificate) const; |
| 92 |
void setUserAgent(const std::string userAgent) const; |
| 93 |
|
| 94 |
private: |
| 95 |
static std::string readPairFile(const std::string & pairFile); |
| 96 |
static bool isSuccess(const std::string &response, Json::Value & root); |
| 97 |
static bool isSuccess(const std::string &response); |
| 98 |
|
| 99 |
std::string buildQueryString(const ApiParams_t & paramMap, bool putSessionVar) const; |
| 100 |
std::string call(const std::string & urlPath, const ApiParams_t & paramsMap, bool putSessionVar) const; |
| 101 |
std::string apiCall(const std::string &function, const ApiParams_t & paramsMap, bool putSessionVar = true) const; |
| 102 |
bool pairDevice(Json::Value & root); |
| 103 |
bool deletePairing(const Json::Value & root); |
| 104 |
std::string getPairFilePath() const; |
| 105 |
void createPairFile(Json::Value & contentRoot) const; |
| 106 |
|
| 107 |
static const std::string API_URL[SP_END]; |
| 108 |
static const std::string API_UNIT[SP_END]; |
| 109 |
static const std::string PAIR_FILE; |
| 110 |
const ServiceProvider_t m_serviceProvider; |
| 111 |
const std::string m_userName; |
| 112 |
const std::string m_userPassword; |
| 113 |
const std::string m_overridenMac; |
| 114 |
const std::string m_product; |
| 115 |
const std::string m_userAgent; |
| 116 |
const uint64_t m_instanceNo; |
| 117 |
std::string m_serial; |
| 118 |
std::string m_deviceId; |
| 119 |
std::string m_password; |
| 120 |
bool m_pinUnlocked; |
| 121 |
std::shared_ptr<const std::string> m_sessionId; |
| 122 |
}; |
| 123 |
|
| 124 |
} // namespace sledovanitvcz |
| 125 |
#endif // sledovanitcz_ApiManager_h |