std::string ZatData::GetChannelStreamUrl(int uniqueId) { ZatChannel *channel = FindChannel(uniqueId); //XBMC->QueueNotification(QUEUE_INFO, "Getting URL for channel %s", XBMC->UnknownToUTF8(channel->name.c_str())); ostringstream dataStream; dataStream << "cid=" << channel->cid << "&stream_type=hls&format=json"; HTTPSocketRaw *socket = new HTTPSocketRaw(); Request request; request.url = "zattoo.com/zapi/watch"; request.method = POST; request.body = dataStream.str(); request.AddHeader("Cookie", cookie); Response response; socket->Execute(request, response); cookie = response.cookie; std::string jsonString = response.body; Json::Value json; Json::Reader reader; bool parsingSuccessful = reader.parse(jsonString,json); string url = json["stream"]["url"].asString(); return url; }
Json::Value ZatData::loadFavourites() { ostringstream urlStream; urlStream << "zattoo.com/zapi/channels/favorites"; HTTPSocketRaw *socket = new HTTPSocketRaw(); Request request; request.url = urlStream.str(); request.AddHeader("Cookie", cookie); Response response; socket->Execute(request, response); cookie = response.cookie; std::string jsonString = response.body; cout << jsonString << endl; Json::Value json; Json::Reader reader; reader.parse(jsonString,json); return json["favorites"]; }
void ZatData::sendHello() { ostringstream dataStream; dataStream << "uuid=888b4f54-c127-11e5-9912-ba0be0483c18&lang=en&format=json&client_app_token=" << appToken; HTTPSocketRaw *socket = new HTTPSocketRaw(); Request request; request.url = "zattoo.com/zapi/session/hello"; request.method = POST; request.body = dataStream.str(); request.AddHeader("Cookie", cookie); Response response; socket->Execute(request, response); cookie = response.cookie; //httpResponse resp = postRequest("/zapi/session/hello", data); }
bool ZatData::login() { ostringstream dataStream; dataStream << "login="******"&password="******"&format=json"; HTTPSocketRaw *socket = new HTTPSocketRaw(); Request request; request.url = "zattoo.com/zapi/account/login"; request.method = POST; request.body = dataStream.str(); request.AddHeader("Cookie", cookie); Response response; socket->Execute(request, response); cookie = response.cookie; std::string jsonString = response.body; Json::Value json; Json::Reader reader; bool parsingSuccessful = reader.parse(jsonString,json); if (!parsingSuccessful){ // report to the user the failure and their locations in the document. D(cout << "Failed to parse login\n" << reader.getFormatedErrorMessages()); return false; } string succ = json["success"].asString(); if(succ == "False") { return false; } powerHash = json["account"]["power_guide_hash"].asString(); D(cout << "Power Hash: " << powerHash << endl); return true; }
bool ZatData::LoadEPG(time_t iStart, time_t iEnd) { // iStart -= (iStart % (3600/2)) - 86400; // Do s // iEnd = iStart + 3600*3; //Do some time magic that the start date is not to far in the past because zattoo doesnt like that time_t tempStart = iStart - (iStart % (3600/2)) - 86400; time_t tempEnd = tempStart + 3600*5; //Add 5 hours while(tempEnd < iEnd) { ostringstream urlStream; urlStream << "zattoo.com/zapi/v2/cached/program/power_guide/" << powerHash << "?end=" << tempEnd << "&start=" << tempStart << "&format=json"; HTTPSocket *socket = new HTTPSocketRaw(); Request request; request.url = urlStream.str(); request.AddHeader("Cookie", cookie); Response response; socket->Execute(request,response); cookie = response.cookie; std::string jsonString = response.body; Json::Value json; Json::Reader reader; bool parsingSuccessful = reader.parse(jsonString,json); //D(cout << json << endl); Json::Value channels = json["channels"]; //Load the channel groups and channels for ( int index = 0; index < channels.size(); ++index ) { string cid = channels[index]["cid"].asString(); for (int i = 0; i < channels[index]["programs"].size(); ++i) { Json::Value program = channels[index]["programs"][i]; int channelId = GetChannelId(cid.c_str()); ZatChannel *channel = FindChannel(channelId); if (!channel) { continue; } PVRIptvEpgEntry entry; entry.strTitle = program["t"].asString(); entry.startTime = program["s"].asInt(); entry.endTime = program["e"].asInt(); entry.iBroadcastId = program["id"].asInt(); entry.strIconPath = program["i_url"].asString(); entry.iChannelId = channel->iChannelNumber; entry.strPlot = program["et"].asString(); Json::Value genres = program["g"]; ostringstream generesStream; for (int genre = 0; genre < genres.size(); genre++) { generesStream << genres[genre].asString() << " "; } entry.strGenreString = generesStream.str(); if (channel) channel->epg.insert(channel->epg.end(), entry); } } tempStart = tempEnd; tempEnd = tempStart + 3600*5; //Add 5 hours } return true; }
void ZatData::loadChannels() { Json::Value favs = loadFavourites(); ostringstream urlStream; urlStream << "zattoo.com/zapi/v2/cached/channels/" << powerHash << "?details=False"; HTTPSocketRaw *socket = new HTTPSocketRaw(); Request request; request.url = urlStream.str(); request.AddHeader("Cookie", cookie); Response response; socket->Execute(request, response); cookie = response.cookie; std::string jsonString = response.body; Json::Value json; Json::Reader reader; if (!reader.parse(jsonString,json)){ // report to the user the failure and their locations in the document. std::cout << "Failed to parse configuration\n" << reader.getFormatedErrorMessages(); return; } channelNumber = 1; Json::Value groups = json["channel_groups"]; PVRZattooChannelGroup favGroup; favGroup.name = "Favoriten"; //Load the channel groups and channels for ( int index = 0; index < groups.size(); ++index ) { PVRZattooChannelGroup group; group.name = groups[index]["name"].asString(); Json::Value channels = groups[index]["channels"]; for(int i = 0; i < channels.size(); ++i) { Json::Value qualities = channels[i]["qualities"]; for(int q = 0; q < qualities.size(); ++q) { if(qualities[q]["availability"].asString() == "available") { ZatChannel channel; channel.name = qualities[q]["title"].asString(); channel.strStreamURL = ""; //cout << channel.name << endl; std::string cid = channels[i]["cid"].asString(); //returns std::size_t channel.iUniqueId = GetChannelId(cid.c_str()); channel.cid = cid; channel.iChannelNumber = ++channelNumber; channel.strLogoPath = "http://logos.zattic.com"; channel.strLogoPath.append(qualities[q]["logo_white_84"].asString()); group.channels.insert(group.channels.end(), channel); //Yeah thats bad performance for (int fav = 0; fav < favs.size(); fav++) { if (favs[fav].asString() == cid) { favGroup.channels.insert(favGroup.channels.end(), channel); } } break; } } } if (group.channels.size() > 0) channelGroups.insert(channelGroups.end(),group); } if (favGroup.channels.size() > 0) channelGroups.insert(channelGroups.end(),favGroup); }