2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
25 #include "TuxBoxUtil.h"
27 #include "filesystem/CurlFile.h"
28 #include "dialogs/GUIDialogContextMenu.h"
29 #include "Application.h"
30 #include "ApplicationMessenger.h"
31 #include "GUIInfoManager.h"
32 #include "video/VideoInfoTag.h"
33 #include "guilib/GUIWindowManager.h"
34 #include "dialogs/GUIDialogOK.h"
35 #include "dialogs/GUIDialogYesNo.h"
36 #include "filesystem/File.h"
38 #include "settings/AdvancedSettings.h"
40 #include "guilib/LocalizeStrings.h"
41 #include "StringUtils.h"
42 #include "utils/XBMCTinyXML.h"
45 using namespace XFILE;
49 CTuxBoxService g_tuxboxService;
51 CTuxBoxService::CTuxBoxService() : CThread("TuxBoxService")
54 CTuxBoxService::~CTuxBoxService()
57 CTuxBoxUtil::CTuxBoxUtil(void)
59 sCurSrvData.requested_audio_channel = 0;
60 sZapstream.initialized = false;
61 sZapstream.available = false;
63 CTuxBoxUtil::~CTuxBoxUtil(void)
66 bool CTuxBoxService::Start()
68 if(g_advancedSettings.m_iTuxBoxEpgRequestTime != 0)
77 void CTuxBoxService::Stop()
79 CLog::Log(LOGDEBUG, "%s - Stopping CTuxBoxService thread", __FUNCTION__);
82 void CTuxBoxService::OnStartup()
84 CLog::Log(LOGDEBUG, "%s - Starting CTuxBoxService thread", __FUNCTION__);
85 SetPriority( GetMinPriority() );
87 void CTuxBoxService::OnExit()
89 CThread::m_bStop = true;
91 bool CTuxBoxService::IsRunning()
93 return !CThread::m_bStop;
95 void CTuxBoxService::Process()
97 CStdString strCurrentServiceName = g_tuxbox.sCurSrvData.service_name;
100 while(!CThread::m_bStop && g_application.m_pPlayer->IsPlaying())
102 strURL = g_application.CurrentFileItem().GetPath();
103 if(!URIUtils::IsTuxBox(strURL))
106 int iRequestTimer = g_advancedSettings.m_iTuxBoxEpgRequestTime *1000; //seconds
107 Sleep(iRequestTimer);
110 if(g_tuxbox.GetHttpXML(url,"currentservicedata"))
112 CLog::Log(LOGDEBUG, "%s - receive current service data was successful", __FUNCTION__);
113 if(!strCurrentServiceName.IsEmpty()&&
114 !strCurrentServiceName.Equals("NULL") &&
115 !g_tuxbox.sCurSrvData.service_name.IsEmpty() &&
116 !g_tuxbox.sCurSrvData.service_name.Equals("-") &&
117 !g_tuxbox.vVideoSubChannel.mode)
119 //Detect Channel Change
120 //We need to detect the channel on the TuxBox Device!
121 //On changing the channel on the device we will loose the stream and mplayer seems not able to detect it to stop
122 if (strCurrentServiceName != g_tuxbox.sCurSrvData.service_name && g_application.m_pPlayer->IsPlaying() && !g_tuxbox.sZapstream.available)
124 CLog::Log(LOGDEBUG," - ERROR: Non controlled channel change detected! Stopping current playing stream!");
125 CApplicationMessenger::Get().MediaStop();
129 //Update infomanager from tuxbox client
130 g_infoManager.UpdateFromTuxBox();
133 CLog::Log(LOGDEBUG, "%s - Could not receive current service data", __FUNCTION__);
136 bool CTuxBoxUtil::CreateNewItem(const CFileItem& item, CFileItem& item_new)
139 item_new.SetLabel(item.GetLabel());
140 item_new.SetPath(item.GetPath());
141 item_new.SetArt("thumb", item.GetArt("thumb"));
143 if(g_tuxbox.GetZapUrl(item.GetPath(), item_new))
145 if(vVideoSubChannel.mode)
146 vVideoSubChannel.current_name = item_new.GetLabel()+" ("+vVideoSubChannel.current_name+")";
151 if(!sBoxStatus.recording.Equals("1")) //Don't Show this Dialog, if the Box is in Recording mode! A previos YN Dialog was send to user!
153 CLog::Log(LOGDEBUG, "%s ---------------------------------------------------------", __FUNCTION__);
154 CLog::Log(LOGDEBUG, "%s - WARNING: Zaping Failed no Zap Point found!", __FUNCTION__);
155 CLog::Log(LOGDEBUG, "%s ---------------------------------------------------------", __FUNCTION__);
157 strText.Format(g_localizeStrings.Get(21334).c_str(), item.GetLabel());
158 CGUIDialogOK::ShowAndGetInput(21331, strText, 21333, 0);
163 bool CTuxBoxUtil::ParseBouquets(TiXmlElement *root, CFileItemList &items, CURL &url, CStdString strFilter, CStdString strChild)
165 CStdString strOptions, strPort;
166 TiXmlElement *pRootElement =root;
167 TiXmlNode *pNode = NULL;
168 TiXmlNode *pIt = NULL;
171 strOptions = url.GetOptions();
175 CLog::Log(LOGWARNING, "%s - No %s found", __FUNCTION__, strChild.c_str());
178 if (strFilter.IsEmpty())
180 pNode = pRootElement->FirstChild(strChild.c_str());
183 CLog::Log(LOGWARNING, "%s - No %s found", __FUNCTION__,strChild.c_str());
188 pIt = pNode->FirstChild("name");
191 CStdString strItemName = pIt->FirstChild()->Value();
193 pIt = pNode->FirstChild("reference");
196 CStdString strItemPath = pIt->FirstChild()->Value();
197 // add. bouquets to item list!
198 CFileItemPtr pItem(new CFileItem);
199 pItem->m_bIsFolder = true;
200 pItem->SetLabel(strItemName);
203 fileUrl.SetProtocol("tuxbox");
204 fileUrl.SetUserName(url.GetUserName());
205 fileUrl.SetPassword(url.GetPassWord());
206 fileUrl.SetHostName(url.GetHostName());
207 if (url.GetPort() != 0 && url.GetPort() != 80)
208 fileUrl.SetPort(url.GetPort());
209 fileUrl.SetOptions(url.GetOptions());
210 fileUrl.SetOption("reference", strItemPath);
211 pItem->SetPath(fileUrl.Get());
215 CLog::Log(LOGDEBUG, "%s - Name: %s", __FUNCTION__,strItemName.c_str());
216 CLog::Log(LOGDEBUG, "%s - Adress: %s", __FUNCTION__,pItem->GetPath().c_str());
219 pNode = pNode->NextSibling(strChild.c_str());
224 bool CTuxBoxUtil::ParseBouquetsEnigma2(TiXmlElement *root, CFileItemList &items, CURL &url, CStdString& strFilter, CStdString& strChild)
227 TiXmlElement *pRootElement = root;
228 TiXmlNode *pNode = NULL;
229 TiXmlNode *pIt = NULL;
234 CLog::Log(LOGWARNING, "%s - No %s found", __FUNCTION__, strChild.c_str());
237 if (strFilter.IsEmpty())
239 pNode = pRootElement->FirstChildElement("e2bouquet");
242 CLog::Log(LOGWARNING, "%s - No %s found", __FUNCTION__,strChild.c_str());
247 CFileItemPtr pItem(new CFileItem);
248 pIt = pNode->FirstChildElement("e2servicereference");
249 CStdString strItemPath = pIt->FirstChild()->Value();
250 pIt = pNode->FirstChildElement("e2servicename");
251 CStdString strItemName = pIt->FirstChild()->Value();
252 pItem->m_bIsFolder = true;
253 pItem->SetLabel(strItemName);
256 fileUrl.SetProtocol("tuxbox");
257 fileUrl.SetHostName(url.GetHostName());
258 if (url.GetPort() != 0 && url.GetPort() != 80)
259 fileUrl.SetPort(url.GetPort());
260 fileUrl.SetFileName(strItemName + "/");
261 pItem->SetPath(fileUrl.Get());
264 pNode = pNode->NextSiblingElement("e2bouquet");
269 bool CTuxBoxUtil::ParseChannels(TiXmlElement *root, CFileItemList &items, CURL &url, CStdString strFilter, CStdString strChild)
272 TiXmlElement *pRootElement =root;
273 TiXmlNode *pNode = NULL;
274 TiXmlNode *pIt = NULL;
275 TiXmlNode *pIta = NULL;
280 CLog::Log(LOGWARNING, "%s - No %ss found", __FUNCTION__,strChild.c_str());
283 if(!strFilter.IsEmpty())
285 pNode = pRootElement->FirstChild(strChild.c_str());
288 CLog::Log(LOGWARNING, "%s - No %s found", __FUNCTION__,strChild.c_str());
293 pIt = pNode->FirstChild("name");
296 CStdString strItemName = pIt->FirstChild()->Value();
298 pIt = pNode->FirstChild("reference");
299 if (strFilter.Equals(pIt->FirstChild()->Value()))
301 pIt = pNode->FirstChild("service");
304 CLog::Log(LOGWARNING, "%s - No service found", __FUNCTION__);
309 pIta = pIt->FirstChild("name");
312 strItemName = pIta->FirstChild()->Value();
314 pIta = pIt->FirstChild("reference");
317 CStdString strItemPath = pIta->FirstChild()->Value();
318 // channel listing add. to item list!
319 CFileItemPtr pbItem(new CFileItem);
320 pbItem->m_bIsFolder = false;
321 pbItem->SetLabel(strItemName);
322 pbItem->SetLabelPreformated(true);
325 fileUrl.SetProtocol("tuxbox");
326 fileUrl.SetUserName(url.GetUserName());
327 fileUrl.SetPassword(url.GetPassWord());
328 fileUrl.SetHostName(url.GetHostName());
329 if (url.GetPort() != 0 && url.GetPort() != 80)
330 fileUrl.SetPort(url.GetPort());
331 fileUrl.SetFileName("cgi-bin/zapTo");
332 fileUrl.SetOption("path", strItemPath+".ts");
333 pbItem->SetPath(fileUrl.Get());
335 pbItem->SetArt("thumb", GetPicon(strItemName)); //Set Picon Image
338 CLog::Log(LOGDEBUG, "%s - Name: %s", __FUNCTION__,strItemName.c_str());
339 CLog::Log(LOGDEBUG, "%s - Adress: %s", __FUNCTION__,pbItem->GetPath().c_str());
345 pIt = pIt->NextSibling("service");
349 pNode = pNode->NextSibling(strChild.c_str());
355 bool CTuxBoxUtil::ParseChannelsEnigma2(TiXmlElement *root, CFileItemList &items, CURL &url, CStdString& strFilter, CStdString& strChild)
357 TiXmlElement *pRootElement = root;
358 TiXmlNode *pNode = NULL;
359 TiXmlNode *pIt = NULL;
360 TiXmlNode *pIta = NULL;
361 TiXmlNode *pItb = NULL;
366 CLog::Log(LOGWARNING, "%s - No %ss found", __FUNCTION__,strChild.c_str());
369 if(!strFilter.IsEmpty())
371 pNode = pRootElement->FirstChild(strChild.c_str());
374 CLog::Log(LOGWARNING, "%s - No %s found", __FUNCTION__,strChild.c_str());
379 pIt = pNode->FirstChildElement("e2servicename");
380 CStdString bqtName = pIt->FirstChild()->Value();
381 pIt = pNode->FirstChildElement("e2servicelist");
382 pIta = pIt->FirstChildElement("e2service");
385 pItb = pIta->FirstChildElement("e2servicereference");
386 CStdString strItemPath = pItb->FirstChild()->Value();
387 pItb = pIta->FirstChildElement("e2servicename");
388 CStdString strItemName = pItb->FirstChild()->Value();
389 if(bqtName == url.GetShareName())
391 CFileItemPtr pbItem(new CFileItem);
392 pbItem->m_bIsFolder = false;
393 pbItem->SetLabel(strItemName);
396 fileUrl.SetProtocol("http");
397 fileUrl.SetHostName(url.GetHostName());
398 fileUrl.SetPort(8001);
399 fileUrl.SetFileName(strItemPath);
400 pbItem->SetPath(fileUrl.Get());
402 pbItem->SetMimeType("video/mpeg2");
404 CLog::Log(LOGDEBUG, "%s - Name: %s", __FUNCTION__,strItemName.c_str());
405 CLog::Log(LOGDEBUG, "%s - Adress: %s", __FUNCTION__,pbItem->GetPath().c_str());
407 pIta = pIta->NextSiblingElement("e2service");
409 pNode = pNode->NextSiblingElement("e2bouquet");
414 bool CTuxBoxUtil::ZapToUrl(CURL url, const CStdString &pathOption)
417 CStdString strZapUrl, strPostUrl, strZapName, strFilter;
418 //Extract the ZAP to Service String
420 strFilter = pathOption.Left(pathOption.size()-3);
421 //Get the Service Name
425 urlx.SetProtocol("http");
426 urlx.SetUserName(url.GetUserName());
427 urlx.SetPassword(url.GetPassWord());
428 urlx.SetHostName(url.GetHostName());
429 if (url.GetPort() != 0 && url.GetPort() != 80)
430 urlx.SetPort(url.GetPort());
432 postUrl.SetFileName("cgi-bin/zapTo");
433 postUrl.SetOption("path", strFilter);
435 //Check Recording State!
436 if(GetHttpXML(urlx,"boxstatus"))
438 if(sBoxStatus.recording.Equals("1"))
440 CLog::Log(LOGDEBUG, "%s ---------------------------------------------------------", __FUNCTION__);
441 CLog::Log(LOGDEBUG, "%s - WARNING: Device is Recording! Record Mode is: %s", __FUNCTION__,sBoxStatus.recording.c_str());
442 CLog::Log(LOGDEBUG, "%s ---------------------------------------------------------", __FUNCTION__);
443 CGUIDialogYesNo* dialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO);
446 //Target TuxBox is in Recording mode! Are you sure to stream ?YN
447 dialog->SetHeading(21331);
448 dialog->SetLine( 0, 21332);
449 dialog->SetLine( 1, 21335);
450 dialog->SetLine( 2, "" );
452 if (!dialog->IsConfirmed())
454 //DialogYN = NO -> Return false!
463 if(http.Open(postUrl))
466 CLog::Log(LOGDEBUG, "%s - Zapped to: %s", __FUNCTION__,postUrl.Get().c_str());
469 GetHttpXML(urlx,"streaminfo");
471 //Extract StreamInformations
473 //PMT must be a valid value to be sure that the ZAP is OK and we can stream!
474 while(sStrmInfo.pmt.Equals("ffffffffh") && iRetry!=10) //try 10 Times
476 CLog::Log(LOGDEBUG, "%s - Requesting STREAMINFO! TryCount: %i!", __FUNCTION__,iRetry);
477 GetHttpXML(urlx,"streaminfo");
482 // PMT Not Valid? Try Time 10 reached, checking for advancedSettings m_iTuxBoxZapWaitTime
483 if(sStrmInfo.pmt.Equals("ffffffffh") && g_advancedSettings.m_iTuxBoxZapWaitTime > 0 )
486 CLog::Log(LOGDEBUG, "%s - Starting TuxBox ZapWaitTimer!", __FUNCTION__);
487 while(sStrmInfo.pmt.Equals("ffffffffh") && iRetry!=10) //try 10 Times
489 CLog::Log(LOGDEBUG, "%s - Requesting STREAMINFO! TryCount: %i!", __FUNCTION__,iRetry);
490 GetHttpXML(urlx,"streaminfo");
492 if(sStrmInfo.pmt.Equals("ffffffffh"))
494 CLog::Log(LOGERROR, "%s - STREAMINFO ERROR! Could not receive all data, TryCount: %i!", __FUNCTION__,iRetry);
495 CLog::Log(LOGERROR, "%s - PMT is: %s (not a Valid Value)! Waiting %i sec.", __FUNCTION__,sStrmInfo.pmt.c_str(), g_advancedSettings.m_iTuxBoxZapWaitTime);
496 Sleep(g_advancedSettings.m_iTuxBoxZapWaitTime*1000);
501 //PMT Failed! No StreamInformations availible.. closing stream
502 if (sStrmInfo.pmt.Equals("ffffffffh"))
504 CLog::Log(LOGERROR, "%s-------------------------------------------------------------", __FUNCTION__);
505 CLog::Log(LOGERROR, "%s - STREAMINFO ERROR! Could not receive all data, TryCount: %i!", __FUNCTION__,iRetry);
506 CLog::Log(LOGERROR, "%s - PMT is: %s (not a Valid Value)! There is nothing to Stream!", __FUNCTION__,sStrmInfo.pmt.c_str());
507 CLog::Log(LOGERROR, "%s - The Stream will stopped!", __FUNCTION__);
508 CLog::Log(LOGERROR, "%s-------------------------------------------------------------", __FUNCTION__);
512 GetHttpXML(urlx,"currentservicedata");
514 GetHttpXML(urlx,"boxstatus");
516 GetHttpXML(urlx,"boxinfo");
518 GetHttpXML(urlx,"serviceepg");
523 bool CTuxBoxUtil::GetZapUrl(const CStdString& strPath, CFileItem &items )
526 CStdString strOptions = url.GetOptions();
527 if (strOptions.IsEmpty())
530 if (url.HasOption("path"))
532 if(ZapToUrl(url, url.GetOption("path")))
534 //Check VideoSubChannels
535 if(GetHttpXML(url,"currentservicedata")) //Update Currentservicedata
537 //Detect VideoSubChannels
538 CStdString strVideoSubChannelName, strVideoSubChannelPID;
539 if(GetVideoSubChannels(strVideoSubChannelName,strVideoSubChannelPID ))
541 // new videosubchannel selected! settings options to new video zap id
542 // zap again now to new videosubchannel
543 if(ZapToUrl(url, strVideoSubChannelPID + ".ts"))
545 vVideoSubChannel.mode = true;
546 vVideoSubChannel.current_name = strVideoSubChannelName;
550 vVideoSubChannel.mode= false;
553 CStdString strStreamURL, strVideoStream;
554 CStdString strLabel, strLabel2;
555 CStdString strAudioChannelName, strAudioChannelPid;
557 sAudioChannel sRequestedAudioChannel;
559 if (!GetGUIRequestedAudioChannel(sRequestedAudioChannel))
561 if (g_advancedSettings.m_bTuxBoxSendAllAPids && sCurSrvData.audio_channels.size() > 1)
563 for (vector<sAudioChannel>::iterator sChannel = sCurSrvData.audio_channels.begin(); sChannel!=sCurSrvData.audio_channels.end(); ++sChannel)
565 if (sChannel->pid != sRequestedAudioChannel.pid)
566 strAPids += "," + sChannel->pid.Right(4);
568 CLog::Log(LOGDEBUG, "%s - Sending all audio pids: %s%s", __FUNCTION__, strAudioChannelPid.c_str(), strAPids.c_str());
570 strVideoStream.Format("0,%s,%s,%s%s",sStrmInfo.pmt.Left(4).c_str(), sStrmInfo.vpid.Left(4).c_str(), sStrmInfo.apid.Left(4).c_str(), strAPids.c_str());
573 strVideoStream.Format("0,%s,%s,%s",sStrmInfo.pmt.Left(4).c_str(), sStrmInfo.vpid.Left(4).c_str(), sStrmInfo.apid.Left(4).c_str());
576 strVideoStream.Format("0,%s,%s,%s",sStrmInfo.pmt.Left(4).c_str(), sStrmInfo.vpid.Left(4).c_str(), strAudioChannelPid.Left(4).c_str());
579 streamURL.SetProtocol("http");
580 streamURL.SetUserName(url.GetUserName());
581 streamURL.SetPassword(url.GetPassWord());
582 streamURL.SetHostName(url.GetHostName());
583 streamURL.SetPort(g_advancedSettings.m_iTuxBoxStreamtsPort);
584 streamURL.SetFileName(strVideoStream.c_str());
586 if (!g_tuxbox.sZapstream.initialized)
587 g_tuxbox.InitZapstream(strPath);
589 // Use the Zapstream service when available.
590 if (g_tuxbox.sZapstream.available)
592 sAudioChannel sSelectedAudioChannel;
593 if (GetRequestedAudioChannel(sSelectedAudioChannel))
595 if (sSelectedAudioChannel.pid != sStrmInfo.apid)
597 if (SetAudioChannel(strPath, sSelectedAudioChannel))
598 CLog::Log(LOGDEBUG, "%s - Zapstream: Requested audio channel is %s, pid %s.", __FUNCTION__, sSelectedAudioChannel.name.c_str(), sSelectedAudioChannel.pid.c_str());
601 streamURL.SetFileName("");
602 streamURL.SetPort(g_advancedSettings.m_iTuxBoxZapstreamPort);
605 if (g_application.m_pPlayer->IsPlaying() && !g_tuxbox.sZapstream.available)
606 CApplicationMessenger::Get().MediaStop();
608 strLabel.Format("%s: %s %s-%s",items.GetLabel().c_str(), sCurSrvData.current_event_date.c_str(),sCurSrvData.current_event_start.c_str(), sCurSrvData.current_event_start.c_str());
609 strLabel2.Format("%s", sCurSrvData.current_event_description.c_str());
612 CStdString strGenre, strTitle;
613 strGenre.Format("%s %s - (%s: %s)",g_localizeStrings.Get(143),sCurSrvData.current_event_description, g_localizeStrings.Get(209),sCurSrvData.next_event_description);
614 strTitle.Format("%s",sCurSrvData.current_event_details);
615 int iDuration = atoi(sCurSrvData.current_event_duration.c_str());
617 items.GetVideoInfoTag()->m_genre = StringUtils::Split(strGenre, g_advancedSettings.m_videoItemSeparator); // VIDEOPLAYER_GENRE: current_event_description (Film Name)
618 items.GetVideoInfoTag()->m_strTitle = strTitle; // VIDEOPLAYER_TITLE: current_event_details (Film beschreibung)
619 items.GetVideoInfoTag()->m_duration = iDuration; //VIDEOPLAYER_DURATION: current_event_duration (laufzeit in sec.)
621 items.SetPath(streamURL.Get());
622 items.m_iDriveType = url.GetPort(); // Dirty Hack! But i need to hold the Port ;)
623 items.SetLabel(items.GetLabel()); // VIDEOPLAYER_DIRECTOR: service_name (Program Name)
624 items.SetLabel2(sCurSrvData.current_event_description); // current_event_description (Film Name)
625 items.m_bIsFolder = false;
626 items.SetMimeType("video/x-mpegts");
633 // Notice: Zapstream is a streamts enhancement from PLi development team.
634 // If you are using a non-PLi based image you might not have Zapstream installed.
635 bool CTuxBoxUtil::InitZapstream(const CStdString& strPath)
642 g_tuxbox.sZapstream.initialized = true;
644 if (!g_advancedSettings.m_bTuxBoxZapstream)
646 CLog::Log(LOGDEBUG, "%s - Zapstream is disabled in advancedsettings.xml.", __FUNCTION__);
647 return g_tuxbox.sZapstream.available = false;
650 url.SetProtocol("http");
653 url.SetPort(g_advancedSettings.m_iTuxBoxZapstreamPort);
655 while (iTryConnect < 3)
657 http.SetTimeout(iTimeout);
662 CHttpHeader h = http.GetHttpHeader();
663 CStdString strValue = h.GetValue("server");
665 if (strValue.Find("zapstream") >= 0 )
667 CLog::Log(LOGDEBUG, "%s - Zapstream is available on port %i.", __FUNCTION__, g_advancedSettings.m_iTuxBoxZapstreamPort);
668 return g_tuxbox.sZapstream.available = true;
676 CLog::Log(LOGDEBUG, "%s - Zapstream is not available on port %i.", __FUNCTION__, g_advancedSettings.m_iTuxBoxZapstreamPort);
679 bool CTuxBoxUtil::SetAudioChannel( const CStdString& strPath, const AUDIOCHANNEL& sAC )
686 url.SetProtocol("http");
687 url.SetFileName("cgi-bin/setAudio");
688 url.SetOptions("?channel=1&language=" + sAC.pid);
691 g_tuxbox.sZapstream.initialized = true;
693 while (iTryConnect < 3)
695 http.SetTimeout(iTimeout);
709 bool CTuxBoxUtil::GetHttpXML(CURL url,CStdString strRequestType)
711 // Check and Set URL Request Option
712 if(!strRequestType.IsEmpty())
714 if(strRequestType.Equals("streaminfo"))
716 url.SetOptions("xml/streaminfo");
718 else if(strRequestType.Equals("currentservicedata"))
720 url.SetOptions("xml/currentservicedata");
722 else if(strRequestType.Equals("boxstatus"))
724 url.SetOptions("xml/boxstatus");
726 else if(strRequestType.Equals("boxinfo"))
728 url.SetOptions("xml/boxinfo");
730 else if(strRequestType.Equals("serviceepg"))
732 url.SetOptions("xml/serviceepg");
736 CLog::Log(LOGERROR, "%s - Request Type is not defined! You requested: %s", __FUNCTION__,strRequestType.c_str());
742 CLog::Log(LOGERROR, "%s - strRequestType Request Type is Empty!", __FUNCTION__);
746 // Clean Up the URL, so we have a clean request!
756 int size_total = (int)http.GetLength();
760 // read response from server into string buffer
762 strTmp.reserve(size_total);
764 while( (size_read = http.Read( buffer, sizeof(buffer)-1) ) > 0 )
766 buffer[size_read] = 0;
768 data_size += size_read;
771 // parse returned xml
773 TiXmlElement *XMLRoot=NULL;
774 strTmp.Replace("></",">-</"); //FILL EMPTY ELEMENTS WITH "-"!
775 doc.Parse(strTmp, http.GetServerReportedCharset());
778 XMLRoot = doc.RootElement();
779 CStdString strRoot = XMLRoot->Value();
780 if( strRoot.Equals("streaminfo"))
781 return StreamInformations(XMLRoot);
782 if(strRoot.Equals("currentservicedata"))
783 return CurrentServiceData(XMLRoot);
784 if(strRoot.Equals("boxstatus"))
785 return BoxStatus(XMLRoot);
786 if(strRoot.Equals("boxinfo"))
787 return BoxInfo(XMLRoot);
788 if(strRoot.Equals("serviceepg") || strRoot.Equals("service_epg"))
789 return ServiceEPG(XMLRoot);
791 CLog::Log(LOGERROR, "%s - Unable to parse xml", __FUNCTION__);
792 CLog::Log(LOGERROR, "%s - Request String: %s", __FUNCTION__,strRoot.c_str());
797 CLog::Log(LOGERROR, "%s - http length is invalid!", __FUNCTION__);
801 CLog::Log(LOGERROR, "%s - Open URL Failed! Unable to get XML structure", __FUNCTION__);
804 bool CTuxBoxUtil::StreamInformations(TiXmlElement *pRootElement)
808 http://192.168.0.110:31339/0,0065,01ff,0200,0201,0203,01ff
810 http://getIP:31339/0,pmtpid,vpid,apid,apids,apids,pcrpid;
812 vpid,pmtpid,pcrpid,apid --> xml/streaminfo
813 apids --> /xml/currentservicedata
815 apid: is the defined audio stream!
816 Normal Stereo: http://192.168.0.110:31339/0,0065,01ff,0200,0201,0203,01ff
817 Normal English: http://192.168.0.110:31339/0,0065,01ff,0201,,,01ff
818 Normal DD5.1/AC3: http://192.168.0.110:31339/0,0065,01ff,0203,,,01ff
821 TiXmlNode *pNode = NULL;
822 TiXmlNode *pIt = NULL;
823 if(pRootElement != NULL)
825 CStdString strRoot = pRootElement->Value();
826 pNode = pRootElement->FirstChild("frontend");
829 sStrmInfo.frontend = pNode->FirstChild()->Value();
830 CLog::Log(LOGDEBUG, "%s - Frontend: %s", __FUNCTION__, sStrmInfo.frontend.c_str());
832 pNode = pRootElement->FirstChild("service");
835 CLog::Log(LOGDEBUG, "%s - Service", __FUNCTION__);
836 pIt = pNode->FirstChild("name");
839 sStrmInfo.service_name = pIt->FirstChild()->Value();
840 CLog::Log(LOGDEBUG, "%s - Name: %s", __FUNCTION__, sStrmInfo.service_name.c_str());
842 pIt = pNode->FirstChild("reference");
845 sStrmInfo.service_reference = pIt->FirstChild()->Value();
846 CLog::Log(LOGDEBUG, "%s - Reference: %s", __FUNCTION__, sStrmInfo.service_reference.c_str());
850 pNode = pRootElement->FirstChild("provider");
851 if(pNode && pNode->FirstChild())
853 sStrmInfo.provider= pNode->FirstChild()->Value();
854 CLog::Log(LOGDEBUG, "%s - Provider: %s", __FUNCTION__, sStrmInfo.provider.c_str());
856 pNode = pRootElement->FirstChild("vpid");
859 sStrmInfo.vpid = pNode->FirstChild()->Value();
860 CLog::Log(LOGDEBUG, "%s - Vpid: %s", __FUNCTION__, sStrmInfo.vpid.c_str());
862 pNode = pRootElement->FirstChild("apid");
865 sStrmInfo.apid = pNode->FirstChild()->Value();
866 CLog::Log(LOGDEBUG, "%s - Apid: %s", __FUNCTION__, sStrmInfo.apid.c_str());
868 pNode = pRootElement->FirstChild("pcrpid");
871 sStrmInfo.pcrpid = pNode->FirstChild()->Value();
872 CLog::Log(LOGDEBUG, "%s - PcrPid: %s", __FUNCTION__, sStrmInfo.pcrpid.c_str());
874 pNode = pRootElement->FirstChild("tpid");
877 sStrmInfo.tpid = pNode->FirstChild()->Value();
878 CLog::Log(LOGDEBUG, "%s - Tpid: %s", __FUNCTION__, sStrmInfo.tpid.c_str());
880 pNode = pRootElement->FirstChild("tsid");
883 sStrmInfo.tsid = pNode->FirstChild()->Value();
884 CLog::Log(LOGDEBUG, "%s - Tsid: %s", __FUNCTION__, sStrmInfo.tsid.c_str());
886 pNode = pRootElement->FirstChild("onid");
889 sStrmInfo.onid = pNode->FirstChild()->Value();
890 CLog::Log(LOGDEBUG, "%s - Onid: %s", __FUNCTION__, sStrmInfo.onid.c_str());
892 pNode = pRootElement->FirstChild("sid");
895 sStrmInfo.sid = pNode->FirstChild()->Value();
896 CLog::Log(LOGDEBUG, "%s - Sid: %s", __FUNCTION__, sStrmInfo.sid.c_str());
898 pNode = pRootElement->FirstChild("pmt");
901 sStrmInfo.pmt = pNode->FirstChild()->Value();
902 CLog::Log(LOGDEBUG, "%s - Pmt: %s", __FUNCTION__, sStrmInfo.pmt.c_str());
904 pNode = pRootElement->FirstChild("video_format");
907 sStrmInfo.video_format = pNode->FirstChild()->Value();
908 CLog::Log(LOGDEBUG, "%s - Video Format: %s", __FUNCTION__, sStrmInfo.video_format.c_str());
910 pNode = pRootElement->FirstChild("supported_crypt_systems");
913 sStrmInfo.supported_crypt_systems = pNode->FirstChild()->Value();
914 CLog::Log(LOGDEBUG, "%s - Supported Crypt Systems: %s", __FUNCTION__, sStrmInfo.supported_crypt_systems.c_str());
916 pNode = pRootElement->FirstChild("used_crypt_systems");
919 sStrmInfo.used_crypt_systems = pNode->FirstChild()->Value();
920 CLog::Log(LOGDEBUG, "%s - Used Crypt Systems: %s", __FUNCTION__, sStrmInfo.used_crypt_systems.c_str());
922 pNode = pRootElement->FirstChild("satellite");
925 sStrmInfo.satellite = pNode->FirstChild()->Value();
926 CLog::Log(LOGDEBUG, "%s - Satellite: %s", __FUNCTION__, sStrmInfo.satellite.c_str());
928 pNode = pRootElement->FirstChild("frequency");
931 sStrmInfo.frequency = pNode->FirstChild()->Value();
932 CLog::Log(LOGDEBUG, "%s - Frequency: %s", __FUNCTION__, sStrmInfo.frequency.c_str());
934 pNode = pRootElement->FirstChild("symbol_rate");
937 sStrmInfo.symbol_rate = pNode->FirstChild()->Value();
938 CLog::Log(LOGDEBUG, "%s - Symbol Rate: %s", __FUNCTION__, sStrmInfo.symbol_rate.c_str());
940 pNode = pRootElement->FirstChild("polarisation");
943 sStrmInfo.polarisation = pNode->FirstChild()->Value();
944 CLog::Log(LOGDEBUG, "%s - Polarisation: %s", __FUNCTION__, sStrmInfo.polarisation.c_str());
946 pNode = pRootElement->FirstChild("inversion");
949 sStrmInfo.inversion = pNode->FirstChild()->Value();
950 CLog::Log(LOGDEBUG, "%s - Inversion: %s", __FUNCTION__, sStrmInfo.inversion.c_str());
952 pNode = pRootElement->FirstChild("fec");
955 sStrmInfo.fec = pNode->FirstChild()->Value();
956 CLog::Log(LOGDEBUG, "%s - Fec: %s", __FUNCTION__, sStrmInfo.fec.c_str());
958 pNode = pRootElement->FirstChild("snr");
961 sStrmInfo.snr = pNode->FirstChild()->Value();
962 CLog::Log(LOGDEBUG, "%s - Snr: %s", __FUNCTION__, sStrmInfo.snr.c_str());
964 pNode = pRootElement->FirstChild("agc");
967 sStrmInfo.agc = pNode->FirstChild()->Value();
968 CLog::Log(LOGDEBUG, "%s - Agc: %s", __FUNCTION__, sStrmInfo.agc.c_str());
970 pNode = pRootElement->FirstChild("ber");
973 sStrmInfo.ber = pNode->FirstChild()->Value();
974 CLog::Log(LOGDEBUG, "%s - ber: %s", __FUNCTION__, sStrmInfo.ber.c_str());
976 pNode = pRootElement->FirstChild("lock");
979 sStrmInfo.lock = pNode->FirstChild()->Value();
980 CLog::Log(LOGDEBUG, "%s - Lock: %s", __FUNCTION__, sStrmInfo.lock.c_str());
982 pNode = pRootElement->FirstChild("sync");
985 sStrmInfo.sync = pNode->FirstChild()->Value();
986 CLog::Log(LOGDEBUG, "%s - Sync: %s", __FUNCTION__, sStrmInfo.sync.c_str());
992 bool CTuxBoxUtil::CurrentServiceData(TiXmlElement *pRootElement)
994 TiXmlNode *pNode = NULL;
995 TiXmlNode *pIt = NULL;
996 TiXmlNode *pVal = NULL;
999 CLog::Log(LOGDEBUG, "%s - Current Service Data", __FUNCTION__);
1000 pNode = pRootElement->FirstChild("service");
1003 CLog::Log(LOGDEBUG, "%s - Service", __FUNCTION__);
1004 pIt = pNode->FirstChild("name");
1007 sCurSrvData.service_name = pIt->FirstChild()->Value();
1008 CLog::Log(LOGDEBUG, "%s - Service Name: %s", __FUNCTION__, pIt->FirstChild()->Value());
1010 pIt = pNode->FirstChild("reference");
1013 sCurSrvData.service_reference = pIt->FirstChild()->Value();
1014 CLog::Log(LOGDEBUG, "%s - Service Reference: %s", __FUNCTION__, pIt->FirstChild()->Value());
1018 pNode = pRootElement->FirstChild("audio_channels");
1021 CLog::Log(LOGDEBUG, "%s - Audio Channels", __FUNCTION__);
1024 pIt = pNode->FirstChild("channel");
1025 sCurSrvData.audio_channels.clear();
1029 sAudioChannel newChannel;
1031 pVal = pIt->FirstChild("pid");
1033 newChannel.pid = pVal->FirstChild()->Value();
1035 pVal = pIt->FirstChild("selected");
1037 newChannel.selected = pVal->FirstChild()->Value();
1039 pVal = pIt->FirstChild("name");
1041 newChannel.name = pVal->FirstChild()->Value();
1043 CLog::Log(LOGDEBUG, "%s - Audio Channels: Channel %i -> PID: %s Selected: %s Name: %s", __FUNCTION__, i, newChannel.pid.c_str(), newChannel.selected.c_str(), newChannel.name.c_str() );
1046 sCurSrvData.audio_channels.push_back( newChannel );
1047 pIt = pIt->NextSibling("channel");
1050 pNode = pRootElement->FirstChild("audio_track");
1053 sCurSrvData.audio_track = pNode->FirstChild()->Value();
1054 CLog::Log(LOGDEBUG, "%s - Audio Track: %s", __FUNCTION__, pNode->FirstChild()->Value() );
1056 pNode = pRootElement->FirstChild("video_channels");
1059 CLog::Log(LOGDEBUG, "%s - Video Channels", __FUNCTION__);
1060 pIt = pNode->FirstChild("service");
1063 vVideoSubChannel.name.clear();
1064 vVideoSubChannel.reference.clear();
1065 vVideoSubChannel.selected.clear();
1069 pVal = pIt->FirstChild("name");
1072 vVideoSubChannel.name.push_back(pVal->FirstChild()->Value());
1073 CLog::Log(LOGDEBUG, "%s - Video Sub Channel %i: Name: %s", __FUNCTION__, i,pVal->FirstChild()->Value());
1075 pVal = pIt->FirstChild("reference");
1078 vVideoSubChannel.reference.push_back(pVal->FirstChild()->Value());
1079 CLog::Log(LOGDEBUG, "%s - Video Sub Channel %i: Reference: %s", __FUNCTION__, i,pVal->FirstChild()->Value());
1081 pVal = pIt->FirstChild("selected");
1084 vVideoSubChannel.selected.push_back(pVal->FirstChild()->Value());
1085 CLog::Log(LOGDEBUG, "%s - Video Sub Channel %i: Selected: %s", __FUNCTION__, i,pVal->FirstChild()->Value());
1087 pIt = pIt->NextSibling("service");
1093 vVideoSubChannel.name.clear();
1094 vVideoSubChannel.reference.clear();
1095 vVideoSubChannel.selected.clear();
1098 pNode = pRootElement->FirstChild("current_event");
1101 CLog::Log(LOGDEBUG, "%s - Current Event", __FUNCTION__);
1102 pIt = pNode->FirstChild("date");
1105 sCurSrvData.current_event_date = pIt->FirstChild()->Value();
1106 CLog::Log(LOGDEBUG, "%s - Date: %s", __FUNCTION__, pIt->FirstChild()->Value());
1108 pIt = pNode->FirstChild("time");
1111 sCurSrvData.current_event_time = pIt->FirstChild()->Value();
1112 CLog::Log(LOGDEBUG, "%s - Time: %s", __FUNCTION__, pIt->FirstChild()->Value());
1115 pIt = pNode->FirstChild("start");
1118 sCurSrvData.current_event_start = pIt->FirstChild()->Value();
1119 CLog::Log(LOGDEBUG, "%s - Start: %s", __FUNCTION__, pIt->FirstChild()->Value());
1122 pIt = pNode->FirstChild("duration");
1125 sCurSrvData.current_event_duration = pIt->FirstChild()->Value();
1126 CLog::Log(LOGDEBUG, "%s - Duration: %s", __FUNCTION__, pIt->FirstChild()->Value());
1129 pIt = pNode->FirstChild("description");
1132 sCurSrvData.current_event_description = pIt->FirstChild()->Value();
1133 CLog::Log(LOGDEBUG, "%s - Description: %s", __FUNCTION__, pIt->FirstChild()->Value());
1135 pIt = pNode->FirstChild("details");
1138 sCurSrvData.current_event_details = pIt->FirstChild()->Value();
1139 CLog::Log(LOGDEBUG, "%s - Details: %s", __FUNCTION__, pIt->FirstChild()->Value());
1142 pNode = pRootElement->FirstChild("next_event");
1145 CLog::Log(LOGDEBUG, "%s - Next Event", __FUNCTION__);
1146 pIt = pNode->FirstChild("date");
1149 sCurSrvData.next_event_date = pIt->FirstChild()->Value();
1150 CLog::Log(LOGDEBUG, "%s - Date: %s", __FUNCTION__, pIt->FirstChild()->Value());
1152 pIt = pNode->FirstChild("time");
1155 sCurSrvData.next_event_time = pIt->FirstChild()->Value();
1156 CLog::Log(LOGDEBUG, "%s - Time: %s", __FUNCTION__, pIt->FirstChild()->Value());
1159 pIt = pNode->FirstChild("start");
1162 sCurSrvData.next_event_start = pIt->FirstChild()->Value();
1163 CLog::Log(LOGDEBUG, "%s - Start: %s", __FUNCTION__, pIt->FirstChild()->Value());
1166 pIt = pNode->FirstChild("duration");
1169 sCurSrvData.next_event_duration = pIt->FirstChild()->Value();
1170 CLog::Log(LOGDEBUG, "%s - Duration: %s", __FUNCTION__, pIt->FirstChild()->Value());
1173 pIt = pNode->FirstChild("description");
1176 sCurSrvData.next_event_description = pIt->FirstChild()->Value();
1177 CLog::Log(LOGDEBUG, "%s - Description: %s", __FUNCTION__, pIt->FirstChild()->Value());
1179 pIt = pNode->FirstChild("details");
1182 sCurSrvData.next_event_details = pIt->FirstChild()->Value();
1183 CLog::Log(LOGDEBUG, "%s - Details: %s", __FUNCTION__, pIt->FirstChild()->Value());
1191 bool CTuxBoxUtil::BoxStatus(TiXmlElement *pRootElement)
1193 //Tuxbox Controll Commands
1195 /cgi-bin/admin?command=wakeup
1196 /cgi-bin/admin?command=standby
1197 /cgi-bin/admin?command=shutdown
1198 /cgi-bin/admin?command=reboot
1199 /cgi-bin/admin?command=restart
1202 TiXmlNode *pNode = NULL;
1206 CLog::Log(LOGDEBUG, "%s - BoxStatus", __FUNCTION__);
1207 pNode = pRootElement->FirstChild("current_time");
1210 sBoxStatus.current_time = pNode->FirstChild()->Value();
1211 CLog::Log(LOGDEBUG, "%s - Current Time: %s", __FUNCTION__, pNode->FirstChild()->Value());
1213 pNode = pRootElement->FirstChild("standby");
1216 sBoxStatus.standby = pNode->FirstChild()->Value();
1217 CLog::Log(LOGDEBUG, "%s - Standby: %s", __FUNCTION__, pNode->FirstChild()->Value());
1219 pNode = pRootElement->FirstChild("recording");
1222 sBoxStatus.recording = pNode->FirstChild()->Value();
1223 CLog::Log(LOGDEBUG, "%s - Recording: %s", __FUNCTION__, pNode->FirstChild()->Value());
1225 pNode = pRootElement->FirstChild("mode");
1228 sBoxStatus.mode = pNode->FirstChild()->Value();
1229 CLog::Log(LOGDEBUG, "%s - Mode: %s", __FUNCTION__, pNode->FirstChild()->Value());
1231 pNode = pRootElement->FirstChild("ip");
1234 if (sBoxStatus.ip != pNode->FirstChild()->Value() )
1236 g_tuxbox.sZapstream.initialized = false;
1237 g_tuxbox.sZapstream.available = false;
1239 sBoxStatus.ip = pNode->FirstChild()->Value();
1240 CLog::Log(LOGDEBUG, "%s - Ip: %s", __FUNCTION__, pNode->FirstChild()->Value());
1246 bool CTuxBoxUtil::BoxInfo(TiXmlElement *pRootElement)
1248 TiXmlNode *pNode = NULL;
1249 TiXmlNode *pIt = NULL;
1253 CLog::Log(LOGDEBUG, "%s - BoxInfo", __FUNCTION__);
1254 pNode = pRootElement->FirstChild("image");
1257 CLog::Log(LOGDEBUG, "%s - Image", __FUNCTION__);
1258 pIt = pNode->FirstChild("version");
1261 sBoxInfo.image_version = pIt->FirstChild()->Value();
1262 CLog::Log(LOGDEBUG, "%s - Image Version: %s", __FUNCTION__, pIt->FirstChild()->Value());
1264 pIt = pNode->FirstChild("url");
1267 sBoxInfo.image_url = pIt->FirstChild()->Value();
1268 CLog::Log(LOGDEBUG, "%s - Image Url: %s", __FUNCTION__, pIt->FirstChild()->Value());
1270 pIt = pNode->FirstChild("comment");
1273 sBoxInfo.image_comment = pIt->FirstChild()->Value();
1274 CLog::Log(LOGDEBUG, "%s - Image Comment: %s", __FUNCTION__, pIt->FirstChild()->Value());
1276 pIt = pNode->FirstChild("catalog");
1279 sBoxInfo.image_catalog = pIt->FirstChild()->Value();
1280 CLog::Log(LOGDEBUG, "%s - Image Catalog: %s", __FUNCTION__, pIt->FirstChild()->Value());
1283 pNode = pRootElement->FirstChild("firmware");
1286 sBoxInfo.firmware = pNode->FirstChild()->Value();
1287 CLog::Log(LOGDEBUG, "%s - Firmware: %s", __FUNCTION__, pNode->FirstChild()->Value());
1289 pNode = pRootElement->FirstChild("fpfirmware");
1292 sBoxInfo.fpfirmware = pNode->FirstChild()->Value();
1293 CLog::Log(LOGDEBUG, "%s - FP Firmware: %s", __FUNCTION__, pNode->FirstChild()->Value());
1295 pNode = pRootElement->FirstChild("webinterface");
1298 sBoxInfo.webinterface = pNode->FirstChild()->Value();
1299 CLog::Log(LOGDEBUG, "%s - Web Interface: %s", __FUNCTION__, pNode->FirstChild()->Value());
1301 pNode = pRootElement->FirstChild("model");
1304 sBoxInfo.model = pNode->FirstChild()->Value();
1305 CLog::Log(LOGDEBUG, "%s - Model: %s", __FUNCTION__, pNode->FirstChild()->Value());
1307 pNode = pRootElement->FirstChild("manufacturer");
1310 sBoxInfo.manufacturer = pNode->FirstChild()->Value();
1311 CLog::Log(LOGDEBUG, "%s - Manufacturer: %s", __FUNCTION__, pNode->FirstChild()->Value());
1313 pNode = pRootElement->FirstChild("processor");
1316 sBoxInfo.processor = pNode->FirstChild()->Value();
1317 CLog::Log(LOGDEBUG, "%s - Processor: %s", __FUNCTION__, pNode->FirstChild()->Value());
1319 pNode = pRootElement->FirstChild("usbstick");
1322 sBoxInfo.usbstick = pNode->FirstChild()->Value();
1323 CLog::Log(LOGDEBUG, "%s - USB Stick: %s", __FUNCTION__, pNode->FirstChild()->Value());
1325 pNode = pRootElement->FirstChild("disk");
1328 sBoxInfo.disk = pNode->FirstChild()->Value();
1329 CLog::Log(LOGDEBUG, "%s - Disk: %s", __FUNCTION__, pNode->FirstChild()->Value());
1335 bool CTuxBoxUtil::ServiceEPG(TiXmlElement *pRootElement)
1337 TiXmlNode *pNode = NULL;
1338 TiXmlNode *pIt = NULL;
1342 CLog::Log(LOGDEBUG, "%s - Service EPG", __FUNCTION__);
1343 pNode = pRootElement->FirstChild("service");
1346 CLog::Log(LOGDEBUG, "%s - Service", __FUNCTION__);
1347 pIt = pNode->FirstChild("reference");
1350 sServiceEPG.service_reference = pIt->FirstChild()->Value();
1351 CLog::Log(LOGDEBUG, "%s - Service Reference: %s", __FUNCTION__, pIt->FirstChild()->Value());
1353 pIt = pNode->FirstChild("name");
1356 sServiceEPG.service_name = pIt->FirstChild()->Value();
1357 CLog::Log(LOGDEBUG, "%s - Service Name: %s", __FUNCTION__, pIt->FirstChild()->Value());
1360 //Todo there is more then 1 event! Create a Event List!
1361 pNode = pRootElement->FirstChild("event");
1364 CLog::Log(LOGDEBUG, "%s - Event", __FUNCTION__);
1365 pIt = pNode->FirstChild("date");
1368 sServiceEPG.date = pIt->FirstChild()->Value();
1369 CLog::Log(LOGDEBUG, "%s - Date: %s", __FUNCTION__, pIt->FirstChild()->Value());
1371 pIt = pNode->FirstChild("time");
1374 sServiceEPG.time = pIt->FirstChild()->Value();
1375 CLog::Log(LOGDEBUG, "%s - Time: %s", __FUNCTION__, pIt->FirstChild()->Value());
1377 pIt = pNode->FirstChild("duration");
1380 sServiceEPG.duration = pIt->FirstChild()->Value();
1381 CLog::Log(LOGDEBUG, "%s - Duration: %s", __FUNCTION__, pIt->FirstChild()->Value());
1383 pIt = pNode->FirstChild("descritption");
1386 sServiceEPG.descritption = pIt->FirstChild()->Value();
1387 CLog::Log(LOGDEBUG, "%s - Descritption: %s", __FUNCTION__, pIt->FirstChild()->Value());
1389 pIt = pNode->FirstChild("genre");
1392 sServiceEPG.genre = pIt->FirstChild()->Value();
1393 CLog::Log(LOGDEBUG, "%s - Genre: %s", __FUNCTION__, pIt->FirstChild()->Value());
1395 pIt = pNode->FirstChild("genrecategory");
1398 sServiceEPG.genrecategory = pIt->FirstChild()->Value();
1399 CLog::Log(LOGDEBUG, "%s - Genrecategory: %s", __FUNCTION__, pIt->FirstChild()->Value());
1401 pIt = pNode->FirstChild("start");
1404 sServiceEPG.start = pIt->FirstChild()->Value();
1405 CLog::Log(LOGDEBUG, "%s - Start: %s", __FUNCTION__, pIt->FirstChild()->Value());
1407 pIt = pNode->FirstChild("details");
1410 sServiceEPG.details = pIt->FirstChild()->Value();
1411 CLog::Log(LOGDEBUG, "%s - Details: %s", __FUNCTION__, pIt->FirstChild()->Value());
1418 //PopUp and request the AudioChannel
1419 //No PopUp: On 1x detected AudioChannel
1420 bool CTuxBoxUtil::GetGUIRequestedAudioChannel(AUDIOCHANNEL& sRequestedAC)
1422 sRequestedAC = sCurSrvData.audio_channels[0];
1424 // Audio Selection is Disabled! Return false to use default values!
1425 if(!g_advancedSettings.m_bTuxBoxAudioChannelSelection)
1427 CLog::Log(LOGDEBUG, "%s - Audio Channel Selection is Disabled! Returning False to use the default values!", __FUNCTION__);
1431 // We have only one Audio Channel return false to use default values!
1432 if(sCurSrvData.audio_channels.size() == 1)
1435 // popup the context menu
1436 CContextButtons buttons;
1438 // add the needed Audio buttons
1439 for (unsigned int i = 0; i < sCurSrvData.audio_channels.size(); ++i)
1440 buttons.Add(i, sCurSrvData.audio_channels[i].name);
1442 int channel = CGUIDialogContextMenu::ShowAndGetChoice(buttons);
1445 sRequestedAC = sCurSrvData.audio_channels[channel];
1446 sCurSrvData.requested_audio_channel = channel;
1447 CLog::Log(LOGDEBUG, "%s - Audio channel %s requested.", __FUNCTION__, sRequestedAC.name.c_str());
1452 bool CTuxBoxUtil::GetRequestedAudioChannel(AUDIOCHANNEL& sRequestedAC)
1454 sRequestedAC = sCurSrvData.audio_channels[sCurSrvData.requested_audio_channel];
1458 bool CTuxBoxUtil::GetVideoSubChannels(CStdString& strVideoSubChannelName, CStdString& strVideoSubChannelPid)
1460 // no video sub channel return false!
1461 if(vVideoSubChannel.name.size() <= 0 || vVideoSubChannel.reference.size() <= 0)
1464 // IsPlaying, Stop it..
1465 if(g_application.m_pPlayer->IsPlaying())
1466 CApplicationMessenger::Get().MediaStop();
1468 // popup the context menu
1469 CContextButtons buttons;
1471 // add the needed Audio buttons
1472 for (unsigned int i = 0; i < vVideoSubChannel.name.size(); ++i)
1473 buttons.Add(i, vVideoSubChannel.name[i]);
1475 // get selected Video Sub Channel name and reference zap
1476 int channel = CGUIDialogContextMenu::ShowAndGetChoice(buttons);
1479 strVideoSubChannelName = vVideoSubChannel.name[channel];
1480 strVideoSubChannelPid = vVideoSubChannel.reference[channel];
1481 vVideoSubChannel.name.clear();
1482 vVideoSubChannel.reference.clear();
1483 vVideoSubChannel.selected.clear();
1488 //Input: Service Name (Channel Namne)
1489 //Output: picon url (on ERROR the default icon path will be returned)
1490 CStdString CTuxBoxUtil::GetPicon(CStdString strServiceName)
1492 if(!g_advancedSettings.m_bTuxBoxPictureIcon)
1494 CLog::Log(LOGDEBUG, "%s PictureIcon Detection is Disabled! Using default icon", __FUNCTION__);
1497 if (strServiceName.IsEmpty())
1499 CLog::Log(LOGDEBUG, "%s Service Name is Empty! Can not detect a PictureIcon. Using default icon!", __FUNCTION__);
1504 CStdString piconXML, piconPath, defaultPng;
1505 CStdString strName, strPng;
1506 piconPath = "special://xbmc/userdata/PictureIcon/Picon/";
1507 defaultPng = piconPath+"tuxbox.png";
1508 piconXML = "special://xbmc/userdata/PictureIcon/picon.xml";
1509 CXBMCTinyXML piconDoc;
1511 if (!CFile::Exists(piconXML))
1514 if (!piconDoc.LoadFile(piconXML))
1516 CLog::Log(LOGERROR, "Error loading %s, Line %d\n%s", piconXML.c_str(), piconDoc.ErrorRow(), piconDoc.ErrorDesc());
1520 TiXmlElement *pRootElement = piconDoc.RootElement();
1521 if (!pRootElement || strcmpi(pRootElement->Value(),"picon") != 0)
1523 CLog::Log(LOGERROR, "Error loading %s, no <picon> node", piconXML.c_str());
1527 TiXmlElement* pServices = pRootElement->FirstChildElement("services");
1528 TiXmlElement* pService;
1529 pService = pServices->FirstChildElement("service");
1532 if(pService->Attribute("name"))
1533 strName.Format("%s",pService->Attribute("name"));
1535 if(pService->Attribute("png"))
1536 strPng.Format("%s",pService->Attribute("png"));
1538 if(strName.Equals(strServiceName))
1540 strPng.Format("%s%s",piconPath.c_str(), strPng.c_str());
1542 CLog::Log(LOGDEBUG, "%s %s: Path is: %s", __FUNCTION__,strServiceName.c_str(), strPng.c_str());
1545 pService = pService->NextSiblingElement("service");
1551 // iMODE: 0 = TV, 1 = Radio, 2 = Data, 3 = Movies, 4 = Root
1552 // SUBMODE: 0 = n/a, 1 = All, 2 = Satellites, 2 = Providers, 4 = Bouquets
1553 CStdString CTuxBoxUtil::GetSubMode(int iMode, CStdString& strXMLRootString, CStdString& strXMLChildString)
1555 //Todo: add a setting: "Don't Use Request mode" to advanced.xml
1557 // MODE: 0 = TV, 1 = Radio, 2 = Data, 3 = Movies, 4 = Root
1558 // SUBMODE: 0 = n/a, 1 = All, 2 = Satellites, 2 = Providers, 4 = Bouquets
1560 CStdString strSubMode;
1562 if(iMode <0 || iMode >4)
1564 strSubMode.Format("xml/services?mode=0&submode=4");
1565 strXMLRootString.Format("bouquets");
1566 strXMLChildString.Format("bouquet");
1570 // popup the context menu
1572 // FIXME: Localize these
1573 CContextButtons choices;
1574 choices.Add(1, "All");
1575 choices.Add(2, "Satellites");
1576 choices.Add(3, "Providers");
1577 choices.Add(4, "Bouquets");
1579 int iSubMode = CGUIDialogContextMenu::ShowAndGetChoice(choices);
1582 strXMLRootString.Format("services");
1583 strXMLChildString.Format("service");
1585 else if (iSubMode == 2)
1587 strXMLRootString.Format("satellites");
1588 strXMLChildString.Format("satellite");
1590 else if (iSubMode == 3)
1592 strXMLRootString.Format("providers");
1593 strXMLChildString.Format("provider");
1595 else // if (iSubMode == 4 || iSubMode < 0)
1598 strXMLRootString.Format("bouquets");
1599 strXMLChildString.Format("bouquet");
1601 strSubMode.Format("xml/services?mode=%i&submode=%i",iMode,iSubMode);
1604 //Input: url/path of share/item file/folder
1605 //Output: the detected submode root and child string
1606 CStdString CTuxBoxUtil::DetectSubMode(CStdString strSubMode, CStdString& strXMLRootString, CStdString& strXMLChildString)
1608 //strSubMode = "xml/services?mode=0&submode=1"
1609 CStdString strFilter;
1610 int ipointMode = strSubMode.Find("?mode=");
1611 int ipointSubMode = strSubMode.Find("&submode=");
1613 strFilter = strSubMode.GetAt(ipointMode+6);
1615 if (ipointSubMode >=0)
1618 strTemp = strSubMode.GetAt(ipointSubMode+9);
1619 if(strTemp.Equals("1"))
1621 strXMLRootString.Format("unknowns");
1622 strXMLChildString.Format("unknown");
1624 else if(strTemp.Equals("2"))
1626 strXMLRootString.Format("satellites");
1627 strXMLChildString.Format("satellite");
1629 else if(strTemp.Equals("3"))
1631 strXMLRootString.Format("providers");
1632 strXMLChildString.Format("provider");
1634 else if(strTemp.Equals("4"))
1636 strXMLRootString.Format("bouquets");
1637 strXMLChildString.Format("bouquet");