diff --git a/src/nhttpd/tuxboxapi/coolstream/controlapi.cpp b/src/nhttpd/tuxboxapi/coolstream/controlapi.cpp index 381d72a87..2c29ca2b6 100644 --- a/src/nhttpd/tuxboxapi/coolstream/controlapi.cpp +++ b/src/nhttpd/tuxboxapi/coolstream/controlapi.cpp @@ -155,8 +155,10 @@ const CControlAPI::TyCgiCall CControlAPI::yCgiCallList[]= {"getbouquets", &CControlAPI::GetBouquetsCGI, "+xml"}, {"getmode", &CControlAPI::GetModeCGI, "text/plain"}, {"setmode", &CControlAPI::SetModeCGI, "text/plain"}, - {"epg", &CControlAPI::EpgCGI, ""}, - {"zapto", &CControlAPI::ZaptoCGI, "text/plain"}, + {"epgsearchxml", &CControlAPI::EpgSearchXMLCGI, ""}, + {"epgsearch", &CControlAPI::EpgSearchTXTCGI, ""}, + {"epg", &CControlAPI::EpgCGI, ""}, + {"zapto", &CControlAPI::ZaptoCGI, "text/plain"}, {"getonidsid", &CControlAPI::GetChannel_IDCGI, "text/plain"}, {"currenttpchannels", &CControlAPI::GetTPChannel_IDCGI, "text/plain"}, // boxcontrol - system @@ -1283,6 +1285,128 @@ void CControlAPI::epgDetailList(CyhookHandler *hh) { hh->WriteLn(result); } } +//------------------------------------------------------------------------------------------------- +inline static bool sortByDateTime (const CChannelEvent& a, const CChannelEvent& b) +{ + return a.startTime < b.startTime; +} +extern const char * GetGenre(const unsigned char contentClassification); // UTF-8 +void CControlAPI::EpgSearchXMLCGI(CyhookHandler *hh) +{ + EpgSearchCGI(hh, true);//xml_forat = true +} +void CControlAPI::EpgSearchTXTCGI(CyhookHandler *hh) +{ + EpgSearchCGI(hh, false);//xml_forat = false +} + +void CControlAPI::EpgSearchCGI(CyhookHandler *hh, bool xml_forat ) +{ + t_channel_id channel_id; + CChannelEventList evtlist; + bool param_empty = hh->ParamList.empty(); + const int m_search_epg_item = 5; + if(!param_empty){ + if(xml_forat){ + hh->SetHeader(HTTP_OK, "text/xml; charset=UTF-8"); + hh->WriteLn(""); + hh->WriteLn(""); + } + else{ + hh->SetHeader(HTTP_OK, "text/plain; charset=UTF-8"); // default + } + + std::string m_search_keyword =hh->ParamList["1"]; + + std::vector v; + int channel_nr = CNeutrinoApp::getInstance ()->channelList->getSize();//unique channelList TV or Radio + for(int channel = 0; channel < channel_nr; channel++){ + channel_id = CNeutrinoApp::getInstance ()->channelList->getChannelFromIndex(channel)->channel_id; + v.push_back(channel_id); + } + std::map ch_id_map; + std::vector::iterator it; + for (it = v.begin(); it != v.end(); ++it){ + ch_id_map[*it & 0xFFFFFFFFFFFFULL] = *it; + } + CEitManager::getInstance()->getEventsServiceKey(0,evtlist, m_search_epg_item,m_search_keyword, true);//all_chann + + if(!evtlist.empty()){ + std::map::iterator map_it; + CChannelEventList::iterator e; + for ( e=evtlist.begin(); e!=evtlist.end();++e){ + map_it = ch_id_map.find(e->channelID); + if (map_it != ch_id_map.end()){ + e->channelID = map_it->second;//map channelID48 to channelID + } + else{ + evtlist.erase(e--);// remove event for not found channels in channelList + } + } + } + if(!evtlist.empty()){ + sort(evtlist.begin(),evtlist.end(),sortByDateTime); + } + + time_t azeit=time(NULL); + CShortEPGData epg; + CEPGData longepg; + char tmpstr[256] ={0}; + CChannelEventList::iterator eventIterator; + unsigned int u_azeit = ( azeit > -1)? azeit:0; + for (eventIterator = evtlist.begin(); eventIterator != evtlist.end(); ++eventIterator){ + if (CEitManager::getInstance()->getEPGidShort(eventIterator->eventID, &epg)) { + if( (eventIterator->startTime+eventIterator->duration) < u_azeit) + continue; + struct tm *tmStartZeit = localtime(&eventIterator->startTime); + if(xml_forat){ + hh->printf("\t"); + hh->printf("\t\t%s\n",NeutrinoAPI->GetServiceName(eventIterator->channelID).c_str()); + hh->printf("\t\t%s\n",ZapitTools::UTF8_to_UTF8XML(epg.title.c_str()).c_str()); + hh->printf("\t\t%s\n",ZapitTools::UTF8_to_UTF8XML(epg.info1.c_str()).c_str()); + hh->printf("\t\t%s\n",ZapitTools::UTF8_to_UTF8XML(epg.info2.c_str()).c_str()); + if (CEitManager::getInstance()->getEPGid(eventIterator->eventID, eventIterator->startTime, &longepg)) { + hh->printf("\t\t%u\n", longepg.fsk); + if (longepg.contentClassification.length()> 0){ + std::string genere = GetGenre(longepg.contentClassification[0]); + hh->printf("\t\t%s\n", ZapitTools::UTF8_to_UTF8XML(genere.c_str()).c_str()); + } + } + strftime(tmpstr, sizeof(tmpstr), "%Y-%m-%d", tmStartZeit ); + hh->printf("\t\t%s\n", tmpstr); + strftime(tmpstr, sizeof(tmpstr), ". %H:%M", tmStartZeit ); + hh->printf("\t\t\n", tmpstr); + hh->printf("\t\t%d\n", eventIterator->duration); + hh->printf("\t\t\t" PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS "\n",eventIterator->channelID); + hh->printf("\t\t\t%ld\n",eventIterator->eventID); + hh->printf("\t"); + }else{ + std::string datetimer_str ; + strftime(tmpstr, sizeof(tmpstr), "%Y-%m-%d %H:%M", tmStartZeit ); + datetimer_str = tmpstr; + datetimer_str += " "; + datetimer_str += g_Locale->getText(CLocaleManager::getMonth(tmStartZeit)); + datetimer_str += " "; + datetimer_str += g_Locale->getText(CLocaleManager::getWeekday(tmStartZeit)); + + hh->WriteLn(datetimer_str); + hh->WriteLn(NeutrinoAPI->GetServiceName(eventIterator->channelID)); + hh->WriteLn(epg.title); + if(!epg.info1.empty()) + hh->WriteLn(epg.info1); + if(!epg.info2.empty()) + hh->WriteLn(epg.info2); + hh->WriteLn("----------------------------------------------------------"); + + } + } + } + if(xml_forat) + hh->printf(""); + }else + hh->SendError(); + +} //------------------------------------------------------------------------- /** Return EPG data @@ -1300,6 +1424,7 @@ void CControlAPI::epgDetailList(CyhookHandler *hh) { * stoptime : show only items until stoptime reached * @endcode */ + //------------------------------------------------------------------------- void CControlAPI::EpgCGI(CyhookHandler *hh) { NeutrinoAPI->eList.clear(); diff --git a/src/nhttpd/tuxboxapi/coolstream/controlapi.h b/src/nhttpd/tuxboxapi/coolstream/controlapi.h index 151dbf160..33d969ae6 100644 --- a/src/nhttpd/tuxboxapi/coolstream/controlapi.h +++ b/src/nhttpd/tuxboxapi/coolstream/controlapi.h @@ -40,7 +40,9 @@ private: void SendTimers(CyhookHandler *hh); void SendTimersXML(CyhookHandler *hh); void epgDetailList(CyhookHandler *hh); - + void EpgSearchXMLCGI(CyhookHandler *hh); + void EpgSearchTXTCGI(CyhookHandler *hh); + void EpgSearchCGI(CyhookHandler *hh, bool xml_forat = false); // subs friend class CNeutrinoWebserver; // for timer /fb/ compatibility void doModifyTimer(CyhookHandler *hh);