controlapi: allow to get both tv and radio channels in xmltv.m3u

Usage:
/control/xmltv.m3u?mode=tv to get tv channels
/control/xmltv.m3u?mode=radio to get radio channels
/control/xmltv.m3u  to get both tv and radio channels


Origin commit data
------------------
Branch: ni/coolstream
Commit: d63669b309
Author: vanhofen <vanhofen@gmx.de>
Date: 2020-02-16 (Sun, 16 Feb 2020)

Origin message was:
------------------
- controlapi: allow to get both tv and radio channels in xmltv.m3u

Usage:
/control/xmltv.m3u?mode=tv   to get tv channels
/control/xmltv.m3u?mode=radio to get radio channels
/control/xmltv.m3u       to get both tv and radio channels


------------------
This commit was generated by Migit
This commit is contained in:
vanhofen
2020-02-16 19:56:01 +01:00
parent 75777867f4
commit cd56814af6

View File

@@ -3261,7 +3261,7 @@ void CControlAPI::xmltvepgCGI(CyhookHandler *hh)
CChannelEventList eList; CChannelEventList eList;
CChannelEventList::iterator eventIterator; CChannelEventList::iterator eventIterator;
for (int i = 0; i < (int) g_bouquetManager->Bouquets.size(); i++) for (unsigned int i = 0; i < g_bouquetManager->Bouquets.size(); i++)
{ {
g_bouquetManager->Bouquets[i]->getTvChannels(chanlist); g_bouquetManager->Bouquets[i]->getTvChannels(chanlist);
@@ -3273,7 +3273,7 @@ void CControlAPI::xmltvepgCGI(CyhookHandler *hh)
if(!chanlist.empty() && !g_bouquetManager->Bouquets[i]->bHidden && g_bouquetManager->Bouquets[i]->bUser) if(!chanlist.empty() && !g_bouquetManager->Bouquets[i]->bHidden && g_bouquetManager->Bouquets[i]->bUser)
{ {
for(int j = 0; j < (int) chanlist.size(); j++) for(unsigned int j = 0; j < chanlist.size(); j++)
{ {
CZapitChannel * channel = chanlist[j]; CZapitChannel * channel = chanlist[j];
channel_id = channel->getChannelID() & 0xFFFFFFFFFFFFULL; channel_id = channel->getChannelID() & 0xFFFFFFFFFFFFULL;
@@ -3318,7 +3318,6 @@ void CControlAPI::xmltvepgCGI(CyhookHandler *hh)
} // for m-loop } // for m-loop
} }
result = hh->outObject("tv generator-info-name=\"Neutrino XMLTV Generator v1.0\"", result); result = hh->outObject("tv generator-info-name=\"Neutrino XMLTV Generator v1.0\"", result);
result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE tv SYSTEM \"xmltv.dtd\">\n" + result; result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE tv SYSTEM \"xmltv.dtd\">\n" + result;
@@ -3329,11 +3328,15 @@ void CControlAPI::xmltvepgCGI(CyhookHandler *hh)
void CControlAPI::xmltvm3uCGI(CyhookHandler *hh) void CControlAPI::xmltvm3uCGI(CyhookHandler *hh)
{ {
hh->outStart(); hh->outStart();
std::string result = ""; std::string result("#EXTM3U\n");
int mode = CZapitClient::MODE_TV; int mode;
if (hh->ParamList["mode"] == "radio") if (hh->ParamList["mode"] == "tv")
mode = CZapitClient::MODE_TV;
else if (hh->ParamList["mode"] == "radio")
mode = CZapitClient::MODE_RADIO; mode = CZapitClient::MODE_RADIO;
else
mode = CZapitClient::MODE_ALL;
std::string host = ""; std::string host = "";
if (!hh->ParamList["host"].empty()) if (!hh->ParamList["host"].empty())
@@ -3347,41 +3350,49 @@ void CControlAPI::xmltvm3uCGI(CyhookHandler *hh)
// build url // build url
std::string url = host; std::string url = host;
/* strip off optional custom port */
if (url.rfind(":") != 4) if (url.rfind(":") != 4)
url = url.substr(0, url.rfind(":")); url = url.substr(0, url.rfind(":")); // strip off optional custom port
url += ":31339/id="; url += ":31339/id=";
result += "#EXTM3U\n"; for (unsigned int i = 0; i < g_bouquetManager->Bouquets.size(); i++)
for (int i = 0; i < (int) g_bouquetManager->Bouquets.size(); i++)
{ {
ZapitChannelList chanlist; ZapitChannelList chanlist;
if (mode == CZapitClient::MODE_RADIO)
// FIXME: Maybe there's a nicer solution
for (int m = CZapitClient::MODE_TV; m < CZapitClient::MODE_ALL; m++)
{
if (mode == CZapitClient::MODE_RADIO || m == CZapitClient::MODE_RADIO)
g_bouquetManager->Bouquets[i]->getRadioChannels(chanlist); g_bouquetManager->Bouquets[i]->getRadioChannels(chanlist);
else else
g_bouquetManager->Bouquets[i]->getTvChannels(chanlist); g_bouquetManager->Bouquets[i]->getTvChannels(chanlist);
if (!chanlist.empty() && !g_bouquetManager->Bouquets[i]->bHidden && g_bouquetManager->Bouquets[i]->bUser) if (!chanlist.empty() && !g_bouquetManager->Bouquets[i]->bHidden && g_bouquetManager->Bouquets[i]->bUser)
{ {
for (int j = 0; j < (int) chanlist.size(); j++) for (unsigned int j = 0; j < chanlist.size(); j++)
{ {
CZapitChannel *channel = chanlist[j]; CZapitChannel *channel = chanlist[j];
std::string bouq_name = g_bouquetManager->Bouquets[i]->bName; std::string bouq_name = g_bouquetManager->Bouquets[i]->bName;
std::string chan_id_short = string_printf(PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS, channel->getChannelID() & 0xFFFFFFFFFFFFULL); std::string chan_id_short = string_printf(PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS, channel->getChannelID() & 0xFFFFFFFFFFFFULL);
result += "#EXTINF:-1 tvg-id=\"" + chan_id_short + "\""; result += "#EXTINF:-1 tvg-id=\"" + chan_id_short + "\"";
result += " tvg-name=\"" + channel->getName() + "\"";
if (!NeutrinoAPI->getLogoFile(channel->getChannelID()).empty()) if (!NeutrinoAPI->getLogoFile(channel->getChannelID()).empty())
result += " tvg-logo=\"" + host + NeutrinoAPI->getLogoFile(channel->getChannelID()) + "\""; result += " tvg-logo=\"" + host + NeutrinoAPI->getLogoFile(channel->getChannelID()) + "\"";
else else
result += " tvg-logo=\"\""; result += " tvg-logo=\"\"";
if (mode == CZapitClient::MODE_RADIO) if (mode == CZapitClient::MODE_RADIO || m == CZapitClient::MODE_RADIO)
result += " radio=\"true\""; result += " radio=\"true\"";
else
result += " radio=\"\"";
result += " group-prefix=\"" + std::string(hostname) + "\""; result += " group-prefix=\"" + std::string(hostname) + "\"";
result += " group-title=\"" + bouq_name + "\","; result += " group-title=\"" + bouq_name + "\",";
result += channel->getName() + "\n"; result += channel->getName() + "\n";
result += url + string_printf(PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS, channel->getChannelID()) + "\n"; result += url + string_printf(PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS, channel->getChannelID()) + "\n";
} }
} }
if (mode != CZapitClient::MODE_ALL)
break;
} // for m-loop
} }
hh->SendResult(result); hh->SendResult(result);